diff --git a/src/main/java/cn/dreeam/surf/modules/patch/NBTBan.java b/src/main/java/cn/dreeam/surf/modules/patch/NBTBan.java index df042e6..ec724d0 100644 --- a/src/main/java/cn/dreeam/surf/modules/patch/NBTBan.java +++ b/src/main/java/cn/dreeam/surf/modules/patch/NBTBan.java @@ -2,46 +2,46 @@ import cn.dreeam.surf.config.Config; import cn.dreeam.surf.util.Util; -import de.tr7zw.changeme.nbtapi.NBT; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.Inventory; - -import java.util.concurrent.atomic.AtomicInteger; +import org.bukkit.inventory.ItemStack; public class NBTBan implements Listener { - @EventHandler(ignoreCancelled = true) + @EventHandler public void onJoin(PlayerJoinEvent event) { if (!Config.preventNBTBanEnabled) return; Inventory inv = event.getPlayer().getInventory(); - AtomicInteger itemSize = new AtomicInteger(); - // TODO if (Util.isNewerAndEqual(20, 5)) { - inv.forEach(i -> { + for (ItemStack i : inv) { if (i != null && i.getType().name().contains("SHULKER_BOX")) { - itemSize.addAndGet(NBT.itemStackToNBT(i).toString().length()); + if (!i.hasItemMeta()) continue; + + int itemSize = i.getItemMeta().getAsComponentString().length(); - if (itemSize.get() > Config.preventNBTBanLimit) { + if (itemSize > Config.preventNBTBanLimit) { inv.remove(i); Util.sendMessage(event.getPlayer(), Config.preventNBTBanMessage); } } - }); + } } else { - inv.forEach(i -> { + for (ItemStack i : inv) { if (i != null && i.getType().name().contains("SHULKER_BOX")) { - itemSize.addAndGet(NBT.itemStackToNBT(i).toString().length()); + if (!i.hasItemMeta()) continue; + + int itemSize = i.getItemMeta().getAsString().length(); - if (itemSize.get() > Config.preventNBTBanLimit) { + if (itemSize > Config.preventNBTBanLimit) { inv.remove(i); Util.sendMessage(event.getPlayer(), Config.preventNBTBanMessage); } } - }); + } } } }