SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Add BlockBreakEvent' (#156) from blockPickup into master

Reviewed-by: Lixfel <lixfel@steamwar.de>
Dieser Commit ist enthalten in:
Lixfel 2020-05-22 16:44:40 +02:00
Commit 0868a4eca9
2 geänderte Dateien mit 33 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -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();

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,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;
}
}
}
} }