diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java index fee262e1..dad0bfac 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java @@ -1,9 +1,8 @@ package me.xginko.aef.modules.combat; +import com.cryptomorin.xseries.XMaterial; import me.xginko.aef.modules.AEFModule; import me.xginko.aef.utils.models.ExpiringSet; -import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -11,7 +10,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; import java.time.Duration; import java.util.UUID; @@ -51,31 +49,29 @@ public void disable() { private void onAnchorBreak(PlayerInteractEvent event) { if (breakDelayMillis <= 0) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - final ItemStack interactItem = event.getItem(); - if (interactItem == null || interactItem.getType() != Material.GLOWSTONE) return; - final Player player = event.getPlayer(); - if (player.getWorld().isRespawnAnchorWorks()) return; + if (event.getClickedBlock().getType() != XMaterial.RESPAWN_ANCHOR.parseMaterial()) return; + if (event.getItem() == null || event.getItem().getType() != XMaterial.GLOWSTONE.parseMaterial()) return; + if (event.getPlayer().getWorld().isRespawnAnchorWorks()) return; - if (breakCooldowns.contains(player.getUniqueId())) { + if (breakCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); if (updateInv) event.getPlayer().updateInventory(); } else { - breakCooldowns.add(player.getUniqueId()); + breakCooldowns.add(event.getPlayer().getUniqueId()); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onAnchorPlace(BlockPlaceEvent event) { if (placeDelayMillis <= 0) return; - if (event.getBlock().getType() != Material.RESPAWN_ANCHOR) return; - final Player player = event.getPlayer(); - if (player.getWorld().isRespawnAnchorWorks()) return; + if (event.getBlock().getType() != XMaterial.RESPAWN_ANCHOR.parseMaterial()) return; + if (event.getPlayer().getWorld().isRespawnAnchorWorks()) return; - if (placeCooldowns.contains(player.getUniqueId())) { + if (placeCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); if (updateInv) event.getPlayer().updateInventory(); } else { - placeCooldowns.add(player.getUniqueId()); + placeCooldowns.add(event.getPlayer().getUniqueId()); } } } \ No newline at end of file diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java index fe3cde97..83b999f1 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java @@ -4,7 +4,6 @@ import io.papermc.paper.event.player.PlayerBedFailEnterEvent; import me.xginko.aef.modules.AEFModule; import me.xginko.aef.utils.models.ExpiringSet; -import org.bukkit.block.Block; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -57,8 +56,7 @@ private void onBedBreak(PlayerBedFailEnterEvent event) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBedPlace(BlockPlaceEvent event) { if (placeDelayMillis <= 0) return; - final Block placed = event.getBlockPlaced(); - if (!MaterialTags.BEDS.isTagged(placed) || placed.getWorld().isBedWorks()) return; + if (!MaterialTags.BEDS.isTagged(event.getBlockPlaced()) || event.getBlockPlaced().getWorld().isBedWorks()) return; if (placeCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BowBomb.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BowBomb.java index 8664811b..eb6c83ef 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BowBomb.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/BowBomb.java @@ -1,7 +1,7 @@ package me.xginko.aef.modules.combat; +import com.cryptomorin.xseries.XEntityType; import me.xginko.aef.modules.AEFModule; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -35,10 +35,9 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onProjectileLaunch(EntityShootBowEvent event) { - if ( - event.getEntityType() == EntityType.PLAYER - && event.getProjectile().getVelocity().lengthSquared() > maxBowSquaredVelocity - ) { + if (event.getEntityType() != XEntityType.PLAYER.get()) return; // Skeletons also shoot bows + + if (event.getProjectile().getVelocity().lengthSquared() > maxBowSquaredVelocity) { event.setCancelled(true); } } diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/Burrow.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/Burrow.java index 9113b1ee..c13ee99b 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/Burrow.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/Burrow.java @@ -68,7 +68,7 @@ private void onSelfPlace(BlockPlaceEvent event) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onPlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); - if (!player.getGameMode().equals(GameMode.SURVIVAL)) return; + if (player.getGameMode() != GameMode.SURVIVAL) return; if (player.isInsideVehicle() || player.isGliding()) return; final Location playerLocation = player.getLocation(); diff --git a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java index ac4b0893..822ba510 100755 --- a/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java +++ b/AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java @@ -51,21 +51,20 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onCrystalBreak(PrePlayerAttackEntityEvent event) { if (breakDelayMillis <= 0 || !event.willAttack()) return; + if (event.getAttacked().getType() != XEntityType.END_CRYSTAL.get()) return; - if (event.getAttacked().getType() == XEntityType.END_CRYSTAL.get()) { - if (breakCooldowns.contains(event.getPlayer().getUniqueId())) { - event.setCancelled(true); - if (updateInv) event.getPlayer().updateInventory(); - } else { - breakCooldowns.add(event.getPlayer().getUniqueId()); - } + if (breakCooldowns.contains(event.getPlayer().getUniqueId())) { + event.setCancelled(true); + if (updateInv) event.getPlayer().updateInventory(); + } else { + breakCooldowns.add(event.getPlayer().getUniqueId()); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onCrystalPlace(PlayerInteractEvent event) { if (placeDelayMillis <= 0) return; - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; // Need to right-click a block to place a crystal final ItemStack interactItem = event.getItem(); if (interactItem == null || interactItem.getType() != XMaterial.END_CRYSTAL.parseMaterial()) return; diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java index 175b0894..3514f210 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/AnchorAuraDelay.java @@ -5,7 +5,6 @@ import me.xginko.aef.utils.WorldUtil; import me.xginko.aef.utils.models.ExpiringSet; import org.bukkit.Material; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -13,7 +12,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; import java.time.Duration; import java.util.UUID; @@ -21,13 +19,12 @@ public class AnchorAuraDelay extends AEFModule implements Listener { private final ExpiringSet placeCooldowns, breakCooldowns; - private final Material RESPAWN_ANCHOR, GLOWSTONE; + private final Material GLOWSTONE; private final long placeDelayMillis, breakDelayMillis; private final boolean updateInv; public AnchorAuraDelay() { super("combat.anchor-aura-delay"); - this.RESPAWN_ANCHOR = XMaterial.RESPAWN_ANCHOR.parseMaterial(); this.GLOWSTONE = XMaterial.GLOWSTONE.parseMaterial(); this.updateInv = config.getBoolean(configPath + ".update-inventory-on-cancel", false, "Can help with desync but recommended to leave off unless needed."); @@ -56,31 +53,29 @@ public void disable() { private void onAnchorBreak(PlayerInteractEvent event) { if (breakDelayMillis <= 0) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - final ItemStack interactItem = event.getItem(); - if (interactItem == null || interactItem.getType() != GLOWSTONE) return; - final Player player = event.getPlayer(); - if (WorldUtil.isRespawnAnchorWorks(player.getWorld())) return; + if (event.getClickedBlock().getType() != XMaterial.RESPAWN_ANCHOR.parseMaterial()) return; + if (event.getItem() == null || event.getItem().getType() != XMaterial.GLOWSTONE.parseMaterial()) return; + if (WorldUtil.isRespawnAnchorWorks(event.getPlayer().getWorld())) return; - if (breakCooldowns.contains(player.getUniqueId())) { + if (breakCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); if (updateInv) event.getPlayer().updateInventory(); } else { - breakCooldowns.add(player.getUniqueId()); + breakCooldowns.add(event.getPlayer().getUniqueId()); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onAnchorPlace(BlockPlaceEvent event) { if (placeDelayMillis <= 0) return; - if (event.getBlock().getType() != RESPAWN_ANCHOR) return; - final Player player = event.getPlayer(); - if (WorldUtil.isRespawnAnchorWorks(player.getWorld())) return; + if (event.getBlock().getType() != XMaterial.RESPAWN_ANCHOR.parseMaterial()) return; + if (WorldUtil.isRespawnAnchorWorks(event.getPlayer().getWorld())) return; - if (placeCooldowns.contains(player.getUniqueId())) { + if (placeCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); if (updateInv) event.getPlayer().updateInventory(); } else { - placeCooldowns.add(player.getUniqueId()); + placeCooldowns.add(event.getPlayer().getUniqueId()); } } } \ No newline at end of file diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java index f8112766..2ff9f057 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BedAuraDelay.java @@ -3,10 +3,9 @@ import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XTag; import me.xginko.aef.modules.AEFModule; +import me.xginko.aef.utils.WorldUtil; import me.xginko.aef.utils.models.ExpiringSet; 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; @@ -59,9 +58,8 @@ public void disable() { private void onBedBreak(PlayerInteractEvent event) { if (breakDelayMillis <= 0) return; if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - final Block clicked = event.getClickedBlock(); - if (!beds.contains(clicked.getType())) return; - if (clicked.getWorld().getEnvironment() == World.Environment.NORMAL) return; + if (!beds.contains(event.getClickedBlock().getType())) return; + if (WorldUtil.isBedWorks(event.getClickedBlock().getWorld())) return; if (breakCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); @@ -73,9 +71,8 @@ private void onBedBreak(PlayerInteractEvent event) { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onBedPlace(BlockPlaceEvent event) { if (placeDelayMillis <= 0) return; - final Block placed = event.getBlockPlaced(); - if (!beds.contains(placed.getType())) return; - if (placed.getWorld().getEnvironment() == World.Environment.NORMAL) return; + if (!beds.contains(event.getBlockPlaced().getType())) return; + if (WorldUtil.isBedWorks(event.getBlockPlaced().getWorld())) return; if (placeCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BowBomb.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BowBomb.java index 8664811b..eb6c83ef 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BowBomb.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/BowBomb.java @@ -1,7 +1,7 @@ package me.xginko.aef.modules.combat; +import com.cryptomorin.xseries.XEntityType; import me.xginko.aef.modules.AEFModule; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.HandlerList; @@ -35,10 +35,9 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onProjectileLaunch(EntityShootBowEvent event) { - if ( - event.getEntityType() == EntityType.PLAYER - && event.getProjectile().getVelocity().lengthSquared() > maxBowSquaredVelocity - ) { + if (event.getEntityType() != XEntityType.PLAYER.get()) return; // Skeletons also shoot bows + + if (event.getProjectile().getVelocity().lengthSquared() > maxBowSquaredVelocity) { event.setCancelled(true); } } diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java index e0eee167..f376cb08 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/combat/CrystalAuraDelay.java @@ -13,7 +13,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.inventory.ItemStack; import java.time.Duration; import java.util.UUID; @@ -54,26 +53,22 @@ public void disable() { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onCrystalBreak(EntityDamageByEntityEvent event) { if (breakDelayMillis <= 0) return; + if (event.getEntityType() != XEntityType.END_CRYSTAL.get()) return; + if (event.getDamager().getType() != XEntityType.PLAYER.get()) return; - if ( - event.getEntityType() == XEntityType.END_CRYSTAL.get() - && event.getDamager().getType() == XEntityType.PLAYER.get() - ) { - if (breakCooldowns.contains(event.getDamager().getUniqueId())) { - event.setCancelled(true); - if (updateInv) ((Player) event.getDamager()).updateInventory(); - } else { - breakCooldowns.add(event.getDamager().getUniqueId()); - } + if (breakCooldowns.contains(event.getDamager().getUniqueId())) { + event.setCancelled(true); + if (updateInv) ((Player) event.getDamager()).updateInventory(); + } else { + breakCooldowns.add(event.getDamager().getUniqueId()); } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) private void onCrystalPlace(PlayerInteractEvent event) { if (placeDelayMillis <= 0) return; - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; - final ItemStack interactItem = event.getItem(); - if (interactItem == null || interactItem.getType() != XMaterial.END_CRYSTAL.parseMaterial()) return; + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; // Need to right-click a block to place a crystal + if (event.getItem() == null || event.getItem().getType() != XMaterial.END_CRYSTAL.parseMaterial()) return; if (placeCooldowns.contains(event.getPlayer().getUniqueId())) { event.setCancelled(true); diff --git a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java index 8ccaa282..785cce63 100755 --- a/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java +++ b/AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/utils/WorldUtil.java @@ -7,14 +7,16 @@ public class WorldUtil { - private static final MethodHandle GET_MIN_WORLD_HEIGHT, RESPAWNANCHOR_WORKS; - private static final boolean GET_MIN_WORLD_HEIGHT_AVAILABLE, RESPAWN_ANCHOR_WORKS_AVAILABLE; + private static final MethodHandle GET_MIN_WORLD_HEIGHT, RESPAWNANCHOR_WORKS, BED_WORKS; + private static final boolean GET_MIN_WORLD_HEIGHT_AVAILABLE, RESPAWN_ANCHOR_WORKS_AVAILABLE, BED_WORKS_AVAILABLE; static { GET_MIN_WORLD_HEIGHT_AVAILABLE = Crafty.hasMethod(World.class, "getMinHeight"); GET_MIN_WORLD_HEIGHT = Crafty.findMethod(World.class, "getMinHeight", int.class); RESPAWN_ANCHOR_WORKS_AVAILABLE = Crafty.hasMethod(World.class, "isRespawnAnchorWorks"); RESPAWNANCHOR_WORKS = Crafty.findMethod(World.class, "isRespawnAnchorWorks", boolean.class); + BED_WORKS_AVAILABLE = Crafty.hasMethod(World.class, "isBedWorks"); + BED_WORKS = Crafty.findMethod(World.class, "isBedWorks", boolean.class); } public static int getMinWorldHeight(World world) { @@ -40,13 +42,26 @@ private static int getMinWorldHeightFromConfig(World world) { public static boolean isRespawnAnchorWorks(World world) { if (!RESPAWN_ANCHOR_WORKS_AVAILABLE) { - return world.getEnvironment() == World.Environment.NORMAL; + return world.getEnvironment() != World.Environment.NORMAL; } try { return (boolean) RESPAWNANCHOR_WORKS.invoke(world); } catch (Throwable t) { AnarchyExploitFixes.prefixedLogger().error("Error checking if respawn anchors work in world '{}'.", world.getName(), t); + return world.getEnvironment() != World.Environment.NORMAL; + } + } + + public static boolean isBedWorks(World world) { + if (!BED_WORKS_AVAILABLE) { + return world.getEnvironment() == World.Environment.NORMAL; + } + + try { + return (boolean) BED_WORKS.invoke(world); + } catch (Throwable t) { + AnarchyExploitFixes.prefixedLogger().error("Error checking if beds work in world '{}'.", world.getName(), t); return world.getEnvironment() == World.Environment.NORMAL; } }