From 8b1b9433114bc2c943498e8645fdcf811138eda0 Mon Sep 17 00:00:00 2001 From: xGinko Date: Thu, 12 Sep 2024 19:24:57 +0200 Subject: [PATCH] remove hacky pearl phase patch until theres a better one --- .../aef/modules/patches/PearlPhase.java | 141 ------------------ .../aef/modules/patches/PearlPhase.java | 109 -------------- 2 files changed, 250 deletions(-) delete mode 100644 AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java delete mode 100644 AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java deleted file mode 100644 index 1c65dd580..000000000 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java +++ /dev/null @@ -1,141 +0,0 @@ -package me.xginko.aef.modules.patches; - -import com.cryptomorin.xseries.XMaterial; -import me.xginko.aef.modules.AEFModule; -import me.xginko.aef.utils.LocationUtil; -import me.xginko.aef.utils.MaterialUtil; -import me.xginko.aef.utils.PlatformUtil; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerTeleportEvent; - -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class PearlPhase extends AEFModule implements Listener { - - private final Set glitchyMaterial; - private final double maxDistance; - private final int radius; - private long schedulingTimeoutMillis; - - public PearlPhase() { - super("patches.pearl-phase"); - config.addComment(configPath+ ".enable", - "Attempts to patch a pearl phasing exploit by cancelling the teleport\n" + - "if the pearl is thrown at or near a specific block.\n" + - "At the time of the creation of this module, this is an issue with NoCheatPlus."); - this.radius = Math.min(1, config.getInt(configPath + ".search-radius", 2, - "How many blocks around the teleport location should be searched\n" + - "for potential glitch blocks if the teleport location isn't one itself.")); - this.maxDistance = config.getDouble(configPath + ".maximum-distance-to-cancel-teleport", 3.0); - - Stream concatA = Stream.concat(MaterialUtil.SLAB_LIKE.stream(), - Stream.of(XMaterial.COBWEB, XMaterial.POWDER_SNOW).filter(XMaterial::isSupported).map(XMaterial::parseMaterial)); - Stream concatB = Stream.concat(MaterialUtil.PRESSURE_PLATES.stream(), MaterialUtil.TRAPDOORS.stream()); - List defaults = Stream.concat(concatA, concatB) - .map(Enum::name) - .sorted() - .toList(); - this.glitchyMaterial = config.getList(configPath+".glitchy-materials", defaults) - .stream() - .map(configuredType -> { - try { - return Material.valueOf(configuredType); - } catch (IllegalArgumentException e) { - notRecognized(Material.class, configuredType); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toCollection(() -> EnumSet.noneOf(Material.class))); - if (PlatformUtil.isFolia()) { - this.schedulingTimeoutMillis = config.getInt(configPath + ".check-timeout-millis", 800, - "We will have to schedule the check on folia, meaning theres a chance\n" + - "the task might take longer than expected. To make sure that does not cause\n" + - "more lag, we set a time limit here."); - } - } - - @Override - public boolean shouldEnable() { - return config.getBoolean(configPath+".enable", false); - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onPlayerTeleport(PlayerTeleportEvent event) { - if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; - - Location destination = event.getTo(); - if (LocationUtil.getRelDistance2D(event.getFrom(), destination) >= maxDistance) return; - - if (!PlatformUtil.isFolia()) { - if (isPotentialPhase(destination)) - event.setCancelled(true); - return; - } - - try { - CompletableFuture future = new CompletableFuture<>(); - // We will have to schedule the check on folia because the event might not - // fire from the same thread as the region of the destination location. - plugin.getServer().getRegionScheduler().execute(plugin, destination, () -> - future.complete(isPotentialPhase(destination))); - if (future.get(schedulingTimeoutMillis, TimeUnit.MILLISECONDS)) - event.setCancelled(true); - } catch (ExecutionException | InterruptedException | TimeoutException e) { - error("Error while checking if the destination would trigger phasing.", e); - } - } - - private boolean isPotentialPhase(Location location) { - Block destBlock = location.getBlock(); - - if (glitchyMaterial.contains(destBlock.getType())) { - return true; - } - - int centerX = destBlock.getX(); - int centerY = destBlock.getY(); - int centerZ = destBlock.getZ(); - World world = destBlock.getWorld(); - - for (int x = centerX - radius; x <= centerX + radius; x++) { - for (int z = centerZ - radius; z <= centerZ + radius; z++) { - for (int y = Math.max(world.getMinHeight(), centerY - radius); y <= centerY + radius; y++) { - if (y > world.getMaxHeight()) break; - - if (glitchyMaterial.contains(world.getBlockAt(x, y, z).getType())) { - return true; - } - } - } - } - - return false; - } -} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java deleted file mode 100644 index 18f0d9372..000000000 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/patches/PearlPhase.java +++ /dev/null @@ -1,109 +0,0 @@ -package me.xginko.aef.modules.patches; - -import com.cryptomorin.xseries.XMaterial; -import me.xginko.aef.modules.AEFModule; -import me.xginko.aef.utils.LocationUtil; -import me.xginko.aef.utils.MaterialUtil; -import me.xginko.aef.utils.WorldUtil; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerTeleportEvent; - -import java.util.EnumSet; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class PearlPhase extends AEFModule implements Listener { - - private final Set glitchyMaterial; - private final double maxDistance; - private final int radius; - - public PearlPhase() { - super("patches.pearl-phase"); - config.addComment(configPath+ ".enable", - "Attempts to patch a pearl phasing exploit by cancelling the teleport\n" + - "if the pearl is thrown at or near a specific block.\n" + - "At the time of the creation of this module, this is an issue with NoCheatPlus."); - this.radius = Math.min(1, config.getInt(configPath + ".search-radius", 2, - "How many blocks around the teleport location should be searched\n" + - "for potential glitch blocks if the teleport location isn't one itself.")); - this.maxDistance = config.getDouble(configPath + ".maximum-distance-to-cancel-teleport", 3.0); - Stream concatA = Stream.concat(MaterialUtil.SLAB_LIKE.stream(), - Stream.of(XMaterial.COBWEB, XMaterial.POWDER_SNOW).filter(XMaterial::isSupported).map(XMaterial::parseMaterial)); - Stream concatB = Stream.concat(MaterialUtil.PRESSURE_PLATES.stream(), MaterialUtil.TRAPDOORS.stream()); - List defaults = Stream.concat(concatA, concatB) - .map(Enum::name) - .sorted() - .collect(Collectors.toList()); - this.glitchyMaterial = config.getList(configPath+".glitchy-materials", defaults) - .stream() - .map(configuredType -> { - try { - return Material.valueOf(configuredType); - } catch (IllegalArgumentException e) { - notRecognized(Material.class, configuredType); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toCollection(() -> EnumSet.noneOf(Material.class))); - } - - @Override - public boolean shouldEnable() { - return config.getBoolean(configPath+".enable", false); - } - - @Override - public void enable() { - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @Override - public void disable() { - HandlerList.unregisterAll(this); - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - private void onPlayerTeleport(PlayerTeleportEvent event) { - if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL) return; - - Location destination = event.getTo(); - if (LocationUtil.getRelDistance2D(event.getFrom(), destination) >= maxDistance) return; - - Block destBlock = destination.getBlock(); - - if (glitchyMaterial.contains(destBlock.getType())) { - event.setCancelled(true); - return; - } - - int centerX = destBlock.getX(); - int centerY = destBlock.getY(); - int centerZ = destBlock.getZ(); - World world = destBlock.getWorld(); - - for (int x = centerX - radius; x <= centerX + radius; x++) { - for (int z = centerZ - radius; z <= centerZ + radius; z++) { - for (int y = Math.max(WorldUtil.getMinWorldHeight(world), centerY - radius); y <= centerY + radius; y++) { - if (y > world.getMaxHeight()) break; - - if (glitchyMaterial.contains(world.getBlockAt(x, y, z).getType())) { - event.setCancelled(true); - return; - } - } - } - } - } -}