--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java 2012/09/23 12:30:09 1850 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/HomeCommand.java 2012/09/23 18:56:24 1851 @@ -51,33 +51,17 @@ String name = p.getName(); if ( command.getName().equals("home") ) { - - String worldName = config.getString( name + ".world"); - if (worldName != null) { - double yaw = config.getDouble( name + ".yaw", 0.0); - double pitch = config.getDouble( name + ".pitch", 0.0); - double x = config.getDouble( name + ".x", 0.0); - double y = config.getDouble( name + ".y", 0.0); - double z = config.getDouble( name + ".z", 0.0); - - World world = p.getServer().getWorld(worldName); - int blockX = (int) Math.floor(x); - int blockZ = (int) Math.floor(z); - world.loadChunk(blockX, blockZ); - - final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch); - - Runnable r = new Runnable() { - public void run() { - p.teleport(loc); - } - }; - int tickCount = 2; // 2 ticks = 100ms - - p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount); - + tpUser(p, name); + } + if ( command.getName().equals("ophome") ) { + if (args.length != 1) { + p.sendMessage("Usage: /ophome "); + return true; + } + if ( p.isOp() ) { + tpUser(p, args[0]); } else { - p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!"); + p.sendMessage("Only operators may use this command"); } } @@ -100,4 +84,35 @@ return true; } + + private void tpUser(final Player p, String name) { + String worldName = config.getString( name + ".world"); + if (worldName != null) { + double yaw = config.getDouble( name + ".yaw", 0.0); + double pitch = config.getDouble( name + ".pitch", 0.0); + double x = config.getDouble( name + ".x", 0.0); + double y = config.getDouble( name + ".y", 0.0); + double z = config.getDouble( name + ".z", 0.0); + + World world = p.getServer().getWorld(worldName); + int blockX = (int) Math.floor(x); + int blockZ = (int) Math.floor(z); + world.loadChunk(blockX, blockZ); + + final Location loc = new Location( world, x, y, z, (float)yaw, (float)pitch); + + Runnable r = new Runnable() { + public void run() { + p.teleport(loc); + } + }; + int tickCount = 2; // 2 ticks = 100ms + + p.getServer().getScheduler().scheduleSyncDelayedTask(plugin, r, tickCount); + + } else { + p.sendMessage(ChatColor.YELLOW + "You haven't set a home yet!"); + } + + } }