diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java index 258328f95..0f2dc67db 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/VehicleLimit.java @@ -5,6 +5,7 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.EntityUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; @@ -34,8 +35,7 @@ public VehicleLimit() { this.plugin = AnarchyExploitFixes.getInstance(); this.VEHICLE_TYPES = new HashSet<>(); // Used to cache entity types of vehicles for faster operations // Prefill with known types; - this.VEHICLE_TYPES.add(EntityType.BOAT); - this.VEHICLE_TYPES.add(EntityType.CHEST_BOAT); + this.VEHICLE_TYPES.addAll(EntityUtil.BOATS); this.VEHICLE_TYPES.addAll(EntityTags.HORSES.getValues()); this.VEHICLE_TYPES.addAll(EntityTags.MINECARTS.getValues()); Config config = AnarchyExploitFixes.getConfiguration(); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java index 380a44f78..5474bd49e 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java @@ -6,8 +6,8 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.utils.EntityUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; -import org.bukkit.entity.Boat; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -43,9 +43,10 @@ protected void register() { @Override public void onPacketReceiving(PacketEvent event) { if (event.isPlayerTemporary()) return; - Player player = event.getPlayer(); - Entity vehicle = player.getVehicle(); - if (!(vehicle instanceof Boat)) return; + final Player player = event.getPlayer(); + if (!player.isInsideVehicle()) return; + final Entity vehicle = player.getVehicle(); + if (!EntityUtil.BOATS.contains(vehicle.getType())) return; final UUID playerUniqueID = player.getUniqueId(); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java new file mode 100644 index 000000000..b26b30214 --- /dev/null +++ b/AnarchyExploitFixesFolia/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java @@ -0,0 +1,16 @@ +package me.moomoo.anarchyexploitfixes.utils; + +import org.bukkit.entity.EntityType; + +import java.util.HashSet; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class EntityUtil { + + public static final HashSet BOATS = Stream.of( + EntityType.BOAT, + EntityType.CHEST_BOAT + ).collect(Collectors.toCollection(HashSet::new)); + +} diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java index a60b629a4..49a336f52 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/chunklimits/MinecartLimit.java @@ -3,26 +3,22 @@ import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; import me.moomoo.anarchyexploitfixes.config.Config; import me.moomoo.anarchyexploitfixes.modules.AnarchyExploitFixesModule; +import me.moomoo.anarchyexploitfixes.utils.EntityUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Vehicle; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.vehicle.VehicleCreateEvent; -import java.util.Arrays; -import java.util.HashSet; import java.util.logging.Level; -import java.util.stream.Collectors; public class MinecartLimit implements AnarchyExploitFixesModule, Listener, Runnable { private final AnarchyExploitFixes plugin; - private final HashSet MINECART_TYPES; private final long checkPeriod; private final int maxMinecartsPerChunk; private final boolean logIsEnabled; @@ -30,9 +26,6 @@ public class MinecartLimit implements AnarchyExploitFixesModule, Listener, Runna public MinecartLimit() { shouldEnable(); this.plugin = AnarchyExploitFixes.getInstance(); - this.MINECART_TYPES = Arrays.stream(EntityType.values()) - .filter(type -> type.name().toUpperCase().contains("MINECART")) - .collect(Collectors.toCollection(HashSet::new)); Config config = AnarchyExploitFixes.getConfiguration(); config.addComment("chunk-limits.minecart-limit.enable", "Limit the amount of minecarts to prevent lag."); @@ -66,12 +59,12 @@ public boolean shouldEnable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onCreate(VehicleCreateEvent event) { Vehicle vehicle = event.getVehicle(); - if (!MINECART_TYPES.contains(vehicle.getType())) return; + if (!EntityUtil.MINECARTS.contains(vehicle.getType())) return; int minecartCount = 0; for (Entity entity : vehicle.getChunk().getEntities()) { - if (!MINECART_TYPES.contains(entity.getType())) continue; + if (!EntityUtil.MINECARTS.contains(entity.getType())) continue; minecartCount++; if (minecartCount <= maxMinecartsPerChunk) continue; @@ -91,7 +84,7 @@ public void run() { int minecartCount = 0; for (Entity entity : chunk.getEntities()) { - if (!MINECART_TYPES.contains(entity.getType())) continue; + if (!EntityUtil.MINECARTS.contains(entity.getType())) continue; minecartCount++; if (minecartCount <= maxMinecartsPerChunk) continue; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java index 007e16ff2..b3eaf92fb 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/boatfly/BoatFlyPositionPacketListener.java @@ -6,8 +6,8 @@ import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketEvent; import me.moomoo.anarchyexploitfixes.AnarchyExploitFixes; +import me.moomoo.anarchyexploitfixes.utils.EntityUtil; import me.moomoo.anarchyexploitfixes.utils.LogUtil; -import org.bukkit.entity.Boat; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -43,9 +43,10 @@ protected void register() { @Override public void onPacketReceiving(PacketEvent event) { if (event.isPlayerTemporary()) return; - Player player = event.getPlayer(); - Entity vehicle = player.getVehicle(); - if (!(vehicle instanceof Boat)) return; + final Player player = event.getPlayer(); + if (!player.isInsideVehicle()) return; + final Entity vehicle = player.getVehicle(); + if (!EntityUtil.BOATS.contains(vehicle.getType())) return; UUID playerUniqueID = player.getUniqueId(); @@ -64,6 +65,7 @@ public void onPacketReceiving(PacketEvent event) { } plugin.getServer().getScheduler().runTask(plugin, vehicle::remove); + if (logIsEnabled) LogUtil.moduleLog(Level.INFO, log_name, "Prevented player '"+player.getName()+"' from boat flying"); if (shouldKickPlayer) diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComUseItemPacketListener.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComUseItemPacketListener.java index 59178203c..cc35c4335 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComUseItemPacketListener.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/modules/protocollib/nocom/NoComUseItemPacketListener.java @@ -34,5 +34,4 @@ public void onPacketReceiving(PacketEvent event) { event.setCancelled(true); } } - } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java new file mode 100644 index 000000000..791c0b66f --- /dev/null +++ b/AnarchyExploitFixesLegacy/src/main/java/me/moomoo/anarchyexploitfixes/utils/EntityUtil.java @@ -0,0 +1,19 @@ +package me.moomoo.anarchyexploitfixes.utils; + +import org.bukkit.entity.EntityType; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.stream.Collectors; + +public class EntityUtil { + + public static final HashSet 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()) + .filter(entityType -> entityType.name().toUpperCase().contains("MINECART")) + .collect(Collectors.toCollection(HashSet::new)); + +}