5 |
|
|
6 |
final static Logger log = Logger.getLogger("HoerupUtils"); |
final static Logger log = Logger.getLogger("HoerupUtils"); |
7 |
|
|
8 |
|
private boolean adminDestroy = false; |
9 |
|
|
10 |
|
private void registerCommands() { |
11 |
|
etc e = etc.getInstance(); |
12 |
|
e.addCommand("/setpos", "[x] [z] <height> - Teleports you to the given coordinates"); |
13 |
|
e.addCommand("/whereis", "[player] - Tells you the position of another player"); |
14 |
|
e.addCommand("/fillarea", ""); |
15 |
|
e.addCommand("/levelarea", ""); |
16 |
|
e.addCommand("/setsurface", ""); |
17 |
|
} |
18 |
|
|
19 |
@Override |
@Override |
20 |
public void disable() {} |
public void disable() { |
21 |
|
registerCommands(); |
22 |
|
} |
23 |
|
|
24 |
@Override |
@Override |
25 |
public void enable() {} |
public void enable() { |
26 |
|
etc e = etc.getInstance(); |
27 |
|
e.removeCommand("/setpos"); |
28 |
|
e.removeCommand("/whereis"); |
29 |
|
e.removeCommand("/fillarea"); |
30 |
|
e.removeCommand("/levelarea"); |
31 |
|
e.removeCommand("/setsurface"); |
32 |
|
} |
33 |
|
|
34 |
@Override |
@Override |
35 |
public void initialize() { |
public void initialize() { |
36 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
37 |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
38 |
|
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
39 |
|
|
40 |
|
|
41 |
|
registerCommands(); |
42 |
} |
} |
43 |
|
|
44 |
|
|
45 |
|
public class AdminDestroy extends PluginListener { |
46 |
|
public boolean onBlockDestroy(Player player, Block block) { |
47 |
|
if (adminDestroy == true && player.isAdmin() ) { |
48 |
|
|
49 |
|
block.setType(0); |
50 |
|
etc.getServer().setBlock(block); |
51 |
|
|
52 |
public static class HoerupUtilsPlugin extends PluginListener { |
return true; |
53 |
final static String USAGE = "Usage: /setpos <x> <z> [height]"; |
} |
54 |
|
return false; |
55 |
|
} |
56 |
|
} |
57 |
|
|
58 |
|
public class HoerupUtilsPlugin extends PluginListener { |
59 |
|
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
60 |
final static int BLOCK_AIR = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
61 |
final static int BLOCK_GRASS = 2; |
final static int BLOCK_GRASS = 2; |
62 |
final static int BLOCK_DIRT = 3; |
final static int BLOCK_DIRT = 3; |
101 |
|
|
102 |
@Override |
@Override |
103 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
104 |
if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) { |
105 |
|
adminDestroy = !adminDestroy; |
106 |
|
player.sendMessage("Admindestroy enabled=" + adminDestroy); |
107 |
|
|
108 |
|
return true; |
109 |
|
} else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
110 |
setPos(player, split); |
setPos(player, split); |
111 |
return true; |
return true; |
112 |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
146 |
final int BLOCK_MAX = 86; |
final int BLOCK_MAX = 86; |
147 |
|
|
148 |
if (split.length != 3) { |
if (split.length != 3) { |
149 |
player.sendMessage("Usage /setsurface <radius> <blockID>"); |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
150 |
return; |
return; |
151 |
} |
} |
152 |
|
|
206 |
} |
} |
207 |
|
|
208 |
private boolean validateLevelOrFill(Player player, String[] split) { |
private boolean validateLevelOrFill(Player player, String[] split) { |
209 |
if (split.length != 2) { |
if (split.length < 2 || split.length > 3) { |
210 |
player.sendMessage("Usage: " + split[0] + " <radius>"); |
player.sendMessage("Usage: " + split[0] + " [radius]"); |
211 |
return false; |
return false; |
212 |
} |
} |
213 |
|
|
223 |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
224 |
return false; |
return false; |
225 |
} |
} |
226 |
|
|
227 |
|
if (split.length == 3) { |
228 |
|
try { |
229 |
|
Integer.parseInt( split[2] ); |
230 |
|
} catch (Exception e) { |
231 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
232 |
|
return false; |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
return true; |
return true; |
237 |
} |
} |
238 |
|
|
239 |
private void fillArea(Player player, String[] split) { |
private void fillArea(Player player, String[] split) { |
240 |
int radius = Integer.parseInt(split[1]); |
int radius = Integer.parseInt(split[1]); |
241 |
|
|
242 |
|
int material = BLOCK_DIRT; |
243 |
|
if (split.length == 3) { |
244 |
|
material = Integer.parseInt( split[2] ); |
245 |
|
} |
246 |
|
|
247 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
248 |
|
|
257 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
258 |
|
|
259 |
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
260 |
srv.setBlockAt(BLOCK_DIRT, x, y, z); |
srv.setBlockAt(material, x, y, z); |
261 |
} |
} |
262 |
|
|
263 |
} |
} |
327 |
|
|
328 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
329 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
330 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
331 |
return; |
return; |
332 |
} |
} |
333 |
|
|