From 34772527e2e52f8a76f8680e0d2d9c19f9324c0e Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sun, 26 Apr 2015 18:51:13 +1000 Subject: [PATCH] Added creaturespawn to chunk processor --- .../plot/commands/DebugUUID.java | 56 +++++++++++++++++++ .../plot/listeners/ChunkListener.java | 38 ++++++++++--- 2 files changed, 85 insertions(+), 9 deletions(-) create mode 100644 PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java new file mode 100644 index 000000000..af3fd5d8b --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -0,0 +1,56 @@ +//////////////////////////////////////////////////////////////////////////////////////////////////// +// PlotSquared - A plot manager and world generator for the Bukkit API / +// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / +// / +// This program is free software; you can redistribute it and/or modify / +// it under the terms of the GNU General Public License as published by / +// the Free Software Foundation; either version 3 of the License, or / +// (at your option) any later version. / +// / +// This program is distributed in the hope that it will be useful, / +// but WITHOUT ANY WARRANTY; without even the implied warranty of / +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / +// GNU General Public License for more details. / +// / +// You should have received a copy of the GNU General Public License / +// along with this program; if not, write to the Free Software Foundation, / +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / +// / +// You can contact us via: support@intellectualsites.com / +//////////////////////////////////////////////////////////////////////////////////////////////////// +package com.intellectualcrafters.plot.commands; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map.Entry; +import java.util.UUID; + +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.util.BlockManager; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class DebugUUID extends SubCommand { + public DebugUUID() { + super("debugexec", "plots.admin", "Multi-purpose debug command", "debugexec", "exec", CommandCategory.DEBUG, false); + } + + @Override + public boolean execute(final PlotPlayer player, final String... args) { + + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java index 17e9942ad..e685631c0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/ChunkListener.java @@ -6,8 +6,11 @@ import org.bukkit.Material; import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.event.world.ChunkUnloadEvent; @@ -30,16 +33,10 @@ public class ChunkListener implements Listener { processChunk(event.getChunk(), false); } - private int count = 0; private Chunk lastChunk = null; @EventHandler public void onItemSpawn(ItemSpawnEvent event) { - count++; - if (count < Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { - lastChunk = null; - return; - } Item entity = event.getEntity(); Chunk chunk = entity.getLocation().getChunk(); if (chunk == lastChunk) { @@ -52,13 +49,34 @@ public class ChunkListener implements Listener { } Entity[] entities = chunk.getEntities(); if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { - PlotSquared.log("[PlotSquared] &cDetected unsafe entity creation (" + (chunk.getX() << 4) + "," + (chunk.getX() << 4) + "). Mitigating threat."); event.getEntity().remove(); event.setCancelled(true); lastChunk = chunk; } else { - count = 0; + lastChunk = null; + } + } + + @EventHandler + public void onEntitySpawn(CreatureSpawnEvent event) { + LivingEntity entity = event.getEntity(); + Chunk chunk = entity.getLocation().getChunk(); + if (chunk == lastChunk) { + event.getEntity().remove(); + event.setCancelled(true); + return; + } + if (!PlotSquared.isPlotWorld(chunk.getWorld().getName())) { + return; + } + Entity[] entities = chunk.getEntities(); + if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { + event.getEntity().remove(); + event.setCancelled(true); + lastChunk = chunk; + } + else { lastChunk = null; } } @@ -110,7 +128,9 @@ public class ChunkListener implements Listener { BlockState[] tiles = chunk.getTileEntities(); if (entities.length > Settings.CHUNK_PROCESSOR_MAX_ENTITIES) { for (Entity ent : entities) { - ent.remove(); + if (!(ent instanceof Player)) { + ent.remove(); + } } PlotSquared.log("[PlotSquared] &a detected unsafe chunk and processed: " + (chunk.getX() << 4) + "," + (chunk.getX() << 4)); }