From 0ebc7e5616520b3c77c2873343a55ce784737cdb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Jan 2020 19:57:21 +0100 Subject: [PATCH] Fixing bugs occured with testing Signed-off-by: Lixfel --- .../steamwar/fightsystem/fight/FightTeam.java | 2 +- .../listener/FreezeWorldStateListener.java | 7 +++-- .../fightsystem/utils/PersonalKitCreator.java | 31 +++++++++++++------ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index a21c46d..8edacca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -202,7 +202,7 @@ public class FightTeam implements IFightTeam{ leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); Inventory inventory = leader.getPlayer().getInventory(); - if (KitManager.getKits(true).size() > 1) + if (KitManager.getKits(true).size() > 1 || Config.PersonalKits) inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); else inventory.setItem(1, new ItemBuilder(Material.AIR).build()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java index 6f2a400..b7fd1bd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java @@ -2,6 +2,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.utils.PersonalKitCreator; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -42,12 +43,14 @@ public class FreezeWorldStateListener extends BasicListener { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - event.setCancelled(true); + if(!PersonalKitCreator.inKitCreator(event.getWhoClicked())) + event.setCancelled(true); } @EventHandler public void onInventoryDrag(InventoryDragEvent event) { - event.setCancelled(true); + if(!PersonalKitCreator.inKitCreator(event.getWhoClicked())) + event.setCancelled(true); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java index 8e5e3d9..9811f81 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java @@ -8,20 +8,22 @@ import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; -import java.util.HashSet; -import java.util.Set; +import java.util.HashMap; +import java.util.Map; public class PersonalKitCreator implements Listener { - private static final Set openKitCreators = new HashSet<>(); + private static final Map openKitCreators = new HashMap<>(); private final Player player; private final SteamwarUser user; @@ -45,14 +47,18 @@ public class PersonalKitCreator implements Listener { } player.setGameMode(GameMode.CREATIVE); - player.openInventory(player.getInventory()); Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - openKitCreators.add(this); + openKitCreators.put(player, this); } public static void closeAll(){ - for(PersonalKitCreator creator : openKitCreators) - creator.close(); + for(PersonalKitCreator creator : openKitCreators.values()){ + creator.player.closeInventory(); + } + } + + public static boolean inKitCreator(HumanEntity player){ + return openKitCreators.containsKey(player); } @EventHandler @@ -61,6 +67,14 @@ public class PersonalKitCreator implements Listener { e.setCancelled(true); } + @EventHandler + public void onMoveEvent(PlayerMoveEvent e){ + if(!player.equals(e.getPlayer())) + return; + + e.setCancelled(true); + } + @EventHandler public void onInventoryClose(InventoryCloseEvent e) { if(!player.equals(e.getPlayer())) @@ -71,11 +85,10 @@ public class PersonalKitCreator implements Listener { private void close(){ PersonalKit.save(user.getId(), Config.SchematicType.toDB(), player.getInventory().getContents(), player.getInventory().getArmorContents()); - player.closeInventory(); player.getInventory().setContents(contents); player.getInventory().setArmorContents(armor); player.setGameMode(GameMode.SURVIVAL); HandlerList.unregisterAll(this); - openKitCreators.remove(this); + openKitCreators.remove(player); } }