From 326e5615a0bdfe528937cb912b08e83726332beb Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 14 Jul 2015 23:25:01 +1000 Subject: [PATCH] Optimize kill road mobs + fix plotme conversion for 0.17 --- PlotSquared/pom.xml | 2 +- .../intellectualcrafters/plot/BukkitMain.java | 117 +++++++++++++++--- .../database/plotme/PlotMeConnector_017.java | 12 +- 3 files changed, 109 insertions(+), 22 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index decc3d593..3aab2903e 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.12.5 + 2.12.6 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index 701c58d4f..704769826 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -5,23 +5,19 @@ import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Field; import java.net.URLClassLoader; -import java.nio.file.Files; +import java.util.ArrayDeque; import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Stack; import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.command.Command; import org.bukkit.command.PluginCommand; -import org.bukkit.command.SimpleCommandMap; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; @@ -116,7 +112,10 @@ import com.intellectualcrafters.plot.listeners.TNTListener; import com.intellectualcrafters.plot.listeners.WorldEvents; import com.intellectualcrafters.plot.listeners.worldedit.WEListener; import com.intellectualcrafters.plot.listeners.worldedit.WESubscriber; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.util.BlockManager; @@ -351,8 +350,13 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { return new BukkitTaskManager(); } + private ArrayDeque fastTickEntities; + private ArrayDeque slowTickEntities; + @Override public void runEntityTask() { +// fastTickEntities = new ArrayDeque<>(); +// slowTickEntities = new ArrayDeque<>(); log(C.PREFIX.s() + "KillAllEntities started."); TaskManager.runTaskRepeat(new Runnable() { long ticked = 0l; @@ -368,21 +372,102 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { this.error = 0l; } World world; - for (final String w : PS.get().getPlotWorlds()) { - world = Bukkit.getWorld(w); + for (final PlotWorld pw : PS.get().getPlotWorldObjects()) { + PlotManager manager = PS.get().getPlotManager(pw.worldname); + world = Bukkit.getWorld(pw.worldname); try { - if (world.getLoadedChunks().length < 1) { - continue; - } - for (final Chunk chunk : world.getLoadedChunks()) { - final Entity[] entities = chunk.getEntities(); - Entity entity; - for (int i = entities.length - 1; i >= 0; i--) { - if (!((entity = entities[i]) instanceof Player) && (MainUtil.getPlot(BukkitUtil.getLocation(entity)) == null)) { + for (Entity entity : world.getEntities()) { + switch (entity.getType()) { + case EGG: + case ENDER_CRYSTAL: + case COMPLEX_PART: + case ARMOR_STAND: + case FISHING_HOOK: + case ENDER_SIGNAL: + case EXPERIENCE_ORB: + case LEASH_HITCH: + case FIREWORK: + case WEATHER: + case LIGHTNING: + case WITHER_SKULL: + case UNKNOWN: + case ITEM_FRAME: + case PAINTING: + case PLAYER: { + // non moving / unremovable + continue; + } + case THROWN_EXP_BOTTLE: + case SPLASH_POTION: + case SNOWBALL: + case ENDER_PEARL: + case ARROW: { + // managed elsewhere | projectile + continue; + } + case MINECART: + case MINECART_CHEST: + case MINECART_COMMAND: + case MINECART_FURNACE: + case MINECART_HOPPER: + case MINECART_MOB_SPAWNER: + case MINECART_TNT: + case BOAT: { + // vehicle + continue; + } + case SMALL_FIREBALL: + case FIREBALL: + case DROPPED_ITEM: { + // dropped item + continue; + } + case PRIMED_TNT: + case FALLING_BLOCK: { + // managed elsewhere + continue; + } + case BAT: + case BLAZE: + case CAVE_SPIDER: + case CHICKEN: + case COW: + case CREEPER: + case ENDERMAN: + case ENDERMITE: + case ENDER_DRAGON: + case GHAST: + case GIANT: + case GUARDIAN: + case HORSE: + case IRON_GOLEM: + case MAGMA_CUBE: + case MUSHROOM_COW: + case OCELOT: + case PIG: + case PIG_ZOMBIE: + case RABBIT: + case SHEEP: + case SILVERFISH: + case SKELETON: + case SLIME: + case SNOWMAN: + case SPIDER: + case SQUID: + case VILLAGER: + case WITCH: + case WITHER: + case WOLF: + case ZOMBIE: + default: { + Location loc = entity.getLocation(); + if (manager.getPlotIdAbs(pw, loc.getBlockX(), 0, loc.getBlockZ()) == null) { entity.remove(); } + break; } } + } } catch (final Throwable e) { ++this.error; } finally { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java index c192fd5f7..e2e62045e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/plotme/PlotMeConnector_017.java @@ -138,8 +138,8 @@ public class PlotMeConnector_017 extends APlotMeConnector { r.close(); stmt.close(); try { - MainUtil.sendConsoleMessage(" - " + plugin + "_denied"); - stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "_denied`"); + MainUtil.sendConsoleMessage(" - " + plugin + "core_denied"); + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_denied`"); r = stmt.executeQuery(); while (r.next()) { @@ -153,8 +153,8 @@ public class PlotMeConnector_017 extends APlotMeConnector { plot.denied.add(denied); } - MainUtil.sendConsoleMessage(" - " + plugin + "_allowed"); - stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "_allowed`"); + MainUtil.sendConsoleMessage(" - " + plugin + "core_allowed"); + stmt = connection.prepareStatement("SELECT * FROM `" + plugin + "core_allowed`"); r = stmt.executeQuery(); while (r.next()) { @@ -171,7 +171,9 @@ public class PlotMeConnector_017 extends APlotMeConnector { stmt.close(); } - catch (Exception e) {} + catch (Exception e) { + e.printStackTrace(); + } HashMap> processed = new HashMap<>(); for (Entry entry : plots.entrySet()) {