From ebb14eb610f8127837c9967b8ee4fde8aa16df6f Mon Sep 17 00:00:00 2001 From: Yaruma3341 Date: Sun, 2 Feb 2020 00:54:07 +0100 Subject: [PATCH] bugfixes --- .../steamwar/lobby/commands/ShieldCommand.java | 2 +- .../lobby/inventorys/LobbyInventory.java | 7 +++++++ .../lobby/listener/ShieldListener.java | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/lobby/commands/ShieldCommand.java b/src/de/steamwar/lobby/commands/ShieldCommand.java index 6452559..8eb99c6 100644 --- a/src/de/steamwar/lobby/commands/ShieldCommand.java +++ b/src/de/steamwar/lobby/commands/ShieldCommand.java @@ -28,7 +28,7 @@ public class ShieldCommand implements CommandExecutor { } LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - boolean newShieldState = lobbyPlayer.isShield() ? false : true; + boolean newShieldState = !lobbyPlayer.isShield(); lobbyPlayer.setShield(newShieldState); player.sendMessage("§7Dein Schild ist jetzt " + (newShieldState ? "§aan" : "§caus") + "§7."); diff --git a/src/de/steamwar/lobby/inventorys/LobbyInventory.java b/src/de/steamwar/lobby/inventorys/LobbyInventory.java index db826af..b29efe4 100644 --- a/src/de/steamwar/lobby/inventorys/LobbyInventory.java +++ b/src/de/steamwar/lobby/inventorys/LobbyInventory.java @@ -11,6 +11,7 @@ public class LobbyInventory { public static Material PARTIKEL = Material.NAME_TAG; public static Material ENDERPEARL_USED = Material.FIREWORK_CHARGE; public static Material ENDERPEARL_READY = Material.ENDER_PEARL; + public static Material SCHILD = Material.SHIELD; public static void givePlayerLobbyItems(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); @@ -33,6 +34,12 @@ public class LobbyInventory { .setUnbreakable(true) .removeAllAtributs() .build()); + + player.getInventory().setItem(8, new ItemBuilder(SCHILD) + .setDisplayName("§bSchild §8| " + (lobbyPlayer.isShield() ? "§caus" : "§aan")) + .setUnbreakable(true) + .removeAllAtributs() + .build()); } diff --git a/src/de/steamwar/lobby/listener/ShieldListener.java b/src/de/steamwar/lobby/listener/ShieldListener.java index d3d92b9..bd89eee 100644 --- a/src/de/steamwar/lobby/listener/ShieldListener.java +++ b/src/de/steamwar/lobby/listener/ShieldListener.java @@ -1,14 +1,19 @@ package de.steamwar.lobby.listener; +import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.inventorys.LobbyInventory; import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Bukkit; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.entity.EnderPearl; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; @@ -75,5 +80,18 @@ public class ShieldListener implements Listener { } } + @EventHandler + public void handlePlayerInteract(PlayerInteractEvent event) { + if(event.getMaterial() != LobbyInventory.SCHILD) return; + Action action = event.getAction(); + if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return; + + event.setCancelled(true); + + Player player = event.getPlayer(); + LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); + lobbyPlayer.setShield(!lobbyPlayer.isShield()); + } + }