From b13362176c4326c74ce4e1f279ab020c3f45a770 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 25 Jul 2020 09:58:09 +0200 Subject: [PATCH 1/9] Fix multiple times techko Signed-off-by: Lixfel --- .../steamwar/fightsystem/winconditions/WinconditionTechKO.java | 2 +- .../fightsystem/winconditions/WinconditionWaterTechKO.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java index 04228cb..702fee7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java @@ -36,7 +36,7 @@ public class WinconditionTechKO extends ListenerWincondition { * Works only for z-Axis fight direction for performance reasons */ public WinconditionTechKO(){ - super(Config.TechKO, EnumSet.of(FightState.RUNNING, FightState.SPECTATE)); + super(Config.TechKO, EnumSet.of(FightState.RUNNING)); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 0b81775..22d14e0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -44,7 +44,7 @@ public class WinconditionWaterTechKO extends Wincondition { } private void checkEmpty(FightTeam team, int teamWater){ - if(teamWater == 0){ + if(teamWater == 0 && FightSystem.getFightState() != FightState.SPECTATE){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO")); } From f441f76f62c60a46f3a0a2742a553ddd328c27ce Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 25 Jul 2020 11:13:20 +0200 Subject: [PATCH 2/9] Fix 1.16 item selection Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/commands/GUI.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index f4e4cc9..bb2fc80 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -101,13 +101,19 @@ public class GUI { } SWInventory inv = new SWInventory(p, 9, Config.GameName + "-Auswahl"); - inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> schemDialog(p, true)); + inv.setItem(8, Material.REDSTONE, "§eÖffentliches " + Config.GameName, (ClickType click) -> { + p.closeInventory(); + schemDialog(p, true); + }); if(Fight.getMaxRank() == 0){ inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Keine privaten Schematics erlaubt", (ClickType click)->{}); }else if(Schematic.getSchemsOfType(p.getUniqueId(), Config.SchematicType).isEmpty() && !Config.test()){ inv.setItem(0, SWItem.getDye(8), (byte)8, "§7Kein privates " + Config.GameName + " vorhanden", (ClickType click)->{}); }else{ - inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> schemDialog(p, false)); + inv.setItem(0, SWItem.getMaterial("CAULDRON_ITEM"), "§ePrivates " + Config.GameName, (ClickType click) -> { + p.closeInventory(); + schemDialog(p, false); + }); } inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); From d0f97430aea076cd479bdf223e38da1e373da51b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 26 Jul 2020 08:44:46 +0200 Subject: [PATCH 3/9] Fix Redstone and Piston item Signed-off-by: Lixfel --- .../fightsystem/listener/InFightInventoryListener.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java index 531b2e5..dff7aa2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java @@ -73,6 +73,14 @@ public class InFightInventoryListener extends BasicListener { Inventory inventory = event.getPlayer().getInventory(); Material type = event.getBlock().getType(); + switch(type){ + case REDSTONE_WIRE: + type = Material.REDSTONE; + break; + case PISTON_HEAD: + type = Material.PISTON; + break; + } ItemStack itemStack; for (int i = 0; i <= 35; i++) { //35 is the last normal inventory slot From 1e327c35884843afee5b599bb0f1bf05b5fc0105 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 26 Jul 2020 12:13:36 +0200 Subject: [PATCH 4/9] Implement mutual exclusivity to prevent stacking Signed-off-by: Lixfel --- .../winconditions/WinconditionPumpkinTechKO.java | 5 +++++ .../winconditions/WinconditionRelativePercent.java | 5 +++++ .../fightsystem/winconditions/WinconditionTechKO.java | 6 ++++++ .../fightsystem/winconditions/WinconditionWaterTechKO.java | 7 ++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 313cbff..21e1d90 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -20,6 +20,7 @@ public class WinconditionPumpkinTechKO extends Wincondition { private static final World WORLD = Bukkit.getWorlds().get(0); private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); private BukkitTask task; + private static boolean running = false; public WinconditionPumpkinTechKO(){ super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); @@ -43,6 +44,9 @@ public class WinconditionPumpkinTechKO extends Wincondition { } private static void recursiveCheck(){ + if(running) + return; + running = true; teamRedPumpkins = getPumpkins(Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, @@ -58,6 +62,7 @@ public class WinconditionPumpkinTechKO extends Wincondition { checkKO(Fight.getRedTeam(), teamRedPumpkins); checkKO(Fight.getBlueTeam(), teamBluePumpkins); + running = false; } private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 0dc010b..8f7bf08 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -61,6 +61,7 @@ public class WinconditionRelativePercent extends Wincondition{ private final FightTeam team; private final int blockCount; private final BukkitTask task; + private boolean running = false; private int currentBlocks; @@ -70,8 +71,12 @@ public class WinconditionRelativePercent extends Wincondition{ this.currentBlocks = blockCount; task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { + if(running) + return; + running = true; currentBlocks = currentBlocks(); checkPercentDefeat(); + running = false; }, 400, 400); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java index 702fee7..b7c0651 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java @@ -31,6 +31,7 @@ public class WinconditionTechKO extends ListenerWincondition { private TechKOCountdown smallerZcountdown = null; private TechKOCountdown biggerZcountdown = null; private BukkitTask task; + private boolean running = false; /** * Works only for z-Axis fight direction for performance reasons @@ -59,6 +60,10 @@ public class WinconditionTechKO extends ListenerWincondition { } private void run(){ + if(running) + return; + running = true; + for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){ int id = tnt.getEntityId(); boolean smallerZ = tnt.getLocation().getZ() < toggle; @@ -87,6 +92,7 @@ public class WinconditionTechKO extends ListenerWincondition { smallerZtime--; biggerZtime--; + running = false; } private FightTeam smallerTeam(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 22d14e0..3d33f10 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -19,6 +19,7 @@ public class WinconditionWaterTechKO extends Wincondition { private static final World WORLD = Bukkit.getWorlds().get(0); private BukkitTask task; + private boolean running = false; public WinconditionWaterTechKO() { super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); @@ -44,13 +45,16 @@ public class WinconditionWaterTechKO extends Wincondition { } private void checkEmpty(FightTeam team, int teamWater){ - if(teamWater == 0 && FightSystem.getFightState() != FightState.SPECTATE){ + if(teamWater == 0){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO")); } } private void checkTask() { + if(running) + return; + running = true; teamRedWater = calcWater( Config.TeamRedCornerX, Config.TeamRedCornerY, @@ -68,6 +72,7 @@ public class WinconditionWaterTechKO extends Wincondition { checkEmpty(Fight.getRedTeam(), teamRedWater); checkEmpty(Fight.getBlueTeam(), teamBlueWater); + running = false; } private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ From ed025915a6e4697b7ed96bf4c279088aacadffb1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 30 Jul 2020 20:49:56 +0200 Subject: [PATCH 5/9] Fix spawners Signed-off-by: Lixfel --- .../fightsystem/listener/FoodLevelChangeListener.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java index 589f3e3..f672b7a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java @@ -3,6 +3,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.states.FightState; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.weather.WeatherChangeEvent; import java.util.EnumSet; @@ -22,4 +23,9 @@ public class FoodLevelChangeListener extends BasicListener { public void onWeatherChange(WeatherChangeEvent event){ event.setCancelled(true); } + + @EventHandler + public void onSpawnerSpawn(SpawnerSpawnEvent e){ + e.setCancelled(true); + } } From bcd3cc976b1697077872cbbab9f2ab4d8c0c4077 Mon Sep 17 00:00:00 2001 From: Jan9103 Date: Thu, 13 Aug 2020 23:23:22 +0200 Subject: [PATCH 6/9] Sleep Preventer --- .../de/steamwar/fightsystem/FightSystem.java | 1 + .../fightsystem/listener/SleepListener.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 98706f7..1c1c865 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -74,6 +74,7 @@ public class FightSystem extends JavaPlugin { new TestListener(); new NormalJoinListener(); new RankedJoinListener(); + new SleepListener(); if(Core.getVersion() > 8) new ExtendedInventoryListener(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java new file mode 100644 index 0000000..8179de4 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java @@ -0,0 +1,18 @@ +package de.steamwar.fightsystem.listener; + +import java.util.EnumSet; + +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerBedEnterEvent; + +import de.steamwar.fightsystem.states.FightState; + +public class SleepListener extends BasicListener{ + public SleepListener() {super(EnumSet.allOf(FightState.class));} + @EventHandler + public void onSleep(PlayerBedEnterEvent e) { + Block b=e.getBed(); + b.getWorld().createExplosion(b.getLocation(),4.0F); //4==tnt => dosnt have any advantage in WS (noFire,sameStrength,moreInvSpace,selfDamage) + } +} \ No newline at end of file From 67fcff77118f15dfc85c16e1d526a551955cbabd Mon Sep 17 00:00:00 2001 From: Jan9103 Date: Sun, 16 Aug 2020 11:23:18 +0200 Subject: [PATCH 7/9] code nutzlos gemacht --- .../src/de/steamwar/fightsystem/listener/SleepListener.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java index 8179de4..8b7ff93 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java @@ -12,7 +12,8 @@ public class SleepListener extends BasicListener{ public SleepListener() {super(EnumSet.allOf(FightState.class));} @EventHandler public void onSleep(PlayerBedEnterEvent e) { - Block b=e.getBed(); - b.getWorld().createExplosion(b.getLocation(),4.0F); //4==tnt => dosnt have any advantage in WS (noFire,sameStrength,moreInvSpace,selfDamage) + e.setCancelled(true); + //Block b=e.getBed(); + //b.getWorld().createExplosion(b.getLocation(),4.0F); //4==tnt => dosnt have any advantage in WS (noFire,sameStrength,moreInvSpace,selfDamage) } } \ No newline at end of file From ce67d0e4f10a589d8c447c7cbde29f6647962a69 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 18 Aug 2020 17:31:05 +0200 Subject: [PATCH 8/9] Improve PersonalKitCreator Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 2 +- .../de/steamwar/fightsystem/commands/GUI.java | 6 +- .../src/de/steamwar/fightsystem/kit/Kit.java | 32 ++- .../listener/FreezeWorldStateListener.java | 1 - .../listener/HotbarGUIListener.java | 73 +++---- .../listener/PersonalKitCreator.java | 187 ++++++++++++++++++ .../fightsystem/utils/PersonalKitCreator.java | 135 ------------- 7 files changed, 256 insertions(+), 180 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 98706f7..c472997 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -74,6 +74,7 @@ public class FightSystem extends JavaPlugin { new TestListener(); new NormalJoinListener(); new RankedJoinListener(); + new PersonalKitCreator(); if(Core.getVersion() > 8) new ExtendedInventoryListener(); @@ -154,7 +155,6 @@ public class FightSystem extends JavaPlugin { throw new SecurityException(fightState.name()); setFightState(FightState.PRE_RUNNING); - PersonalKitCreator.closeAll(); Fight.getBlueTeam().loadKits(); Fight.getRedTeam().loadKits(); setAllPlayersGM(GameMode.SURVIVAL); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index bb2fc80..6a9382f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -1,14 +1,14 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.kit.Kit; import de.steamwar.fightsystem.kit.KitManager; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.PersonalKitCreator; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; @@ -78,7 +78,7 @@ public class GUI { return; if(Config.PersonalKits){ - new PersonalKitCreator(p); + PersonalKitCreator.openKitCreator(p); return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java index 9ab9a64..410e522 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java @@ -5,13 +5,12 @@ import de.steamwar.fightsystem.commands.GUI; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffect; -import java.util.Collection; -import java.util.Iterator; -import java.util.Objects; +import java.util.*; public class Kit { @@ -74,20 +73,41 @@ public class Kit { return enterStage; } - public boolean isStackInKit(ItemStack stack){ + public boolean isEnchantmentInKit(ItemStack stack){ for(ItemStack is : inventory){ - if(stack.equals(is)) + if(similar(stack, is)) return true; } if(armor != null){ for(ItemStack is : armor){ - if(stack.equals(is)) + if(similar(stack, is)) return true; } } return false; } + private boolean similar(ItemStack stack, ItemStack stack2){ + if(stack == null || stack2 == null) + return false; + if(stack.getType() != stack2.getType()) + return false; + if(stack.hasItemMeta() != stack2.hasItemMeta()) + return false; + if(stack.getItemMeta() == null || stack2.getItemMeta() == null) + return true; + + //Enchantment Map comparison used for default similarity check does not work + Map en = stack.getItemMeta().getEnchants(); + Map en2 = new HashMap<>(stack.getItemMeta().getEnchants()); + + for(Map.Entry e : en.entrySet()){ + if(!en2.remove(e.getKey(), e.getValue())) + return false; + } + return en2.isEmpty(); + } + public void loadToPlayer(Player player) { player.getInventory().setContents(inventory); if(armor != null) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java index b8547af..1a73a18 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java @@ -2,7 +2,6 @@ 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; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java index 244e2f4..80741a1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java @@ -22,44 +22,49 @@ public class HotbarGUIListener extends BasicListener { public void handlePlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); - if(event.getItem() != null) { - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam == null) - return; + if(!PersonalKitCreator.notInKitCreator(player)) + return; - event.setCancelled(true); - ItemMeta itemMeta = event.getItem().getItemMeta(); - String displayName = itemMeta.getDisplayName(); + if(event.getItem() == null) + return; - if(displayName == null) - return; + FightTeam fightTeam = Fight.getPlayerTeam(player); + if(fightTeam == null) + return; - if(displayName.equals("§e" + Config.GameName + " wählen")){ - GUI.preSchemDialog(player); - return; - } + event.setCancelled(true); + ItemMeta itemMeta = event.getItem().getItemMeta(); + String displayName = itemMeta.getDisplayName(); + + if(displayName == null) + return; + + if(displayName.equals("§e" + Config.GameName + " wählen")){ + GUI.preSchemDialog(player); + return; + } + + switch (displayName) { + case "§cSpieler rauswerfen": + GUI.chooseRemove(player); + break; + case "§eSpieler einladen": + GUI.chooseInvitation(player); + break; + case "§cNicht bereit": + fightTeam.setReady(true); + break; + case "§aBereit": + fightTeam.setReady(false); + break; + case "§eKit bearbeiten": + case "§eKit wählen": + GUI.kitSelection(player); + break; + case "§eRespawn": + player.teleport(fightTeam.getSpawn()); + break; - switch (displayName) { - case "§cSpieler rauswerfen": - GUI.chooseRemove(player); - break; - case "§eSpieler einladen": - GUI.chooseInvitation(player); - break; - case "§cNicht bereit": - fightTeam.setReady(true); - break; - case "§aBereit": - fightTeam.setReady(false); - break; - case "§eKit bearbeiten": - case "§eKit wählen": - GUI.kitSelection(player); - break; - case "§eRespawn": - player.teleport(fightTeam.getSpawn()); - break; - } } } } \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java new file mode 100644 index 0000000..81523f1 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -0,0 +1,187 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.core.Core; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.kit.Kit; +import de.steamwar.fightsystem.kit.KitManager; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.PersonalKit; +import de.steamwar.sql.SteamwarUser; +import net.md_5.bungee.api.chat.TextComponent; +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.inventory.InventoryAction; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Level; + +public class PersonalKitCreator extends BasicListener { + + private static final Map openKitCreators = new HashMap<>(); + private static final EnumSet enabled = Config.PersonalKits ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class); + + public PersonalKitCreator(){ + super(enabled); + } + + public static void openKitCreator(Player player){ + if(!enabled.contains(FightSystem.getFightState())) + return; + + new InventoryBackup(player); + + FightPlayer fightPlayer = Fight.getFightPlayer(player); + assert fightPlayer != null; + + PersonalKit kit = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()); + if(kit == null){ + fightPlayer.getKit().loadToPlayer(player); + }else{ + player.getInventory().setContents(kit.getInventory()); + player.getInventory().setArmorContents(kit.getArmor()); + } + + player.updateInventory(); + player.setGameMode(GameMode.CREATIVE); + } + + static boolean notInKitCreator(HumanEntity player){ + return !openKitCreators.containsKey(player); + } + + @Override + public void disable(){ + while(!openKitCreators.isEmpty()){ + openKitCreators.values().iterator().next().player.closeInventory(); + } + super.disable(); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e){ + if(!openKitCreators.containsKey(e.getWhoClicked())) + return; + + Player player = (Player) e.getWhoClicked(); + //Deny bad items + if(isBadItem(e.getCursor(), player)) + e.setCancelled(true); + + checkForClear(e, player); + } + + @EventHandler + public void onMoveEvent(PlayerMoveEvent e){ + if(!openKitCreators.containsKey(e.getPlayer())) + return; + + e.setCancelled(true); + toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!")); + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent e) { + InventoryBackup backup = openKitCreators.get(e.getPlayer()); + if(backup == null) + return; + + backup.close(); + } + + @EventHandler + public void onPlayerExit(PlayerQuitEvent e){ + InventoryBackup backup = openKitCreators.get(e.getPlayer()); + if(backup == null) + return; + + backup.close(); + } + + private void checkForClear(InventoryClickEvent e, Player player){ + if(e.getAction() != InventoryAction.PLACE_ALL) + return; + + ItemStack[] items = e.getWhoClicked().getInventory().getContents(); + for(int i = 0; i < items.length; i++){ + ItemStack stack = items[i]; + if(stack != null && i != e.getSlot()) + return; + } + + FightPlayer fightPlayer = Fight.getFightPlayer(player); + assert fightPlayer != null; + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1); + } + + private static boolean isBadItem(ItemStack stack, Player player){ + if(stack == null) + return false; + + //Check for forbidden item + if(Config.ForbiddenItems.contains(stack.getType().name())) + return true; + + //Check for attribute modifiers + if(Core.getVersion() >= 14 && stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers()){ + Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen."); + return true; + } + + Kit normal = KitManager.getKitByName(Config.MemberDefault); + assert normal != null; + return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); + } + + private static class InventoryBackup{ + private final Player player; + private final ItemStack[] contents; + private final ItemStack[] armor; + + private InventoryBackup(Player player){ + openKitCreators.put(player, this); + this.player = player; + this.contents = player.getInventory().getContents(); + this.armor = player.getInventory().getArmorContents(); + } + + private void loadBackup(){ + PlayerInventory inventory = player.getInventory(); + inventory.setContents(contents); + inventory.setArmorContents(armor); + player.updateInventory(); + } + + private void close(){ + openKitCreators.remove(player); + PersonalKit.save(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents())); + loadBackup(); + player.setGameMode(GameMode.SURVIVAL); + } + + private ItemStack[] removeBadItems(ItemStack[] inventory){ + Kit normal = KitManager.getKitByName(Config.MemberDefault); + assert normal != null; + + for(int i = 0; i < inventory.length; i++){ + if(isBadItem(inventory[i], player)) + inventory[i] = null; + } + return inventory; + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java deleted file mode 100644 index ba2fc60..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java +++ /dev/null @@ -1,135 +0,0 @@ -package de.steamwar.fightsystem.utils; - -import de.steamwar.core.Core; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.kit.Kit; -import de.steamwar.fightsystem.kit.KitManager; -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.InventoryAction; -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.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.logging.Level; - -public class PersonalKitCreator implements Listener { - - private static final Map openKitCreators = new HashMap<>(); - - private final Player player; - private final SteamwarUser user; - private final ItemStack[] contents; - private final ItemStack[] armor; - - public PersonalKitCreator(Player player){ - this.player = player; - contents = player.getInventory().getContents(); - armor = player.getInventory().getArmorContents(); - user = SteamwarUser.get(player.getUniqueId()); - - PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB()); - if(kit == null){ - FightPlayer fightPlayer = Fight.getFightPlayer(player); - assert fightPlayer != null; - fightPlayer.getKit().loadToPlayer(player); - }else{ - player.getInventory().setContents(kit.getInventory()); - player.getInventory().setArmorContents(kit.getArmor()); - } - - player.setGameMode(GameMode.CREATIVE); - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - openKitCreators.put(player, this); - } - - public static void closeAll(){ - while(!openKitCreators.isEmpty()){ - openKitCreators.values().iterator().next().player.closeInventory(); - } - } - - public static boolean notInKitCreator(HumanEntity player){ - return !openKitCreators.containsKey(player); - } - - @EventHandler - public void onInventoryClick(InventoryClickEvent e){ - if(!player.equals(e.getWhoClicked())) - return; - - //Deny bad items - if(e.getCursor() != null){ - ItemStack stack = e.getCursor(); - if(Config.ForbiddenItems.contains(stack.getType().name())){ - e.setCancelled(true); - return; - } - - Kit normal = KitManager.getKitByName(Config.MemberDefault); - if(!normal.isStackInKit(stack)){ - if(stack.getEnchantments().size() > 0){ - e.setCancelled(true); - return; - } - if(Core.getVersion() >= 14 && stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers()){ - e.setCancelled(true); - Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen."); - return; - } - } - } - - //Check for clear - if(e.getAction() != InventoryAction.PLACE_ALL) - return; - ItemStack[] items = e.getWhoClicked().getInventory().getContents(); - for(int i = 0; i < items.length; i++){ - ItemStack stack = items[i]; - if(stack != null && i != e.getSlot()) - return; - } - FightPlayer fightPlayer = Fight.getFightPlayer(player); - assert fightPlayer != null; - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> fightPlayer.getKit().loadToPlayer(player), 1); - } - - @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())) - return; - - close(); - } - - private void close(){ - PersonalKit.save(user.getId(), Config.SchematicType.toDB(), player.getInventory().getContents(), player.getInventory().getArmorContents()); - player.getInventory().setContents(contents); - player.getInventory().setArmorContents(armor); - player.setGameMode(GameMode.SURVIVAL); - HandlerList.unregisterAll(this); - openKitCreators.remove(player); - } -} From ddc5874fe92d99685ef2f203ee968ac2090e4a5a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 18 Aug 2020 17:48:07 +0200 Subject: [PATCH 9/9] It works Signed-off-by: Lixfel --- .../fightsystem/listener/SleepListener.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java index 8b7ff93..00f53c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SleepListener.java @@ -1,19 +1,19 @@ -package de.steamwar.fightsystem.listener; - -import java.util.EnumSet; - -import org.bukkit.block.Block; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerBedEnterEvent; - -import de.steamwar.fightsystem.states.FightState; - -public class SleepListener extends BasicListener{ - public SleepListener() {super(EnumSet.allOf(FightState.class));} - @EventHandler - public void onSleep(PlayerBedEnterEvent e) { - e.setCancelled(true); - //Block b=e.getBed(); - //b.getWorld().createExplosion(b.getLocation(),4.0F); //4==tnt => dosnt have any advantage in WS (noFire,sameStrength,moreInvSpace,selfDamage) - } +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.states.FightState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerBedEnterEvent; + +import java.util.EnumSet; + +public class SleepListener extends BasicListener{ + + public SleepListener() { + super(EnumSet.allOf(FightState.class)); + } + + @EventHandler + public void onSleep(PlayerBedEnterEvent e) { + e.setCancelled(true); + } } \ No newline at end of file