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