use of net.minecraft.world.LockCode 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);
}
}
}
}
Aggregations