Search in sources :

Example 11 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    int containerSlotsSize = 0;
    if (is_1_12_2) {
        containerSlotsSize = container.slots.size();
    } else {
        try {
            Field slotsField = Container.class.getField("c");
            List<Slot> slots = (List<Slot>) slotsField.get(container);
            containerSlotsSize = slots.size();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    for (int slot = 0; slot < containerSlotsSize; slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) Field(java.lang.reflect.Field) Container(net.minecraft.server.v1_12_R1.Container) Slot(net.minecraft.server.v1_12_R1.Slot) List(java.util.List) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 12 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.c.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_8_R3.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_8_R3.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 13 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project MyPet by xXKeyleXx.

the class IconMenuInventory method update.

@Override
public void update(IconMenu menu) {
    if (minecraftInventory != null) {
        for (int slot = 0; slot < size; slot++) {
            IconMenuItem menuItem = menu.getOption(slot);
            if (menuItem != null) {
                ItemStack item = createItemStack(menuItem);
                minecraftInventory.setItem(slot, item);
            } else {
                minecraftInventory.setItem(slot, null);
            }
        }
    }
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 14 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project X-Road by nordic-institute.

the class HardwareModuleWorker method listTokens.

@Override
protected List<TokenType> listTokens() throws Exception {
    log.trace("Listing tokens on module '{}'", module.getType());
    Slot[] slots = pkcs11Module.getSlotList(Module.SlotRequirement.TOKEN_PRESENT);
    if (slots.length == 0) {
        log.warn("Did not get any slots from module '{}'. Reinitializing module.", module.getType());
        // Error code doesn't really matter as long as it's PKCS11Exception
        throw new PKCS11Exception(PKCS11Constants.CKR_GENERAL_ERROR);
    }
    log.info("Module '{}' got {} slots", module.getType(), slots.length);
    for (int i = 0; i < slots.length; i++) {
        log.debug("Module '{}' Slot {} ID: {} (0x{})", module.getType(), i, slots[i].getSlotID(), Functions.toHexString(slots[i].getSlotID()));
    }
    // HSM slot ids defined in module data
    Set<Long> slotIds = module.getSlotIds();
    log.debug("Slot configuration for module '{}' defined as {}", module.getType(), slotIds.toString());
    Map<String, TokenType> tokens = new HashMap<>();
    for (int slotIndex = 0; slotIndex < slots.length; slotIndex++) {
        if (slotIds.isEmpty() || slotIds.contains(slots[slotIndex].getSlotID())) {
            TokenType token = createToken(slots, slotIndex);
            TokenType previous = tokens.putIfAbsent(token.getId(), token);
            if (previous == null) {
                log.info("Module '{}' slot #{} has token with ID '{}': {}", module.getType(), slotIndex, token.getId(), token);
            } else {
                log.info("Module '{}' slot #{} has token with ID '{}' but token with that ID is " + " already registered", module.getType(), slotIndex, token.getId());
            }
        }
    }
    return new ArrayList<>(tokens.values());
}
Also used : PKCS11Exception(iaik.pkcs.pkcs11.wrapper.PKCS11Exception) HardwareTokenType(ee.ria.xroad.signer.tokenmanager.token.HardwareTokenType) TokenType(ee.ria.xroad.signer.tokenmanager.token.TokenType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Slot(iaik.pkcs.pkcs11.Slot)

Example 15 with Slot

use of net.minecraft.server.v1_8_R3.Slot in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method serialize.

@Override
public String serialize(Inventory[] inventories) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutput dataOutput = new DataOutputStream(outputStream);
    NBTTagCompound tagCompound = new NBTTagCompound();
    tagCompound.setInt("Length", inventories.length);
    for (int slot = 0; slot < inventories.length; slot++) {
        NBTTagCompound inventoryCompound = new NBTTagCompound();
        serialize(inventories[slot], inventoryCompound);
        tagCompound.set(slot + "", inventoryCompound);
    }
    try {
        NBTCompressedStreamTools.a(tagCompound, dataOutput);
    } catch (Exception ex) {
        return null;
    }
    return "*" + new String(Base64.getEncoder().encode(outputStream.toByteArray()));
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ItemStack (net.minecraft.server.v1_8_R3.ItemStack)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)4 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)4 Slot (net.minecraft.server.v1_12_R1.Slot)3 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)2 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)2 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2 HardwareTokenType (ee.ria.xroad.signer.tokenmanager.token.HardwareTokenType)2 Slot (iaik.pkcs.pkcs11.Slot)2 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)2 Slot (net.minecraft.server.v1_11_R1.Slot)2 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)2 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)2 InventoryHolder (com.bgsoftware.wildchests.objects.inventory.InventoryHolder)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_8_R3.nbt.NbtTagCompound)1 CustomInventory (de.Keyle.MyPet.compat.v1_8_R3.util.inventory.CustomInventory)1 TokenType (ee.ria.xroad.signer.tokenmanager.token.TokenType)1 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1