From 6819ff2ee77645253fb81601fafd4e66978297fc Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 27 Jan 2015 23:51:53 -0500 Subject: [PATCH] =?UTF-8?q?Ajout=20d'une=20protection=20contre=20les=20spa?= =?UTF-8?q?wn=20massif=20d'entit=C3=A9s=20en=20cr=C3=A9atif?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 2 +- .../plugin/pandacraftutils/ConfigManager.java | 15 +++ .../pandacraftutils/PandacraftUtils.java | 5 +- .../cheat_protect/EntitySpamManager.java | 97 +++++++++++++++++++ 5 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/EntitySpamManager.java diff --git a/make_jar.jardesc b/make_jar.jardesc index ae33c3f..0acb522 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index 741212e..207b661 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 3.3 +version: 3.4 diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java index 65b53be..37dcc6d 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/ConfigManager.java @@ -99,6 +99,13 @@ public class ConfigManager { // TODO gérer les codes de coloration; ServerMOTD = "§7Serveur §fPandacraft§7, §eVenez nous rejoindre :D\n§bCreatif§7, §6Survie§7 et §4Faction/PVP§7 !"; + + + EntitySpam_worlds = "creative"; // séparé avec des point-virgules + EntitySpam_limitPerChunks = 50; + + + initChatAnalysisBadWord(); initCommandAlias(); initAutomessages(); @@ -130,6 +137,14 @@ public class ConfigManager { + /* + * Entity Spam + */ + public String EntitySpam_worlds; + public int EntitySpam_limitPerChunks; + + + diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java index cacfd8f..73fcced 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/PandacraftUtils.java @@ -14,6 +14,7 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.modules.SurvivalCuboManager import net.mc_pandacraft.java.plugin.pandacraftutils.modules.TPSAnalysisManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.WESelectionDisplayManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.CreativCheatManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.EntitySpamManager; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect.NoPvpProtectManager; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; @@ -44,6 +45,7 @@ public class PandacraftUtils extends JavaPlugin { public StaffQueueManager staffQueueManager; public TPSAnalysisManager tpsAnalysisManager; public AutoMessagesManager autoMessagesManager; + public EntitySpamManager entitySpamManager; @@ -84,7 +86,7 @@ public class PandacraftUtils extends JavaPlugin { staffQueueManager = new StaffQueueManager(); tpsAnalysisManager = new TPSAnalysisManager(); autoMessagesManager = new AutoMessagesManager(); - + entitySpamManager = new EntitySpamManager(); @@ -113,6 +115,7 @@ public class PandacraftUtils extends JavaPlugin { staffQueueManager = null; tpsAnalysisManager = null; autoMessagesManager = null; + entitySpamManager = null; ConfigManager.reloadConfig(); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/EntitySpamManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/EntitySpamManager.java new file mode 100644 index 0000000..811c590 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/cheat_protect/EntitySpamManager.java @@ -0,0 +1,97 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.modules.cheat_protect; + +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Entity; +import org.bukkit.entity.ThrownExpBottle; +import org.bukkit.entity.Vehicle; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.ExpBottleEvent; +import org.bukkit.event.vehicle.VehicleCreateEvent; + +import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager; +import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; + +public class EntitySpamManager implements Listener { + + private PandacraftUtils plugin = PandacraftUtils.getInstance(); + + public EntitySpamManager() { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + + + /* + * Non pris en charge pour le moment + @EventHandler + public void onCreatureSpawn(CreatureSpawnEvent event) { + + } + */ + + + /** + * Prends en charge l'évènement de création d'un véhicule, et programme sa destruction + * si le chunk dans lequel il se trouve dépasse le nombre d'entité autorisé + * @param event + */ + @EventHandler + public void onVehicleCreate(VehicleCreateEvent event) { + Vehicle v = event.getVehicle(); + Location l = v.getLocation(); + if (!isInWorld(l)) return; + if (containsTooManyEntity(l.getChunk())) + { + plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + private Vehicle vehicle; + public Runnable init(Vehicle v) { + vehicle = v; + return this; + } + @Override + public void run() { + vehicle.remove(); + } + }.init(v), 1); + } + + } + + + @EventHandler + public void onExpBottle(ExpBottleEvent event) { + ThrownExpBottle b = event.getEntity(); + if (!isInWorld(b.getLocation())) return; + if (containsTooManyEntity(b.getLocation().getChunk())) { + event.setExperience(0); + } + } + + + + + + + + + private boolean isInWorld(Location l) { + World w = l.getWorld(); + String config = ConfigManager.getInstance().EntitySpam_worlds; + String[] worlds = config.split(";"); + for (String ws : worlds) + if (w.getName().equalsIgnoreCase(ws)) + return true; + return false; + + } + + private boolean containsTooManyEntity(Chunk c) { + if (!c.isLoaded()) c.load(); + Entity[] ents = c.getEntities(); + return (ents.length > ConfigManager.getInstance().EntitySpam_limitPerChunks); + } + +}