Untitled

mail@pastecode.io avatar
unknown
java
3 years ago
2.5 kB
2
Indexable
Never
package com.liquake.antidupe.rareitemchecks.checks.containers;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.liquake.antidupe.rareitemchecks.checks.RareItemCheckModel;
import com.liquake.antidupe.rareitemchecks.utils.chunkfile.RegionChunkNBT;
import com.liquake.antidupe.rareitemchecks.utils.chunkfile.RegionFileNBT;

import org.bukkit.inventory.ItemStack;

import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTCompoundList;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NBTFile;
import de.tr7zw.changeme.nbtapi.NBTItem;
import de.tr7zw.changeme.nbtapi.NBTReflectionUtil;
import net.minecraft.server.v1_16_R3.NBTTagCompound;

public class ChunkTileEntitiesCheck extends RareItemCheckModel {

    @Override
    public void executeCheck(NBTFile playerDatFile, String playerName) {
        //
    }

    @Override
    public void executeCheck(RegionFileNBT region) {

        for (RegionChunkNBT chunk : region.getChunks()) {
            if (chunk == null) {
                // Skip empty chunks
                continue;
            }
            NBTCompoundList tileEntities = chunk.getTileEntities();
            if (tileEntities == null || tileEntities.isEmpty()) {
                continue;
            }

            for (int index = 0; index < tileEntities.size(); index++) {
                NBTCompound tileEntity = tileEntities.get(index);
                if (tileEntity == null || !tileEntity.hasKey("Items")) {
                    // Doens't contains an inventory skip check
                    continue;
                }
                System.out.println("tileEntity => " + tileEntity.toString());
                checkEntity(tileEntity);
            }

        }

    }

    private void checkEntity(NBTCompound tileEntity) {

        try {

            System.out.println("kjeys " + tileEntity.getKeys().toString());
            System.out.println("compound" + tileEntity.getCompound().toString());
            JsonArray arr = new JsonParser().parse(tileEntity.toString()).getAsJsonObject().get("Items").getAsJsonArray();
            if (arr.size() == 0) {
                return;
            }
            System.out.println("Arr not 0: " + tileEntity.getCompoundList("Items"));

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}