From e4d33a6746388e246dd65e78a51fd3b862874db4 Mon Sep 17 00:00:00 2001 From: xGinko Date: Wed, 24 Jan 2024 19:21:39 +0100 Subject: [PATCH] patch stacked map cursors on folia --- .../modules/AnarchyExploitFixesModule.java | 5 +- .../modules/patches/MapCursorLag.java | 84 +++++++++++++++++++ .../anarchyexploitfixes/utils/EntityUtil.java | 7 +- .../utils/MaterialUtil.java | 8 ++ .../anarchyexploitfixes/utils/EntityUtil.java | 8 +- .../utils/MaterialUtil.java | 35 ++++---- ...moo.anarchyexploitfixes.wrapper.gradle.kts | 2 +- 7 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/MapCursorLag.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 9d0ebe086..6f34d9329 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/AnarchyExploitFixesModule.java @@ -164,7 +164,7 @@ static void reloadModules() { Patches */ modules.add(new BookBan()); - modules.add(new Burrow()); + modules.add(new MapCursorLag()); modules.add(new CommandSign()); modules.add(new GodMode()); modules.add(new TeleportCoordExploit()); @@ -173,12 +173,13 @@ static void reloadModules() { /* Combat */ - modules.add(new BowBomb()); + modules.add(new Burrow()); modules.add(new CrystalAuraDelay()); modules.add(new AnchorAuraDelay()); modules.add(new BedAuraDelay()); modules.add(new PistonAuraDelay()); modules.add(new CrystalAuraHotbarSwitchDelay()); + modules.add(new BowBomb()); /* Preventions */ diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/MapCursorLag.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/MapCursorLag.java new file mode 100644 index 000000000..ec1b9ffac --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/patches/MapCursorLag.java @@ -0,0 +1,84 @@ +package me.moomoo.anarchyexploitfixes.modules.patches; + +import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.EntityUtil; +import me.moomoo.anarchyexploitfixes.utils.MaterialUtil; +import org.bukkit.entity.Entity; +import org.bukkit.entity.ItemFrame; +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.PlayerInteractEntityEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.MapMeta; +import org.bukkit.map.MapView; + +public class MapCursorLag implements AnarchyExploitFixesModule, Listener { + + public MapCursorLag() { + shouldEnable(); + AnarchyExploitFixes.getConfiguration().addComment("patches.map-cursor-lag-patch.enable", + "Patches 2b2t stacked map cursor lag that causes both client and server crashes."); + } + + @Override + public String name() { + return "map-cursor-lag"; + } + + @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.map-cursor-lag-patch.enable", false); + } + + @Override + public void disable() { + HandlerList.unregisterAll(this); + } + + private void disableTracker(ItemFrame itemFrame) { + ItemStack item = itemFrame.getItem(); + if ( + MaterialUtil.isMap(item.getType()) + && item.getItemMeta() instanceof MapMeta mapMeta + && mapMeta.hasMapView() + ) { + MapView mapView = mapMeta.getMapView(); + assert mapView != null; + mapView.setTrackingPosition(false); + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + private void onChunkLoad(ChunkLoadEvent event) { + if (event.isNewChunk()) return; + + for (Entity entity : event.getChunk().getEntities()) { + if (EntityUtil.ITEM_FRAMES.contains(entity.getType())) { + this.disableTracker((ItemFrame) entity); + } + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + private void onInteract(PlayerInteractEntityEvent event) { + Entity rightClicked = event.getRightClicked(); + if (EntityUtil.ITEM_FRAMES.contains(rightClicked.getType())) { + this.disableTracker((ItemFrame) rightClicked); + } + } +} diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java index b26b30214..7b1d9f4c3 100644 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java @@ -3,14 +3,19 @@ import org.bukkit.entity.EntityType; import java.util.HashSet; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; public class EntityUtil { - public static final HashSet BOATS = Stream.of( + public static final Set BOATS = Stream.of( EntityType.BOAT, EntityType.CHEST_BOAT ).collect(Collectors.toCollection(HashSet::new)); + public static final Set ITEM_FRAMES = Stream.of( + EntityType.ITEM_FRAME, + EntityType.GLOW_ITEM_FRAME + ).collect(Collectors.toCollection(HashSet::new)); } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index 93cc903c8..226942eda 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -23,6 +23,14 @@ public static boolean isAnvil(Material material) { }; } + public static boolean isMap(Material material) { + if (material == null) return false; + return switch (material) { + case MAP, FILLED_MAP -> true; + default -> false; + }; + } + public static boolean isBlockDispenseBucket(ItemStack item) { if (item == null) return false; return isBlockDispenseBucket(item.getType()); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java index 791c0b66f..101a70892 100644 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java @@ -4,16 +4,20 @@ import java.util.Arrays; import java.util.HashSet; +import java.util.Set; import java.util.stream.Collectors; public class EntityUtil { - public static final HashSet BOATS = Arrays.stream(EntityType.values()) + public static final Set BOATS = Arrays.stream(EntityType.values()) .filter(entityType -> entityType.name().toUpperCase().contains("BOAT")) .collect(Collectors.toCollection(HashSet::new)); - public static final HashSet MINECARTS = Arrays.stream(EntityType.values()) + public static final Set MINECARTS = Arrays.stream(EntityType.values()) .filter(entityType -> entityType.name().toUpperCase().contains("MINECART")) .collect(Collectors.toCollection(HashSet::new)); + public static final Set ITEM_FRAMES = Arrays.stream(EntityType.values()) + .filter(entityType -> entityType.name().toUpperCase().contains("ITEM_FRAME")) + .collect(Collectors.toCollection(HashSet::new)); } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java index 93b619fa2..032af607d 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/MaterialUtil.java @@ -15,9 +15,9 @@ public class MaterialUtil { // Blocks that the player gets lowered into slightly when walking on them public static final Set SINK_IN_BLOCKS = Stream.of( - XMaterial.SOUL_SAND, - XMaterial.FARMLAND, - XMaterial.MUD + XMaterial.SOUL_SAND, + XMaterial.FARMLAND, + XMaterial.MUD ).filter(XMaterial::isSupported) .map(XMaterial::parseMaterial) .collect(Collectors.toCollection(HashSet::new)); @@ -29,9 +29,16 @@ public class MaterialUtil { .map(XMaterial::parseMaterial) .collect(Collectors.toCollection(HashSet::new)); + public static final Set MAPS = Stream.of( + XMaterial.MAP, + XMaterial.FILLED_MAP + ).filter(XMaterial::isSupported) + .map(XMaterial::parseMaterial) + .collect(Collectors.toCollection(HashSet::new)); + public static final Set REDSTONE = Stream.of( - XMaterial.REDSTONE, - XMaterial.REDSTONE_WIRE + XMaterial.REDSTONE, + XMaterial.REDSTONE_WIRE ).filter(XMaterial::isSupported) .map(XMaterial::parseMaterial) .collect(Collectors.toCollection(HashSet::new)); @@ -144,15 +151,15 @@ public static boolean isShulkerBox(ItemStack item) { .collect(Collectors.toCollection(HashSet::new)); public static final Set BLOCK_DISPENSE_BUCKETS = Stream.of( - XMaterial.WATER_BUCKET, - XMaterial.LAVA_BUCKET, - XMaterial.COD_BUCKET, - XMaterial.SALMON_BUCKET, - XMaterial.PUFFERFISH_BUCKET, - XMaterial.TROPICAL_FISH_BUCKET, - XMaterial.AXOLOTL_BUCKET, - XMaterial.TADPOLE_BUCKET, - XMaterial.POWDER_SNOW_BUCKET + XMaterial.WATER_BUCKET, + XMaterial.LAVA_BUCKET, + XMaterial.COD_BUCKET, + XMaterial.SALMON_BUCKET, + XMaterial.PUFFERFISH_BUCKET, + XMaterial.TROPICAL_FISH_BUCKET, + XMaterial.AXOLOTL_BUCKET, + XMaterial.TADPOLE_BUCKET, + XMaterial.POWDER_SNOW_BUCKET ).filter(XMaterial::isSupported) .map(XMaterial::parseMaterial) .collect(Collectors.toCollection(HashSet::new)); diff --git a/build-logic/src/main/kotlin/me.moomoo.anarchyexploitfixes.wrapper.gradle.kts b/build-logic/src/main/kotlin/me.moomoo.anarchyexploitfixes.wrapper.gradle.kts index 99ae38055..5b9e98d9a 100755 --- a/build-logic/src/main/kotlin/me.moomoo.anarchyexploitfixes.wrapper.gradle.kts +++ b/build-logic/src/main/kotlin/me.moomoo.anarchyexploitfixes.wrapper.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "me.moomoo.anarchyexploitfixes" -version = "2.6.3" +version = "2.6.4" description = "Prevent many exploits that affect anarchy servers." var url: String? = "github.com/moom0o/AnarchyExploitFixes"