SteamWar/FightSystem
Archiviert
13
1

Add BlockBreakEvent Add item not in Inventory

Dieser Commit ist enthalten in:
jojo 2020-05-22 16:40:27 +02:00
Ursprung ad077e8eb2
Commit f8a2585621
2 geänderte Dateien mit 3 neuen und 12 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

@ -67,20 +67,14 @@ public class InFightInventoryListener extends BasicListener {
@EventHandler @EventHandler
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
Inventory inventory = event.getPlayer().getInventory(); Inventory inventory = event.getPlayer().getInventory();
System.out.println("Inventory: " + inventory);
int inventorySize = inventory.getSize(); int inventorySize = inventory.getSize();
System.out.println("Inventory Size: " + inventorySize);
Material type = event.getBlock().getType(); Material type = event.getBlock().getType();
System.out.println("Type: " + type);
ItemStack itemStack; ItemStack itemStack;
System.out.println("Searching Type Slot");
for (int i = 0; i < inventorySize; i++) { for (int i = 0; i < inventorySize; i++) {
itemStack = inventory.getItem(i); itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.getType().equals(type) && itemStack.getAmount() != itemStack.getMaxStackSize()) { if (itemStack != null && itemStack.getType().equals(type) && itemStack.getAmount() != itemStack.getMaxStackSize()) {
System.out.println("Slot Found: " + i);
itemStack.setType(type); itemStack.setType(type);
itemStack.setAmount(itemStack.getAmount() + 1); itemStack.setAmount(itemStack.getAmount() + 1);
inventory.setItem(i, itemStack); inventory.setItem(i, itemStack);
@ -89,14 +83,10 @@ public class InFightInventoryListener extends BasicListener {
} }
} }
System.out.println("Searching Empty Slot");
for (int i = 0; i < inventorySize; i++) { for (int i = 0; i < inventorySize; i++) {
itemStack = inventory.getItem(i); itemStack = inventory.getItem(i);
if (itemStack != null && itemStack.getType().equals(Material.AIR)) { if (itemStack == null || itemStack.getType().equals(Material.AIR)) {
System.out.println("Slot Found: " + i); itemStack = new ItemStack(type, 1);
itemStack.setType(type);
itemStack.setAmount(1);
inventory.setItem(i, itemStack); inventory.setItem(i, itemStack);
event.getPlayer().updateInventory(); event.getPlayer().updateInventory();
return; return;