From 326c3f6a2b6861241b04493ef6e2cd8661214003 Mon Sep 17 00:00:00 2001 From: Steven Lawson Date: Sun, 11 Aug 2013 22:02:18 -0400 Subject: [PATCH] Incomplete features: -Adminworld -Better entity wiping --- appinfo.properties | 6 +- buildnumber.properties | 4 +- .../Commands/Command_adminworld.java | 19 ++++ .../Commands/Command_purgeall.java | 2 +- .../TotalFreedomMod/Commands/Command_rd.java | 2 +- .../Commands/Command_trail.java | 2 +- .../Listener/TFM_EntityListener.java | 4 +- .../Listener/TFM_PlayerListener.java | 8 +- .../TotalFreedomMod/TFM_AdminWorld.java | 87 +++++++++++++++++++ .../TotalFreedomMod/TFM_Heartbeat.java | 2 +- .../TotalFreedomMod/TFM_Util.java | 80 ++++++++++++++--- 11 files changed, 192 insertions(+), 24 deletions(-) create mode 100644 src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java create mode 100644 src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java diff --git a/appinfo.properties b/appinfo.properties index bb5aad83..b8fda0f4 100644 --- a/appinfo.properties +++ b/appinfo.properties @@ -1,5 +1,5 @@ -#Sat, 10 Aug 2013 15:43:16 -0400 +#Sun, 11 Aug 2013 21:06:54 -0400 program.VERSION=2.22 -program.BUILDNUM=392 -program.BUILDDATE=08/10/2013 03\:43 PM +program.BUILDNUM=396 +program.BUILDDATE=08/11/2013 09\:06 PM diff --git a/buildnumber.properties b/buildnumber.properties index cb0e152b..337f8837 100644 --- a/buildnumber.properties +++ b/buildnumber.properties @@ -1,3 +1,3 @@ #Build Number for ANT. Do not edit! -#Sat Aug 10 15:43:16 EDT 2013 -build.number=393 +#Sun Aug 11 21:06:54 EDT 2013 +build.number=397 diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java new file mode 100644 index 00000000..0caf90ec --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_adminworld.java @@ -0,0 +1,19 @@ +package me.StevenLawson.TotalFreedomMod.Commands; + +import me.StevenLawson.TotalFreedomMod.TFM_AdminWorld; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.ONLY_IN_GAME) +@CommandParameters(description = "Go to the AdminWorld.", usage = "/") +public class Command_adminworld extends TFM_Command +{ + @Override + public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) + { + TFM_AdminWorld.getInstance().sendToAdminWorld(sender_p); + + return true; + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java index dbf31568..6cc86eeb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_purgeall.java @@ -19,7 +19,7 @@ public class Command_purgeall extends TFM_Command TFM_Util.adminAction(sender.getName(), "Purging all player data", true); // Purge entities - TFM_Util.wipeEntities(true, true); + TFM_Util.TFM_EntityWiper.wipeEntities(true, true); // Undisguise all players TFM_DisguiseCraftBridge.undisguiseAllPlayers(); diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java index 0ea202b2..e44c6c47 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_rd.java @@ -13,7 +13,7 @@ public class Command_rd extends TFM_Command public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { TFM_Util.adminAction(sender.getName(), "Removing all server entities.", true); - playerMsg((TFM_Util.wipeEntities(true, true)) + " enties removed."); + playerMsg((TFM_Util.TFM_EntityWiper.wipeEntities(true, true)) + " enties removed."); return true; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_trail.java b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_trail.java index 72e24c00..6715b40c 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Commands/Command_trail.java +++ b/src/me/StevenLawson/TotalFreedomMod/Commands/Command_trail.java @@ -41,7 +41,7 @@ public class Command_trail extends TFM_Command trailPlayers.add(sender_p); } - playerMsg("Trail enabled!"); + playerMsg("Trail enabled. Use \"/trail off\" to disable."); } if (!trailPlayers.isEmpty()) diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java index 737fe8b7..7bb6fe46 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_EntityListener.java @@ -125,9 +125,9 @@ public class TFM_EntityListener implements Listener { int mobcount = 0; - for (Entity ent : event.getLocation().getWorld().getLivingEntities()) + for (Entity entity : event.getLocation().getWorld().getLivingEntities()) { - if (ent instanceof Creature || ent instanceof Ghast || ent instanceof Slime || ent instanceof EnderDragon) + if (!(entity instanceof HumanEntity)) { mobcount++; } diff --git a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java index d1e36237..b7dfa052 100644 --- a/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java +++ b/src/me/StevenLawson/TotalFreedomMod/Listener/TFM_PlayerListener.java @@ -466,7 +466,7 @@ public class TFM_PlayerListener implements Listener playerdata.resetMsgCount(); - TFM_Util.wipeEntities(true, true); + TFM_Util.TFM_EntityWiper.wipeEntities(true, true); event.setCancelled(true); return; @@ -641,4 +641,10 @@ public class TFM_PlayerListener implements Listener { TFM_ServerInterface.handlePlayerLogin(event); } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerTeleport(PlayerTeleportEvent event) + { + TFM_AdminWorld.getInstance().validateTeleport(event); + } } diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java new file mode 100644 index 00000000..da6ff3e4 --- /dev/null +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_AdminWorld.java @@ -0,0 +1,87 @@ +package me.StevenLawson.TotalFreedomMod; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.WorldType; +import org.bukkit.block.Block; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class TFM_AdminWorld +{ + private static final String GENERATION_PARAMETERS = "16,stone,32,dirt,1,grass"; + private static final String ADMINWORLD_NAME = "adminworld"; + private World adminWorld = null; + + private TFM_AdminWorld() + { + } + + public void sendToAdminWorld(Player player) + { + if (!TFM_SuperadminList.isUserSuperadmin(player)) + { + return; + } + + if (adminWorld == null || !Bukkit.getWorlds().contains(adminWorld)) + { + generateWorld(); + } + + player.teleport(adminWorld.getSpawnLocation()); + } + + public void validateTeleport(PlayerTeleportEvent event) + { + if (adminWorld == null) + { + return; + } + + if (event.getTo().getWorld() == adminWorld) + { + if (!TFM_SuperadminList.isUserSuperadmin(event.getPlayer())) + { + event.setCancelled(true); + } + } + } + + private void generateWorld() + { + WorldCreator adminWorldCreator = new WorldCreator(ADMINWORLD_NAME); + adminWorldCreator.generateStructures(false); + adminWorldCreator.type(WorldType.NORMAL); + adminWorldCreator.environment(World.Environment.NORMAL); + adminWorldCreator.generator(new CleanroomChunkGenerator(GENERATION_PARAMETERS)); + + adminWorld = Bukkit.getServer().createWorld(adminWorldCreator); + + adminWorld.setSpawnFlags(false, false); + adminWorld.setSpawnLocation(0, 50, 0); + + Block welcomeSignBlock = adminWorld.getBlockAt(0, 50, 0); + welcomeSignBlock.setType(Material.SIGN_POST); + Sign welcomeSign = (Sign) welcomeSignBlock.getState(); + welcomeSign.setLine(0, "AdminWorld"); + welcomeSign.setLine(1, ""); + welcomeSign.setLine(2, ""); + welcomeSign.setLine(3, ""); + + TFM_GameRuleHandler.commitGameRules(); + } + + public static TFM_AdminWorld getInstance() + { + return TFM_AdminWorldHolder.INSTANCE; + } + + private static class TFM_AdminWorldHolder + { + private static final TFM_AdminWorld INSTANCE = new TFM_AdminWorld(); + } +} diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java index d39e692d..e532d5cb 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Heartbeat.java @@ -29,7 +29,7 @@ public class TFM_Heartbeat extends BukkitRunnable if (TotalFreedomMod.autoEntityWipe) { - TFM_Util.wipeEntities(!TotalFreedomMod.allowExplosions, false); + TFM_Util.TFM_EntityWiper.wipeEntities(!TotalFreedomMod.allowExplosions, false); } if (TotalFreedomMod.disableWeather) diff --git a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java index f65e54e7..d9b752f3 100644 --- a/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java +++ b/src/me/StevenLawson/TotalFreedomMod/TFM_Util.java @@ -234,25 +234,81 @@ public class TFM_Util } } - public static int wipeEntities(boolean wipe_explosives, boolean wipe_vehicles) + public static class TFM_EntityWiper { - int removed = 0; - for (World world : Bukkit.getWorlds()) + private static final List> WIPEABLES = new ArrayList>(); + + static { - for (Entity ent : world.getEntities()) + WIPEABLES.add(EnderCrystal.class); + WIPEABLES.add(EnderSignal.class); + WIPEABLES.add(ExperienceOrb.class); + WIPEABLES.add(Projectile.class); + WIPEABLES.add(FallingBlock.class); + WIPEABLES.add(Firework.class); + WIPEABLES.add(Item.class); + } + + private TFM_EntityWiper() + { + throw new AssertionError(); + } + + private static boolean canWipe(Entity entity, boolean wipeExplosives, boolean wipeVehicles) + { + if (wipeExplosives) { - if (ent instanceof Projectile - || ent instanceof Item - || ent instanceof ExperienceOrb - || (ent instanceof Explosive && wipe_explosives) - || (ent instanceof Vehicle && wipe_vehicles)) + if (Explosive.class.isAssignableFrom(entity.getClass())) { - ent.remove(); - removed++; + return true; } } + + if (wipeVehicles) + { + if (Boat.class.isAssignableFrom(entity.getClass())) + { + return true; + } + else if (Minecart.class.isAssignableFrom(entity.getClass())) + { + return true; + } + } + + Iterator> it = WIPEABLES.iterator(); + while (it.hasNext()) + { + if (it.next().isAssignableFrom(entity.getClass())) + { + return true; + } + } + + return false; + } + + public static int wipeEntities(boolean wipeExplosives, boolean wipeVehicles) + { + int removed = 0; + + Iterator worlds = Bukkit.getWorlds().iterator(); + while (worlds.hasNext()) + { + Iterator entities = worlds.next().getEntities().iterator(); + while (entities.hasNext()) + { + Entity entity = entities.next(); + if (canWipe(entity, wipeExplosives, wipeVehicles)) + { + entity.remove(); + removed++; + } + } + } + + return removed; } - return removed; } public static boolean deleteFolder(File file)