1 |
|
|
2 |
import java.util.logging.*; |
import java.util.logging.*; |
3 |
|
import java.util.*; |
4 |
|
|
5 |
public class HoerupUtils extends Plugin { |
public class HoerupUtils extends Plugin { |
6 |
|
|
7 |
final static Logger log = Logger.getLogger("HoerupUtils"); |
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 |
|
} |
18 |
|
|
19 |
@Override |
@Override |
20 |
public void disable() {} |
public void enable() { |
21 |
|
registerCommands(); |
22 |
|
} |
23 |
|
|
24 |
@Override |
@Override |
25 |
public void enable() {} |
public void disable() { |
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 |
|
|
35 |
@Override |
@Override |
36 |
public void initialize() { |
public void initialize() { |
37 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
38 |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
39 |
|
loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); |
40 |
|
|
41 |
|
Jail j = new Jail(); |
42 |
|
loader.addListener( PluginLoader.Hook.TELEPORT, j, this, PluginListener.Priority.MEDIUM); |
43 |
|
loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); |
44 |
|
loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); |
45 |
|
|
46 |
|
AdminDestroy adm = new AdminDestroy(); |
47 |
|
loader.addListener( PluginLoader.Hook.COMMAND, adm, this, PluginListener.Priority.MEDIUM); |
48 |
|
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, adm, this, PluginListener.Priority.MEDIUM ); |
49 |
|
loader.addListener( PluginLoader.Hook.DISCONNECT, adm, this, PluginListener.Priority.MEDIUM ); |
50 |
|
|
51 |
|
|
52 |
|
registerCommands(); |
53 |
} |
} |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
public static class HoerupUtilsPlugin extends PluginListener { |
class ConnectedUsers extends PluginListener { |
58 |
final static String USAGE = "Usage: /setpos <x> <z> [height]"; |
public void onLogin(Player player) { |
59 |
|
List<Player> players = etc.getServer().getPlayerList(); |
60 |
|
int count = players.size(); |
61 |
|
|
62 |
|
StringBuilder sb = new StringBuilder(); |
63 |
|
for (int i=0; i<count; i++) { |
64 |
|
if (i>0) |
65 |
|
sb.append(" "); |
66 |
|
sb.append( players.get(i).getName() ); |
67 |
|
} |
68 |
|
|
69 |
|
player.sendMessage(Colors.Red + "Connected users " + count + ": " + Colors.White + sb.toString() ); |
70 |
|
} |
71 |
|
} |
72 |
|
|
73 |
|
|
74 |
|
public static String getBearingStr(int angle) { |
75 |
|
if (angle < 22) { |
76 |
|
return "N"; |
77 |
|
} else if (angle < 67) { |
78 |
|
return "NE"; |
79 |
|
} else if (angle < 112) { |
80 |
|
return "E"; |
81 |
|
} else if (angle < 157) { |
82 |
|
return "SE"; |
83 |
|
} else if (angle < 202) { |
84 |
|
return "S"; |
85 |
|
} else if (angle < 257) { |
86 |
|
return "SW"; |
87 |
|
} else if (angle < 292) { |
88 |
|
return "W"; |
89 |
|
} else if (angle < 337) { |
90 |
|
return "NW"; |
91 |
|
} else { |
92 |
|
return "N"; |
93 |
|
} |
94 |
|
} |
95 |
|
|
96 |
|
public static int calcDistance(Location loc1, Location loc2) { |
97 |
|
double distX = loc1.x - loc2.x ; |
98 |
|
double distZ = loc1.z - loc2.z ; |
99 |
|
|
100 |
|
int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); |
101 |
|
|
102 |
|
return dist; |
103 |
|
} |
104 |
|
|
105 |
|
public static int calcBearing(Location loc1, Location loc2) { |
106 |
|
double distX = loc1.x - loc2.x ; |
107 |
|
double distZ = loc1.z - loc2.z ; |
108 |
|
|
109 |
|
double angle = Math.toDegrees( Math.atan( distZ / distX ) ); |
110 |
|
if (angle < 0.0) |
111 |
|
angle += 90.0; |
112 |
|
|
113 |
|
|
114 |
|
if (distX >= 0.0 && distZ >= 0.0) { //both positive, 0-90 degrees |
115 |
|
//do nothing |
116 |
|
} else if (distX < 0.0 && distZ >= 0.0) { // 90-180 degrees |
117 |
|
angle += 90.0; |
118 |
|
} else if (distX < 0.0 && distZ < 0.0) {//Both negative 180-270 degrees |
119 |
|
angle += 180.0; |
120 |
|
} else { |
121 |
|
angle += 270.0; |
122 |
|
} |
123 |
|
|
124 |
|
return (int) angle; |
125 |
|
} |
126 |
|
|
127 |
|
public class HoerupUtilsPlugin extends PluginListener { |
128 |
|
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
129 |
final static int BLOCK_AIR = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
130 |
final static int BLOCK_GRASS = 2; |
final static int BLOCK_GRASS = 2; |
131 |
final static int BLOCK_DIRT = 3; |
final static int BLOCK_DIRT = 3; |
167 |
} |
} |
168 |
|
|
169 |
|
|
|
|
|
170 |
@Override |
@Override |
171 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
172 |
if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
194 |
|
|
195 |
} |
} |
196 |
|
|
197 |
|
int roundPos(double input) { |
198 |
|
int result = (int) input; |
199 |
|
if (input < 0.0) { |
200 |
|
result--; |
201 |
|
} |
202 |
|
|
203 |
|
return result; |
204 |
|
} |
205 |
|
|
206 |
private void setSurface(Player player, String[] split) { |
private void setSurface(Player player, String[] split) { |
207 |
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, 46, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
208 |
|
|
209 |
final int BLOCK_MAX = 86; |
final int BLOCK_MAX = 86; |
210 |
|
|
211 |
if (split.length != 3) { |
if (split.length != 3) { |
212 |
player.sendMessage("Usage /setsurface <radius> <blockID>"); |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
213 |
return; |
return; |
214 |
} |
} |
215 |
|
|
249 |
return; |
return; |
250 |
} |
} |
251 |
|
|
252 |
int playerX = (int) player.getX(); |
int playerX = roundPos( player.getX() ); |
253 |
int playerY = (int) player.getY(); |
int playerY = (int) player.getY(); |
254 |
int playerZ = (int) player.getZ(); |
int playerZ = roundPos( player.getZ() ); |
255 |
|
|
256 |
if(playerY <= 2 && blockid != 7) { |
if(playerY <= 2 && blockid != 7) { |
257 |
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
269 |
} |
} |
270 |
|
|
271 |
private boolean validateLevelOrFill(Player player, String[] split) { |
private boolean validateLevelOrFill(Player player, String[] split) { |
272 |
if (split.length != 2) { |
if (split.length < 2 || split.length > 3) { |
273 |
player.sendMessage("Usage: " + split[0] + " <radius>"); |
player.sendMessage("Usage: " + split[0] + " [radius]"); |
274 |
return false; |
return false; |
275 |
} |
} |
276 |
|
|
286 |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
287 |
return false; |
return false; |
288 |
} |
} |
289 |
|
|
290 |
|
if (split.length == 3) { |
291 |
|
try { |
292 |
|
Integer.parseInt( split[2] ); |
293 |
|
} catch (Exception e) { |
294 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
295 |
|
return false; |
296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
return true; |
return true; |
300 |
} |
} |
301 |
|
|
302 |
private void fillArea(Player player, String[] split) { |
private void fillArea(Player player, String[] split) { |
303 |
int radius = Integer.parseInt(split[1]); |
int radius = Integer.parseInt(split[1]); |
304 |
|
|
305 |
|
int material = BLOCK_DIRT; |
306 |
|
if (split.length == 3) { |
307 |
|
material = Integer.parseInt( split[2] ); |
308 |
|
} |
309 |
|
|
310 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
311 |
|
|
312 |
|
|
313 |
int playerX = (int) player.getX(); |
int playerX = roundPos( player.getX() ); |
314 |
int playerY = (int) player.getY(); |
int playerY = (int) player.getY(); |
315 |
int playerZ = (int) player.getZ(); |
int playerZ = roundPos( player.getZ() ); |
316 |
|
|
317 |
Server srv = etc.getServer(); |
Server srv = etc.getServer(); |
318 |
|
|
320 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
321 |
|
|
322 |
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
323 |
srv.setBlockAt(BLOCK_DIRT, x, y, z); |
srv.setBlockAt(material, x, y, z); |
324 |
} |
} |
325 |
|
|
326 |
} |
} |
335 |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
336 |
|
|
337 |
|
|
338 |
int playerX = (int) player.getX(); |
int playerX = roundPos( player.getX() ); |
339 |
int playerY = (int) player.getY(); |
int playerY = (int) player.getY(); |
340 |
int playerZ = (int) player.getZ(); |
int playerZ = roundPos( player.getZ() ); |
341 |
|
|
342 |
Server srv = etc.getServer(); |
Server srv = etc.getServer(); |
343 |
|
|
366 |
} |
} |
367 |
|
|
368 |
|
|
|
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"; |
|
|
} |
|
|
} |
|
|
|
|
369 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
370 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
371 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
372 |
return; |
return; |
373 |
} |
} |
374 |
|
|
411 |
loc2 = p2.getLocation(); |
loc2 = p2.getLocation(); |
412 |
name2 = p2.getName(); |
name2 = p2.getName(); |
413 |
} |
} |
|
//Location loc2 = new Location(); |
|
|
//loc2.x = loc2.y = loc2.z = 0; |
|
|
|
|
|
//System.out.println("p1: " + loc1.x + "," + loc1.z ); |
|
|
//System.out.println("p2: " + loc2.x + "," + loc2.z ); |
|
|
|
|
|
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 ); |
|
414 |
|
|
415 |
System.out.println(">> " + (distZ / distX ) );*/ |
int dist = calcDistance(loc1, loc2); |
416 |
|
int angle = calcBearing(loc1, loc2); |
417 |
|
|
|
double angle = Math.toDegrees( Math.atan( distZ / distX ) ); |
|
|
if (angle < 0.0) |
|
|
angle += 90.0; |
|
418 |
|
|
419 |
|
|
|
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; |
|
|
} |
|
|
|
|
420 |
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) ); |
421 |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
422 |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
p1.sendMessage( Colors.Yellow + "Bearing: " + angle + " (" + getBearingStr( angle) + ")" ); |
423 |
|
|
424 |
|
|
425 |
|
|