From ff7a77cbfd9aef86598a07c4fbb8330ab691529d Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sat, 1 Dec 2012 15:11:00 -0500 Subject: [PATCH] Changes to /rd and /ro. Eliminated use of WorldEdit and op, deop kludge :P --- .../TotalFreedomMod/Commands/Command_rd.java | 2 - .../TotalFreedomMod/Commands/Command_ro.java | 86 +++++++++---------- .../TotalFreedomMod/TFM_Util.java | 32 ++++++- src/plugin.yml | 2 +- 4 files changed, 74 insertions(+), 48 deletions(-) diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java index 4f86e4d8..6c9620f8 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java @@ -12,8 +12,6 @@ public class Command_rd extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - // This terminology is wrong, this doesn't remove *all* entities, by far. - Madgeek - // Back when I was just a player, I didn't even know what "entity" meant... :P - Darth TFM_Util.adminAction(sender.getName(), "Removing all server entities.", false); sender.sendMessage(ChatColor.GRAY + String.valueOf(TFM_Util.wipeEntities(true, true)) + " enties removed."); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java index 480d4f22..120435ca 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_ro.java @@ -13,69 +13,69 @@ public class Command_ro extends TFM_Command @Override public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { - if(args.length < 1 || args.length > 3) { + if (args.length < 1 || args.length > 3) + { return false; } - int radius = 50; + Material from_material = Material.matchMaterial(args[0]); + if (from_material == null) + { + try + { + from_material = Material.getMaterial(Integer.parseInt(args[0])); + } + catch (NumberFormatException ex) + { + } + + if (from_material == null) + { + TFM_Util.playerMsg(sender, "Invalid block: " + args[0], ChatColor.RED); + return true; + } + } + + int radius = 25; + if (args.length >= 2) + { + try + { + radius = Math.max(1, Math.min(50, Integer.parseInt(args[1]))); + } + catch (NumberFormatException ex) + { + TFM_Util.playerMsg(sender, "Invalid radius: " + args[1], ChatColor.RED); + return true; + } + } + Player target_player = null; - Material target_block = Material.matchMaterial(args[0]); - - if (target_block == null) - { - TFM_Util.playerMsg(sender, "Invalid block!"); - return true; - } - - if(args.length >= 2) + if (args.length == 3) { try { - radius = Integer.parseInt(args[1]); - } - catch(NumberFormatException nfex) - { - TFM_Util.playerMsg(sender, nfex.getMessage()); - return true; - } - if(radius > 3000) - { - TFM_Util.playerMsg(sender, "What the hell are you trying to do, you stupid idiot!", ChatColor.RED); - return true; - } - } - - if(args.length == 3) - { - try - { - target_player = getPlayer(args[2]); + target_player = getPlayer(args[2]); } catch (CantFindPlayerException ex) { - sender.sendMessage(ex.getMessage()); + TFM_Util.playerMsg(sender, ex.getMessage(), ChatColor.RED); return true; } } - - if(target_player == null) + if (target_player == null) { - for(Player p : server.getOnlinePlayers()) + for (Player p : server.getOnlinePlayers()) { - boolean is_Op = p.isOp(); - p.setOp(true); - server.dispatchCommand(p, "/removenear " + target_block.getId() + " " + radius); - p.setOp(is_Op); + TFM_Util.replaceBlocks(p.getLocation(), from_material, Material.AIR, radius); } } else { - boolean is_Op = target_player.isOp(); - target_player.setOp(true); - server.dispatchCommand(target_player, "/removenear " + target_block.getId() + " " + radius); - target_player.setOp(is_Op); + TFM_Util.replaceBlocks(target_player.getLocation(), from_material, Material.AIR, radius); } + return true; } -} \ No newline at end of file +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index 623bb486..cfe900a2 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -252,7 +252,7 @@ public class TFM_Util return TFM_SuperadminList.checkPartialSuperadminIP(user_ip); } - public static int wipeEntities(boolean wipe_explosives, boolean wipe_carts) + public static int wipeEntities(boolean wipe_explosives, boolean wipe_vehicles) { int removed = 0; for (World world : Bukkit.getWorlds()) @@ -263,7 +263,7 @@ public class TFM_Util || ent instanceof Item || ent instanceof ExperienceOrb || (ent instanceof Explosive && wipe_explosives) - || (ent instanceof Minecart && wipe_carts)) + || (ent instanceof Vehicle && wipe_vehicles)) { ent.remove(); removed++; @@ -959,6 +959,34 @@ public class TFM_Util return is_match; } + + public static int replaceBlocks(Location center_location, Material from_material, Material to_material, int radius) + { + int affected = 0; + + Block center_block = center_location.getBlock(); + for (int x_offset = -radius; x_offset <= radius; x_offset++) + { + for (int y_offset = -radius; y_offset <= radius; y_offset++) + { + for (int z_offset = -radius; z_offset <= radius; z_offset++) + { + Block test_block = center_block.getRelative(x_offset, y_offset, z_offset); + + if (test_block.getType().equals(from_material)) + { + if (test_block.getLocation().distanceSquared(center_location) < (radius * radius)) + { + test_block.setType(to_material); + affected++; + } + } + } + } + } + + return affected; + } // I wrote all this before i discovered getTargetBlock >.> - might come in handy some day... // public static final double LOOKAT_VIEW_HEIGHT = 1.65; // public static final double LOOKAT_STEP_DISTANCE = 0.2; diff --git a/src/plugin.yml b/src/plugin.yml index 4896985c..caba8958 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -162,7 +162,7 @@ commands: description: Owner Command - Broadcasts the given message with no extra formatting. usage: / rd: - description: Superadmin command - Remove all projectiles, dropped items, experience orbs, primed explosives, and minecarts. Minecarts are optional, based on if "carts" is included after the command. + description: Superadmin command - Remove various server entities that may cause lag, such as dropped items, minecarts, and boats. usage: / ro: description: Superadmin Command - Remove all blocks of a certain type in the radius of certain players.