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);
}
}
}
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);
}
}
}
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);
}
}
}
}
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());
}
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()));
}
Aggregations