use of org.cubeengine.module.itemrepair.repair.RepairRequest in project modules-extra by CubeEngine.
the class ItemRepairListener method onPlayerInteract.
@Listener
public void onPlayerInteract(InteractBlockEvent event, @First Player player) {
if (!(event instanceof InteractBlockEvent.Primary.MainHand) && !(event instanceof InteractBlockEvent.Secondary.MainHand)) {
return;
}
final Location<World> block = event.getTargetBlock().getLocation().orElse(null);
if (block == null) {
return;
}
RepairBlock repairBlock = this.rbm.getRepairBlock(block);
if (repairBlock == null) {
return;
}
event.setCancelled(true);
if (!player.hasPermission(repairBlock.getPermission().getId())) {
i18n.send(player, NEGATIVE, "You are not allowed to use this repair block!");
return;
}
RepairBlockInventory inventory = repairBlock.getInventory(player);
boolean primary = event instanceof Primary;
if (!primary) {
this.cancelRequest(event, player);
Sponge.getCauseStackManager().pushCause(player);
player.openInventory(inventory.inventory);
} else {
event.setCancelled(true);
if (this.repairRequests.containsKey(player.getUniqueId())) {
RepairRequest request = this.repairRequests.get(player.getUniqueId());
if (request.getRepairBlock() == repairBlock) {
repairBlock.repair(request);
this.repairRequests.remove(player.getUniqueId());
}
} else {
if (!this.repairRequests.containsKey(player.getUniqueId())) {
RepairRequest request = repairBlock.requestRepair(inventory);
if (request != null) {
this.repairRequests.put(player.getUniqueId(), request);
}
}
}
}
}
use of org.cubeengine.module.itemrepair.repair.RepairRequest in project modules-extra by CubeEngine.
the class RepairBlock method requestRepair.
public RepairRequest requestRepair(RepairBlockInventory inventory) {
Player player = inventory.player;
Map<Integer, ItemStack> items = this.itemProvider.getRepairableItems(inventory.inventory);
if (items.size() > 0) {
Double price = calculatePrice(items.values());
Text format = economy.getDefaultCurrency().format(new BigDecimal(price));
if (this.config.breakPercentage > 0) {
i18n.send(player, NEGATIVE, "Items will break with a chance of {decimal:2}%", this.config.breakPercentage);
}
if (this.config.failPercentage > 0) {
i18n.send(player, NEGATIVE, "Items will not repair with a chance of {decimal:2}%", this.config.failPercentage);
}
if (this.config.looseEnchantmentsPercentage > 0) {
i18n.send(player, NEGATIVE, "Items will loose all enchantments with a chance of {decimal:2}%", this.config.looseEnchantmentsPercentage);
}
if (this.config.costPercentage > 100) {
i18n.send(player, NEUTRAL, "The repair would cost {txt#amount} (+{decimal:2}%)", format, this.config.costPercentage - 100);
} else if (this.config.costPercentage < 100) {
i18n.send(player, NEUTRAL, "The repair would cost {txt#amount} (-{decimal:2}%)", format, 100 - this.config.costPercentage);
} else {
i18n.send(player, NEUTRAL, "The repair would cost {txt#amount}", format);
}
UniqueAccount acc = economy.getOrCreateAccount(player.getUniqueId()).get();
i18n.send(player, NEUTRAL, "You currently have {txt#balance}", economy.getDefaultCurrency().format(acc.getBalance(economy.getDefaultCurrency())));
i18n.send(player, POSITIVE, "{text:Leftclick} again to repair all your damaged items.");
return new RepairRequest(this, inventory, items, price);
} else {
i18n.send(player, NEGATIVE, "There are no items to repair!");
}
return null;
}
Aggregations