From 87d7ba19de387dad79f726681e769c9cde392e0b Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:06:56 +0100 Subject: [PATCH 01/10] 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 From 42b68011eafaab38bfb0c75800df4ee1558074d9 Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:09:22 +0100 Subject: [PATCH 02/10] Improve distance check --- .../me/totalfreedom/totalfreedommod/MovementValidator.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 10b82409..30520467 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -44,8 +44,9 @@ public class MovementValidator extends FreedomService final Player player = event.getPlayer(); Location from = event.getFrom(); Location to = event.getTo(); + double distance = from.distanceSquared(to); - if (to.getX() >= from.getX() + MAX_DISTANCE_TRAVELED || to.getY() >= from.getY() + MAX_DISTANCE_TRAVELED || to.getZ() >= from.getZ() + MAX_DISTANCE_TRAVELED) + if (distance >= MAX_DISTANCE_TRAVELED) { event.setCancelled(true); player.kickPlayer(ChatColor.RED + "You were moving too quickly!"); From cca95dc3f1a45b525a616cfce494563c70513235 Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:14:02 +0100 Subject: [PATCH 03/10] Add dedicated method for checking if a position is out of bounds --- .../totalfreedommod/MovementValidator.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 30520467..1dcbbf61 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -2,7 +2,6 @@ package me.totalfreedom.totalfreedommod; import io.papermc.lib.PaperLib; -import java.util.Objects; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -32,12 +31,17 @@ public class MovementValidator extends FreedomService public void onPlayerTeleport(PlayerTeleportEvent event) { // Check absolute value to account for negatives - if (Math.abs(Objects.requireNonNull(event.getTo()).getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD) + if (isOutOfBounds(event.getTo())) { event.setCancelled(true); // illegal position, cancel it } } + private boolean isOutOfBounds(final Location position) + { + return Math.abs(position.getX()) >= MAX_XYZ_COORD || Math.abs(position.getY()) >= MAX_XYZ_COORD || Math.abs(position.getZ()) >= MAX_XYZ_COORD; + } + @EventHandler(priority = EventPriority.HIGH) public void onPlayerMove(PlayerMoveEvent event) { @@ -52,7 +56,7 @@ public class MovementValidator extends FreedomService player.kickPlayer(ChatColor.RED + "You were moving too quickly!"); } // Check absolute value to account for negatives - if (Math.abs(event.getTo().getX()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getZ()) >= MAX_XYZ_COORD || Math.abs(event.getTo().getY()) >= MAX_XYZ_COORD) + if (isOutOfBounds(event.getTo())) { event.setCancelled(true); PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); @@ -65,7 +69,7 @@ public class MovementValidator extends FreedomService final Player player = event.getPlayer(); // Validate position - if (Math.abs(player.getLocation().getX()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getZ()) >= MAX_XYZ_COORD || Math.abs(player.getLocation().getY()) >= MAX_XYZ_COORD) + if (isOutOfBounds(player.getLocation())) { PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn } From d30e335f577a713f6a5d976a397ac4fdd9f0c30e Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:17:18 +0100 Subject: [PATCH 04/10] Disallow custom spawns that are out of bounds --- .../totalfreedommod/MovementValidator.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 1dcbbf61..7b70158b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -10,6 +10,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerTeleportEvent; +import org.spigotmc.event.player.PlayerSpawnLocationEvent; public class MovementValidator extends FreedomService { @@ -74,4 +75,23 @@ public class MovementValidator extends FreedomService PaperLib.teleportAsync(player, player.getWorld().getSpawnLocation()); // Illegal position, teleport to spawn } } + + @EventHandler(priority = EventPriority.HIGH) + public void onPlayerSpawn(PlayerSpawnLocationEvent event) + { + final Location playerSpawn = event.getSpawnLocation(); + final Location worldSpawn = event.getPlayer().getWorld().getSpawnLocation(); + + // If the player's spawn is equal to the world's spawn, there is no need to check. + // This will also prevent any possible feedback loops pertaining to setting an out of bounds world spawn to the same world spawn. + if (playerSpawn == worldSpawn) + { + return; + } + + if (isOutOfBounds(worldSpawn)) + { + event.setSpawnLocation(worldSpawn); + } + } } \ No newline at end of file From dcebf7bbe7e99f852910cb114c126344a05e1315 Mon Sep 17 00:00:00 2001 From: Allink Date: Sat, 17 Jun 2023 20:22:23 +0100 Subject: [PATCH 05/10] Use Adventure for kick message --- .../me/totalfreedom/totalfreedommod/MovementValidator.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java index 7b70158b..764e1515 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/MovementValidator.java @@ -2,7 +2,8 @@ package me.totalfreedom.totalfreedommod; import io.papermc.lib.PaperLib; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -54,7 +55,7 @@ public class MovementValidator extends FreedomService if (distance >= MAX_DISTANCE_TRAVELED) { event.setCancelled(true); - player.kickPlayer(ChatColor.RED + "You were moving too quickly!"); + player.kick(Component.text("You were moving too quickly!", NamedTextColor.RED)); } // Check absolute value to account for negatives if (isOutOfBounds(event.getTo())) From 0e7a2d9bce371280dae03e9ccd8a0a265a0f641e Mon Sep 17 00:00:00 2001 From: Allink Date: Tue, 20 Jun 2023 04:32:45 +0100 Subject: [PATCH 06/10] Update to 1.19.4 --- pom.xml | 2 +- src/main/resources/plugin.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d9ed9205..b9784b81 100644 --- a/pom.xml +++ b/pom.xml @@ -130,7 +130,7 @@ io.papermc.paper paper-api - 1.17.1-R0.1-SNAPSHOT + 1.19.4-R0.1-SNAPSHOT provided diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 308beb03..86af8238 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,4 +14,4 @@ softdepend: - JDA - Votifier authors: [Madgeek1450, Prozza] -api-version: "1.17" \ No newline at end of file +api-version: "1.19" \ No newline at end of file From 2fa7b6855b2a99ee6a4d8a9252b71a20915a2c60 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Tue, 11 Jul 2023 09:05:04 -0500 Subject: [PATCH 07/10] Update pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b9784b81..72b5b6d9 100644 --- a/pom.xml +++ b/pom.xml @@ -128,8 +128,8 @@ - io.papermc.paper - paper-api + me.totalfreedom.scissors + Scissors-API 1.19.4-R0.1-SNAPSHOT provided From 171daf25a416438e1563df61340ab18e0203ab77 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Tue, 11 Jul 2023 09:06:11 -0500 Subject: [PATCH 08/10] Update plugin.yml --- src/main/resources/plugin.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 86af8238..7fb91d74 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,4 +14,9 @@ softdepend: - JDA - Votifier authors: [Madgeek1450, Prozza] -api-version: "1.19" \ No newline at end of file +api-version: "1.19" +libraries: + - org.apache.commons:commons-lang3:3.12.0 + - commons-io:commons-io:2.11.0 + - org.jetbrains:annotations:23.0.0 + - org.javassist:javassist:3.29.1-GA From 268b71f8a39f288342dfe32c07c0fc720f4b85ce Mon Sep 17 00:00:00 2001 From: Paldiu Date: Tue, 11 Jul 2023 11:38:45 -0500 Subject: [PATCH 09/10] Update plugin.yml --- src/main/resources/plugin.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7fb91d74..cb414b02 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -10,7 +10,6 @@ softdepend: - WorldEdit - WorldGuard - WorldGuardExtraFlags - - TFGuilds - JDA - Votifier authors: [Madgeek1450, Prozza] From ee594e7c6336df9e8bf26a1c828f0e3d1ab0c677 Mon Sep 17 00:00:00 2001 From: Allink Date: Sun, 23 Jul 2023 00:04:46 +0100 Subject: [PATCH 10/10] Add configuration value for player item drops --- .../totalfreedommod/blocking/EventBlocker.java | 2 +- .../totalfreedommod/command/Command_toggle.java | 12 +++++++++--- .../totalfreedommod/config/ConfigEntry.java | 1 + src/main/resources/config.yml | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java index fb3713cd..7b85d13d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/EventBlocker.java @@ -161,7 +161,7 @@ public class EventBlocker extends FreedomService @EventHandler(priority = EventPriority.NORMAL) public void onPlayerDropItem(PlayerDropItemEvent event) { - if (!plugin.al.isAdmin(event.getPlayer())) + if (!plugin.al.isAdmin(event.getPlayer()) && !ConfigEntry.ALLOW_ITEM_DROPS.getBoolean()) { event.setCancelled(true); } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index 712ff7ff..8cd16733 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -19,9 +19,9 @@ public class Command_toggle extends FreedomCommand private final List toggles = Arrays.asList( "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke [range] [count]", - "explosives [radius]", "unsafeenchs", "bells", "armorstands", "structureblocks", "jigsaws", "grindstones", - "jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", "mp44", - "landmines", "tossmob", "gravity"); + "explosives [radius]", "unsafeenchs", "bells", "armorstands", "structureblocks", "jigsaws", "item_drops", + "grindstones", "jukeboxes", "spawners", "4chan", "beehives", "respawnanchors", "autotp", "autoclear", "minecarts", + "mp44", "landmines", "tossmob", "gravity"); @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) @@ -205,6 +205,12 @@ public class Command_toggle extends FreedomCommand break; } + case "item_drops": + { + toggle("Item drops are", ConfigEntry.ALLOW_ITEM_DROPS); + break; + } + case "grindstones": { toggle("Grindstones are", ConfigEntry.ALLOW_GRINDSTONES); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 598c3d1f..66970325 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -35,6 +35,7 @@ public enum ConfigEntry AUTO_TP(Boolean.class, "allow.auto_tp"), AUTO_CLEAR(Boolean.class, "allow.auto_clear"), ALLOW_GRAVITY(Boolean.class, "allow.gravity"), + ALLOW_ITEM_DROPS(Boolean.class, "allow.item_drops"), // BLOCKED_CHATCODES(String.class, "blocked_chatcodes"), // diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d0f9ff4d..ce93f972 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -234,6 +234,7 @@ allow: auto_tp: false auto_clear: false gravity: false + item_drops: false blocked_commands: #