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 |
22 |
public void disable() { |
public void enable() { |
23 |
registerCommands(); |
registerCommands(); |
24 |
} |
} |
25 |
|
|
26 |
@Override |
@Override |
27 |
public void enable() { |
public void disable() { |
28 |
etc e = etc.getInstance(); |
etc e = etc.getInstance(); |
29 |
e.removeCommand("/setpos"); |
e.removeCommand("/setpos"); |
30 |
e.removeCommand("/whereis"); |
e.removeCommand("/whereis"); |
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 |
|
|
39 |
@Override |
@Override |
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 ); |
43 |
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); |
44 |
|
|
45 |
|
Jail j = new Jail(); |
46 |
|
loader.addListener( PluginLoader.Hook.TELEPORT, j, this, PluginListener.Priority.MEDIUM); |
47 |
|
loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); |
48 |
|
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 |
public class AdminDestroy extends PluginListener { |
class ConnectedUsers extends PluginListener { |
62 |
public boolean onBlockDestroy(Player player, Block block) { |
public void onLogin(Player player) { |
63 |
if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { |
List<Player> players = etc.getServer().getPlayerList(); |
64 |
if (player.getItemInHand() == HAND_EMPTY) { |
int count = players.size(); |
65 |
block.setType(0); |
|
66 |
etc.getServer().setBlock(block); |
StringBuilder sb = new StringBuilder(); |
67 |
return true; |
for (int i=0; i<count; i++) { |
68 |
} |
if (i>0) |
69 |
|
sb.append(" "); |
70 |
|
sb.append( players.get(i).getName() ); |
71 |
} |
} |
72 |
return false; |
|
73 |
|
player.sendMessage(Colors.Red + "Connected users " + count + ": " + Colors.White + sb.toString() ); |
74 |
|
} |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
public static String getBearingStr(int angle) { |
79 |
|
if (angle < 22) { |
80 |
|
return "N"; |
81 |
|
} else if (angle < 67) { |
82 |
|
return "NE"; |
83 |
|
} else if (angle < 112) { |
84 |
|
return "E"; |
85 |
|
} else if (angle < 157) { |
86 |
|
return "SE"; |
87 |
|
} else if (angle < 202) { |
88 |
|
return "S"; |
89 |
|
} else if (angle < 257) { |
90 |
|
return "SW"; |
91 |
|
} else if (angle < 292) { |
92 |
|
return "W"; |
93 |
|
} else if (angle < 337) { |
94 |
|
return "NW"; |
95 |
|
} else { |
96 |
|
return "N"; |
97 |
} |
} |
98 |
} |
} |
99 |
|
|
100 |
|
public static int calcDistance(Location loc1, Location loc2) { |
101 |
|
double distX = loc1.x - loc2.x ; |
102 |
|
double distZ = loc1.z - loc2.z ; |
103 |
|
|
104 |
|
int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); |
105 |
|
|
106 |
|
return dist; |
107 |
|
} |
108 |
|
|
109 |
|
public static int calcBearing(Location loc1, Location loc2) { |
110 |
|
double distX = loc1.x - loc2.x ; |
111 |
|
double distZ = loc1.z - loc2.z ; |
112 |
|
|
113 |
|
double angle = Math.toDegrees( Math.atan( distZ / distX ) ); |
114 |
|
if (angle < 0.0) |
115 |
|
angle += 90.0; |
116 |
|
|
117 |
|
|
118 |
|
if (distX >= 0.0 && distZ >= 0.0) { //both positive, 0-90 degrees |
119 |
|
//do nothing |
120 |
|
} else if (distX < 0.0 && distZ >= 0.0) { // 90-180 degrees |
121 |
|
angle += 90.0; |
122 |
|
} else if (distX < 0.0 && distZ < 0.0) {//Both negative 180-270 degrees |
123 |
|
angle += 180.0; |
124 |
|
} else { |
125 |
|
angle += 270.0; |
126 |
|
} |
127 |
|
|
128 |
|
return (int) angle; |
129 |
|
} |
130 |
|
|
131 |
public class HoerupUtilsPlugin extends PluginListener { |
public class HoerupUtilsPlugin extends PluginListener { |
132 |
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
133 |
final static int BLOCK_AIR = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
134 |
final static int BLOCK_GRASS = 2; |
final static int BLOCK_GRASS = 2; |
135 |
final static int BLOCK_DIRT = 3; |
final static int BLOCK_DIRT = 3; |
136 |
|
|
137 |
|
private HashMap<String, String[]> commands = new HashMap<String,String[]>(); |
138 |
|
|
139 |
|
|
140 |
|
|
141 |
//http://www.minecraftforum.net/viewtopic.php?f=35&t=14739 |
//http://www.minecraftforum.net/viewtopic.php?f=35&t=14739 |
172 |
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); |
173 |
} |
} |
174 |
|
|
175 |
|
public void slopeArea(Player player, java.lang.String[] split) { |
176 |
|
int radius = Integer.parseInt(split[1]); |
177 |
|
|
178 |
|
System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); |
179 |
|
|
180 |
|
|
181 |
|
int playerX = roundPos( player.getX() ); |
182 |
|
int playerY = (int) player.getY(); |
183 |
|
int playerZ = roundPos( player.getZ() ); |
184 |
|
|
185 |
|
Server srv = etc.getServer(); |
186 |
|
|
187 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
188 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
189 |
|
|
190 |
|
|
191 |
|
int xdist = Math.abs(playerX-x); |
192 |
|
int zdist = Math.abs(playerZ-z); |
193 |
|
|
194 |
|
int dist = Math.max(xdist,zdist); |
195 |
|
|
196 |
|
//for (int y=playerY; y<=playerY+radius; y++) { |
197 |
|
for (int y=(playerY+dist); y<=128; y++) { |
198 |
|
srv.setBlockAt(BLOCK_AIR, x, y, z); |
199 |
|
} |
200 |
|
|
201 |
|
} |
202 |
|
|
|
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"); |
|
203 |
} |
} |
204 |
} |
} |
205 |
|
|
|
|
|
206 |
@Override |
@Override |
207 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
208 |
if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) { |
if (! player.canUseCommand(split[0]) ) { |
209 |
adminDestroy(player,split); |
return false; |
210 |
|
} |
211 |
|
|
212 |
|
if ( split[0].equals("/levelarea") || split[0].equals("/la") || split[0].equals("/slopearea") || split[0].equals("/fillarea") || split[0].equals("/setsurface") ) { |
213 |
|
commands.put(player.getName(), split); |
214 |
|
} |
215 |
|
|
216 |
|
if ( split[0].equals("//") ) { |
217 |
|
String cmd[] = commands.get(player.getName() ); |
218 |
|
if (cmd != null) { |
219 |
|
onCommand(player, commands.get(player.getName() ) ); |
220 |
|
} else { |
221 |
|
player.sendMessage("//: no recorded command found"); |
222 |
|
} |
223 |
return true; |
return true; |
224 |
} else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
} else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
225 |
setPos(player, split); |
setPos(player, split); |
227 |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
228 |
whereIs(player, split); |
whereIs(player, split); |
229 |
return true; |
return true; |
230 |
} else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { |
} else if ( (split[0].equals("/levelarea") || split[0].equals("/la")) && player.canUseCommand("/levelarea")) { |
231 |
if (validateLevelOrFill(player,split)) { |
if (validateLevelOrFill(player,split)) { |
232 |
levelArea(player, split); |
levelArea(player, split); |
233 |
} |
} |
234 |
return true; |
return true; |
235 |
|
} else if (split[0].equals("/slopearea") ) { |
236 |
|
if (validateLevelOrFill(player,split)) { |
237 |
|
slopeArea(player,split); |
238 |
|
} |
239 |
|
return true; |
240 |
} else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { |
} else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { |
241 |
if (validateLevelOrFill(player,split)) { |
if (validateLevelOrFill(player,split)) { |
242 |
fillArea(player, split); |
fillArea(player, split); |
261 |
} |
} |
262 |
|
|
263 |
private void setSurface(Player player, String[] split) { |
private void setSurface(Player player, String[] split) { |
264 |
int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 46, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
265 |
|
|
266 |
final int BLOCK_MAX = 86; |
final int BLOCK_MAX = 86; |
267 |
|
|
345 |
} |
} |
346 |
|
|
347 |
if (split.length == 3) { |
if (split.length == 3) { |
348 |
|
int id; |
349 |
try { |
try { |
350 |
Integer.parseInt( split[2] ); |
id = Integer.parseInt( split[2] ); |
351 |
} catch (Exception e) { |
} catch (Exception e) { |
352 |
player.sendMessage(split[0] + ": radius must be an integer"); |
player.sendMessage(split[0] + ": id must be an integer"); |
353 |
|
return false; |
354 |
|
} |
355 |
|
if ( id == 46) { |
356 |
|
player.sendMessage("Sorry dave, i can't do that"); |
357 |
return false; |
return false; |
358 |
} |
} |
359 |
|
|
360 |
} |
} |
361 |
|
|
362 |
return true; |
return true; |
429 |
} |
} |
430 |
|
|
431 |
|
|
|
private String getBearingStr(int angle) { |
|
|
if (angle < 22) { |
|
|
return "N"; |
|
|
} else if (angle < 67) { |
|
|
return "NE"; |
|
|
} else if (angle < 112) { |
|
|
return "E"; |
|
|
} else if (angle < 157) { |
|
|
return "SE"; |
|
|
} else if (angle < 202) { |
|
|
return "S"; |
|
|
} else if (angle < 257) { |
|
|
return "SW"; |
|
|
} else if (angle < 292) { |
|
|
return "W"; |
|
|
} else if (angle < 337) { |
|
|
return "NW"; |
|
|
} else { |
|
|
return "N"; |
|
|
} |
|
|
} |
|
|
|
|
432 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
433 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
434 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
474 |
loc2 = p2.getLocation(); |
loc2 = p2.getLocation(); |
475 |
name2 = p2.getName(); |
name2 = p2.getName(); |
476 |
} |
} |
|
//Location loc2 = new Location(); |
|
|
//loc2.x = loc2.y = loc2.z = 0; |
|
477 |
|
|
478 |
//System.out.println("p1: " + loc1.x + "," + loc1.z ); |
int dist = calcDistance(loc1, loc2); |
479 |
//System.out.println("p2: " + loc2.x + "," + loc2.z ); |
int angle = calcBearing(loc1, loc2); |
480 |
|
|
|
double distX = loc1.x - loc2.x ; |
|
|
double distZ = loc1.z - loc2.z ; |
|
481 |
|
|
|
int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); |
|
|
/*System.out.println("distX:" + distX ); |
|
|
System.out.println("distZ:" + distZ ); |
|
|
|
|
|
System.out.println(">> " + (distZ / distX ) );*/ |
|
|
|
|
|
double angle = Math.toDegrees( Math.atan( distZ / distX ) ); |
|
|
if (angle < 0.0) |
|
|
angle += 90.0; |
|
|
|
|
|
|
|
|
if (distX >= 0.0 && distZ >= 0.0) { //both positive, 0-90 degrees |
|
|
//do nothing |
|
|
} else if (distX < 0.0 && distZ >= 0.0) { // 90-180 degrees |
|
|
angle += 90.0; |
|
|
} else if (distX < 0.0 && distZ < 0.0) {//Both negative 180-270 degrees |
|
|
angle += 180.0; |
|
|
} else { |
|
|
angle += 270.0; |
|
|
} |
|
482 |
|
|
483 |
p1.sendMessage( Colors.Yellow + name2 + " is at x:" + roundToPlaces(loc2.x, 2) + " y:" + roundToPlaces(loc2.y, 2) + " z: " + roundToPlaces(loc2.z, 2) ); |
p1.sendMessage( Colors.Yellow + name2 + " is at x:" + roundToPlaces(loc2.x, 2) + " y:" + roundToPlaces(loc2.y, 2) + " z: " + roundToPlaces(loc2.z, 2) ); |
484 |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
485 |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
p1.sendMessage( Colors.Yellow + "Bearing: " + angle + " (" + getBearingStr( angle) + ")" ); |
486 |
|
|
487 |
|
|
488 |
|
|