1 |
package dk.thoerup.bukkit.hoeruputils; |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
|
3 |
|
import java.util.HashSet; |
4 |
|
import java.util.Set; |
5 |
|
import java.util.Random; |
6 |
|
|
7 |
import org.bukkit.Location; |
import org.bukkit.Location; |
8 |
|
import org.bukkit.Material; |
9 |
import org.bukkit.World; |
import org.bukkit.World; |
10 |
import org.bukkit.block.Block; |
import org.bukkit.block.Block; |
11 |
import org.bukkit.command.Command; |
import org.bukkit.command.Command; |
12 |
import org.bukkit.command.CommandExecutor; |
import org.bukkit.command.CommandExecutor; |
13 |
import org.bukkit.command.CommandSender; |
import org.bukkit.command.CommandSender; |
14 |
import org.bukkit.entity.Player; |
import org.bukkit.entity.Player; |
15 |
|
import org.bukkit.event.block.BlockDamageEvent; |
16 |
|
import org.bukkit.event.block.BlockListener; |
17 |
|
import org.bukkit.event.player.PlayerListener; |
18 |
|
import org.bukkit.event.player.PlayerQuitEvent; |
19 |
|
|
20 |
public class SuperminerCommand implements CommandExecutor { |
public class SuperMiner extends BlockListener implements CommandExecutor { |
21 |
|
|
22 |
|
|
23 |
|
Random rand = new Random(); |
24 |
|
|
25 |
|
Set<String> miners = new HashSet<String>(); |
26 |
|
|
27 |
|
final static int radius = 5; |
28 |
|
|
29 |
@Override |
@Override |
30 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { |
31 |
|
|
32 |
if (!(sender instanceof Player)) { |
if (! (sender instanceof Player) ) { |
33 |
return false; |
return false; |
34 |
} |
} |
|
Player p = (Player) sender; |
|
35 |
|
|
36 |
World world = p.getWorld(); |
if (!sender.isOp()) { |
37 |
Location l = p.getLocation(); |
sender.sendMessage("Only ops can use superminer"); |
38 |
|
return true; |
39 |
|
} |
40 |
|
|
41 |
|
|
42 |
|
Player p = (Player) sender; |
43 |
|
|
44 |
|
if (miners.contains(p.getName())) { |
45 |
|
miners.remove( p.getName() ); |
46 |
|
p.sendMessage("SuperMiner disabled"); |
47 |
|
} else { |
48 |
|
miners.add( p.getName() ); |
49 |
|
p.sendMessage("SuperMiner enabled - go dig some tunnels (with a fish)"); |
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
return true; |
54 |
|
} |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
public void onBlockDamage(BlockDamageEvent event) { |
59 |
|
Player p = event.getPlayer(); |
60 |
|
|
61 |
|
if (! p.isOp() ) |
62 |
|
return; |
63 |
|
|
64 |
|
|
65 |
|
if (p.getItemInHand().getType() == Material.RAW_FISH) { |
66 |
|
if ( miners.contains(p.getName()) ) { |
67 |
|
|
68 |
|
Block b = event.getBlock(); |
69 |
|
|
70 |
|
superMiner(p, p.getWorld(), p.getLocation() ); |
71 |
|
} |
72 |
|
} |
73 |
|
|
74 |
|
} |
75 |
|
|
76 |
|
|
77 |
for (int x=-5; x<=5; x++) { |
public void superMiner(Player player, World world, Location location) { |
|
for (int y=0; y<=5; y++) { |
|
|
for (int z=-5; z<=5; z++) { |
|
78 |
|
|
|
Block b = world.getBlockAt( l.getBlockX()+x, l.getBlockY()+y, l.getBlockZ()+z); |
|
79 |
|
|
80 |
int id = b.getTypeId(); |
Location l = location; |
81 |
|
|
82 |
if (id == 1 || id == 2 || id == 3 || id == 4 || id == 8 || id == 9 || id == 10 || id == 11 || id == 13) { |
for (int x=(radius*-1); x<=radius; x++) { |
83 |
b.setTypeId( 0 ); |
for (int y=0; y<=radius; y++) { |
84 |
} |
for (int z=(radius*-1); z<=radius; z++) { |
|
} |
|
85 |
|
|
86 |
|
Block b = world.getBlockAt( l.getBlockX()+x, l.getBlockY()+y, l.getBlockZ()+z); |
87 |
|
|
88 |
|
int id = b.getTypeId(); |
89 |
|
|
90 |
|
if (id == 1 || id == 2 || id == 3 || id == 4 || id == 8 || id == 9 || id == 10 || id == 11 || id == 13 || id == 87) { |
91 |
|
b.setTypeId( 0 ); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
public PlayerQuitListener getPlayerQuitListener() { |
104 |
|
return new PlayerQuitListener(); |
105 |
|
} |
106 |
|
|
107 |
|
|
108 |
|
public class PlayerQuitListener extends PlayerListener { |
109 |
|
@Override |
110 |
|
public void onPlayerQuit(PlayerQuitEvent event) { |
111 |
|
Player p = event.getPlayer(); |
112 |
|
|
113 |
|
if (miners.contains(p.getName())) { |
114 |
|
miners.remove( p.getName() ); |
115 |
} |
} |
116 |
} |
} |
|
|
|
|
return true; |
|
117 |
} |
} |
118 |
|
|
119 |
} |
} |