SteamWar/FightSystem
Archiviert
13
1

Add BlockBreakEvent

Dieser Commit ist enthalten in:
jojo 2020-05-22 14:38:32 +02:00
Ursprung aed114cda2
Commit 4e844070ca

Datei anzeigen

@ -3,6 +3,7 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
@ -62,4 +63,36 @@ public class InFightInventoryListener extends BasicListener {
public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent event) {
Inventory inventory = event.getPlayer().getInventory();
int inventorySize = inventory.getSize();
Material type = event.getBlock().getType();
ItemStack itemStack;
for (int i = 0; i < inventorySize; i++) {
itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.getType().equals(type) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
itemStack.setType(type);
itemStack.setAmount(itemStack.getAmount() + 1);
inventory.setItem(i, itemStack);
event.getPlayer().updateInventory();
return;
}
}
for (int i = 0; i < inventorySize; i++) {
itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.getType().equals(Material.AIR)) {
itemStack.setType(type);
itemStack.setAmount(1);
inventory.setItem(i, itemStack);
event.getPlayer().updateInventory();
return;
}
}
}
}