Add BlockBreakEvent #156
@ -57,6 +57,7 @@ public class FightSystem extends JavaPlugin {
|
||||
new PlayerStateListener();
|
||||
new ProjectileLaunchListener();
|
||||
new InFightDamageListener();
|
||||
new InFightInventoryListener();
|
||||
new FreezeWorldStateListener();
|
||||
new EventJoinListener();
|
||||
new CheckListener();
|
||||
|
@ -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,35 @@ 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 = new ItemStack(type, 1);
|
||||
inventory.setItem(i, itemStack);
|
||||
event.getPlayer().updateInventory();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren