SteamWar/FightSystem
Archiviert
13
1

Add BlockBreakEvent #156

Manuell gemergt
Lixfel hat 3 Commits von blockPickup nach master 2020-05-22 16:44:40 +02:00 zusammengeführt
Nur Änderungen aus Commit 4e844070ca werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -3,6 +3,7 @@ package de.steamwar.fightsystem.listener;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryDragEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent;
@ -62,4 +63,36 @@ public class InFightInventoryListener extends BasicListener {
public void onDropping(PlayerDropItemEvent e){ public void onDropping(PlayerDropItemEvent e){
e.setCancelled(true); 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;
}
}
}
} }