From 8775e9e37016faadcf2f43baaaf38d5731a4e5eb Mon Sep 17 00:00:00 2001 From: Brianna Date: Thu, 20 Jun 2019 03:33:29 -0400 Subject: [PATCH] Added clearlag support. --- pom.xml | 5 ++++ .../ultimatestacker/UltimateStacker.java | 11 +++++--- .../listeners/ClearLagListeners.java | 26 +++++++++++++++++++ .../utils/settings/Setting.java | 6 ++++- 4 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/songoda/ultimatestacker/listeners/ClearLagListeners.java diff --git a/pom.xml b/pom.xml index c6b2603..5c863e9 100644 --- a/pom.xml +++ b/pom.xml @@ -98,5 +98,10 @@ stackmob 4 + + me.minebuilders + Clearlag + 3.0.6 + diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index e421965..9cf5076 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -28,7 +28,6 @@ import org.apache.commons.lang.ArrayUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -37,7 +36,6 @@ import org.bukkit.plugin.java.JavaPlugin; import java.util.ArrayList; import java.util.List; -import java.util.UUID; public class UltimateStacker extends JavaPlugin { @@ -171,6 +169,9 @@ public class UltimateStacker extends JavaPlugin { pluginManager.registerEvents(new TameListeners(this), this); pluginManager.registerEvents(new SheepDyeListeners(this), this); + if (Setting.CLEAR_LAG.getBoolean() && pluginManager.isPluginEnabled("ClearLag")) + pluginManager.registerEvents(new ClearLagListeners(this), this); + // Register Hologram Plugin if (Setting.SPAWNER_HOLOGRAMS.getBoolean()) { if (pluginManager.isPluginEnabled("HolographicDisplays")) @@ -226,8 +227,10 @@ public class UltimateStacker extends JavaPlugin { return !this.getServer().getPluginManager().isPluginEnabled("EpicSpawners") && Setting.SPAWNERS_ENABLED.getBoolean(); } - public Hologram getHologram() { return hologram; } - + public Hologram getHologram() { + return hologram; + } + public ServerVersion getServerVersion() { return serverVersion; } diff --git a/src/main/java/com/songoda/ultimatestacker/listeners/ClearLagListeners.java b/src/main/java/com/songoda/ultimatestacker/listeners/ClearLagListeners.java new file mode 100644 index 0000000..f3e5b4b --- /dev/null +++ b/src/main/java/com/songoda/ultimatestacker/listeners/ClearLagListeners.java @@ -0,0 +1,26 @@ +package com.songoda.ultimatestacker.listeners; + +import com.songoda.ultimatestacker.UltimateStacker; +import me.minebuilders.clearlag.events.EntityRemoveEvent; +import org.bukkit.entity.Entity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class ClearLagListeners implements Listener { + + private final UltimateStacker instance; + + public ClearLagListeners(UltimateStacker instance) { + this.instance = instance; + } + + @EventHandler + public void onClearLaggTask(EntityRemoveEvent event) { + for (Entity entity : event.getWorld().getEntities()) { + if (instance.getEntityStackManager().isStacked(entity)) { + instance.getEntityStackManager().removeStack(entity); + event.addEntity(entity); + } + } + } +} diff --git a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java index f0742b5..0324772 100644 --- a/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java +++ b/src/main/java/com/songoda/ultimatestacker/utils/settings/Setting.java @@ -17,7 +17,6 @@ public enum Setting { DISABLED_WORLDS("Main.Disabled Worlds", Arrays.asList("World1", "World2", "World3"), "Worlds that stacking doesn't happen in."), - STACK_ENTITIES("Entities.Enabled", true, "Should entities be stacked?"), @@ -44,6 +43,11 @@ public enum Setting { "Should killing a stack of entities kill the whole stack or", "just one out of the stack?"), + CLEAR_LAG("Entities.Clear Lag", false, + "When enabled, the plugin will hook into ClearLag and extend the", + "clear task to include stacked entities from this plugin. If this is enabled", + "the built in task will not run."), + INSTANT_KILL("Entities.Instant Kill", Arrays.asList("FALL", "DROWNING", "LAVA", "VOID"), "Events that will trigger an entire stack to be killed.", "It should be noted that this is useless if the above setting is true.",