Skip to content

Commit

Permalink
Fix prevent nbt ban
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Aug 13, 2024
1 parent a8ee59e commit d9f9356
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/main/java/cn/dreeam/surf/modules/patch/NBTBan.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
}
}
}

0 comments on commit d9f9356

Please sign in to comment.