From 87d7ba19de387dad79f726681e769c9cde392e0b Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:06:56 +0100 Subject: [PATCH] Remove inventory checks in MovementValidator --- .../totalfreedommod/MovementValidator.java | 111 +----------------- 1 file changed, 1 insertion(+), 110 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index e2b621af..10b82409 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -1,25 +1,16 @@ package me.totalfreedom.totalfreedommod; -import com.google.common.collect.Multimap; import io.papermc.lib.PaperLib; -import java.util.Collection; -import java.util.Map; import java.util.Objects; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; public class MovementValidator extends FreedomService { @@ -53,7 +44,7 @@ public class MovementValidator extends FreedomService final Player player = event.getPlayer(); Location from = event.getFrom(); Location to = event.getTo(); - assert to != null; + if (to.getX() >= from.getX() + MAX_DISTANCE_TRAVELED || to.getY() >= from.getY() + MAX_DISTANCE_TRAVELED || to.getZ() >= from.getZ() + MAX_DISTANCE_TRAVELED) { event.setCancelled(true); @@ -65,43 +56,6 @@ public class MovementValidator extends FreedomService event.setCancelled(true); PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); } - - if (exploitItem(event.getPlayer().getInventory().getHelmet())) - { - event.getPlayer().getInventory().setHelmet(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your helmet slot."); - event.setCancelled(true); - } - if (exploitItem(event.getPlayer().getInventory().getBoots())) - { - event.getPlayer().getInventory().setBoots(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your boots slot."); - event.setCancelled(true); - } - if (exploitItem(event.getPlayer().getInventory().getLeggings())) - { - event.getPlayer().getInventory().setLeggings(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your leggings slot."); - event.setCancelled(true); - } - if (exploitItem(event.getPlayer().getInventory().getChestplate())) - { - event.getPlayer().getInventory().setChestplate(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your chestplate slot."); - event.setCancelled(true); - } - if (exploitItem(event.getPlayer().getInventory().getItemInMainHand())) - { - event.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your hand."); - event.setCancelled(true); - } - if (exploitItem(event.getPlayer().getInventory().getItemInOffHand())) - { - event.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your offhand."); - event.setCancelled(true); - } } @EventHandler(priority = EventPriority.HIGH) @@ -115,67 +69,4 @@ public class MovementValidator extends FreedomService PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn } } - - @EventHandler - public void onPlayerHoldItem(PlayerItemHeldEvent event) - { - if (exploitItem(event.getPlayer().getInventory().getItemInMainHand())) - { - event.getPlayer().getInventory().setItemInMainHand(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your hand."); - } - if (exploitItem(event.getPlayer().getInventory().getItemInOffHand())) - { - event.getPlayer().getInventory().setItemInOffHand(new ItemStack(Material.AIR)); - event.getPlayer().sendMessage(ChatColor.RED + "An item with both negative infinity and positive infinity attributes was cleared from your offhand."); - } - } - - private Boolean exploitItem(ItemStack item) - { - if (item == null) - { - return false; - } - - ItemMeta meta = item.getItemMeta(); - if (meta != null) - { - Multimap attributes = meta.getAttributeModifiers(); - if (attributes != null) - { - Map> attrMap = attributes.asMap(); - - // For every attribute... - for (Attribute attr : attributes.keySet()) - { - // Default values - boolean posInf = false; - boolean negInf = false; - - // For every AttributeModifier... - for (AttributeModifier modifier : attrMap.get(attr)) - { - // Are they ∞ or -∞? - if (modifier.getAmount() == Double.POSITIVE_INFINITY) - { - posInf = true; - } - else if (modifier.getAmount() == Double.NEGATIVE_INFINITY) - { - negInf = true; - } - } - - // Are both values set as true? - if (posInf && negInf) - { - return true; - } - } - } - - } - return false; - } } \ No newline at end of file