use of org.spongepowered.api.item.inventory.Inventory in project HuskyCrates-Sponge by codeHusky.
the class TemplateCrateView method getInventory.
@Override
public Inventory getInventory() {
Inventory woop = Inventory.builder().property(InventoryDimension.PROPERTY_NAME, InventoryDimension.of(9, 1)).property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(Text.of(TextColors.DARK_RED, "INVALID CRATE TYPE!"))).listener(ClickInventoryEvent.class, evt -> evt.setCancelled(true)).build(plugin);
woop.offer(ItemStack.of(ItemTypes.BARRIER, 256 * 2 + 64));
for (Inventory e : woop.slots()) {
ItemStack b = e.peek().get();
b.setQuantity(1);
e.set(b);
}
return woop;
}
use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.
the class FocusTeleporter method onRightClick.
@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
Optional<org.spongepowered.api.item.inventory.ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optHeldItem.isPresent()) {
return;
}
org.spongepowered.api.item.inventory.ItemStack held = optHeldItem.get();
if (held.getItem() != this) {
return;
}
Optional<Location<World>> optDestination = getDestination(held);
if (!optDestination.isPresent()) {
return;
}
Inventory result = player.getInventory().query((ItemType) Sponge.getRegistry().getType(ItemType.class, "skree:ender_focus").get());
if (result.size() > 0) {
Task.builder().execute(() -> {
result.poll(1);
player.setLocation(optDestination.get());
}).delayTicks(1).submit(SkreePlugin.inst());
event.setUseBlockResult(Tristate.FALSE);
}
}
use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.
the class GoldRushListener method onChestOpen.
@Listener
public void onChestOpen(InteractInventoryEvent.Open event, @Root Player player) {
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent())
return;
GoldRushInstance inst = optInst.get();
Inventory inventory = event.getTargetInventory();
if (!inst.isLocked() && inventory instanceof ContainerChest) {
IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
if (chestInv instanceof ILockableContainer) {
LockCode newLockCode = new LockCode(UUID.randomUUID().toString());
tileEntityClaimMap.put(newLockCode.getLock(), player);
((ILockableContainer) chestInv).setLockCode(newLockCode);
BigDecimal risk = Optional.ofNullable(inst.cofferRisk.get(player.getUniqueId())).orElse(BigDecimal.ZERO);
Collection<org.spongepowered.api.item.inventory.ItemStack> queue = CofferValueMap.inst().satisfy(risk.toBigInteger());
Iterator<org.spongepowered.api.item.inventory.ItemStack> it = queue.iterator();
for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
if (it.hasNext()) {
chestInv.setInventorySlotContents(i, tf(it.next()));
continue;
}
chestInv.setInventorySlotContents(i, null);
}
}
}
}
use of org.spongepowered.api.item.inventory.Inventory in project Skree by Skelril.
the class PlayerStateServiceImpl method load.
@Override
public void load(Player player, String saveName) {
Iterator<Inventory> slots = player.getInventory().slots().iterator();
List<JsonElement> persistedInventoryContents = getInventoryContents(player, saveName);
for (int i = 0; slots.hasNext(); ++i) {
Inventory slot = slots.next();
if (i < persistedInventoryContents.size()) {
try {
ItemStack stack = deserializeItemStack(persistedInventoryContents.get(i));
slot.set(stack);
continue;
} catch (IOException e) {
e.printStackTrace();
}
}
slot.set(newItemStack(ItemTypes.NONE));
}
}
Aggregations