Search in sources :

Example 11 with Slot

use of net.minecraft.server.v1_9_R2.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 12 with Slot

use of net.minecraft.server.v1_9_R2.Slot in project MechanicsMain by WeaponMechanics.

the class NBT_1_9_R2 method setAttribute.

@Nonnull
@Override
public void setAttribute(@Nonnull ItemStack bukkitItem, @Nonnull AttributeType attribute, @Nullable AttributeSlot slot, double value) {
    net.minecraft.server.v1_9_R2.ItemStack nmsItem = getNMSStack(bukkitItem);
    if (nmsItem.getTag() == null) {
        nmsItem.setTag(new NBTTagCompound());
    }
    NBTTagCompound compound = nmsItem.getTag();
    if (compound.hasKey("AttributeModifiers")) {
        NBTTagList list = (NBTTagList) compound.get("AttributeModifiers");
        // NBT lists don't have an indexOf method, so we need to loop
        // through each attribute, and determine if it is one we want to
        // modify. We want to modify an attribute if the attribute was
        // set using MechanicsCore, and it's attribute type matches the
        // parameter attribute type.
        boolean isModifiedAttribute = false;
        for (int i = 0; i < list.size(); i++) {
            // 10 is the id for nbt lists
            if (list.get(i).getTypeId() != 10) {
                continue;
            }
            NBTTagCompound nbt = list.get(i);
            String name = nbt.getString("Name");
            String attributeName = nbt.getString("AttributeName");
            // There is no offhand, or slot argument in 1_8_8.
            if (!"MechanicsCoreAttribute".equals(name) || !attribute.getMinecraftName().equals(attributeName)) {
                continue;
            }
            // Since this attribute already exists, we only need to modify
            // the existing value. No need to set the name/uuid
            nbt.setDouble("Amount", value);
            isModifiedAttribute = true;
            break;
        }
        if (!isModifiedAttribute) {
            NBTTagCompound nbt = new NBTTagCompound();
            nbt.setString("AttributeName", attribute.getMinecraftName());
            nbt.setString("Name", "MechanicsCoreAttribute");
            nbt.setDouble("Amount", value);
            // 0 == add
            nbt.setInt("Operation", 0);
            nbt.setLong("UUIDLeast", attribute.getUUID().getLeastSignificantBits());
            nbt.setLong("UUIDMost", attribute.getUUID().getMostSignificantBits());
            if (slot != null) {
                nbt.setString("Slot", slot.getSlotName());
            }
        }
    }
    bukkitItem.setItemMeta(CraftItemStack.getItemMeta(nmsItem));
}
Also used : NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) Nonnull(javax.annotation.Nonnull)

Example 13 with Slot

use of net.minecraft.server.v1_9_R2.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.12.2
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) theseSlots.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return ItemStack.a;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return ItemStack.a;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.f();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_13_R2.Slot) ItemStack(net.minecraft.server.v1_13_R2.ItemStack)

Example 14 with Slot

use of net.minecraft.server.v1_9_R2.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method b.

/**
 * The shift clicking method
 */
@Override
public ItemStack b(EntityHuman entityhuman, int i) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.c.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return null;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return null;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return null;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return null;
        }
        slot.f();
        if (itemstack1.count == itemstack.count) {
            return null;
        }
        slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack1, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_8_R3.Slot) ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Example 15 with Slot

use of net.minecraft.server.v1_9_R2.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.15.1
@Override
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) this.slots.get(i);
    if (slot != null && slot.hasItem()) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            this.containerAccess.a((world, blockposition) -> {
                itemstack1.getItem().b(itemstack1, world, entityhuman);
            });
            if (!this.a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if (i >= 10 && i < 46 ? !this.a(itemstack1, 1, 10, false) && (i < 37 ? !this.a(itemstack1, 37, 46, false) : !this.a(itemstack1, 10, 37, false)) : !this.a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.d();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : Slot(net.minecraft.server.v1_15_R1.Slot) ItemStack(net.minecraft.server.v1_15_R1.ItemStack)

Aggregations

Slot (net.minecraft.server.v1_12_R1.Slot)3 ItemStack (net.minecraft.server.v1_9_R2.ItemStack)3 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 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)2 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)1 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)1 CustomInventory (de.Keyle.MyPet.compat.v1_9_R2.util.inventory.CustomInventory)1 TokenType (ee.ria.xroad.signer.tokenmanager.token.TokenType)1 PKCS11Exception (iaik.pkcs.pkcs11.wrapper.PKCS11Exception)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1