-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
patch crash methods involving fast world teleportation
- Loading branch information
Showing
4 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...esFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/WorldChangeCrash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...in/java/me/moomoo/anarchyexploitfixes/modules/patches/crashexploits/WorldChangeCrash.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |