diff --git a/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java b/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java index 0bf5938..d02d944 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/listener/PersonalKitCreator_10.java @@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack; import java.util.HashSet; import java.util.Set; -class PersonalKitCreator_10 { +public class PersonalKitCreator_10 { - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java b/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java index ba74cd1..a76bdc8 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/listener/PersonalKitCreator_12.java @@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack; import java.util.HashSet; import java.util.Set; -class PersonalKitCreator_12 { +public class PersonalKitCreator_12 { - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java index 29c9621..1e76865 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -44,12 +43,8 @@ class TechHider_12 { private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4); - static void start(){ - chunkHider(); - } - - private static void chunkHider(){ - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { + static PacketAdapter chunkHider(){ + return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -123,6 +118,6 @@ class TechHider_12 { byteArray.write(0, data); } } - }).start(ITechHider.threadMultiplier * 4); + }; } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java index a7d185b..ed35380 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java @@ -79,9 +79,8 @@ class FightTeam_14 { e.flushSession(); } - static EditSession pasteSchematic(Schematic schematic, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { + static EditSession pasteSchematic(Clipboard clipboard, int pX, int pY, int pZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { BlockVector3 paste = BlockVector3.at(pX, pY, pZ); - Clipboard clipboard = schematic.load(); World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 dimensions = clipboard.getDimensions(); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java b/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java index bbf665d..74b3b44 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/listener/PersonalKitCreator_14.java @@ -26,14 +26,14 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; -class PersonalKitCreator_14 { +public class PersonalKitCreator_14 { private PersonalKitCreator_14(){} - static boolean hasAttributeModifier(ItemStack stack){ + public static boolean hasAttributeModifier(ItemStack stack){ return stack.hasItemMeta() && Objects.requireNonNull(stack.getItemMeta()).hasAttributeModifiers(); } - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java b/FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java similarity index 97% rename from FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java rename to FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java index 51ab896..3b03787 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WaterRemover_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/listener/WaterRemover_14.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java index aa6af7e..42f546e 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -40,12 +39,8 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider_14 { private TechHider_14(){} - static void start(){ - chunkHider(); - } - - static void chunkHider(){ - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { + static PacketAdapter chunkHider(){ + return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -146,6 +141,6 @@ public class TechHider_14 { byteArray.write(0, data); } } - }).start(ITechHider.threadMultiplier * 4); + }; } } diff --git a/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java b/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java index 9eb6d42..eec0197 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/listener/PersonalKitCreator_15.java @@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack; import java.util.HashSet; import java.util.Set; -class PersonalKitCreator_15 { +public class PersonalKitCreator_15 { - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().getKeys()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java index 576a8f9..ca06d6c 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -42,15 +41,11 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider_15 { private TechHider_15(){} - static void start(){ - chunkHider(); - } - - static void chunkHider(){ + static PacketAdapter chunkHider(){ /* * Bevor editing this function read and understand: https://wiki.vg/Chunk_Format * */ - ProtocolLibrary.getProtocolManager().getAsynchronousManager().registerAsyncHandler(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { + return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { PacketContainer packet = e.getPacket(); @@ -158,7 +153,7 @@ public class TechHider_15 { byteArray.write(0, data); } } - }).start(ITechHider.threadMultiplier * 4); + }; } private static final class VariableValueArray { diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java index 5759ed1..0752e85 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -87,9 +87,7 @@ class FightTeam_8 { e.flushQueue(); } - static EditSession pasteSchematic(Schematic schematic, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { - Clipboard clipboard = schematic.load(); - + static EditSession pasteSchematic(Clipboard clipboard, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { World w = new BukkitWorld(Bukkit.getWorlds().get(0)); Vector dimensions = clipboard.getDimensions(); Vector v = new Vector(pasteX, pasteY, pasteZ); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java index 8f42599..aa34f31 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/PersonalKitCreator_8.java @@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack; import java.util.HashSet; import java.util.Set; -class PersonalKitCreator_8 { +public class PersonalKitCreator_8 { - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java similarity index 96% rename from FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java rename to FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java index a510557..4f7bab9 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WaterRemover_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/WaterRemover_8.java @@ -17,7 +17,7 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; import org.bukkit.Material; import org.bukkit.block.Block; diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java index 77b1002..956e46a 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/listener/PersonalKitCreator_9.java @@ -25,9 +25,9 @@ import org.bukkit.inventory.ItemStack; import java.util.HashSet; import java.util.Set; -class PersonalKitCreator_9 { +public class PersonalKitCreator_9 { - static boolean hasItems(ItemStack stack){ + public static boolean hasItems(ItemStack stack){ Set keys = new HashSet<>(CraftItemStack.asNMSCopy(stack).getTag().c()); keys.remove("Enchantments"); keys.remove("Damage"); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 7447e2c..5f3c451 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -171,19 +171,19 @@ public class Config { PreFightDuration = config.getInt("Times.PreFightDuration"); SpectatorDuration = config.getInt("Times.SpectatorDuration"); - int schemsizeX = worldconfig.getInt("Arena.Schemsize.x"); - int schemsizeY = worldconfig.getInt("Arena.Schemsize.y"); - int schemsizeZ = worldconfig.getInt("Arena.Schemsize.z"); + int schemsizeX = config.getInt("Arena.Schemsize.x"); + int schemsizeY = config.getInt("Arena.Schemsize.y"); + int schemsizeZ = config.getInt("Arena.Schemsize.z"); int teamBlueCornerX = worldconfig.getInt("Arena.TeamBlueCorner.x"); int teamBlueCornerY = worldconfig.getInt("Arena.TeamBlueCorner.y"); int teamBlueCornerZ = worldconfig.getInt("Arena.TeamBlueCorner.z"); TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x"); TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y"); TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z"); - Schem2BorderX = worldconfig.getInt("Arena.Schem2Border.x"); - Schem2BorderZ = worldconfig.getInt("Arena.Schem2Border.z"); + Schem2BorderX = config.getInt("Arena.Schem2Border.x"); + Schem2BorderZ = config.getInt("Arena.Schem2Border.z"); underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); - BorderFromSchematic = worldconfig.getInt("Arena.BorderFromSchematic"); + BorderFromSchematic = config.getInt("Arena.BorderFromSchematic"); AlignWater = worldconfig.getBoolean("Arena.AlignWater"); WaterDepth = worldconfig.getInt("Arena.WaterDepth"); GroundWalkable = config.getBoolean("Arena.GroundWalkable"); @@ -417,6 +417,9 @@ public class Config { public static boolean check(){ return CheckSchemID != 0; } + public static boolean fixedTeams(){ + return event() || Ranked; + } public static boolean recording(){ return event(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 0cf770b..400af23 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -26,13 +26,13 @@ import de.steamwar.fightsystem.countdown.*; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.record.Recorder; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.utils.EnterHandler; +import de.steamwar.fightsystem.utils.FightStatistics; +import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import de.steamwar.sql.Schematic; @@ -41,9 +41,6 @@ import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; import java.util.logging.Level; public class FightSystem extends JavaPlugin { @@ -51,36 +48,19 @@ public class FightSystem extends JavaPlugin { public static final String PREFIX = "§eArena§8» "; private static FightSystem plugin; - private static FightState fightState = FightState.PRE_LEADER_SETUP; - private static Map stateDependentFeatures = new HashMap<>(); - private static int fightTime = 0; - private static Countdown mainCountdown; - @Override public void onLoad() { - setPlugin(this); + plugin = this; IFightSystem.init(this); } @Override public void onEnable() { Fight.init(); - KitManager.loadAllKits(); - TechHider.init(); - FightScoreboard.init(); RecordSystem.init(); - try { - CommandRemover.removeAll("gamemode"); - CommandInjector.injectCommand(new GamemodeCommand()); - } catch (Exception e) { - getLogger().log(Level.SEVERE, "Failed to replace commands", e); - Bukkit.shutdown(); - return; - } - new EntityDamageListener(); - new EntityExplodeListener(); + new WaterRemover(); new FoodLevelChangeListener(); new PistonListener(); new PlayerChatListener(); @@ -105,6 +85,7 @@ public class FightSystem extends JavaPlugin { new VersionDependentListener(); new EnterHandler(); + new TechHider(); new WinconditionAllDead(); new WinconditionCaptainDead(); @@ -116,40 +97,44 @@ public class FightSystem extends JavaPlugin { new WinconditionTimeout(); new WinconditionHeartRatioTimeout(); new WinconditionTechKO(); + new EventTeamOffWincondition(); - Objects.requireNonNull(getCommand("leave")).setExecutor(new LeaveCommand()); - Objects.requireNonNull(getCommand("kit")).setExecutor(new KitCommand()); - Objects.requireNonNull(getCommand("remove")).setExecutor(new RemoveCommand()); - Objects.requireNonNull(getCommand("accept")).setExecutor(new AcceptCommand()); - Objects.requireNonNull(getCommand("decline")).setExecutor(new DeclineCommand()); - Objects.requireNonNull(getCommand("invite")).setExecutor(new InviteCommand()); - Objects.requireNonNull(getCommand("ready")).setExecutor(new ReadyCommand()); - Objects.requireNonNull(getCommand("ak")).setExecutor(new AkCommand()); - Objects.requireNonNull(getCommand("leader")).setExecutor(new LeaderCommand()); - Objects.requireNonNull(getCommand("lockschem")).setExecutor(new LockschemCommand()); + new NoPlayersOnlineCountdown(); + new PreSchemPasteCountdown(); + new SetupOverCountdown(); + new PreRunningCountdown(); + new SpectateOverCountdown(); - mainCountdown = new NoPlayersOnlineCountdown(); - fightTime = Config.TimeoutTime; + new LeaveCommand(); + new KitCommand(); + new RemoveCommand(); + new AcceptCommand(); + new DeclineCommand(); + new InviteCommand(); + new ReadyCommand(); + new AkCommand(); + new LeaderCommand(); + new LockschemCommand(); + + try { + CommandRemover.removeAll("gamemode"); + CommandInjector.injectCommand(new GamemodeCommand()); + } catch (Exception e) { + getLogger().log(Level.SEVERE, "Failed to replace commands", e); + Bukkit.shutdown(); + return; + } if(Config.event() || Config.Ranked) { - Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand()); - Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand()); - Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand()); - Objects.requireNonNull(getCommand("leader")).setExecutor(new EventDummyCommand()); - setPreSchemState(); }else if(Config.test()){ if(Config.check()){ - Bukkit.getScheduler().runTaskLater(this, () -> Fight.getBlueTeam().setSchematic(Schematic.getSchemFromDB(Config.CheckSchemID)), 0); - }else{ - Bukkit.getScheduler().runTaskLater(this, Fight.getBlueTeam()::pasteDummy, 0); + Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); } - Bukkit.getScheduler().runTaskLater(this, Fight.getRedTeam()::pasteDummy, 0); setPreSchemState(); - setPostSchemState(); + Bukkit.getScheduler().runTaskLater(this, FightSystem::setPostSchemState, 0); } - } @Override @@ -158,63 +143,36 @@ public class FightSystem extends JavaPlugin { } public static void setPreSchemState() { - if(fightState != FightState.PRE_LEADER_SETUP) - throw new SecurityException(fightState.name()); - setFightState(FightState.PRE_SCHEM_SETUP); - - Fight.calcAvailibleSchemTypes(); - mainCountdown = new PreSchemPasteCountdown(); + FightState.setFightState(FightState.PRE_SCHEM_SETUP); } public static void setPostSchemState() { - if(fightState != FightState.PRE_SCHEM_SETUP) - throw new SecurityException(fightState.name()); - setFightState(FightState.POST_SCHEM_SETUP); + FightState.setFightState(FightState.POST_SCHEM_SETUP); - TechHider.start(); - if(!Config.test()){ - Fight.getBlueTeam().pasteSchematic(); - Fight.getRedTeam().pasteSchematic(); - } - - if(Config.test()) - mainCountdown = null; - else - mainCountdown = new SetupOverCountdown(); + Fight.getBlueTeam().pasteSchematic(); + Fight.getRedTeam().pasteSchematic(); } public static void setPreRunningState() { - if(fightState != FightState.POST_SCHEM_SETUP) - throw new SecurityException(fightState.name()); - setFightState(FightState.PRE_RUNNING); + FightState.setFightState(FightState.PRE_RUNNING); Fight.getBlueTeam().loadKits(); Fight.getRedTeam().loadKits(); setAllPlayersGM(GameMode.SURVIVAL); Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); - mainCountdown = new PreRunningCountdown(); - Fight.replaceSync(); - - if(Config.event()) - new EventTeamOffWincondition(); } public static void setRunningState() { - if(fightState != FightState.PRE_RUNNING) - throw new SecurityException(fightState.name()); - setFightState(FightState.RUNNING); - setAllPlayersGM(GameMode.SURVIVAL); + FightState.setFightState(FightState.RUNNING); FightStatistics.start(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } public static void setSpectateState(FightTeam winFightTeam, String windescription) { - if(fightState == FightState.SPECTATE) - return; - setFightState(FightState.SPECTATE); + FightState.setFightState(FightState.SPECTATE); setAllPlayersGM(GameMode.SPECTATOR); Fight.getBlueTeam().teleportToSpawn(); @@ -239,15 +197,10 @@ public class FightSystem extends JavaPlugin { } if(!Config.test()){ - new SpectateOverCountdown(); FightStatistics.saveStats(winFightTeam, windescription); } } - public static void setFightTime(int fightTime) { - FightSystem.fightTime = fightTime; - } - public static void setEventLeiter(Player el){ IFightSystem.setEventLeiter(el); } @@ -260,35 +213,14 @@ public class FightSystem extends JavaPlugin { return IFightSystem.getEventFight(); } - private static void setPlugin(FightSystem pl){ - plugin = pl; - } - public static FightSystem getPlugin() { return plugin; } - public static FightState getFightState() { - return fightState; - } - - public static int getFightTime() { - return fightTime; - } - public static void shutdown(String reason){ IFightSystem.shutdown(reason); } - public static void registerStateDependent(StateDependent stateDependent){ - if(stateDependent.enabled().isEmpty()) - return; - boolean enabled = stateDependent.enabled().contains(fightState); - stateDependentFeatures.put(stateDependent, enabled); - if(enabled) - stateDependent.enable(); - } - private static void setAllPlayersGM(GameMode gm) { for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm); @@ -298,32 +230,4 @@ public class FightSystem extends JavaPlugin { } } - private static void setFightState(FightState state){ - fightState = state; - if(mainCountdown != null){ - mainCountdown.disable(); - mainCountdown = null; - } - postStateChange(); - } - - private static void postStateChange(){ - for(Map.Entry feature : stateDependentFeatures.entrySet()){ - //Enable feature if should be enabled and currently disabled - if(feature.getKey().enabled().contains(fightState)){ - if(!feature.getValue()){ - feature.getKey().enable(); - feature.setValue(true); - } - feature.getKey().stateChange(fightState); - } - - - //Disable feature if should be disabled and currently enabled - if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){ - feature.getKey().disable(); - feature.setValue(false); - } - } - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java index 33bfdc4..73bc815 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java @@ -19,12 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class AcceptCommand implements CommandExecutor { +public class AcceptCommand extends BasicCommand { + + public AcceptCommand() { + super(!Config.fixedTeams(), FightState.SETUP, "accept"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java index fd83d45..bb59238 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java @@ -19,211 +19,34 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.Config; -import de.steamwar.sql.Schematic; -import de.steamwar.sql.SchematicType; +import de.steamwar.fightsystem.fight.Kit; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; -import net.md_5.bungee.api.ChatColor; -import net.md_5.bungee.api.chat.ClickEvent; -import net.md_5.bungee.api.chat.ComponentBuilder; -import net.md_5.bungee.api.chat.HoverEvent; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; +public class AkCommand extends BasicCommand { -public class AkCommand implements CommandExecutor { - - private static final String SCHEMLIST_COMMAND = "/ak schemlist "; - private static final int FILES_PER_PAGE = 15; + public AkCommand() { + super(Config.test(), FightState.ALL, "ak"); + } @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) { return false; } Player player = (Player) sender; - switch(args.length){ - case 1: - if(args[0].equalsIgnoreCase("schem") || args[0].equalsIgnoreCase("schemlist")){ - - //TEXT COMPONENTS - TextComponent publicList = new TextComponent("PUBLIC"); - publicList.setColor(ChatColor.YELLOW); - publicList.setBold(true); - publicList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePublic Liste...").create())); - publicList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist public")); - - TextComponent privateList = new TextComponent("PRIVATE"); - privateList.setColor(ChatColor.YELLOW); - privateList.setBold(true); - privateList.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§ePrivate Liste...").create())); - privateList.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schemlist 0")); - //TEXT COMPONENTS - - player.spigot().sendMessage(publicList); - player.spigot().sendMessage(privateList); - }else - Commands.sendHelp(player); - break; - case 2: - if(args[0].equalsIgnoreCase("addkit")){ - if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){ - Commands.sendHelp(player); - return false; - } - KitManager.saveInventory(args[1], player); - } else if(args[0].equalsIgnoreCase("schemlist") && FightSystem.getFightState() == FightState.PRE_SCHEM_SETUP) { - try { - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam != null && fightTeam.getFightPlayer(player).isLeader()) { - if(args[1].equalsIgnoreCase("public")) { - sendPlayerSchematicList(true, 0, player, Config.SchematicType); - return false; - } else { - int page; - page = Integer.parseInt(args[1]); - sendPlayerSchematicList(false, page, player, Config.SchematicType); - } - } - } catch (NumberFormatException ex) { - player.sendMessage(FightSystem.PREFIX + "§cDu musst eine Seitenzahl angeben!"); - return false; - } - } else - Commands.sendHelp(player); - break; - case 3: - if(args[0].equalsIgnoreCase("schem")) { - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam == null) { - player.sendMessage(FightSystem.PREFIX + "§cDu bist in keinem Team!"); - return false; - }else if(fightTeam.hasSchematic()) { - player.sendMessage(FightSystem.PREFIX + "§cDie Schematic ist bereits gewählt!"); - return false; - } - - Schematic schem; - if(args[2].equalsIgnoreCase("public")) { - schem = Schematic.getSchemFromDB(args[1], SteamwarUser.get(0).getUUID()); - } else if(args[2].equalsIgnoreCase("private")) { - schem = Schematic.getSchemFromDB(args[1], player.getUniqueId()); - } else - return false; - - - if(schem == null) { - schem = Schematic.getSchemFromDB(args[1], 0); - if(schem == null){ - player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic gibt es nicht!"); - return false; - } - } - if(schem.getSchemType() != Config.SchematicType) { - player.sendMessage(FightSystem.PREFIX + "§cDiese Schematic ist kein " + Config.GameName); - return false; - } - - fightTeam.setSchematic(schem); - }else - Commands.sendHelp(player); - break; - default: - Commands.sendHelp(player); + if(SteamwarUser.get(player.getUniqueId()).getUserGroup() != UserGroup.Developer){ + Commands.sendHelp(player); + return false; } + Kit.createKit(args[0], player); return false; } - - private void sendPlayerSchematicList(boolean publicSchematics, int currentPage, Player player, SchematicType schematicType) { - List preSchematicList; - List schematicList = new ArrayList<>(); - if(publicSchematics) { - preSchematicList = Schematic.getSchemsAccessibleByUser(0); - } else { - preSchematicList = Schematic.getSchemsAccessibleByUser(player.getUniqueId()); - } - - for(Schematic s : preSchematicList) { - if(s.getSchemType() == schematicType) - schematicList.add(s); - } - - if(schematicList.isEmpty()) { - player.sendMessage(FightSystem.PREFIX + "§cDu hast noch keine Schematic(s)!"); - return; - } - - int pages; - - double doublePages = (double) schematicList.size() / (double) FILES_PER_PAGE; - int intPages = schematicList.size() / FILES_PER_PAGE; - - if(schematicList.size() <= FILES_PER_PAGE) { - pages = 1; - } else if(doublePages > intPages) { - pages = (intPages + 1); - } else - pages = intPages; - - if(currentPage >= pages) return; - - player.sendMessage("§5======§8[§dSeite " + (currentPage + 1) + " §7/ §d" + pages + " §7| §d" + schematicList.size() + " Schematic(s)§8]§5======"); - - for(int i = currentPage * FILES_PER_PAGE; i < (currentPage * FILES_PER_PAGE) + FILES_PER_PAGE; i++) { - if(schematicList.size() <= i) break; - - Schematic schem = schematicList.get(i); - - TextComponent schematics = new TextComponent("§b" + schem.getSchemName()); - schematics.setBold(true); - - schematics.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("Schematic benutzen...").create())); - schematics.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/ak schem " + schem.getSchemName() + (publicSchematics ? " public" : " private"))); - - player.spigot().sendMessage(schematics); - } - - if(pages <= 1) return; - - if(currentPage == 0) { - TextComponent nextPage = new TextComponent("Nächste Seite >>"); - nextPage.setColor(ChatColor.RED); - nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + "1")); - player.spigot().sendMessage(nextPage); - } else if((currentPage + 1) == pages) { - TextComponent beforePage = new TextComponent("<< Vorherige Seite"); - beforePage.setColor(ChatColor.RED); - beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1))); - player.spigot().sendMessage(beforePage); - } else { - TextComponent beforePage = new TextComponent("<< Seite "); - beforePage.setColor(ChatColor.RED); - beforePage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Vorherige Seite...").create())); - beforePage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage - 1))); - - TextComponent nextPage = new TextComponent(">>"); - nextPage.setColor(ChatColor.RED); - nextPage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§6Nächste Seite...").create())); - nextPage.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, SCHEMLIST_COMMAND + (currentPage + 1))); - - beforePage.addExtra(nextPage); - player.spigot().sendMessage(beforePage); - } - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java new file mode 100644 index 0000000..7d88be7 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java @@ -0,0 +1,40 @@ +package de.steamwar.fightsystem.commands; + +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; + +import java.util.Set; + +public abstract class BasicCommand implements CommandExecutor, StateDependent { + + private final Set enabled; + private final PluginCommand command; + + protected BasicCommand(boolean condition, Set enabled, String name){ + this.enabled = enabled; + this.command = FightSystem.getPlugin().getCommand(name); + assert command != null; + disable(); + + if(condition) + FightState.registerStateDependent(this); + } + + @Override + public Set enabled() { + return enabled; + } + + @Override + public void enable() { + command.setExecutor(this); + } + + @Override + public void disable() { + command.setExecutor(new UnavailableCommand()); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index 6bdef6a..39f9995 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -19,12 +19,15 @@ 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.fight.Kit; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.sql.PersonalKit; +import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -36,7 +39,7 @@ public class Commands { } static boolean checkSetup(Player p){ - if(!FightSystem.getFightState().setup()){ + if(!FightState.setup()){ p.sendMessage(FightSystem.PREFIX + "§cDer Kampf hat bereits begonnen!"); return true; } @@ -201,14 +204,21 @@ public class Commands { if(fightPlayer == null) return; - Kit k = KitManager.getKitByName(kitName); + Kit k = null; + if(Config.PersonalKits){ + PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName); + if(kit != null) + kit.setInUse(); + }else{ + k = Kit.getKitByName(kitName); + } + if(k == null){ p.sendMessage(FightSystem.PREFIX + "§cDieses Kit gibt es nicht!"); return; } - if((fightPlayer.isLeader() && !k.isLeaderAllowed()) || - (!fightPlayer.isLeader() && !k.isMemberAllowed())){ + if(!k.canUseKit(fightPlayer.isLeader())){ p.sendMessage(FightSystem.PREFIX + "§cDu darfst dieses Kit nicht verwenden!"); return; } @@ -227,7 +237,6 @@ public class Commands { p.sendMessage("§8/§eleader §8- §7Werde der Leader eines Teams"); }else{ if(fightPlayer.isLeader()){ - p.sendMessage("§8/§eak schem §8<§eSchematic§8> - §7Setze deine Schematic"); p.sendMessage("§8/§eready §8- §7Setzt das eigene Team auf bereit"); p.sendMessage("§8/§einvite §8<§eSpieler§8> - §7Lade einen Spieler in dein Team ein"); p.sendMessage("§8/§eremove §8<§eSpieler§8> - §7Wirft einen Spieler aus dem Team"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java index 83558ea..85580ad 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java @@ -19,12 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class DeclineCommand implements CommandExecutor { +public class DeclineCommand extends BasicCommand { + + public DeclineCommand() { + super(!Config.fixedTeams(), FightState.SETUP, "decline"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index 485b0b9..3babf48 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -24,13 +24,14 @@ 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.fight.Kit; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.inventory.SWAnvilInv; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; +import de.steamwar.sql.PersonalKit; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -91,30 +92,59 @@ public class GUI { inv.open(); } - public static void kitSelection(Player p){ + public static void kitSelection(Player p, String query){ FightPlayer fightPlayer = Fight.getFightPlayer(p); if(fightPlayer == null) return; + List> entries = new ArrayList<>(); + if(Config.PersonalKits){ - PersonalKitCreator.openKitSelector(p, ""); - return; + List kits = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB()); + kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), new Kit(kit)))); + }else{ + List kitList = Kit.getAvailableKits(fightPlayer.isLeader()); + for(Kit k : kitList){ + entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, k.leaderExclusive(), null), k)); + } } - List> iconList = new ArrayList<>(); + entries.removeIf(entry -> !entry.getObject().getName().toLowerCase().contains(query.toLowerCase())); - List kitList = KitManager.getKits(fightPlayer.isLeader()); - for(Kit k : kitList){ - iconList.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, k.getName(), null, !k.isMemberAllowed(), null), k)); - } - - SWListInv inv = new SWListInv<>(p, "Kitauswahl", iconList, (ClickType click, Kit k) -> k.preview(p)); + SWListInv inv = new SWListInv<>(p, "Kitauswahl", false, entries, (clickType, kit) -> kit.preview(p)); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + if(entries.isEmpty()) { + inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden")); + } + if(Config.PersonalKits){ + inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(p, "Kitname eingeben"); + anvilInv.setItem(Material.LEATHER_CHESTPLATE); + anvilInv.setCallback(s -> { + SteamwarUser user = SteamwarUser.get(p.getUniqueId()); + if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) { + p.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!"); + p.closeInventory(); + return; + } + Kit prototype = Kit.getAvailableKits(Fight.getFightPlayer(p).isLeader()).get(0); + PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor()); + PersonalKitCreator.openKitCreator(p, kit); + }); + anvilInv.open(); + }); + } + inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> { + SWAnvilInv anvilInv = new SWAnvilInv(p, "§eNach Kit suchen"); + anvilInv.setItem(Material.PAPER); + anvilInv.setCallback(s -> kitSelection(p, s)); + anvilInv.open(); + }); inv.open(); } public static void preSchemDialog(Player p){ - if(!Config.test() && FightSystem.getFightState() != FightState.PRE_SCHEM_SETUP){ + if(!Config.test() && FightState.getFightState() != FightState.PRE_SCHEM_SETUP){ p.sendMessage(FightSystem.PREFIX + "§cDu kannst ohne Gegner keine Schematic wählen"); return; } @@ -153,7 +183,7 @@ public class GUI { FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null) return; - if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP) + if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP) fightTeam.setSchematic(s); p.closeInventory(); }); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java index 5557a81..1578d6c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java @@ -19,12 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class InviteCommand implements CommandExecutor { +public class InviteCommand extends BasicCommand { + + public InviteCommand() { + super(!Config.fixedTeams(), FightState.SETUP, "invite"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java index ee0898a..f7e1bf4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java @@ -19,12 +19,17 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class KitCommand implements CommandExecutor { +public class KitCommand extends BasicCommand { + + public KitCommand() { + super(true, FightState.SETUP, "kit"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { @@ -33,7 +38,7 @@ public class KitCommand implements CommandExecutor { Player player = (Player) sender; if(args.length != 1) - GUI.kitSelection(player); + GUI.kitSelection(player, ""); else{ Commands.kit(player, args[0]); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java index 90348e3..487086e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java @@ -19,23 +19,28 @@ 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.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class LeaderCommand implements CommandExecutor { +import java.util.EnumSet; + +public class LeaderCommand extends BasicCommand { + + public LeaderCommand() { + super(!Config.fixedTeams(), Config.test() ? FightState.ALL : EnumSet.of(FightState.PRE_LEADER_SETUP), "leader"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) return false; Player player = (Player) sender; - if(Commands.checkSetup(player)) - return false; - if(args.length == 0){ if(Fight.getFightPlayer(player) == null){ if(!Fight.getBlueTeam().hasTeamLeader()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java index 12bc850..4eebee8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java @@ -19,12 +19,17 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class LeaveCommand implements CommandExecutor { +public class LeaveCommand extends BasicCommand { + + public LeaveCommand() { + super(true, FightState.SETUP, "leave"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 9f3f6be..e947c27 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -22,16 +22,21 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.Schematic; import de.steamwar.sql.SchematicType; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class LockschemCommand implements CommandExecutor { +public class LockschemCommand extends BasicCommand { + + public LockschemCommand() { + super(true, FightState.ALL, "lockschem"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java index 873fe34..708bcb6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java @@ -19,12 +19,17 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class ReadyCommand implements CommandExecutor { +public class ReadyCommand extends BasicCommand { + + public ReadyCommand() { + super(true, FightState.SETUP, "ready"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index 427b582..bb9175d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -19,12 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class RemoveCommand implements CommandExecutor { +public class RemoveCommand extends BasicCommand { + + public RemoveCommand() { + super(!Config.fixedTeams(), FightState.SETUP, "remove"); + } + @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if(!(sender instanceof Player)) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/EventDummyCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java similarity index 86% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/EventDummyCommand.java rename to FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java index d9d5b7e..63734df 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/EventDummyCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java @@ -24,10 +24,10 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; -public class EventDummyCommand implements CommandExecutor { +public class UnavailableCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - sender.sendMessage(FightSystem.PREFIX + "§cWährend des Events ist der Befehl nicht verfügbar."); + sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar."); return false; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java index 6618edd..5a649cf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -34,11 +34,12 @@ import org.bukkit.scheduler.BukkitTask; public abstract class Countdown { - private int time; - private final BukkitTask task; + protected int time; private final Sound sound; private final boolean level; + private BukkitTask task = null; + abstract String countdownCounting(); abstract void countdownFinished(); @@ -46,8 +47,6 @@ public abstract class Countdown { this.time = time; this.sound = getSound(sound); this.level = level; - - task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 0, 20); } public static Sound getSound(SWSound sound){ @@ -68,8 +67,15 @@ public abstract class Countdown { } } + public void enable() { + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20); + } + public void disable() { - task.cancel(); + if(task != null){ + task.cancel(); + task = null; + } } private void broadcast(String message){ @@ -80,7 +86,13 @@ public abstract class Countdown { BasicListener.toActionbar(p, msg); } + public int getTimeLeft(){ + return time; + } + void count(){ + time--; + switch (time) { case 900: case 600: case 300: case 180: case 120: broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()); @@ -106,14 +118,8 @@ public abstract class Countdown { break; default: } + if(this.level) - Fight.setLevel(time); - - time--; - onTime(time); - } - - void onTime(int time){ - //Implemented in some countdowns + Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(time)); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index ca54a2b..236c85f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -35,8 +35,9 @@ public class EnternCountdown extends Countdown { private List chunkPos; public EnternCountdown(FightPlayer fp) { - super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false); + super(Config.EnterStages.get(fp.getKit().getEnterStage()), SWSound.BLOCK_NOTE_PLING, false); fightPlayer = fp; + enable(); } @Override @@ -52,13 +53,9 @@ public class EnternCountdown extends Countdown { @Override void count(){ - if(!fightPlayer.isLiving()){ - disable(); - return; - } + time--; Player player = fightPlayer.getPlayer(); - int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage()); switch (time) { case 900: case 600: case 300: case 180: case 120: BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting())); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index be59e4e..8af6e9f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -20,12 +20,19 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; -public class NoPlayersOnlineCountdown extends Countdown { +import java.util.EnumSet; +import java.util.Set; + +public class NoPlayersOnlineCountdown extends Countdown implements StateDependent { + private static final Set enabled = EnumSet.of(FightState.PRE_LEADER_SETUP); public NoPlayersOnlineCountdown() { super(Config.NoPlayerOnlineDuration, null, false); + FightState.registerStateDependent(this); } @Override @@ -37,4 +44,9 @@ public class NoPlayersOnlineCountdown extends Countdown { public void countdownFinished() { Bukkit.getServer().shutdown(); } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index 5f44d9e..438390e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; -public class PreRunningCountdown extends Countdown { +import java.util.EnumSet; +import java.util.Set; + +public class PreRunningCountdown extends Countdown implements StateDependent { + private static final Set enabled = EnumSet.of(FightState.PRE_RUNNING); public PreRunningCountdown() { super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true); + FightState.registerStateDependent(this); } @Override @@ -37,4 +44,9 @@ public class PreRunningCountdown extends Countdown { public void countdownFinished() { FightSystem.setRunningState(); } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java index 19c2e73..0088037 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java @@ -21,13 +21,18 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; -public class PreSchemPasteCountdown extends Countdown { +import java.util.EnumSet; +import java.util.Set; + +public class PreSchemPasteCountdown extends Countdown implements StateDependent { + private static final Set enabled = EnumSet.of(FightState.PRE_SCHEM_SETUP); public PreSchemPasteCountdown() { super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false); + FightState.registerStateDependent(this); } @Override @@ -37,13 +42,11 @@ public class PreSchemPasteCountdown extends Countdown { @Override void countdownFinished() { - checkTeam(Fight.getBlueTeam()); - checkTeam(Fight.getRedTeam()); FightSystem.setPostSchemState(); } - private void checkTeam(FightTeam team){ - if(!team.hasSchematic()) - team.pasteDummy(); + @Override + public Set enabled() { + return enabled; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java index 75a1fff..d01e6af 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java @@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; -public class SetupOverCountdown extends Countdown { +import java.util.EnumSet; +import java.util.Set; + +public class SetupOverCountdown extends Countdown implements StateDependent { + private static final Set enabled = Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.POST_SCHEM_SETUP); public SetupOverCountdown() { super(Config.SetupDuration, null, false); + FightState.registerStateDependent(this); } @Override @@ -37,4 +44,9 @@ public class SetupOverCountdown extends Countdown { public void countdownFinished() { FightSystem.setPreRunningState(); } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index c8e35d9..74e5abf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -21,11 +21,18 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; -public class SpectateOverCountdown extends Countdown { +import java.util.EnumSet; +import java.util.Set; + +public class SpectateOverCountdown extends Countdown implements StateDependent { + private static final Set enabled = Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.SPECTATE); public SpectateOverCountdown() { super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false); + FightState.registerStateDependent(this); } @Override @@ -37,4 +44,9 @@ public class SpectateOverCountdown extends Countdown { public void countdownFinished() { FightSystem.shutdown(null); } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java index 5d60997..f958f8a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java @@ -31,6 +31,7 @@ public class TechKOCountdown extends Countdown { public TechKOCountdown(FightTeam team, int countdownTime) { super(countdownTime, SWSound.BLOCK_NOTE_PLING, false); this.team = team; + enable(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index eaff639..c138d99 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -25,11 +25,15 @@ import org.bukkit.Bukkit; public class TimeOverCountdown extends Countdown { + private static TimeOverCountdown instance = null; + private final Runnable timeOver; public TimeOverCountdown(Runnable timeOver) { super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false); this.timeOver = timeOver; + instance = this; + enable(); } @Override @@ -43,8 +47,9 @@ public class TimeOverCountdown extends Countdown { timeOver.run(); } - @Override - void onTime(int time) { - FightSystem.setFightTime(time); + public static int getRemainingTime(){ + if(instance == null) + return -1; + return instance.getTimeLeft(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index a720c85..5a062a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -41,9 +41,8 @@ import java.util.logging.Level; public class Fight { private Fight(){} - public static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader); - public static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); - private static int schemRank; + private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.TeamRedRotate, false, Config.RedLeader); + private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.TeamBlueRotate, true, Config.BlueLeader); public static void init(){ IFight.init(redTeam, blueTeam); @@ -99,10 +98,6 @@ public class Fight { Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } - public static void setLevel(int level) { - Bukkit.getServer().getOnlinePlayers().forEach(player -> player.setLevel(level)); - } - public static FightTeam getTeamByName(String name) { if(redTeam.getName().equalsIgnoreCase(name)) return redTeam; @@ -112,11 +107,8 @@ public class Fight { } public static void replaceSync() { - Fight.getRedTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT); - Fight.getBlueTeam().replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT); - - Fight.getRedTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK); - Fight.getBlueTeam().replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK); + redTeam.replaceSync(); + blueTeam.replaceSync(); } public static void setPlayerGamemode(Player player, GameMode gameMode) { @@ -159,33 +151,26 @@ public class Fight { public static int getMaxRank(){ /* MaxRank of 0 is Pubonly*/ - return schemRank; - } - - public static void calcAvailibleSchemTypes() { if(Config.OnlyPublicSchematics){ - schemRank = 0; - return; + return 0; } if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){ - schemRank = 1000; - return; + return 1000; } if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null || blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){ - schemRank = 1000; - return; + return 1000; } if(Config.RanksEnabled) - schemRank = Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader())); + return Math.min(schemRank(redTeam.getLeader()), schemRank(blueTeam.getLeader())); else if(Schematic.getSchemsOfType(redTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty() || Schematic.getSchemsOfType(blueTeam.getLeader().getPlayer().getUniqueId(), Config.SchematicType).isEmpty()) - schemRank = 0; + return 0; else - schemRank = 1; + return 1; } private static int schemRank(FightPlayer fightPlayer){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java index 7814cdb..ea37ce4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -19,10 +19,10 @@ package de.steamwar.fightsystem.fight; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.kit.Kit; +import de.steamwar.fightsystem.countdown.EnternCountdown; +import de.steamwar.sql.PersonalKit; +import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; public class FightPlayer { @@ -32,22 +32,41 @@ public class FightPlayer { private boolean isOut; private Kit kit; private int kills; + private EnternCountdown enternCountdown = null; public void sendMessage(String message) { - if (this.player != null && this.player.isOnline()) - this.player.sendMessage(message); + this.player.sendMessage(message); } FightPlayer(Player player, FightTeam team) { this.player = player; this.team = team; this.isOut = false; - kit = KitManager.getKitByName(Config.MemberDefault); + kit = Kit.getKitByName(Config.MemberDefault); + if(Config.PersonalKits){ + PersonalKit personalKit = PersonalKit.getKitInUse(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()); + if(personalKit != null){ + kit = new Kit(personalKit); + } + } kills = 0; } public void setOut() { isOut = true; + if(enternCountdown != null){ + enternCountdown.disable(); + } + } + + public void setEnternCountdown(EnternCountdown countdown){ + enternCountdown = countdown; + } + + public void stopEnternCountdown(){ + if(enternCountdown != null){ + enternCountdown.disable(); + } } public Player getPlayer() { @@ -84,8 +103,8 @@ public class FightPlayer { } public boolean canEntern(){ - if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0) + if(enternCountdown == null) return false; - return Config.EnterStages.get(kit.getEnterStage()) >= FightSystem.getFightTime(); + return enternCountdown.getTimeLeft() == 0; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java new file mode 100644 index 0000000..6d63711 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -0,0 +1,201 @@ +package de.steamwar.fightsystem.fight; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import de.steamwar.core.VersionedRunnable; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.IFightSystem; +import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.utils.ColorConverter; +import de.steamwar.sql.NoClipboardException; +import de.steamwar.sql.Schematic; +import org.bukkit.*; +import org.bukkit.block.Block; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.block.*; +import org.bukkit.event.inventory.InventoryMoveItemEvent; + +import java.io.IOException; +import java.util.List; +import java.util.Random; +import java.util.Set; +import java.util.logging.Level; + +public class FightSchematic implements StateDependent { + + private final FightTeam team; + private final int pasteX; + private final int pasteY; + private final int pasteZ; + private final int cornerX; + private final int cornerY; + private final int cornerZ; + private final boolean rotate; + + private Clipboard clipboard = null; + private int schematic = 0; + + public FightSchematic(FightTeam team, int pasteX, int pasteY, int pasteZ, int cornerX, int cornerY, int cornerZ, boolean rotate) { + this.team = team; + this.pasteX = pasteX; + this.pasteY = pasteY; + this.pasteZ = pasteZ; + this.cornerX = cornerX; + this.cornerY = cornerY; + this.cornerZ = cornerZ; + this.rotate = rotate; + FightState.registerStateDependent(this); + } + + public boolean hasSchematic(){ + return clipboard == null; + } + + public int getId(){ + return schematic; + } + + public void setSchematic(Schematic schem) { + schematic = schem.getSchemID(); + try { + clipboard = schem.load(); + } catch (IOException e) { + team.broadcast(FightSystem.PREFIX + "§cKonnte die Schematic nicht laden!"); + Bukkit.getLogger().log(Level.SEVERE, "Couldn't load Schematic " + schem.getSchemName(), e); + } + } + + @Override + public Set enabled() { + return FightState.SCHEM; + } + + @Override + public void enable() { + if(clipboard == null){ + List publics = Schematic.getSchemsOfType(0, Config.SchematicType); + if(publics.isEmpty()) + return; + + setSchematic(publics.get(new Random().nextInt(publics.size()))); + } + + if(Config.recording()){ + if(team.isBlue()) + RecordSystem.blueSchem(schematic); + else + RecordSystem.redSchem(schematic); + } + + FreezeWorld freezer = new FreezeWorld(); + DyeColor c = ColorConverter.chat2dye(team.getColor()); + + try { + VersionedRunnable.call(new VersionedRunnable(() -> { + try { + EditSession e = FightTeam_8.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate); + FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { + throw new SecurityException("Error pasting arena in schematic", ex); + } + }, 8), new VersionedRunnable(() -> { + try { + EditSession e = FightTeam_8.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate); + FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { + throw new SecurityException("Error pasting arena in schematic", ex); + } + }, 12), new VersionedRunnable(() -> { + try { + EditSession e = FightTeam_14.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate); + FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { + throw new SecurityException("Error pasting arena in schematic", ex); + } + }, 14)); + } catch (SecurityException securityException) { + team.broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); + throw securityException; + } + + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); + } + + public void replaceSync(boolean replace, Material target, Material replacement){ + if(!replace) + return; + + World world = Bukkit.getWorlds().get(0); + Location minPoint = new Location(world,cornerX, cornerY, cornerZ); + Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ)); + + FreezeWorld freezer = null; + if(!Config.ReplaceWithBlockupdates) + freezer = new FreezeWorld(); + + for(int x = minPoint.getBlockX(); x < maxPoint.getBlockX(); x++) { + for(int z = minPoint.getBlockZ(); z < maxPoint.getBlockZ(); z++) { + for(int y = minPoint.getBlockY(); y < maxPoint.getBlockY(); y++) { + Block block = world.getBlockAt(x, y, z); + if(block.getType() == target) + block.setType(replacement); + } + } + } + + if(!Config.ReplaceWithBlockupdates) + HandlerList.unregisterAll(freezer); + } + + @Override + public void disable() { + //TODO: Reset team area + } + + private static class FreezeWorld implements Listener { + private FreezeWorld(){ + Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); + } + + @EventHandler + public void onBlockPhysicsEvent(BlockPhysicsEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onPistonExtend(BlockPistonExtendEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onPistonRetract(BlockPistonRetractEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onBlockGrow(BlockGrowEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onRedstoneEvent(BlockRedstoneEvent e){ + e.setNewCurrent(e.getOldCurrent()); + } + + @EventHandler + public void onBlockDispense(BlockDispenseEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onInventoryMoveEvent(InventoryMoveItemEvent e){ + e.setCancelled(true); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 94b9131..7cfe8cc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -19,41 +19,27 @@ package de.steamwar.fightsystem.fight; -import com.sk89q.worldedit.EditSession; import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.IFightSystem; -import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.fightsystem.utils.FightScoreboard; import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition; import de.steamwar.inventory.SWItem; -import de.steamwar.sql.NoClipboardException; -import de.steamwar.sql.PersonalKit; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import org.bukkit.*; -import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.block.*; -import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.PlayerInventory; import org.bukkit.scoreboard.NameTagVisibility; import org.bukkit.scoreboard.Team; -import java.io.IOException; import java.util.*; @@ -67,7 +53,7 @@ public class FightTeam implements IFightTeam{ private final String name; private final String prefix; private final ChatColor color; - private int schematic = 0; + private FightSchematic schematic; private final Team team; private final boolean blue; @@ -92,6 +78,7 @@ public class FightTeam implements IFightTeam{ this.cornerX = cornerX; this.cornerY = cornerY; this.cornerZ = cornerZ; + this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, cornerX, cornerY, cornerZ, rotate); this.blue = blue; this.designatedLeader = designatedLeader; color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); @@ -168,7 +155,7 @@ public class FightTeam implements IFightTeam{ Fight.setPlayerGamemode(player, GameMode.SURVIVAL); player.teleport(spawn); - if(KitManager.getKits(false).size() > 1 || Config.PersonalKits) + if(Kit.getAvailableKits(false).size() > 1 || Config.PersonalKits) player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName("§eRespawn").build()); if(!Config.test()) @@ -187,7 +174,7 @@ public class FightTeam implements IFightTeam{ team.removeEntry(player.getName()); fightPlayer.getPlayer().getInventory().clear(); - if(fightPlayer.equals(leader) && FightSystem.getFightState().setup()) + if(fightPlayer.equals(leader) && FightState.setup()) setLeader(null); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); @@ -231,9 +218,11 @@ public class FightTeam implements IFightTeam{ if(ready) setReady(false); - leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); + if(!Config.PersonalKits) + leader.setKit(Kit.getKitByName(Config.LeaderDefault)); + Inventory inventory = leader.getPlayer().getInventory(); - if (KitManager.getKits(true).size() > 1) + if (Kit.getAvailableKits(true).size() > 1) inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit wählen").build()); else if(Config.PersonalKits) inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§eKit bearbeiten").build()); @@ -247,7 +236,7 @@ public class FightTeam implements IFightTeam{ inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§cNicht bereit").build()); - if(Config.test() || FightSystem.getFightState() != FightState.POST_SCHEM_SETUP) + if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP) inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName("§e" + Config.GameName + " wählen").build()); } @@ -260,68 +249,12 @@ public class FightTeam implements IFightTeam{ } public void pasteSchematic(){ - if(Config.recording()){ - if(blue) - RecordSystem.blueSchem(schematic); - else - RecordSystem.redSchem(schematic); - } - - FreezeWorld freezer = new FreezeWorld(); - DyeColor c = ColorConverter.chat2dye(color); - Schematic schem; - try{ - schem = Schematic.getSchemFromDB(this.schematic); - }catch(SecurityException e){ - pasteDummy(); - return; - } - - try { - VersionedRunnable.call(new VersionedRunnable(() -> { - try { - EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); - FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); - } - }, 8), new VersionedRunnable(() -> { - try { - EditSession e = FightTeam_8.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); - FightTeam_12.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); - } - }, 12), new VersionedRunnable(() -> { - try { - EditSession e = FightTeam_14.pasteSchematic(schem, pasteX, pasteY, pasteZ, rotate); - FightTeam_14.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { - throw new SecurityException("Error pasting arena in schematic", ex); - } - }, 14)); - } catch (SecurityException securityException) { - broadcast(FightSystem.PREFIX + "§cFehler beim Pasten der Schematic"); - throw securityException; - } - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> HandlerList.unregisterAll(freezer), 3); - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), this::teleportToSpawn,40); - } - - public void pasteDummy(){ - List publics = Schematic.getSchemsOfType(0, Config.SchematicType); - if(publics.isEmpty()) - return; - - schematic = publics.get(new Random().nextInt(publics.size())).getSchemID(); - pasteSchematic(); - if(!Config.test() && leader != null) leader.getPlayer().getInventory().clear(0); } public void setSchematic(Schematic schematic){ - this.schematic = schematic.getSchemID(); + setNotPastingSchem(schematic); broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); if(!Config.test()) @@ -334,14 +267,18 @@ public class FightTeam implements IFightTeam{ } } + public void setNotPastingSchem(Schematic schematic){ + this.schematic.setSchematic(schematic); + } + public boolean hasSchematic(){ - return schematic != 0; + return schematic.hasSchematic(); } public void setReady(boolean ready) { Player l = leader.getPlayer(); - if(schematic == 0){ + if(!schematic.hasSchematic()){ l.sendMessage(FightSystem.PREFIX + "§cZuerst muss eine Schematic gewählt sein!"); return; } @@ -375,7 +312,7 @@ public class FightTeam implements IFightTeam{ } public int getSchematic() { - return schematic; + return schematic.getId(); } public Location getSpawn() { @@ -399,47 +336,14 @@ public class FightTeam implements IFightTeam{ public void loadKits(){ for(FightPlayer fightPlayer : players.values()) { - if(fightPlayer.getPlayer() == null) - continue; fightPlayer.getPlayer().getInventory().clear(); - - PersonalKit personalKit = null; - if(Config.PersonalKits) - personalKit = PersonalKit.getKitInUse(SteamwarUser.get(fightPlayer.getPlayer().getUniqueId()).getId(), Config.SchematicType.toDB()); - - if(personalKit != null){ - PlayerInventory inventory = fightPlayer.getPlayer().getInventory(); - inventory.setContents(personalKit.getInventory()); - inventory.setArmorContents(personalKit.getArmor()); - }else if(fightPlayer.getKit() != null) - fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer()); + fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer()); } } - void replaceSync(boolean replace, Material target, Material replacement) { - if(!replace) - return; - - World world = Bukkit.getWorlds().get(0); - Location minPoint = new Location(world, cornerX, cornerY, cornerZ); - Location maxPoint = new Location(world, (cornerX + Config.SchemsizeX), (cornerY + Config.SchemsizeY), (cornerZ + Config.SchemsizeZ)); - - FreezeWorld freezer = null; - if(!Config.ReplaceWithBlockupdates) - freezer = new FreezeWorld(); - - for(int x = minPoint.getBlockX(); x <= maxPoint.getBlockX(); x++) { - for(int z = minPoint.getBlockZ(); z <= maxPoint.getBlockZ(); z++) { - for(int y = minPoint.getBlockY(); y <= maxPoint.getBlockY(); y++) { - Block block = world.getBlockAt(x, y, z); - if(block.getType() == target) - block.setType(replacement); - } - } - } - - if(!Config.ReplaceWithBlockupdates) - HandlerList.unregisterAll(freezer); + void replaceSync() { + schematic.replaceSync(Config.ReplaceObsidian, Material.OBSIDIAN, Material.TNT); + schematic.replaceSync(Config.ReplaceBedrock, Material.BEDROCK, Material.SLIME_BLOCK); } private void setTeamColor(Team team, ChatColor color){ @@ -449,44 +353,7 @@ public class FightTeam implements IFightTeam{ new VersionedRunnable(() -> FightTeam_14.setTeamColor(team, color), 14)); } - private static class FreezeWorld implements Listener { - private FreezeWorld(){ - Bukkit.getPluginManager().registerEvents(this, IFightSystem.getPlugin()); - } - - @EventHandler - public void onBlockPhysicsEvent(BlockPhysicsEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onPistonExtend(BlockPistonExtendEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onPistonRetract(BlockPistonRetractEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onBlockGrow(BlockGrowEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onRedstoneEvent(BlockRedstoneEvent e){ - e.setNewCurrent(e.getOldCurrent()); - } - - @EventHandler - public void onBlockDispense(BlockDispenseEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onInventoryMoveEvent(InventoryMoveItemEvent e){ - e.setCancelled(true); - } + public ChatColor getColor() { + return color; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java new file mode 100644 index 0000000..6daffdf --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java @@ -0,0 +1,349 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package de.steamwar.fightsystem.fight; + +import de.steamwar.core.Core; +import de.steamwar.core.VersionedCallable; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.commands.Commands; +import de.steamwar.fightsystem.commands.GUI; +import de.steamwar.fightsystem.listener.*; +import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWItem; +import de.steamwar.sql.PersonalKit; +import de.steamwar.sql.SteamwarUser; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BlockDataMeta; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffect; + +import java.io.File; +import java.io.IOException; +import java.util.*; +import java.util.logging.Level; + +public class Kit { + private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile); + private static final ArrayList loadedKits = new ArrayList<>(); + + static { + if(!kits.exists()) { + Bukkit.getLogger().log(Level.SEVERE, "Kitconfig fehlend!"); + } + + FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits); + ConfigurationSection kitSection = kitData.getConfigurationSection("Kits"); + + for(String key : Objects.requireNonNull(kitSection).getKeys(false)) { + loadedKits.add(new Kit(Objects.requireNonNull(kitSection.getConfigurationSection(key)))); + } + } + + private final String name; + private final ItemStack[] inventory; + private final ItemStack[] armor; + private final Collection effects; + private final int enterStage; + private final boolean tnt; + private final boolean leaderAllowed; + private final boolean memberAllowed; + + public Kit(String name, Player player) { + this.name = name; + this.inventory = player.getInventory().getContents(); + this.armor = player.getInventory().getArmorContents(); + this.effects = player.getActivePotionEffects(); + this.leaderAllowed = true; + this.memberAllowed = true; + this.enterStage = 0; + this.tnt = true; + } + + public Kit(ConfigurationSection kit){ + name = kit.getName(); + inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]); + if(kit.isList("Armor")) + armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); + else + armor = null; + leaderAllowed = kit.getBoolean("LeaderAllowed"); + memberAllowed = kit.getBoolean("MemberAllowed"); + if(kit.isList("Effects")) + effects = (List) kit.getList("Effects"); + else + effects = null; + enterStage = kit.getInt("EnterStage", 0); + tnt = kit.getBoolean("TNT", true); + } + + public Kit(PersonalKit kit){ + this.name = kit.getName(); + this.inventory = kit.getInventory(); + this.armor = kit.getArmor(); + this.effects = Collections.emptyList(); + this.leaderAllowed = true; + this.memberAllowed = true; + this.enterStage = 0; + this.tnt = true; + } + + public static Kit getKitByName(String kitName) { + for(Kit kit : loadedKits) { + if(kit.getName().equalsIgnoreCase(kitName)) + return kit; + } + return null; + } + + public static List getAvailableKits(boolean leader){ + List kits = new ArrayList<>(); + for (Kit k : loadedKits) { + if (k.canUseKit(leader)){ + kits.add(k); + } + } + return kits; + } + + public String getName() { + return name; + } + + public boolean canUseKit(boolean leader){ + if (leader) { + return leaderAllowed; + } else { + return memberAllowed; + } + } + + public boolean leaderExclusive() { + return !memberAllowed; + } + + public ItemStack[] getInventory() { + return inventory; + } + + public ItemStack[] getArmor() { + return armor; + } + + /* Is this kit allowed to set/handle tnt? */ + public boolean isTnt(){ + return tnt; + } + + /* In which stage is entern allowed? */ + public int getEnterStage() { + return enterStage; + } + + public void toPersonalKit(PersonalKit kit) { + kit.setContainer(inventory, armor); + } + + public void removeBadItems(){ + Kit normal = Kit.getKitByName(Config.MemberDefault); + assert normal != null; + + for(int i = 0; i < inventory.length; i++){ + if(isBadItem(inventory[i])) + inventory[i] = null; + } + + } + + public static boolean isBadItem(ItemStack stack){ + 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 && PersonalKitCreator_14.hasAttributeModifier(stack)){ + return true; + } + + if(stack.hasItemMeta()){ + ItemMeta meta = stack.getItemMeta(); + if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData()) + return true; //Blocks always upwards slabs etc. + + if(VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8), + new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9), + new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10), + new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12), + new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14), + new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15))) + return true; //Blocks prefilled inventories + } + + Kit normal = Kit.getKitByName(Config.MemberDefault); + assert normal != null; + return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); + } + + private boolean isEnchantmentInKit(ItemStack stack){ + for(ItemStack is : inventory){ + if(similar(stack, is)) + return true; + } + if(armor != null){ + for(ItemStack is : armor){ + 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) + player.getInventory().setArmorContents(armor); + player.updateInventory(); + if(effects != null) + player.addPotionEffects(effects); + } + + /** + * Opens a kit preview with the options to go back to kit selection or to select the kit. + */ + public void preview(Player player){ + SWInventory inv = new SWInventory(player, 54, name); + + //36 = Inventargröße + for(int i = 0; i < 36; i++){ + if(inventory[i] == null) + continue; + SWItem item = new SWItem(); + item.setItemStack(inventory[i]); + inv.setItem(i, item); + } + + if(armor != null){ + for(int i = 0; i < 4; i++){ + if(armor[i] == null) + continue; + SWItem item = new SWItem(); + item.setItemStack(armor[i]); + inv.setItem(36 + i, item); + } + } + + if(effects != null){ + Iterator it = effects.iterator(); + int pos = 44; + while(it.hasNext()){ + PotionEffect effect = it.next(); + SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName()); + inv.setItem(pos, item); + pos--; + } + } + + inv.setCallback(-999, click -> player.closeInventory()); + if(Config.PersonalKits){ + inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> PersonalKitCreator.openKitCreator(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB(), name))); + inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> { + player.closeInventory(); + SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?"); + conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory()); + conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> { + player.closeInventory(); + SteamwarUser user = SteamwarUser.get(player.getUniqueId()); + PersonalKit kit = PersonalKit.get(user.getId(), Config.SchematicType.toDB(), name); + if(kit.isInUse()) { + List kits = PersonalKit.get(user.getId(), Config.SchematicType.toDB()); + if(!kits.isEmpty()){ + PersonalKit kit1 = kits.get(0); + kit1.setInUse(); + FightPlayer fightPlayer = Fight.getFightPlayer(player); + assert fightPlayer != null; + fightPlayer.setKit(new Kit(kit1)); + } + } + kit.delete(); + }); + conf.open(); + }); + } + inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", click -> { + Commands.kit(player, name); + player.closeInventory(); + }); + inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", click -> GUI.kitSelection(player, "")); + inv.open(); + } + + public static void createKit(String kitName, Player player){ + loadedKits.add(new Kit(kitName, player)); + YamlConfiguration yamlConfiguration = new YamlConfiguration(); + for(Kit k : loadedKits){ + ConfigurationSection section = yamlConfiguration.createSection("Kits." + k.getName()); + section.set("Items", k.inventory); + if(k.armor != null) + section.set("Armor", k.armor); + section.set("LeaderAllowed", k.leaderAllowed); + section.set("MemberAllowed", k.memberAllowed); + section.set("Effects", k.effects); + section.set("EnterStage", k.enterStage); + section.set("TNT", k.tnt); + } + + try { + yamlConfiguration.save(kits); + }catch(IOException e){ + throw new SecurityException("Failed to save kits.data", e); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java deleted file mode 100644 index 61049a9..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ /dev/null @@ -1,207 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.kit; - -import de.steamwar.fightsystem.commands.Commands; -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.*; - -public class Kit { - - private final String name; - private final boolean leaderAllowed; - private final boolean memberAllowed; - private final ItemStack[] inventory; - private final ItemStack[] armor; - private final Collection effects; - private final int enterStage; - private final boolean tnt; - - Kit(String name, Player player) { - this.name = name; - this.leaderAllowed = true; - this.memberAllowed = true; - this.inventory = player.getInventory().getContents(); - this.armor = player.getInventory().getArmorContents(); - this.effects = player.getActivePotionEffects(); - this.enterStage = 0; - this.tnt = true; - } - - Kit(ConfigurationSection kit){ - name = kit.getName(); - inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]); - if(kit.isList("Armor")) - armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); - else - armor = null; - leaderAllowed = kit.getBoolean("LeaderAllowed"); - memberAllowed = kit.getBoolean("MemberAllowed"); - if(kit.isList("Effects")) - effects = (Collection) kit.getList("Effects"); - else - effects = null; - enterStage = kit.getInt("EnterStage", 0); - tnt = kit.getBoolean("TNT", true); - } - - public String getName() { - return name; - } - - public boolean isLeaderAllowed() { - return leaderAllowed; - } - - public boolean isMemberAllowed() { - return memberAllowed; - } - - public ItemStack[] getInventory() { - return inventory; - } - - public ItemStack[] getArmor() { - return armor; - } - - /* Is this kit allowed to set/handle tnt? */ - public boolean isTnt(){ - return tnt; - } - - /* In which stage is entern allowed? */ - public int getEnterStage() { - return enterStage; - } - - public boolean isEnchantmentInKit(ItemStack stack){ - for(ItemStack is : inventory){ - if(similar(stack, is)) - return true; - } - if(armor != null){ - for(ItemStack is : armor){ - 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) - player.getInventory().setArmorContents(armor); - player.updateInventory(); - if(effects != null) - player.addPotionEffects(effects); - } - - void saveKit(ConfigurationSection section){ - section.set("Items", inventory); - if(armor != null) - section.set("Armor", armor); - section.set("LeaderAllowed", leaderAllowed); - section.set("MemberAllowed", memberAllowed); - section.set("Effects", effects); - section.set("EnterStage", enterStage); - section.set("TNT", tnt); - } - - /** - * Opens a kit preview with the options to go back to kit selection or to select the kit. - * @param player - */ - public void preview(Player player){ - SWInventory inv = new SWInventory(player, 54, name); - - preview(inv, inventory, armor, effects); - - inv.setCallback(-999, (click) -> player.closeInventory()); - inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> { - Commands.kit(player, name); - player.closeInventory(); - }); - inv.setItem(53, SWItem.getDye(1), (byte)1, "§cZurück", (click) -> GUI.kitSelection(player)); - inv.open(); - } - - public static void preview(SWInventory inv, ItemStack[] inventory, ItemStack[] armor, Collection effects) { - //36 = Inventargröße - for(int i = 0; i < 36; i++){ - if(inventory[i] == null) - continue; - SWItem item = new SWItem(); - item.setItemStack(inventory[i]); - inv.setItem(i, item); - } - - if(armor != null){ - for(int i = 0; i < 4; i++){ - if(armor[i] == null) - continue; - SWItem item = new SWItem(); - item.setItemStack(armor[i]); - inv.setItem(36 + i, item); - } - } - - if(effects != null){ - Iterator it = effects.iterator(); - int pos = 44; - while(it.hasNext()){ - PotionEffect effect = it.next(); - SWItem item = new SWItem(SWItem.getMaterial("POTION"), effect.getType().getName()); - inv.setItem(pos, item); - pos--; - } - } - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java deleted file mode 100644 index bf58691..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.kit; - -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -public class KitManager { - private KitManager(){} - - private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), Config.KitFile); - private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits); - - private static final ArrayList loadedKits = new ArrayList<>(); - - public static void saveInventory(String kitName, Player player){ - loadedKits.add(new Kit(kitName, player)); - saveAllKits(); - } - - public static Kit getKitByName(String kitName) { - for(Kit kit : loadedKits) { - if(kit.getName().equalsIgnoreCase(kitName)) - return kit; - } - return null; - } - - public static List getKits(boolean leader){ - List kits = new ArrayList<>(); - if(leader){ - for (Kit k : loadedKits) - if (k.isLeaderAllowed()) - kits.add(k); - }else{ - for (Kit k : loadedKits) - if (k.isMemberAllowed()) - kits.add(k); - } - return kits; - } - - public static void loadAllKits() { - if(!kits.exists()) { - saveAllKits(); - Bukkit.getLogger().log(Level.SEVERE, "kit config fehlend!"); - FightSystem.shutdown(null); - return; - } - - if(kitData.getConfigurationSection("Kits") != null) { - for(String key : kitData.getConfigurationSection("Kits").getKeys(false)) { - loadedKits.add(new Kit(kitData.getConfigurationSection("Kits." + key))); - } - } - } - - private static void saveAllKits(){ - YamlConfiguration yamlConfiguration = new YamlConfiguration(); - for(Kit k : loadedKits) - k.saveKit(yamlConfiguration.createSection("Kits." + k.getName())); - - try { - yamlConfiguration.save(kits); - }catch(IOException e){ - throw new SecurityException("Failed to save kits.data", e); - } - } - -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java index 467a6e6..be70bc2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java @@ -38,7 +38,7 @@ public abstract class BasicListener implements Listener, StateDependent { BasicListener(Set enabled){ this.enabled = enabled; - FightSystem.registerStateDependent(this); + FightState.registerStateDependent(this); } boolean notFighting(Player p){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java deleted file mode 100644 index 2ff7c63..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.WaterRemover; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityExplodeEvent; - -import java.util.EnumSet; - -public class EntityExplodeListener extends BasicListener { - - public EntityExplodeListener() { - super(EnumSet.of(FightState.RUNNING)); - } - - @EventHandler - public void handleEntityExplode(EntityExplodeEvent event) { - event.setYield(0); //No drops (additionally to world config) - WaterRemover.add(event.blockList()); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java index 7b690a1..c45428c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java @@ -185,7 +185,7 @@ public class EventRecordListener extends BasicListener { } private void setKitItems(FightTeam team){ - if(FightSystem.getFightState() != FightState.PRE_RUNNING) + if(FightState.getFightState() != FightState.PRE_RUNNING) return; for(FightPlayer fp : team.getPlayers()){ @@ -222,6 +222,6 @@ public class EventRecordListener extends BasicListener { private boolean isNotSent(Player p){ FightPlayer fp = Fight.getFightPlayer(p); - return fp == null || !fp.isLiving() || FightSystem.getFightState() == FightState.SPECTATE; + return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java index 962bf57..f0a5732 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java @@ -78,7 +78,7 @@ public class HotbarGUIListener extends BasicListener { break; case "§eKit bearbeiten": case "§eKit wählen": - GUI.kitSelection(player); + GUI.kitSelection(player, ""); break; case "§eRespawn": player.teleport(fightTeam.getSpawn()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index ecf9627..132a60c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -19,25 +19,16 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.core.Core; -import de.steamwar.core.VersionedCallable; 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.fight.Kit; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.inventory.SWAnvilInv; -import de.steamwar.inventory.SWInventory; -import de.steamwar.inventory.SWItem; -import de.steamwar.inventory.SWListInv; 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.Material; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -47,12 +38,11 @@ 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 org.bukkit.inventory.meta.BlockDataMeta; -import org.bukkit.inventory.meta.ItemMeta; -import java.util.*; -import java.util.logging.Level; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; public class PersonalKitCreator extends BasicListener { @@ -63,85 +53,10 @@ public class PersonalKitCreator extends BasicListener { super(enabled); } - public static void openKitSelector(Player player, String qry) { - List kits = PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()); - kits.removeIf(kit -> !kit.getName().toLowerCase().contains(qry.toLowerCase())); - List> entries = new ArrayList<>(kits.size()); - kits.forEach(kit -> entries.add(new SWListInv.SWListEntry<>(new SWItem(Material.LEATHER_CHESTPLATE, "§e" + kit.getName(), new ArrayList<>(), kit.isInUse(), clickType -> {}), kit))); - SWListInv inv = new SWListInv<>(player, "§eKit wählen", false, entries, (clickType, kit) -> preview(player, kit)); - if(entries.isEmpty()) - inv.setItem(22, new SWItem(Material.BARRIER, "§cKeine Kits gefunden")); - inv.setItem(48, Material.NETHER_STAR, "§eNeues Kit", clickType -> { - SWAnvilInv anvilInv = new SWAnvilInv(player, "Kitname eingeben"); - anvilInv.setItem(Material.LEATHER_CHESTPLATE); - anvilInv.setCallback(s -> { - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(PersonalKit.nameInUse(user.getId(), Config.SchematicType.toDB(), s)) { - player.sendMessage(FightSystem.PREFIX + "§cDieser Kitname wird bereits genutzt!"); - player.closeInventory(); - return; - } - Kit prototype = KitManager.getKits(Fight.getFightPlayer(player).isLeader()).get(0); - PersonalKit kit = PersonalKit.create(user.getId(), Config.SchematicType.toDB(), s, prototype.getInventory(), prototype.getArmor()); - openKitCreator(player, kit); - }); - anvilInv.open(); - }); - inv.setItem(50, Material.NAME_TAG, "§eSuchen", clickType -> { - SWAnvilInv anvilInv = new SWAnvilInv(player, "§eNach Kit suchen"); - anvilInv.setItem(Material.PAPER); - anvilInv.setCallback(s -> openKitSelector(player, s)); - anvilInv.open(); - }); - inv.open(); - } - - public static void preview(Player player, PersonalKit kit){ - SWInventory inv = new SWInventory(player, 54, kit.getName()); - - Kit.preview(inv, kit.getInventory(), kit.getArmor(), null); - - inv.setItem(45, Material.LEATHER_CHESTPLATE, "§aKit benutzen", clickType -> useKit(player, kit)); - inv.setItem(49, SWItem.getMaterial("WOOD_AXE"), "§7Kit bearbeiten", clickType -> openKitCreator(player, kit)); - inv.setItem(53, Material.BARRIER, "§cKit löschen", clickType -> { - player.closeInventory(); - SWInventory conf = new SWInventory(player, 9, "Kit wirklich löchen?"); - conf.setItem(8, SWItem.getDye(1), "§cAbbrechen", click -> player.closeInventory()); - conf.setItem(0, SWItem.getDye(10), "§aLöschen", click -> { - player.closeInventory(); - if(kit.isInUse()) { - useKit(player, PersonalKit.get(SteamwarUser.get(player.getUniqueId()).getId(), Config.SchematicType.toDB()).get(0)); - } - kit.delete(); - }); - conf.open(); - }); - inv.open(); - } - - private static void useKit(Player player, PersonalKit kit) { - kit.setInUse(); - player.closeInventory(); - } - public static void openKitCreator(Player player, PersonalKit kit){ - if(!enabled.contains(FightSystem.getFightState())) - return; - player.closeInventory(); new InventoryBackup(player, kit); - - FightPlayer fightPlayer = Fight.getFightPlayer(player); - assert fightPlayer != null; - - if(kit == null){ - fightPlayer.getKit().loadToPlayer(player); - }else{ - player.getInventory().setContents(kit.getInventory()); - player.getInventory().setArmorContents(kit.getArmor()); - } - - player.updateInventory(); + new Kit(kit).loadToPlayer(player); player.setGameMode(GameMode.CREATIVE); toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!")); } @@ -165,10 +80,23 @@ public class PersonalKitCreator extends BasicListener { Player player = (Player) e.getWhoClicked(); //Deny bad items - if(isBadItem(e.getCursor(), player)) + if(Kit.isBadItem(e.getCursor())) e.setCancelled(true); - checkForClear(e, player); + /* Should the inventory reset? */ + 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 @@ -198,97 +126,28 @@ public class PersonalKitCreator extends BasicListener { 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 && PersonalKitCreator_14.hasAttributeModifier(stack)){ - Bukkit.getLogger().log(Level.SEVERE, "Spieler " + player.getName() + " hat versucht ein Item mit einem Attribute-Modifier zu bekommen."); - return true; - } - - if(stack.hasItemMeta()){ - ItemMeta meta = stack.getItemMeta(); - if(meta instanceof BlockDataMeta && ((BlockDataMeta)meta).hasBlockData()) - return true; //Blocks always upwards slabs etc. - - if(hasItems(stack)) - return true; //Blocks prefilled inventories - } - - Kit normal = KitManager.getKitByName(Config.MemberDefault); - assert normal != null; - return !normal.isEnchantmentInKit(stack) && !stack.getEnchantments().isEmpty(); - } - - private static boolean hasItems(ItemStack stack){ - return VersionedCallable.call(new VersionedCallable<>(() -> PersonalKitCreator_8.hasItems(stack), 8), - new VersionedCallable<>(() -> PersonalKitCreator_9.hasItems(stack), 9), - new VersionedCallable<>(() -> PersonalKitCreator_10.hasItems(stack), 10), - new VersionedCallable<>(() -> PersonalKitCreator_12.hasItems(stack), 12), - new VersionedCallable<>(() -> PersonalKitCreator_14.hasItems(stack), 14), - new VersionedCallable<>(() -> PersonalKitCreator_15.hasItems(stack), 15)); - } - private static class InventoryBackup{ private final Player player; - private final ItemStack[] contents; - private final ItemStack[] armor; private final PersonalKit kit; + private final Kit backup; private InventoryBackup(Player player, PersonalKit kit){ openKitCreators.put(player, this); this.player = player; - this.contents = player.getInventory().getContents(); - this.armor = player.getInventory().getArmorContents(); + this.backup = new Kit("backup", player); this.kit = kit; } - private void loadBackup(){ - PlayerInventory inventory = player.getInventory(); - inventory.setContents(contents); - inventory.setArmorContents(armor); - player.updateInventory(); - } - private void close(){ openKitCreators.remove(player); - kit.setContainer(removeBadItems(player.getInventory().getContents()), removeBadItems(player.getInventory().getArmorContents())); - loadBackup(); + Kit kit1 = new Kit(kit.getName(), player); + kit1.removeBadItems(); + kit1.toPersonalKit(kit); + backup.loadToPlayer(player); player.setGameMode(GameMode.SURVIVAL); - useKit(player, kit); - } - - 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; + kit.setInUse(); + player.closeInventory(); + Objects.requireNonNull(Fight.getFightPlayer(player)).setKit(new Kit(kit)); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java index fe95bce..f05c79b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java @@ -108,7 +108,7 @@ public class PlayerMoveListener extends BasicListener { if(to.getY() <= Config.underArenaBorder) { if(player.getGameMode() == GameMode.SPECTATOR || team == null) reset(event, DENY_ARENA); - else if(FightSystem.getFightState().infight()) + else if(FightState.getFightState().infight()) player.damage(2); else if(!Config.GroundWalkable) player.teleport(team.getSpawn()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java index 3830c12..a37fc22 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java @@ -68,7 +68,7 @@ public class PlayerStateListener extends BasicListener{ Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5); } else { player.teleport(fightTeam.getSpawn()); - if(FightSystem.getFightState().setup()) + if(FightState.setup()) Fight.setPlayerGamemode(player, GameMode.SURVIVAL); else Fight.setPlayerGamemode(player, GameMode.SPECTATOR); @@ -103,13 +103,12 @@ public class PlayerStateListener extends BasicListener{ if(fightTeam == null) return; - FightState fightState = FightSystem.getFightState(); - if(fightState.setup()){ + if(FightState.setup()){ fightTeam.removePlayer(player); if(Config.recording()) RecordSystem.entityDespawns(player); - }else if(fightState.ingame()){ + }else if(FightState.ingame()){ FightPlayer fightPlayer = fightTeam.getFightPlayer(player); if(fightPlayer.isLiving()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java similarity index 75% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index 973ca54..1895673 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -17,22 +17,31 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; import de.steamwar.core.VersionedCallable; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityExplodeEvent; -import java.util.List; +import java.util.EnumSet; -public class WaterRemover { - private WaterRemover(){} +public class WaterRemover extends BasicListener { private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY; - public static void add(List l) { - for(Block b : l){ + public WaterRemover() { + super(EnumSet.of(FightState.RUNNING)); + } + + @EventHandler + public void handleEntityExplode(EntityExplodeEvent event) { + event.setYield(0); //No drops (additionally to world config) + + for(Block b : event.blockList()){ //b cannot be water or air due to current explosion checkBlock(b.getRelative(BlockFace.UP)); @@ -43,8 +52,10 @@ public class WaterRemover { } } - private static void checkBlock(Block b) { - if(!removeWater(b)) + private void checkBlock(Block b) { + //checks for water and removes it, if present + if(!VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8), + new VersionedCallable<>(() -> WaterRemover_14.removeWater(b), 14))) return; if(b.getY() < MIN_Y) @@ -61,10 +72,4 @@ public class WaterRemover { return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8), new VersionedCallable<>(() -> WaterRemover_14.isWater(block), 14)); } - - public static boolean removeWater(Block block){ - //checks for water and removes it, if present - return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(block), 8), - new VersionedCallable<>(() -> WaterRemover_14.removeWater(block), 14)); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index 4b403e6..ce7b19b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -274,7 +274,7 @@ public class RecordSystem { private static void checkWorldState(){ tick(); - if(FightSystem.getFightState() == FightState.SPECTATE) + if(FightState.getFightState() == FightState.SPECTATE) return; for(TNTPrimed tnt : WORLD.getEntitiesByClass(TNTPrimed.class)){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index 3a07821..fc6e52f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -19,39 +19,70 @@ package de.steamwar.fightsystem.states; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + public enum FightState { - PRE_LEADER_SETUP(true, true, false, false), - PRE_SCHEM_SETUP(true, true, false, false), - POST_SCHEM_SETUP(true, true, false, false), - PRE_RUNNING(false, false, true, false), - RUNNING(false, false, true, true), - SPECTATE(false, true, false, false); + PRE_LEADER_SETUP, + PRE_SCHEM_SETUP, + POST_SCHEM_SETUP, + PRE_RUNNING, + RUNNING, + SPECTATE; - private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP - private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE - private final boolean ingame; //PRE_RUNNING, RUNNING - private final boolean infight; //RUNNING + public static Set SETUP = EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP); + public static Set INGAME = EnumSet.of(PRE_RUNNING, RUNNING); + public static Set ALL = EnumSet.allOf(FightState.class); + public static Set SCHEM = EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP)); - FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){ - this.setup = setup; - this.outgame = outgame; - this.ingame = ingame; - this.infight = infight; + private static final Map stateDependentFeatures = new HashMap<>(); + private static FightState fightState = PRE_LEADER_SETUP; + + public static FightState getFightState() { + return fightState; } - public boolean setup(){ - return setup; + public static void registerStateDependent(StateDependent stateDependent){ + if(stateDependent.enabled().isEmpty()) + return; + boolean enabled = stateDependent.enabled().contains(fightState); + stateDependentFeatures.put(stateDependent, enabled); + if(enabled) + stateDependent.enable(); } - public boolean outgame(){ - return outgame; + public static void setFightState(FightState state){ + fightState = state; + + for(Map.Entry feature : stateDependentFeatures.entrySet()){ + //Enable feature if should be enabled and currently disabled + if(feature.getKey().enabled().contains(fightState)){ + if(!feature.getValue()){ + feature.getKey().enable(); + feature.setValue(true); + } + feature.getKey().stateChange(fightState); + } + + //Disable feature if should be disabled and currently enabled + if(!feature.getKey().enabled().contains(fightState) && feature.getValue()){ + feature.getKey().disable(); + feature.setValue(false); + } + } } - public boolean ingame(){ - return ingame; + public static boolean setup(){ + return SETUP.contains(fightState); } - public boolean infight(){ - return infight; + public static boolean ingame(){ + return INGAME.contains(fightState); + } + + public static boolean infight(){ + return fightState == RUNNING; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java index a2408f9..a6b480d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; @@ -29,15 +28,13 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import java.util.EnumSet; -import java.util.HashSet; import java.util.Set; public class EnterHandler implements StateDependent { - private static final Set enabled = EnumSet.of(FightState.RUNNING); - private static final Set countdowns = new HashSet<>(); + private static final Set enabled = EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING); public EnterHandler(){ - FightSystem.registerStateDependent(this); + FightState.registerStateDependent(this); } @Override @@ -45,13 +42,6 @@ public class EnterHandler implements StateDependent { return enabled; } - private void registerTeam(FightTeam team){ - for(FightPlayer fp : team.getPlayers()){ - if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0) - countdowns.add(new EnternCountdown(fp)); - } - } - @Override public void enable() { registerTeam(Fight.getBlueTeam()); @@ -60,9 +50,20 @@ public class EnterHandler implements StateDependent { @Override public void disable() { - for(EnternCountdown countdown : countdowns){ - countdown.disable(); + unregisterTeam(Fight.getBlueTeam()); + unregisterTeam(Fight.getRedTeam()); + } + + private void registerTeam(FightTeam team){ + for(FightPlayer fp : team.getPlayers()){ + if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0) + fp.setEnternCountdown(new EnternCountdown(fp)); + } + } + + private void unregisterTeam(FightTeam team){ + for(FightPlayer fp : team.getPlayers()){ + fp.stopEnternCountdown(); } - countdowns.clear(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index dde9310..1652f53 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.TPSWatcher; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; @@ -44,7 +45,7 @@ public class FightScoreboard { private static String title = ""; private static final HashMap scores = new HashMap<>(); - public static void init(){ + static { Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200); } @@ -84,8 +85,8 @@ public class FightScoreboard { title = "§6Kampf"; if(Config.recording()) RecordSystem.scoreboardTitle(title); - if (Config.Timeout || Config.Points || Config.HeartRatioTimeout) { - int fightTime = FightSystem.getFightTime(); + int fightTime = TimeOverCountdown.getRemainingTime(); + if (fightTime != -1) { if (fightTime >= 60) addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); else @@ -94,7 +95,7 @@ public class FightScoreboard { addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); - if(fullScoreboard.contains(FightSystem.getFightState())){ + if(fullScoreboard.contains(FightState.getFightState())){ if (Config.PercentSystem){ addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getRedPercent()) / 100.0) + "%", 1); addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + (Math.round(100.0 * WinconditionPercentSystem.getBluePercent()) / 100.0) + "%", 0); @@ -120,9 +121,9 @@ public class FightScoreboard { index = 0; FightTeam team = null; if(index == 1) - team = Fight.redTeam; + team = Fight.getRedTeam(); if(index == 2) - team = Fight.blueTeam; + team = Fight.getBlueTeam(); scores.clear(); if(team != null) teamScoreboard(team); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 23fcdf4..e95fa3b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -76,7 +77,7 @@ public class FightStatistics { } try { - int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), + int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, TimeOverCountdown.getRemainingTime(), blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription); for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 3b9df81..0391143 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketEvent; @@ -30,32 +31,44 @@ import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.MultiBlockChangeInfo; import com.comphenix.protocol.wrappers.WrappedBlockData; import de.steamwar.core.Core; -import de.steamwar.core.VersionedRunnable; +import de.steamwar.core.VersionedCallable; import de.steamwar.core.events.ChunkListener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; import static de.steamwar.fightsystem.utils.ITechHider.bypass; -public class TechHider { - private TechHider(){} +public class TechHider implements StateDependent { - private static boolean running = false; + private static final boolean DISABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; - public static void init(){ - if(disabled()) + private final Set enabled; + private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + private final PacketAdapter chunkHider; + + public TechHider(){ + FightState.registerStateDependent(this); + enabled = DISABLED + ? EnumSet.noneOf(FightState.class) + : EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP)); + chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), + new VersionedCallable<>(TechHider_12::chunkHider, 12), + new VersionedCallable<>(TechHider_14::chunkHider, 14), + new VersionedCallable<>(TechHider_15::chunkHider, 15)); + + if(DISABLED) return; if(Core.getVersion() > 8){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { + protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); @@ -65,7 +78,7 @@ public class TechHider { } }); } - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) { + protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ENTITY) { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); @@ -76,133 +89,136 @@ public class TechHider { }); } - public static void start(){ - if(running) - return; - running = true; - - if(disabled()) - return; - - blockActionHider(); - blockHider(); - multiBlockHider(); - updateBlockEntity(); - VersionedRunnable.call(new VersionedRunnable(TechHider_12::start, 12), - new VersionedRunnable(TechHider_14::start, 14), - new VersionedRunnable(TechHider_15::start, 15)); + @Override + public Set enabled() { + return enabled; } - private static void multiBlockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); + @Override + public void enable() { + protocolManager.addPacketListener(blockHider); + protocolManager.addPacketListener(multiBlockHider); + protocolManager.addPacketListener(blockActionHider); + if(Core.getVersion() > 8) { + protocolManager.addPacketListener(updateBlockEntity); + } + if(chunkHider != null) { + protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(ITechHider.threadMultiplier * 4); + } + } - Player p = e.getPlayer(); - ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); - if(bypass(p, pos.getChunkX(), pos.getChunkZ())) - return; + @Override + public void disable() { + protocolManager.removePacketListener(blockHider); + protocolManager.removePacketListener(multiBlockHider); + protocolManager.removePacketListener(blockActionHider); + if(Core.getVersion() > 8) { + protocolManager.removePacketListener(updateBlockEntity); + } + if(chunkHider != null) { + protocolManager.getAsynchronousManager().unregisterAsyncHandler(chunkHider); + } + } - PacketContainer cached = ITechHider.packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } + private final PacketAdapter multiBlockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MULTI_BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); - cached = packet.shallowClone(); - ITechHider.packetCache.put(packet, cached); + Player p = e.getPlayer(); + ChunkCoordIntPair pos = packet.getChunkCoordIntPairs().read(0); + if(bypass(p, pos.getChunkX(), pos.getChunkZ())) + return; + + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ e.setPacket(cached); - StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); - MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); - boolean changed = false; - for(MultiBlockChangeInfo mbci : changes){ - WrappedBlockData block = mbci.getData(); - if(Config.HiddenBlockTags.contains(block.getType().name())){ - changed = true; - block.setType(ITechHider.obfuscateMaterial); - mbci.setData(block); - } - } - - if(changed){ - blockStructure.write(0, changes); - } + return; } - }); - } - private static void blockHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - PacketContainer cached = ITechHider.packetCache.get(packet); - if(cached != null){ - e.setPacket(cached); - return; - } - - cached = packet.deepClone(); - ITechHider.packetCache.put(packet, cached); - e.setPacket(cached); - StructureModifier blockStructure = cached.getBlockData(); - WrappedBlockData block = blockStructure.read(0); + cached = packet.shallowClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); + MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); + boolean changed = false; + for(MultiBlockChangeInfo mbci : changes){ + WrappedBlockData block = mbci.getData(); if(Config.HiddenBlockTags.contains(block.getType().name())){ + changed = true; block.setType(ITechHider.obfuscateMaterial); - blockStructure.write(0, block); + mbci.setData(block); } } - }); - } - private static void blockActionHider(){ - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); - - Player p = e.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - e.setCancelled(true); + if(changed){ + blockStructure.write(0, changes); } - }); - } + } + }; - private static void updateBlockEntity(){ - if(Core.getVersion() < 9) - return; + private final PacketAdapter blockHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_CHANGE) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); - ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.TILE_ENTITY_DATA) { - @Override - public void onPacketSending(PacketEvent event) { - PacketContainer packet = event.getPacket(); - BlockPosition pos = packet.getBlockPositionModifier().read(0); + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; - Player p = event.getPlayer(); - if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) - return; - - // 9 == Set sign text - if(packet.getIntegers().read(0) != 9) - return; - - event.setCancelled(true); + PacketContainer cached = ITechHider.packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; } - }); - } + + cached = packet.deepClone(); + ITechHider.packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getBlockData(); + WrappedBlockData block = blockStructure.read(0); + if(Config.HiddenBlockTags.contains(block.getType().name())){ + block.setType(ITechHider.obfuscateMaterial); + blockStructure.write(0, block); + } + } + }; + + private final PacketAdapter blockActionHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_ACTION) { + @Override + public void onPacketSending(PacketEvent e) { + PacketContainer packet = e.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = e.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + e.setCancelled(true); + } + }; + + private final PacketAdapter updateBlockEntity = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.TILE_ENTITY_DATA) { + @Override + public void onPacketSending(PacketEvent event) { + PacketContainer packet = event.getPacket(); + BlockPosition pos = packet.getBlockPositionModifier().read(0); + + Player p = event.getPlayer(); + if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) + return; + + // 9 == Set sign text + if(packet.getIntegers().read(0) != 9) + return; + + event.setCancelled(true); + } + }; public static List prepareChunkReload(Player p){ - if(disabled()) + if(DISABLED) return Collections.emptyList(); List chunksToReload = new ArrayList<>(); for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++) @@ -213,7 +229,7 @@ public class TechHider { } public static void reloadChunks(Player p, List chunksToReload){ - if(disabled()) + if(DISABLED) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(ChunkPos chunk : chunksToReload){ @@ -223,10 +239,6 @@ public class TechHider { }, 40); } - private static boolean disabled(){ - return Config.OnlyPublicSchematics || Config.test() || !Config.TechhiderActive; - } - public static class ChunkPos{ final int x; final int z; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index 38b7203..b89c1c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -42,7 +42,7 @@ public class EventTeamOffWincondition extends Wincondition { @Override public void disable() { - //Team off is a on time trigger + //Team off is a one time trigger } private void teamOff(FightTeam team){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java index a26ef73..78b4645 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; @@ -32,7 +31,7 @@ abstract class Wincondition implements StateDependent { Wincondition(boolean condition, Set enabled){ this.enabled = enabled; if(condition) - FightSystem.registerStateDependent(this); + FightState.registerStateDependent(this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 1fe5ad3..2d4309d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -55,7 +55,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize; bluePercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.redTeam, "Percent"); + FightSystem.setSpectateState(Fight.getRedTeam(), "Percent"); } //Team Red }else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) { @@ -64,7 +64,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize; redPercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.blueTeam, "Percent"); + FightSystem.setSpectateState(Fight.getBlueTeam(), "Percent"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java new file mode 100644 index 0000000..97d0c14 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java @@ -0,0 +1,40 @@ +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.states.FightState; + +import java.util.EnumSet; + +public class WinconditionPercentTimeout extends Wincondition { + + private static final String WINDESCRIPTION = "PercentTimeout"; + + private TimeOverCountdown countdown; + + public WinconditionPercentTimeout() { + super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING)); + } + + @Override + public void enable() { + countdown = new TimeOverCountdown(() -> { + double bluePercent = WinconditionPercentSystem.getBluePercent(); + double redPercent = WinconditionPercentSystem.getRedPercent(); + + if(bluePercent > redPercent) + FightSystem.setSpectateState(Fight.getBlueTeam(), WINDESCRIPTION); + else if(bluePercent < redPercent) + FightSystem.setSpectateState(Fight.getRedTeam(), WINDESCRIPTION); + else + FightSystem.setSpectateState(null, WINDESCRIPTION); + }); + } + + @Override + public void disable(){ + countdown.disable(); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 0f30223..c8d762f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; @@ -114,7 +115,7 @@ public class WinconditionRelativePercent extends Wincondition{ private int currentBlocks(){ // Entern active - if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= FightSystem.getFightTime()) + if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeOverCountdown.getRemainingTime()) return currentBlocks; int blocks = 0; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index d7c3e3c..c3ec8d8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -23,8 +23,8 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.listener.WaterRemover; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.WaterRemover; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.scheduler.BukkitTask;