1 |
|
|
2 |
import java.util.logging.*; |
import java.util.logging.*; |
3 |
|
import java.util.*; |
4 |
|
|
5 |
public class Setpos extends Plugin { |
public class HoerupUtils extends Plugin { |
6 |
|
|
7 |
final static Logger log = Logger.getLogger("SetposPlugin"); |
final static Logger log = Logger.getLogger("HoerupUtils"); |
8 |
|
|
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 |
|
e.addCommand("/slopearea", ""); |
18 |
|
e.addCommand("/admindestroy",""); |
19 |
|
} |
20 |
|
|
21 |
@Override |
@Override |
22 |
public void disable() {} |
public void enable() { |
23 |
|
registerCommands(); |
24 |
|
} |
25 |
|
|
26 |
@Override |
@Override |
27 |
public void enable() {} |
public void disable() { |
28 |
|
etc e = etc.getInstance(); |
29 |
|
e.removeCommand("/setpos"); |
30 |
|
e.removeCommand("/whereis"); |
31 |
|
e.removeCommand("/fillarea"); |
32 |
|
e.removeCommand("/levelarea"); |
33 |
|
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 RealSetposPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
43 |
|
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(); |
57 |
|
} |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
class ConnectedUsers extends PluginListener { |
62 |
|
public void onLogin(Player player) { |
63 |
|
List<Player> players = etc.getServer().getPlayerList(); |
64 |
|
int count = players.size(); |
65 |
|
|
66 |
|
StringBuilder sb = new StringBuilder(); |
67 |
|
for (int i=0; i<count; i++) { |
68 |
|
if (i>0) |
69 |
|
sb.append(" "); |
70 |
|
sb.append( players.get(i).getName() ); |
71 |
|
} |
72 |
|
|
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 static class RealSetposPlugin 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 AIRBLOCK = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
134 |
|
final static int BLOCK_GRASS = 2; |
135 |
|
final static int BLOCK_DIRT = 3; |
136 |
|
|
137 |
|
|
138 |
|
|
167 |
private boolean isFree(int x, int y, int z) { |
private boolean isFree(int x, int y, int z) { |
168 |
Server srv = etc.getServer(); |
Server srv = etc.getServer(); |
169 |
|
|
170 |
return (srv.getBlockIdAt(x,y,z) == AIRBLOCK && srv.getBlockIdAt(x,y+1,z) == AIRBLOCK); |
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 |
|
|
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("/setpos") ) { |
if (! player.canUseCommand(split[0]) ) { |
207 |
|
return false; |
208 |
|
} |
209 |
|
|
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" ) ) { |
} 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") ) { |
} else if ( (split[0].equals("/levelarea") || split[0].equals("/la")) && player.canUseCommand("/levelarea")) { |
217 |
levelArea(player, split); |
if (validateLevelOrFill(player,split)) { |
218 |
|
levelArea(player, split); |
219 |
|
} |
220 |
|
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")) { |
227 |
|
if (validateLevelOrFill(player,split)) { |
228 |
|
fillArea(player, split); |
229 |
|
} |
230 |
|
return true; |
231 |
|
} else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) { |
232 |
|
setSurface(player,split); |
233 |
return true; |
return true; |
234 |
} else { |
} else { |
235 |
return false; |
return false; |
237 |
|
|
238 |
} |
} |
239 |
|
|
240 |
private void levelArea(Player player, String[] split) { |
int roundPos(double input) { |
241 |
if (split.length != 2) { |
int result = (int) input; |
242 |
player.sendMessage("Usage: /levelarea <radius>"); |
if (input < 0.0) { |
243 |
|
result--; |
244 |
|
} |
245 |
|
|
246 |
|
return result; |
247 |
|
} |
248 |
|
|
249 |
|
private void setSurface(Player player, String[] split) { |
250 |
|
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} ; |
251 |
|
|
252 |
|
final int BLOCK_MAX = 86; |
253 |
|
|
254 |
|
if (split.length != 3) { |
255 |
|
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
256 |
return; |
return; |
257 |
} |
} |
258 |
|
|
259 |
|
|
260 |
int radius; |
int radius; |
261 |
try { |
try { |
262 |
radius = Integer.parseInt(split[1]); |
radius = Integer.parseInt(split[1]); |
263 |
} catch (Exception e) { |
} catch (Exception e) { |
264 |
player.sendMessage("levelarea: radius must be an integer"); |
player.sendMessage("setsurface: radius must be an integer"); |
265 |
return; |
return; |
266 |
} |
} |
267 |
|
|
268 |
if (radius > 20) { |
if (radius > 20) { |
269 |
player.sendMessage("levelarea: radius may not exceed 20"); |
player.sendMessage("setsurface: radius may not exceed 20"); |
270 |
return; |
return; |
271 |
} |
} |
272 |
|
|
273 |
|
|
274 |
|
int blockid; |
275 |
|
try { |
276 |
|
blockid = Integer.parseInt(split[2]); |
277 |
|
} catch (Exception e) { |
278 |
|
player.sendMessage("setsurface: blockid must be an integer"); |
279 |
|
return; |
280 |
|
} |
281 |
|
|
282 |
|
boolean validblock = false; |
283 |
|
for (int i=0; i<valid_block_array.length; i++) { |
284 |
|
if (valid_block_array[i] == blockid) { |
285 |
|
validblock = true; |
286 |
|
break; |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
if ( !validblock ) { |
291 |
|
player.sendMessage("setsurface: block now allowed"); |
292 |
|
return; |
293 |
|
} |
294 |
|
|
295 |
|
int playerX = roundPos( player.getX() ); |
296 |
|
int playerY = (int) player.getY(); |
297 |
|
int playerZ = roundPos( player.getZ() ); |
298 |
|
|
299 |
|
if(playerY <= 2 && blockid != 7) { |
300 |
|
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
301 |
|
return; |
302 |
|
} |
303 |
|
|
304 |
|
Server srv = etc.getServer(); |
305 |
|
|
306 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
307 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
308 |
|
int y = getGroundLevel(x,z) - 1; |
309 |
|
srv.setBlockAt(blockid, x, y, z); |
310 |
|
} |
311 |
|
} |
312 |
|
} |
313 |
|
|
314 |
|
private boolean validateLevelOrFill(Player player, String[] split) { |
315 |
|
if (split.length < 2 || split.length > 3) { |
316 |
|
player.sendMessage("Usage: " + split[0] + " [radius]"); |
317 |
|
return false; |
318 |
|
} |
319 |
|
|
320 |
|
int radius; |
321 |
|
try { |
322 |
|
radius = Integer.parseInt(split[1]); |
323 |
|
} catch (Exception e) { |
324 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
325 |
|
return false; |
326 |
|
} |
327 |
|
|
328 |
|
if (radius > 20) { |
329 |
|
player.sendMessage(split[0] + ": radius may not exceed 20"); |
330 |
|
return false; |
331 |
|
} |
332 |
|
|
333 |
|
if (split.length == 3) { |
334 |
|
try { |
335 |
|
Integer.parseInt( split[2] ); |
336 |
|
} catch (Exception e) { |
337 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
338 |
|
return false; |
339 |
|
} |
340 |
|
} |
341 |
|
|
342 |
|
return true; |
343 |
|
} |
344 |
|
|
345 |
|
private void fillArea(Player player, String[] split) { |
346 |
|
int radius = Integer.parseInt(split[1]); |
347 |
|
|
348 |
|
int material = BLOCK_DIRT; |
349 |
|
if (split.length == 3) { |
350 |
|
material = Integer.parseInt( split[2] ); |
351 |
|
} |
352 |
|
|
353 |
|
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
354 |
|
|
355 |
|
|
356 |
|
int playerX = roundPos( player.getX() ); |
357 |
|
int playerY = (int) player.getY(); |
358 |
|
int playerZ = roundPos( player.getZ() ); |
359 |
|
|
360 |
|
Server srv = etc.getServer(); |
361 |
|
|
362 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
363 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
364 |
|
|
365 |
|
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
366 |
|
srv.setBlockAt(material, x, y, z); |
367 |
|
} |
368 |
|
|
369 |
|
} |
370 |
|
|
371 |
|
} |
372 |
|
} |
373 |
|
|
374 |
|
private void levelArea(Player player, String[] split) { |
375 |
|
|
376 |
|
int radius = Integer.parseInt(split[1]); |
377 |
|
|
378 |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
379 |
|
|
380 |
|
|
381 |
int playerX = (int) player.getX(); |
int playerX = roundPos( player.getX() ); |
382 |
int playerY = (int) player.getY(); |
int playerY = (int) player.getY(); |
383 |
int playerZ = (int) player.getZ(); |
int playerZ = roundPos( player.getZ() ); |
384 |
|
|
385 |
Server srv = etc.getServer(); |
Server srv = etc.getServer(); |
386 |
|
|
391 |
//for (int y=playerY; y<=playerY+radius; y++) { |
//for (int y=playerY; y<=playerY+radius; y++) { |
392 |
for (int y=playerY; y<=128; y++) { |
for (int y=playerY; y<=128; y++) { |
393 |
count++; |
count++; |
394 |
srv.setBlockAt(0, x, y, z); |
srv.setBlockAt(BLOCK_AIR, x, y, z); |
395 |
} |
} |
396 |
|
|
397 |
} |
} |
409 |
} |
} |
410 |
|
|
411 |
|
|
|
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"; |
|
|
} |
|
|
} |
|
|
|
|
412 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
413 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
414 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
415 |
return; |
return; |
416 |
} |
} |
417 |
|
|
454 |
loc2 = p2.getLocation(); |
loc2 = p2.getLocation(); |
455 |
name2 = p2.getName(); |
name2 = p2.getName(); |
456 |
} |
} |
|
//Location loc2 = new Location(); |
|
|
//loc2.x = loc2.y = loc2.z = 0; |
|
457 |
|
|
458 |
//System.out.println("p1: " + loc1.x + "," + loc1.z ); |
int dist = calcDistance(loc1, loc2); |
459 |
//System.out.println("p2: " + loc2.x + "," + loc2.z ); |
int angle = calcBearing(loc1, loc2); |
460 |
|
|
|
double distX = loc1.x - loc2.x ; |
|
|
double distZ = loc1.z - loc2.z ; |
|
|
|
|
|
int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); |
|
|
/*System.out.println("distX:" + distX ); |
|
|
System.out.println("distZ:" + distZ ); |
|
461 |
|
|
|
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; |
|
|
} |
|
462 |
|
|
463 |
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) ); |
464 |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
465 |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
p1.sendMessage( Colors.Yellow + "Bearing: " + angle + " (" + getBearingStr( angle) + ")" ); |
466 |
|
|
467 |
|
|
468 |
|
|