Skip to content

Commit

Permalink
patch stacked map cursors on folia
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Jan 24, 2024
1 parent 8500da2 commit e4d33a6
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityType> BOATS = Stream.of(
public static final Set<EntityType> BOATS = Stream.of(
EntityType.BOAT,
EntityType.CHEST_BOAT
).collect(Collectors.toCollection(HashSet::new));

public static final Set<EntityType> ITEM_FRAMES = Stream.of(
EntityType.ITEM_FRAME,
EntityType.GLOW_ITEM_FRAME
).collect(Collectors.toCollection(HashSet::new));
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityType> BOATS = Arrays.stream(EntityType.values())
public static final Set<EntityType> BOATS = Arrays.stream(EntityType.values())
.filter(entityType -> entityType.name().toUpperCase().contains("BOAT"))
.collect(Collectors.toCollection(HashSet::new));

public static final HashSet<EntityType> MINECARTS = Arrays.stream(EntityType.values())
public static final Set<EntityType> MINECARTS = Arrays.stream(EntityType.values())
.filter(entityType -> entityType.name().toUpperCase().contains("MINECART"))
.collect(Collectors.toCollection(HashSet::new));

public static final Set<EntityType> ITEM_FRAMES = Arrays.stream(EntityType.values())
.filter(entityType -> entityType.name().toUpperCase().contains("ITEM_FRAME"))
.collect(Collectors.toCollection(HashSet::new));
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class MaterialUtil {

// Blocks that the player gets lowered into slightly when walking on them
public static final Set<Material> 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));
Expand All @@ -29,9 +29,16 @@ public class MaterialUtil {
.map(XMaterial::parseMaterial)
.collect(Collectors.toCollection(HashSet::new));

public static final Set<Material> MAPS = Stream.of(
XMaterial.MAP,
XMaterial.FILLED_MAP
).filter(XMaterial::isSupported)
.map(XMaterial::parseMaterial)
.collect(Collectors.toCollection(HashSet::new));

public static final Set<Material> REDSTONE = Stream.of(
XMaterial.REDSTONE,
XMaterial.REDSTONE_WIRE
XMaterial.REDSTONE,
XMaterial.REDSTONE_WIRE
).filter(XMaterial::isSupported)
.map(XMaterial::parseMaterial)
.collect(Collectors.toCollection(HashSet::new));
Expand Down Expand Up @@ -144,15 +151,15 @@ public static boolean isShulkerBox(ItemStack item) {
.collect(Collectors.toCollection(HashSet::new));

public static final Set<Material> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit e4d33a6

Please sign in to comment.