From 9f22115b309e34a5a31197bbf17a41b9f9492515 Mon Sep 17 00:00:00 2001 From: Super_ Date: Mon, 25 Nov 2019 23:08:13 -0500 Subject: [PATCH] patch jukebox exploit (#157) he beat seth omg --- .../totalfreedommod/TotalFreedomMod.java | 3 + .../blocking/BlockBlocker.java | 2 + .../blocking/InventoryBlocker.java | 63 +++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/blocking/InventoryBlocker.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java index 48893d42..aa9a6160 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/TotalFreedomMod.java @@ -12,6 +12,7 @@ import me.totalfreedom.totalfreedommod.blocking.BlockBlocker; import me.totalfreedom.totalfreedommod.blocking.EditBlocker; import me.totalfreedom.totalfreedommod.blocking.EventBlocker; import me.totalfreedom.totalfreedommod.blocking.InteractBlocker; +import me.totalfreedom.totalfreedommod.blocking.InventoryBlocker; import me.totalfreedom.totalfreedommod.blocking.MobBlocker; import me.totalfreedom.totalfreedommod.blocking.PVPBlocker; import me.totalfreedom.totalfreedommod.blocking.PotionBlocker; @@ -87,6 +88,7 @@ public class TotalFreedomMod extends AeroPlugin public MobBlocker mb; public InteractBlocker ib; public PotionBlocker pb; + public InventoryBlocker inb; public LoginProcess lp; public AntiNuke nu; public AntiSpam as; @@ -194,6 +196,7 @@ public class TotalFreedomMod extends AeroPlugin mb = services.registerService(MobBlocker.class); ib = services.registerService(InteractBlocker.class); pb = services.registerService(PotionBlocker.class); + inb = services.registerService(InventoryBlocker.class); lp = services.registerService(LoginProcess.class); nu = services.registerService(AntiNuke.class); as = services.registerService(AntiSpam.class); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java index 75f89596..63c1014a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/BlockBlocker.java @@ -118,10 +118,12 @@ public class BlockBlocker extends FreedomService break; } case SPAWNER: + { player.sendMessage(ChatColor.GRAY + "Spawners are disabled."); player.getInventory().setItem(player.getInventory().getHeldItemSlot(), new ItemStack(Material.COOKIE, 1)); event.setCancelled(true); break; + } } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/blocking/InventoryBlocker.java b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InventoryBlocker.java new file mode 100644 index 00000000..5b1de26f --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/blocking/InventoryBlocker.java @@ -0,0 +1,63 @@ +package me.totalfreedom.totalfreedommod.blocking; + +import me.totalfreedom.totalfreedommod.FreedomService; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import net.minecraft.server.v1_14_R1.NBTTagCompound; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +public class InventoryBlocker extends FreedomService +{ + public InventoryBlocker(TotalFreedomMod plugin) + { + super(plugin); + } + + private BukkitTask inventoryChecker; + + @Override + protected void onStart() + { + inventoryChecker = new BukkitRunnable() + { + @Override + public void run() + { + for (Player player : Bukkit.getOnlinePlayers()) + { + Inventory inv = player.getInventory(); + for (int i = 0; i < inv.getSize(); i++) + { + ItemStack item = inv.getItem(i); + if (item == null) + continue; + if (!item.hasItemMeta()) + continue; + if (item.getType() == Material.JUKEBOX) + { + if (!CraftItemStack.asNMSCopy(item).hasTag()) + continue; + net.minecraft.server.v1_14_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(item); + NBTTagCompound compound = nmsItem.getTag(); + compound.set("BlockEntityTag", null); + inv.setItem(i, new ItemStack(CraftItemStack.asBukkitCopy(nmsItem))); + } + } + } + } + }.runTaskTimer(plugin, 0L, 1); + } + + @Override + protected void onStop() + { + inventoryChecker.cancel(); + inventoryChecker = null; + } +}