Skip to content

Commit

Permalink
patch crash methods involving fast world teleportation
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 22, 2024
1 parent 8bd29d3 commit 7cca8cf
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void reloadModules() {
modules.add(new GodMode());
modules.add(new TeleportCoordExploit());
modules.add(new BeehiveCoordinates());
modules.add(new WorldChangeCrash());
/*
Combat
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UUID> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -182,6 +179,7 @@ static void reloadModules() {
modules.add(new EndGatewayCrash());
modules.add(new MultipleEnderdragons());
modules.add(new RedstoneOnTrapdoorCrash());
modules.add(new WorldChangeCrash());
/*
Combat
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UUID> 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());
}
}
}

0 comments on commit 7cca8cf

Please sign in to comment.