32 |
e.removeCommand("/levelarea"); |
e.removeCommand("/levelarea"); |
33 |
e.removeCommand("/setsurface"); |
e.removeCommand("/setsurface"); |
34 |
} |
} |
35 |
|
|
36 |
|
|
37 |
@Override |
@Override |
38 |
public void initialize() { |
public void initialize() { |
39 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
40 |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
41 |
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
42 |
|
loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); |
43 |
|
|
44 |
|
Jail j = new Jail(); |
45 |
|
loader.addListener( PluginLoader.Hook.TELEPORT, j, this, PluginListener.Priority.MEDIUM); |
46 |
|
loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); |
47 |
|
loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); |
48 |
|
|
49 |
|
|
50 |
|
|
51 |
registerCommands(); |
registerCommands(); |
54 |
final static int HAND_EMPTY = -1; |
final static int HAND_EMPTY = -1; |
55 |
|
|
56 |
|
|
57 |
|
class ConnectedUsers extends PluginListener { |
58 |
|
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 |
public class AdminDestroy extends PluginListener { |
public class AdminDestroy extends PluginListener { |
74 |
public boolean onBlockDestroy(Player player, Block block) { |
public boolean onBlockDestroy(Player player, Block block) { |
75 |
if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { |
if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { |
76 |
if (player.getItemInHand() == HAND_EMPTY) { |
if (player.getItemInHand() == HAND_EMPTY) { |
77 |
|
|
78 |
|
int oldType = block.getType(); |
79 |
|
|
80 |
block.setType(0); |
block.setType(0); |
81 |
etc.getServer().setBlock(block); |
etc.getServer().setBlock(block); |
82 |
|
|
83 |
|
if (oldType > 4 && oldType != 13) { //dont drop stone or dirt, gravel |
84 |
|
etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), oldType); // diamond resource block should drop diamonds and not a new diamond resource block |
85 |
|
} |
86 |
|
|
87 |
return true; |
return true; |
88 |
} |
} |
89 |
} |
} |
91 |
} |
} |
92 |
} |
} |
93 |
|
|
94 |
|
public static String getBearingStr(int angle) { |
95 |
|
if (angle < 22) { |
96 |
|
return "N"; |
97 |
|
} else if (angle < 67) { |
98 |
|
return "NE"; |
99 |
|
} else if (angle < 112) { |
100 |
|
return "E"; |
101 |
|
} else if (angle < 157) { |
102 |
|
return "SE"; |
103 |
|
} else if (angle < 202) { |
104 |
|
return "S"; |
105 |
|
} else if (angle < 257) { |
106 |
|
return "SW"; |
107 |
|
} else if (angle < 292) { |
108 |
|
return "W"; |
109 |
|
} else if (angle < 337) { |
110 |
|
return "NW"; |
111 |
|
} else { |
112 |
|
return "N"; |
113 |
|
} |
114 |
|
} |
115 |
|
|
116 |
|
public static int calcDistance(Location loc1, Location loc2) { |
117 |
|
double distX = loc1.x - loc2.x ; |
118 |
|
double distZ = loc1.z - loc2.z ; |
119 |
|
|
120 |
|
int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); |
121 |
|
|
122 |
|
return dist; |
123 |
|
} |
124 |
|
|
125 |
|
public static int calcBearing(Location loc1, Location loc2) { |
126 |
|
double distX = loc1.x - loc2.x ; |
127 |
|
double distZ = loc1.z - loc2.z ; |
128 |
|
|
129 |
|
double angle = Math.toDegrees( Math.atan( distZ / distX ) ); |
130 |
|
if (angle < 0.0) |
131 |
|
angle += 90.0; |
132 |
|
|
133 |
|
|
134 |
|
if (distX >= 0.0 && distZ >= 0.0) { //both positive, 0-90 degrees |
135 |
|
//do nothing |
136 |
|
} else if (distX < 0.0 && distZ >= 0.0) { // 90-180 degrees |
137 |
|
angle += 90.0; |
138 |
|
} else if (distX < 0.0 && distZ < 0.0) {//Both negative 180-270 degrees |
139 |
|
angle += 180.0; |
140 |
|
} else { |
141 |
|
angle += 270.0; |
142 |
|
} |
143 |
|
|
144 |
|
return (int) angle; |
145 |
|
} |
146 |
|
|
147 |
public class HoerupUtilsPlugin extends PluginListener { |
public class HoerupUtilsPlugin extends PluginListener { |
148 |
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
149 |
final static int BLOCK_AIR = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
402 |
} |
} |
403 |
|
|
404 |
|
|
|
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"; |
|
|
} |
|
|
} |
|
|
|
|
405 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
406 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
407 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
447 |
loc2 = p2.getLocation(); |
loc2 = p2.getLocation(); |
448 |
name2 = p2.getName(); |
name2 = p2.getName(); |
449 |
} |
} |
|
//Location loc2 = new Location(); |
|
|
//loc2.x = loc2.y = loc2.z = 0; |
|
450 |
|
|
451 |
//System.out.println("p1: " + loc1.x + "," + loc1.z ); |
int dist = calcDistance(loc1, loc2); |
452 |
//System.out.println("p2: " + loc2.x + "," + loc2.z ); |
int angle = calcBearing(loc1, loc2); |
453 |
|
|
|
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 ); |
|
454 |
|
|
|
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; |
|
|
} |
|
455 |
|
|
456 |
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) ); |
457 |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
458 |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
p1.sendMessage( Colors.Yellow + "Bearing: " + angle + " (" + getBearingStr( angle) + ")" ); |
459 |
|
|
460 |
|
|
461 |
|
|