6 |
|
|
7 |
final static Logger log = Logger.getLogger("HoerupUtils"); |
final static Logger log = Logger.getLogger("HoerupUtils"); |
8 |
|
|
|
//private boolean adminDestroy = false; |
|
|
private Set<String> adminDestroyers = new HashSet<String>(); |
|
9 |
|
|
10 |
private void registerCommands() { |
private void registerCommands() { |
11 |
etc e = etc.getInstance(); |
etc e = etc.getInstance(); |
14 |
e.addCommand("/fillarea", ""); |
e.addCommand("/fillarea", ""); |
15 |
e.addCommand("/levelarea", ""); |
e.addCommand("/levelarea", ""); |
16 |
e.addCommand("/setsurface", ""); |
e.addCommand("/setsurface", ""); |
17 |
|
e.addCommand("/slopearea", ""); |
18 |
|
e.addCommand("/admindestroy",""); |
19 |
} |
} |
20 |
|
|
21 |
@Override |
@Override |
31 |
e.removeCommand("/fillarea"); |
e.removeCommand("/fillarea"); |
32 |
e.removeCommand("/levelarea"); |
e.removeCommand("/levelarea"); |
33 |
e.removeCommand("/setsurface"); |
e.removeCommand("/setsurface"); |
34 |
|
e.removeCommand("/slopearea"); |
35 |
|
e.removeCommand("/admindestroy"); |
36 |
} |
} |
37 |
|
|
38 |
|
|
40 |
public void initialize() { |
public void initialize() { |
41 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
42 |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
|
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
|
43 |
loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); |
44 |
|
|
45 |
Jail j = new Jail(); |
Jail j = new Jail(); |
47 |
loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); |
48 |
loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); |
49 |
|
|
50 |
|
AdminDestroy adm = new AdminDestroy(); |
51 |
|
loader.addListener( PluginLoader.Hook.COMMAND, adm, this, PluginListener.Priority.MEDIUM); |
52 |
|
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, adm, this, PluginListener.Priority.MEDIUM ); |
53 |
|
loader.addListener( PluginLoader.Hook.DISCONNECT, adm, this, PluginListener.Priority.MEDIUM ); |
54 |
|
|
55 |
|
|
56 |
registerCommands(); |
registerCommands(); |
57 |
} |
} |
58 |
|
|
|
final static int HAND_EMPTY = -1; |
|
59 |
|
|
60 |
|
|
61 |
class ConnectedUsers extends PluginListener { |
class ConnectedUsers extends PluginListener { |
74 |
} |
} |
75 |
} |
} |
76 |
|
|
|
public class AdminDestroy extends PluginListener { |
|
|
public boolean onBlockDestroy(Player player, Block block) { |
|
|
if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { |
|
|
if (player.getItemInHand() == HAND_EMPTY) { |
|
|
|
|
|
int oldType = block.getType(); |
|
|
|
|
|
block.setType(0); |
|
|
etc.getServer().setBlock(block); |
|
|
|
|
|
if (oldType > 4 && oldType != 13) { //dont drop stone or dirt, gravel |
|
|
etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), oldType); // diamond resource block should drop diamonds and not a new diamond resource block |
|
|
} |
|
|
|
|
|
return true; |
|
|
} |
|
|
} |
|
|
return false; |
|
|
} |
|
|
} |
|
77 |
|
|
78 |
public static String getBearingStr(int angle) { |
public static String getBearingStr(int angle) { |
79 |
if (angle < 22) { |
if (angle < 22) { |
170 |
return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); |
return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); |
171 |
} |
} |
172 |
|
|
173 |
|
public void slopeArea(Player player, java.lang.String[] split) { |
174 |
|
int radius = Integer.parseInt(split[1]); |
175 |
|
|
176 |
|
System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); |
177 |
|
|
178 |
|
|
179 |
|
int playerX = roundPos( player.getX() ); |
180 |
|
int playerY = (int) player.getY(); |
181 |
|
int playerZ = roundPos( player.getZ() ); |
182 |
|
|
183 |
|
Server srv = etc.getServer(); |
184 |
|
|
185 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
186 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
187 |
|
|
188 |
|
|
189 |
|
int xdist = Math.abs(playerX-x); |
190 |
|
int zdist = Math.abs(playerZ-z); |
191 |
|
|
192 |
|
int dist = Math.max(xdist,zdist); |
193 |
|
|
194 |
|
//for (int y=playerY; y<=playerY+radius; y++) { |
195 |
|
for (int y=(playerY+dist); y<=128; y++) { |
196 |
|
srv.setBlockAt(BLOCK_AIR, x, y, z); |
197 |
|
} |
198 |
|
|
199 |
|
} |
200 |
|
|
|
public void adminDestroy(Player player, String[] split) { |
|
|
String name = player.getName(); |
|
|
if (adminDestroyers.contains(name) ) { |
|
|
adminDestroyers.remove(name); |
|
|
player.sendMessage("Admindestroy disabled"); |
|
|
} else { |
|
|
adminDestroyers.add(name); |
|
|
player.sendMessage("Admindestroy enabled"); |
|
201 |
} |
} |
202 |
} |
} |
203 |
|
|
|
|
|
204 |
@Override |
@Override |
205 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
206 |
if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) { |
if (! player.canUseCommand(split[0]) ) { |
207 |
adminDestroy(player,split); |
return false; |
208 |
return true; |
} |
209 |
} else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
|
210 |
|
if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
211 |
setPos(player, split); |
setPos(player, split); |
212 |
return true; |
return true; |
213 |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
214 |
whereIs(player, split); |
whereIs(player, split); |
215 |
return true; |
return true; |
216 |
} else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { |
} else if ( (split[0].equals("/levelarea") || split[0].equals("/la")) && player.canUseCommand("/levelarea")) { |
217 |
if (validateLevelOrFill(player,split)) { |
if (validateLevelOrFill(player,split)) { |
218 |
levelArea(player, split); |
levelArea(player, split); |
219 |
} |
} |
220 |
return true; |
return true; |
221 |
|
} else if (split[0].equals("/slopearea") ) { |
222 |
|
if (validateLevelOrFill(player,split)) { |
223 |
|
slopeArea(player,split); |
224 |
|
} |
225 |
|
return true; |
226 |
} else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { |
} else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { |
227 |
if (validateLevelOrFill(player,split)) { |
if (validateLevelOrFill(player,split)) { |
228 |
fillArea(player, split); |
fillArea(player, split); |