--- miscJava/minecraft-plugins/setposplugin/src/Setpos.java 2010/10/15 12:34:50 1166 +++ miscJava/minecraft-plugins/setposplugin/src/Setpos.java 2010/10/18 21:33:18 1170 @@ -64,18 +64,65 @@ @Override public boolean onCommand(Player player, java.lang.String[] split) { - if( split[0].equals("/setpos") ) { + if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { setPos(player, split); return true; - } else if ( split[0].equals("/whereis" ) ) { + } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { whereIs(player, split); return true; + } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { + levelArea(player, split); + return true; } else { return false; } } + private void levelArea(Player player, String[] split) { + if (split.length != 2) { + player.sendMessage("Usage: /levelarea "); + return; + } + + int radius; + try { + radius = Integer.parseInt(split[1]); + } catch (Exception e) { + player.sendMessage("levelarea: radius must be an integer"); + return; + } + + if (radius > 20) { + player.sendMessage("levelarea: radius may not exceed 20"); + return; + } + + + System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); + + + int playerX = (int) player.getX(); + int playerY = (int) player.getY(); + int playerZ = (int) player.getZ(); + + Server srv = etc.getServer(); + + int count = 0; + for (int x=(playerX-radius); x<=(playerX+radius); x++) { + for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { + + //for (int y=playerY; y<=playerY+radius; y++) { + for (int y=playerY; y<=128; y++) { + count++; + srv.setBlockAt(0, x, y, z); + } + + } + + } + } + double roundToPlaces(double value, int places) { @@ -109,18 +156,50 @@ } public void whereIs(Player p1, java.lang.String[] split) { - if (split.length != 2) { - p1.sendMessage( Colors.Rose + "usage: /whereis "); + if (split.length < 2 || split.length >3) { + p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); return; } - Player p2 = etc.getServer().getPlayer(split[1]); - if (p2 == null) { - p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] ); - return; - } Location loc1 = p1.getLocation(); - Location loc2 = p2.getLocation(); + Location loc2; + String name2; + + if (split[1].equals("home") ) { + + Warp home = etc.getDataSource().getHome( p1.getName() ); + if (home == null) { + p1.sendMessage(Colors.Rose + "you haven't set a home."); + return; + } + loc2 = home.Location; + name2 = "Your home"; + } else if (split[1].equals("warp")) { + if (split.length != 3) { + p1.sendMessage("you have to enter the name of the warp point"); + return; + } + Warp warp = etc.getDataSource().getWarp( split[2] ); + if (warp == null) { + p1.sendMessage("Found now warp with name " + split[2]); + return; + } + loc2 = warp.Location; + name2 = "Warppoint " + split[2]; + + + } else { + + Player p2 = etc.getServer().getPlayer(split[1]); + + if (p2 == null) { + p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] ); + return; + } + + loc2 = p2.getLocation(); + name2 = p2.getName(); + } //Location loc2 = new Location(); //loc2.x = loc2.y = loc2.z = 0; @@ -151,7 +230,7 @@ angle += 270.0; } - p1.sendMessage( Colors.Yellow + p2.getName() + " is at x:" + roundToPlaces(p2.getX(),2) + " y:" + roundToPlaces(p2.getY(),2) + " z: " + roundToPlaces(p2.getZ(),2) ); + 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) + ")" );