From 7cca8cf7cd74958a0945076df0ee0073d0e83c23 Mon Sep 17 00:00:00 2001 From: xGinko Date: Mon, 22 Jan 2024 18:06:03 +0100 Subject: [PATCH] patch crash methods involving fast world teleportation --- .../modules/AnarchyExploitFixesModule.java | 1 + .../modules/patches/WorldChangeCrash.java | 77 +++++++++++++++++++ .../modules/AnarchyExploitFixesModule.java | 6 +- .../crashexploits/WorldChangeCrash.java | 71 +++++++++++++++++ 4 files changed, 151 insertions(+), 4 deletions(-) create mode 100755 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java create mode 100755 AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 568e0145a..b55c841bc 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -168,6 +168,7 @@ static void reloadModules() { modules.add(new GodMode()); modules.add(new TeleportCoordExploit()); modules.add(new BeehiveCoordinates()); + modules.add(new WorldChangeCrash()); /* Combat */ diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java new file mode 100755 index 000000000..aef4f41c6 --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java @@ -0,0 +1,77 @@ +package me.moomoo.anarchyexploitfixes.modules.patches; + +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.config.Config; +import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; +import org.apache.commons.math3.util.FastMath; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.time.Duration; +import java.util.UUID; +import java.util.logging.Level; + +public class WorldChangeCrash implements AnarchyExploitFixesModule, Listener { + + private final ExpiringSet recentWorldChangers; + private final boolean logIsEnabled; + + public WorldChangeCrash() { + shouldEnable(); + Config config = AnarchyExploitFixes.getConfiguration(); + this.recentWorldChangers = new ExpiringSet<>(Duration.ofMillis( + FastMath.max(config.getInt("patches.crash-exploits.prevent-fast-world-teleport-crash.teleport-delay-millis", 1000, + "Time in milliseconds until an entity can teleport to another world again."), 1))); + config.addComment("patches.crash-exploits.prevent-fast-world-teleport-crash.enable", + "Prevents dispensers from crashing the server when dispensing items out of bounds: https://www.youtube.com/watch?v=XL17P87O6xA"); + this.logIsEnabled = config.getBoolean("patches.crash-exploits.prevent-fast-world-teleport-crash.log", false); + } + + @Override + public String name() { + return "prevent-fast-world-teleport-crash"; + } + + @Override + public String category() { + return "patches"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("patches.crash-exploits.prevent-fast-world-teleport-crash.enable", true); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onTeleport(EntityTeleportEvent event) { + if (event.getFrom().getWorld().getUID().equals(event.getTo().getWorld().getUID())) return; + + if (recentWorldChangers.contains(event.getEntity().getUniqueId())) { + event.setCancelled(true); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled too fast world teleport of entity: " + + event.getEntityType().name() + " at \n" + + "x: "+event.getEntity().getLocation().getX() + ", " + + "y: "+event.getEntity().getLocation().getY() + ", " + + "z: "+event.getEntity().getLocation().getX() + ", " + + "world: "+event.getEntity().getLocation().getWorld().getName()); + } else { + recentWorldChangers.add(event.getEntity().getUniqueId()); + } + } +} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java index 60068267a..78e916822 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -36,10 +36,7 @@ import me.moomoo.anarchyexploitfixes.modules.misc.MaskKickMessages; import me.moomoo.anarchyexploitfixes.modules.misc.PreventMessageKick; import me.moomoo.anarchyexploitfixes.modules.patches.*; -import me.moomoo.anarchyexploitfixes.modules.patches.crashexploits.DispenserCrash; -import me.moomoo.anarchyexploitfixes.modules.patches.crashexploits.EndGatewayCrash; -import me.moomoo.anarchyexploitfixes.modules.patches.crashexploits.MultipleEnderdragons; -import me.moomoo.anarchyexploitfixes.modules.patches.crashexploits.RedstoneOnTrapdoorCrash; +import me.moomoo.anarchyexploitfixes.modules.patches.crashexploits.*; import me.moomoo.anarchyexploitfixes.modules.preventions.*; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonExplodePermBlockRemoval; import me.moomoo.anarchyexploitfixes.modules.preventions.blockbreak.PistonPlaceWhileRetractPermBlockRemoval; @@ -182,6 +179,7 @@ static void reloadModules() { modules.add(new EndGatewayCrash()); modules.add(new MultipleEnderdragons()); modules.add(new RedstoneOnTrapdoorCrash()); + modules.add(new WorldChangeCrash()); /* Combat */ diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java new file mode 100755 index 000000000..84c967677 --- /dev/null +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java @@ -0,0 +1,71 @@ +package me.moomoo.anarchyexploitfixes.modules.patches.crashexploits; + +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.config.Config; +import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.LogUtil; +import me.moomoo.anarchyexploitfixes.utils.models.ExpiringSet; +import org.apache.commons.math3.util.FastMath; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityTeleportEvent; + +import java.time.Duration; +import java.util.UUID; +import java.util.logging.Level; + +public class WorldChangeCrash implements AnarchyExploitFixesModule, Listener { + + private final ExpiringSet recentWorldChangers; + private final boolean logIsEnabled; + + public WorldChangeCrash() { + shouldEnable(); + Config config = AnarchyExploitFixes.getConfiguration(); + this.recentWorldChangers = new ExpiringSet<>(Duration.ofMillis( + FastMath.max(config.getInt("patches.crash-exploits.prevent-fast-world-teleport-crash.teleport-delay-millis", 1000, + "Time in milliseconds until an entity can teleport to another world again."), 1))); + config.addComment("patches.crash-exploits.prevent-fast-world-teleport-crash.enable", + "Prevents dispensers from crashing the server when dispensing items out of bounds: https://www.youtube.com/watch?v=XL17P87O6xA"); + this.logIsEnabled = config.getBoolean("patches.crash-exploits.prevent-fast-world-teleport-crash.log", false); + } + + @Override + public String name() { + return "prevent-fast-world-teleport-crash"; + } + + @Override + public String category() { + return "patches"; + } + + @Override + public void enable() { + AnarchyExploitFixes plugin = AnarchyExploitFixes.getInstance(); + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean shouldEnable() { + return AnarchyExploitFixes.getConfiguration().getBoolean("patches.crash-exploits.prevent-fast-world-teleport-crash.enable", true); + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + private void onTeleport(EntityTeleportEvent event) { + if (event.getFrom().getWorld().getUID().equals(event.getTo().getWorld().getUID())) return; + + if (recentWorldChangers.contains(event.getEntity().getUniqueId())) { + event.setCancelled(true); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, name(), "Cancelled too fast world teleport of entity: " + + event.getEntityType().name() + " at \n" + + "x: "+event.getEntity().getLocation().getX() + ", " + + "y: "+event.getEntity().getLocation().getY() + ", " + + "z: "+event.getEntity().getLocation().getX() + ", " + + "world: "+event.getEntity().getLocation().getWorld().getName()); + } else { + recentWorldChangers.add(event.getEntity().getUniqueId()); + } + } +}