use of com.skelril.skree.content.registry.item.currency.CofferItem in project Skree by Skelril.
the class GoldRushListener method onChestClose.
@Listener
public void onChestClose(InteractInventoryEvent.Close event) {
Inventory inventory = event.getTargetInventory();
if (inventory instanceof ContainerChest) {
IInventory chestInv = ((ContainerChest) inventory).getLowerChestInventory();
if (chestInv instanceof ILockableContainer) {
String lockCode = ((ILockableContainer) chestInv).getLockCode().getLock();
Optional<Player> optPlayer = Optional.ofNullable(tileEntityClaimMap.remove(lockCode));
if (optPlayer.isPresent()) {
Player player = optPlayer.get();
((ILockableContainer) chestInv).setLockCode(LockCode.EMPTY_CODE);
Optional<GoldRushInstance> optInst = manager.getApplicableZone(player);
if (!optInst.isPresent()) {
return;
}
// TODO Sponge port
GoldRushInstance inst = optInst.get();
List<org.spongepowered.api.item.inventory.ItemStack> toEvaluate = new ArrayList<>();
ArrayDeque<org.spongepowered.api.item.inventory.ItemStack> toReturn = new ArrayDeque<>();
for (int i = 0; i < chestInv.getSizeInventory(); ++i) {
ItemStack stack = chestInv.getStackInSlot(i);
if (stack == ItemStack.EMPTY) {
continue;
}
if (stack.getItem() instanceof CofferItem) {
toEvaluate.add(tf(stack));
} else {
toReturn.add(tf(stack));
}
chestInv.setInventorySlotContents(i, ItemStack.EMPTY);
}
BigDecimal value = BigDecimal.ZERO;
for (org.spongepowered.api.item.inventory.ItemStack stack : toEvaluate) {
value = value.add(new BigDecimal(CofferValueMap.inst().getValue(Collections.singleton(stack)).orElse(BigInteger.ZERO)));
}
inst.cofferRisk.put(player.getUniqueId(), value);
for (Inventory slot : player.getInventory().slots()) {
if (toReturn.isEmpty()) {
break;
}
if (slot.size() == 0) {
slot.set(toReturn.poll());
}
}
if (!toReturn.isEmpty()) {
new ItemDropper(player.getLocation()).dropStacks(toReturn, SpawnTypes.PLUGIN);
}
player.sendMessage(Text.of(TextColors.YELLOW, "You are now risking ", format(value), " coffers."));
MessageChannel targetChannel = inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR);
targetChannel.send(Text.of(TextColors.YELLOW, "Group risk of ", format(inst.getTotalRisk()), " coffers."));
targetChannel.send(Text.of(TextColors.YELLOW, "Risk of lava ", inst.getChanceOfLava(), " / 100."));
targetChannel.send(Text.of(TextColors.YELLOW, "Security system delay ", inst.getBaseTime(), " +/- ", inst.getTimeVariance(), " seconds."));
}
}
}
}
Aggregations