From 08d1ebfb123fdec172187c757513a0e3858b3e01 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 25 Mar 2022 13:33:02 +0100 Subject: [PATCH] Fix double firework and no firework --- .../lobby/listener/InventoryInteraction.java | 22 ++++++++++++++++++- .../steamwar/lobby/listener/PlayerSpawn.java | 13 ++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/de/steamwar/lobby/listener/InventoryInteraction.java b/src/de/steamwar/lobby/listener/InventoryInteraction.java index 94c4b20..967fac9 100644 --- a/src/de/steamwar/lobby/listener/InventoryInteraction.java +++ b/src/de/steamwar/lobby/listener/InventoryInteraction.java @@ -19,17 +19,37 @@ package de.steamwar.lobby.listener; +import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.command.ModifyCommand; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.block.Action; import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.inventory.ItemStack; public class InventoryInteraction extends BasicListener { + { + Bukkit.getScheduler().runTaskTimer(LobbySystem.getPlugin(), () -> { + Bukkit.getOnlinePlayers().forEach(player -> { + ItemStack itemStack = player.getInventory().getItem(PlayerSpawn.FIREWORK_SLOT); + if (itemStack == null || itemStack.getType() == Material.AIR) { + player.getInventory().setItem(PlayerSpawn.FIREWORK_SLOT, PlayerSpawn.FIREWORK); + return; + } + if (itemStack.getAmount() > 1) { + player.getInventory().setItem(PlayerSpawn.FIREWORK_SLOT, PlayerSpawn.FIREWORK); + } + }); + }, 0L, 1L); + } + @EventHandler public void handlePlayerInteract(PlayerInteractEvent event) { ItemStack item = event.getItem(); diff --git a/src/de/steamwar/lobby/listener/PlayerSpawn.java b/src/de/steamwar/lobby/listener/PlayerSpawn.java index 5d3cc97..b386287 100644 --- a/src/de/steamwar/lobby/listener/PlayerSpawn.java +++ b/src/de/steamwar/lobby/listener/PlayerSpawn.java @@ -36,6 +36,12 @@ import org.bukkit.inventory.PlayerInventory; public class PlayerSpawn extends BasicListener { + public static final int FIREWORK_SLOT = 3; + public static final ItemStack FIREWORK = new ItemBuilder(Material.FIREWORK_ROCKET, 1).setDisplayName("§5Rakete").build(); + public static final int PARTICLE_SLOT = 5; + public static final ItemStack PARTICLE = new ItemBuilder(Material.NAME_TAG).setDisplayName("§6Partikel").setUnbreakable(true).removeAllAttributes().build(); + private static final ItemStack ELYTRA = new ItemBuilder(Material.ELYTRA).setDisplayName("§5Elytra").setUnbreakable(true).removeAllAttributes().build(); + @EventHandler(priority = EventPriority.HIGH) public void onJoin(PlayerJoinEvent e) { Player player = e.getPlayer(); @@ -52,17 +58,14 @@ public class PlayerSpawn extends BasicListener { Bukkit.getScheduler().runTaskLater(LobbySystem.getPlugin(), () -> new ImALobbyPacket().send(player), 20); } - private static final ItemStack ELYTRA = new ItemBuilder(Material.ELYTRA).setDisplayName("§5Elytra").setUnbreakable(true).removeAllAttributes().build(); - public static final ItemStack PARTICLE = new ItemBuilder(Material.NAME_TAG).setDisplayName("§6Partikel").setUnbreakable(true).removeAllAttributes().build(); - private void giveItems(Player player) { PlayerInventory inventory = player.getInventory(); inventory.setItem(EquipmentSlot.CHEST, ELYTRA); - player.getInventory().setItem(3, new ItemBuilder(Material.FIREWORK_ROCKET, 1).setDisplayName("§5Rakete").build()); + player.getInventory().setItem(FIREWORK_SLOT, FIREWORK); - player.getInventory().setItem(5, PARTICLE); + player.getInventory().setItem(PARTICLE_SLOT, PARTICLE); } @EventHandler(priority = EventPriority.HIGH)