From 00967a2d3e6d3a5c5e9721e2d626a7615adb2783 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jan 2020 17:25:11 +0100 Subject: [PATCH] WIP Adding personal kits Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 + .../fightsystem/utils/PersonalKitCreator.java | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index aa0782d..51f438e 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -97,6 +97,7 @@ public class Config { //default kits public static final String MemberDefault; public static final String LeaderDefault; + public static final boolean PersonalKits; //tech hider parameter public static final Set HiddenBlocks; @@ -177,6 +178,7 @@ public class Config { MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); + PersonalKits = config.getBoolean("Kits.PersonalKits"); ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks"); Set blocks = new HashSet<>(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java new file mode 100644 index 0000000..2a36a20 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/PersonalKitCreator.java @@ -0,0 +1,46 @@ +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +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.InventoryCloseEvent; +import org.bukkit.inventory.ItemStack; + +public class PersonalKitCreator implements Listener { + + private final Player player; + private final ItemStack[] contents; + private final ItemStack[] armor; + + public PersonalKitCreator(Player player){ + this.player = player; + contents = player.getInventory().getContents(); + armor = player.getInventory().getArmorContents(); + + //TODO Get Current Kit inventory + //TODO Prevent unwanted items + player.getInventory().setContents(); + player.getInventory().setArmorContents(); + + player.setGameMode(GameMode.CREATIVE); + player.openInventory(this.inventory); + Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent e) { + if(!player.equals(e.getPlayer())) + return; + + //TODO Autoclose inventory on PreFightStart + player.closeInventory(); + player.getInventory().setContents(contents); + player.getInventory().setArmorContents(contents); + player.setGameMode(GameMode.SURVIVAL); + HandlerList.unregisterAll(this); + } +}