/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/SuperMiner.java
ViewVC logotype

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/dk/thoerup/bukkit/hoeruputils/SuperMiner.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20