use of org.cubeengine.module.itemrepair.repair.blocks.RepairBlock.RepairBlockInventory in project modules-extra by CubeEngine.
the class RepairBlockManager method removePlayer.
public void removePlayer(final Player player) {
if (player == null) {
return;
}
RepairBlockInventory inventory;
for (RepairBlock repairBlock : this.repairBlocks.values()) {
inventory = repairBlock.removeInventory(player);
if (inventory != null) {
final World world = player.getWorld();
final Location loc = player.getLocation();
Sponge.getCauseStackManager().pushCause(player);
for (Inventory slot : inventory.inventory) {
if (slot.peek().isPresent()) {
Entity drop = world.createEntity(EntityTypes.ITEM, loc.getPosition());
drop.offer(Keys.REPRESENTED_ITEM, slot.peek().get().createSnapshot());
world.spawnEntity(drop);
}
}
}
}
}
use of org.cubeengine.module.itemrepair.repair.blocks.RepairBlock.RepairBlockInventory 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);
}
}
}
}
}
Aggregations