--- miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/11/12 20:54:29 1192 +++ miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java 2010/11/17 19:42:01 1193 @@ -32,12 +32,20 @@ e.removeCommand("/levelarea"); e.removeCommand("/setsurface"); } + @Override public void initialize() { PluginLoader loader = etc.getLoader(); loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); + loader.addListener( PluginLoader.Hook.LOGIN, new ConnectedUsers(), this, PluginListener.Priority.MEDIUM ); + + Jail j = new Jail(); + loader.addListener( PluginLoader.Hook.TELEPORT, j, this, PluginListener.Priority.MEDIUM); + loader.addListener( PluginLoader.Hook.COMMAND, j, this, PluginListener.Priority.MEDIUM ); + loader.addListener( PluginLoader.Hook.PLAYER_MOVE, j, this, PluginListener.Priority.MEDIUM ); + registerCommands(); @@ -46,12 +54,36 @@ final static int HAND_EMPTY = -1; + class ConnectedUsers extends PluginListener { + public void onLogin(Player player) { + List players = etc.getServer().getPlayerList(); + int count = players.size(); + + StringBuilder sb = new StringBuilder(); + for (int i=0; i0) + sb.append(" "); + sb.append( players.get(i).getName() ); + } + + player.sendMessage(Colors.Red + "Connected users " + count + ": " + Colors.White + sb.toString() ); + } + } + 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; } } @@ -59,6 +91,59 @@ } } + public static 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"; + } + } + + public static int calcDistance(Location loc1, Location loc2) { + double distX = loc1.x - loc2.x ; + double distZ = loc1.z - loc2.z ; + + int dist = (int) Math.round( Math.sqrt( (distX*distX) + (distZ*distZ)) ); + + return dist; + } + + public static int calcBearing(Location loc1, Location loc2) { + double distX = loc1.x - loc2.x ; + double distZ = loc1.z - loc2.z ; + + 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; + } + + return (int) angle; + } + public class HoerupUtilsPlugin extends PluginListener { final static String USAGE = "Usage: /setpos [x] [z] "; final static int BLOCK_AIR = 0; //block id = 0 is air @@ -317,28 +402,6 @@ } - 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"; - } - } - public void whereIs(Player p1, java.lang.String[] split) { if (split.length < 2 || split.length >3) { p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) " ); @@ -384,39 +447,15 @@ loc2 = p2.getLocation(); name2 = p2.getName(); } - //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 ); + int dist = calcDistance(loc1, loc2); + int angle = calcBearing(loc1, loc2); - 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 ); -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; - } 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 + "Distance is " + dist + " blocks" ); - p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); + p1.sendMessage( Colors.Yellow + "Bearing: " + angle + " (" + getBearingStr( angle) + ")" );