From 93b5fd8a030f66ad1b5106a6f8f353355d4cb8ea Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 10 Mar 2021 17:12:24 +0100 Subject: [PATCH 01/15] Some big refactoring Signed-off-by: Lixfel --- .../listener/PersonalKitCreator_10.java | 4 +- .../listener/PersonalKitCreator_12.java | 4 +- .../fightsystem/utils/TechHider_12.java | 11 +- .../fightsystem/fight/FightTeam_14.java | 3 +- .../listener/PersonalKitCreator_14.java | 6 +- .../{utils => listener}/WaterRemover_14.java | 2 +- .../fightsystem/utils/TechHider_14.java | 11 +- .../listener/PersonalKitCreator_15.java | 4 +- .../fightsystem/utils/TechHider_15.java | 11 +- .../fightsystem/fight/FightTeam_8.java | 4 +- .../listener/PersonalKitCreator_8.java | 4 +- .../{utils => listener}/WaterRemover_8.java | 2 +- .../listener/PersonalKitCreator_9.java | 4 +- .../src/de/steamwar/fightsystem/Config.java | 15 +- .../de/steamwar/fightsystem/FightSystem.java | 176 ++------- .../fightsystem/commands/AcceptCommand.java | 10 +- .../fightsystem/commands/AkCommand.java | 197 +--------- .../fightsystem/commands/BasicCommand.java | 40 ++ .../fightsystem/commands/Commands.java | 23 +- .../fightsystem/commands/DeclineCommand.java | 10 +- .../de/steamwar/fightsystem/commands/GUI.java | 58 ++- .../fightsystem/commands/InviteCommand.java | 10 +- .../fightsystem/commands/KitCommand.java | 11 +- .../fightsystem/commands/LeaderCommand.java | 15 +- .../fightsystem/commands/LeaveCommand.java | 9 +- .../commands/LockschemCommand.java | 9 +- .../fightsystem/commands/ReadyCommand.java | 9 +- .../fightsystem/commands/RemoveCommand.java | 10 +- ...myCommand.java => UnavailableCommand.java} | 4 +- .../fightsystem/countdown/Countdown.java | 32 +- .../countdown/EnternCountdown.java | 9 +- .../countdown/NoPlayersOnlineCountdown.java | 14 +- .../countdown/PreRunningCountdown.java | 14 +- .../countdown/PreSchemPasteCountdown.java | 19 +- .../countdown/SetupOverCountdown.java | 14 +- .../countdown/SpectateOverCountdown.java | 14 +- .../countdown/TechKOCountdown.java | 1 + .../countdown/TimeOverCountdown.java | 11 +- .../de/steamwar/fightsystem/fight/Fight.java | 35 +- .../fightsystem/fight/FightPlayer.java | 35 +- .../fightsystem/fight/FightSchematic.java | 201 ++++++++++ .../steamwar/fightsystem/fight/FightTeam.java | 179 ++------- .../de/steamwar/fightsystem/fight/Kit.java | 349 ++++++++++++++++++ .../src/de/steamwar/fightsystem/kit/Kit.java | 207 ----------- .../steamwar/fightsystem/kit/KitManager.java | 97 ----- .../fightsystem/listener/BasicListener.java | 2 +- .../listener/EntityExplodeListener.java | 40 -- .../listener/EventRecordListener.java | 4 +- .../listener/HotbarGUIListener.java | 2 +- .../listener/PersonalKitCreator.java | 201 ++-------- .../listener/PlayerMoveListener.java | 2 +- .../listener/PlayerStateListener.java | 7 +- .../{utils => listener}/WaterRemover.java | 33 +- .../fightsystem/record/RecordSystem.java | 2 +- .../fightsystem/states/FightState.java | 77 ++-- .../fightsystem/utils/EnterHandler.java | 31 +- .../fightsystem/utils/FightScoreboard.java | 13 +- .../fightsystem/utils/FightStatistics.java | 3 +- .../steamwar/fightsystem/utils/TechHider.java | 258 +++++++------ .../EventTeamOffWincondition.java | 2 +- .../winconditions/Wincondition.java | 3 +- .../WinconditionPercentSystem.java | 4 +- .../WinconditionPercentTimeout.java | 40 ++ .../WinconditionRelativePercent.java | 3 +- .../WinconditionWaterTechKO.java | 2 +- 65 files changed, 1281 insertions(+), 1355 deletions(-) rename FightSystem_14/src/de/steamwar/fightsystem/{utils => listener}/WaterRemover_14.java (97%) rename FightSystem_8/src/de/steamwar/fightsystem/{utils => listener}/WaterRemover_8.java (96%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java rename FightSystem_Main/src/de/steamwar/fightsystem/commands/{EventDummyCommand.java => UnavailableCommand.java} (86%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/fight/Kit.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java rename FightSystem_Main/src/de/steamwar/fightsystem/{utils => listener}/WaterRemover.java (75%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java 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; From 7268be7de9195d26b7cf571b1e017409eb1745ca Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 10 Mar 2021 22:45:17 +0100 Subject: [PATCH 02/15] Refactor winconditions Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 24 +--- .../winconditions/Winconditions.java | 34 +++++ .../de/steamwar/fightsystem/FightSystem.java | 4 +- .../countdown/TimeOverCountdown.java | 9 -- .../fightsystem/fight/FightSchematic.java | 19 +++ .../steamwar/fightsystem/fight/FightTeam.java | 5 +- .../fightsystem/utils/FightScoreboard.java | 55 ++++---- .../fightsystem/utils/FightStatistics.java | 9 +- .../EventTeamOffWincondition.java | 15 +- .../winconditions/ListenerWincondition.java | 9 +- .../winconditions/PercentWincondition.java | 7 + ...dition.java => PrintableWincondition.java} | 25 +--- .../RankedPlayerLeftWincondition.java | 25 +++- .../winconditions/TimeoutWincondition.java | 56 ++++++++ .../winconditions/Wincondition.java | 47 ++++++- .../winconditions/WinconditionAllDead.java | 18 +-- .../WinconditionCaptainDead.java | 18 +-- .../WinconditionHeartRatioTimeout.java | 37 ++--- .../WinconditionPercentSystem.java | 76 ++++++----- .../WinconditionPercentTimeout.java | 59 ++++---- .../winconditions/WinconditionPoints.java | 129 +++++++++--------- .../WinconditionPumpkinTechKO.java | 86 +++++------- .../WinconditionRelativePercent.java | 108 +++++++-------- ...echKO.java => WinconditionTimeTechKO.java} | 6 +- .../winconditions/WinconditionTimeout.java | 22 +-- .../WinconditionWaterTechKO.java | 88 +++++------- 26 files changed, 534 insertions(+), 456 deletions(-) create mode 100644 FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java rename FightSystem_Main/src/de/steamwar/fightsystem/winconditions/{PlayerWincondition.java => PrintableWincondition.java} (59%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java rename FightSystem_Main/src/de/steamwar/fightsystem/winconditions/{WinconditionTechKO.java => WinconditionTimeTechKO.java} (95%) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 5f3c451..7152d59 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem; +import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; import de.steamwar.sql.Team; @@ -33,6 +34,7 @@ import org.bukkit.util.Vector; import java.io.File; import java.util.*; import java.util.logging.Level; +import java.util.stream.Collectors; public class Config { @@ -104,16 +106,7 @@ public class Config { public static final boolean Ranked; //Active win conditions - public static final boolean Timeout; - public static final boolean HeartRatioTimeout; - public static final boolean AllDead; - public static final boolean CaptainDead; - public static final boolean PercentSystem; - public static final boolean RelativePercent; - public static final boolean Points; - public static final boolean TechKO; - public static final boolean WaterTechKO; - public static final boolean PumpkinTechKO; + public static final Set ActiveWinconditions; //win condition parameters public static final int TimeoutTime; @@ -202,16 +195,7 @@ public class Config { GameName = config.getString("Output.GameName"); TeamChatDetection = config.getString("Output.TeamChatDetection"); - Timeout = config.getBoolean("WinConditions.Timeout"); - HeartRatioTimeout = config.getBoolean("WinConditions.HeartRatioTimeout"); - AllDead = config.getBoolean("WinConditions.AllDead"); - CaptainDead = config.getBoolean("WinConditions.CaptainDead"); - PercentSystem = config.getBoolean("WinConditions.PercentSystem"); - RelativePercent = config.getBoolean("WinConditions.RelativePercent"); - Points = config.getBoolean("WinConditions.Points"); - TechKO = config.getBoolean("WinConditions.TechKO"); - WaterTechKO = config.getBoolean("WinConditions.WaterTechKO"); - PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO"); + ActiveWinconditions = config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet()); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java b/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java new file mode 100644 index 0000000..0394ee7 --- /dev/null +++ b/FightSystem_API/src/de/steamwar/fightsystem/winconditions/Winconditions.java @@ -0,0 +1,34 @@ +/* + 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.winconditions; + +public enum Winconditions { + TIMEOUT, + HEART_RATIO_TIMEOUT, + PERCENT_TIMEOUT, + ALL_DEAD, + CAPTAIN_DEAD, + PERCENT_SYSTEM, + RELATIVE_PERCENT, + POINTS, + TIME_TECH_KO, + WATER_TECH_KO, + PUMPKIN_TECH_KO +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 400af23..2eca2ee 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -96,8 +96,10 @@ public class FightSystem extends JavaPlugin { new WinconditionPoints(); new WinconditionTimeout(); new WinconditionHeartRatioTimeout(); - new WinconditionTechKO(); + new WinconditionTimeTechKO(); new EventTeamOffWincondition(); + new RankedPlayerLeftWincondition(); + new WinconditionPercentTimeout(); new NoPlayersOnlineCountdown(); new PreSchemPasteCountdown(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index c138d99..acb6d6f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -25,14 +25,11 @@ 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(); } @@ -46,10 +43,4 @@ public class TimeOverCountdown extends Countdown { Bukkit.broadcastMessage(FightSystem.PREFIX +"§aZeit abgelaufen!"); timeOver.run(); } - - public static int getRemainingTime(){ - if(instance == null) - return -1; - return instance.getTimeLeft(); - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 6d63711..4835b41 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -1,3 +1,22 @@ +/* + 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 com.sk89q.worldedit.EditSession; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 7cfe8cc..265dee2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -29,7 +29,6 @@ import de.steamwar.fightsystem.states.FightState; 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.Schematic; import de.steamwar.sql.SteamwarUser; @@ -204,9 +203,7 @@ public class FightTeam implements IFightTeam{ if(!players.isEmpty()) { setLeader(players.values().iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); - }else if(Config.Ranked){ - RankedPlayerLeftWincondition.leaderQuit(this); - }else if(!Config.event()){ + }else if(!Config.event() && !Config.Ranked){ FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); } return; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index 1652f53..5e92c7b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -34,11 +34,10 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Scoreboard; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Set; +import java.util.*; public class FightScoreboard { + private FightScoreboard(){} private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static int index = 0; @@ -72,9 +71,7 @@ public class FightScoreboard { } private static void teamScoreboard(FightTeam fightTeam){ - title = fightTeam.getColoredName(); - if(Config.recording()) - RecordSystem.scoreboardTitle(title); + setTitle(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) addScore(fightTeam.getPrefix() + fp.getPlayer().getName(), (int) Math.ceil(fp.getPlayer().getHealth())); @@ -82,37 +79,31 @@ public class FightScoreboard { } private static void generalScoreboard(){ - title = "§6Kampf"; - if(Config.recording()) - RecordSystem.scoreboardTitle(title); - int fightTime = TimeOverCountdown.getRemainingTime(); - if (fightTime != -1) { + setTitle("§eKampf"); + List scores = new ArrayList<>(); + + TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown(); + if(timeOverCountdown != null){ + int fightTime = timeOverCountdown.getTimeLeft(); if (fightTime >= 60) - addScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s", 4); + scores.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s"); else - addScore("§7Zeit: §a" + fightTime + "s", 4); + scores.add("§7Zeit: §a" + fightTime + "s"); } - addScore("§7TPS: §e" + TPSWatcher.getTPS(), 3); + scores.add("§7TPS: §e" + TPSWatcher.getTPS()); 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); - }else if(Config.WaterTechKO){ - addScore(Fight.getRedTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamRedWater(), 1); - addScore(Fight.getBlueTeam().getPrefix() + "Wasser: " + WinconditionWaterTechKO.getTeamBlueWater(), 0); - }else if(Config.RelativePercent){ - addScore(Fight.getRedTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getRed().getPrintablePercent() + "%", 1); - addScore(Fight.getBlueTeam().getPrefix() + "Schaden: " + WinconditionRelativePercent.getBlue().getPrintablePercent() + "%", 0); - }else if(Config.Points){ - addScore(Fight.getRedTeam().getPrefix() + "Punkte: " + WinconditionPoints.getRed().getPoints(), 1); - addScore(Fight.getBlueTeam().getPrefix() + "Punkte: " + WinconditionPoints.getBlue().getPoints(), 0); - }else if(Config.PumpkinTechKO){ - addScore(Fight.getRedTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamRedPumpkins(), 1); - addScore(Fight.getBlueTeam().getPrefix() + "Kanonen: " + WinconditionPumpkinTechKO.getTeamBluePumpkins(), 0); + for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){ + scores.add(wincondition.getDisplay(Fight.getRedTeam())); + scores.add(wincondition.getDisplay(Fight.getBlueTeam())); } } + + int value = scores.size(); + for(String score : scores){ + addScore(score, value--); + } } private static void nextIndexDisplay() { @@ -131,6 +122,12 @@ public class FightScoreboard { generalScoreboard(); } + private static void setTitle(String t) { + title = t; + if(Config.recording()) + RecordSystem.scoreboardTitle(t); + } + private static void addScore(String string, int i) { if(Config.recording()) RecordSystem.scoreboardData(string, i); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index e95fa3b..a65d25b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -25,6 +25,7 @@ import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.winconditions.TimeoutWincondition; import de.steamwar.sql.Elo; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; @@ -76,8 +77,14 @@ public class FightStatistics { redSchem = null; } + int remainingTime = 0; + TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown(); + if(timeOverCountdown != null){ + remainingTime = timeOverCountdown.getTimeLeft(); + } + try { - int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, TimeOverCountdown.getRemainingTime(), + int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime, blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription); for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index b89c1c0..638cabe 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -20,24 +20,26 @@ package de.steamwar.fightsystem.winconditions; 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 org.bukkit.Bukkit; import java.util.EnumSet; public class EventTeamOffWincondition extends Wincondition { public EventTeamOffWincondition(){ - super(Config.event(), EnumSet.of(FightState.PRE_RUNNING)); + super(Config.event(), EnumSet.of(FightState.PRE_RUNNING), "TeamOffline"); } @Override public void enable() { - teamOff(Fight.getBlueTeam()); - teamOff(Fight.getRedTeam()); + if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){ + win(null, null, null, "§cBeide Teams sind offline!"); + }else{ + teamOff(Fight.getBlueTeam()); + teamOff(Fight.getRedTeam()); + } } @Override @@ -47,8 +49,7 @@ public class EventTeamOffWincondition extends Wincondition { private void teamOff(FightTeam team){ if(team.allPlayersOut()){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!"); - FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline"); + win(Fight.getOpposite(team), "§cDas Team ", " §cist offline!"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java index 311285b..2eaf446 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java @@ -29,9 +29,12 @@ import java.util.Set; abstract class ListenerWincondition extends Wincondition implements Listener { - ListenerWincondition(boolean condition, Set enabled){ - //If the condition is not met, never enable - super(condition, enabled); + protected ListenerWincondition(Winconditions condition, Set enabled, String windescription){ + super(condition, enabled, windescription); + } + + protected ListenerWincondition(boolean condition, Set enabled, String windescription) { + super(condition, enabled, windescription); } /** diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java new file mode 100644 index 0000000..4997c13 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -0,0 +1,7 @@ +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.fight.FightTeam; + +public interface PercentWincondition { + double getPercent(FightTeam team); +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java similarity index 59% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java rename to FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java index 472a7c5..31053a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PrintableWincondition.java @@ -1,6 +1,6 @@ -/* +/* 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 @@ -19,25 +19,8 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import org.bukkit.entity.Player; -import java.util.EnumSet; - -abstract class PlayerWincondition extends ListenerWincondition { - - PlayerWincondition(boolean condition) { - super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); - } - - boolean isTarget(Player player){ - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam == null) - return false; - - fightTeam.getFightPlayer(player).setOut(); - return true; - } +public interface PrintableWincondition { + String getDisplay(FightTeam team); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java index 77a8a38..371ee08 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java @@ -19,14 +19,29 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; -public class RankedPlayerLeftWincondition { - private RankedPlayerLeftWincondition(){} +public class RankedPlayerLeftWincondition extends ListenerWincondition{ - public static void leaderQuit(FightTeam leaderlessTeam){ - FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit"); + public RankedPlayerLeftWincondition(){ + super(Config.Ranked, FightState.INGAME, "LeaderQuit"); + } + + @EventHandler + public void handlePlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + FightTeam team = isTarget(player); + if(team == null) + return; + + if(team.isPlayerLeader(player)) { + win(Fight.getOpposite(team), "§cDer Leader von ", " §chat den Kampf verlassen!"); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java new file mode 100644 index 0000000..9529474 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java @@ -0,0 +1,56 @@ +/* + 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.winconditions; + +import de.steamwar.fightsystem.countdown.TimeOverCountdown; +import de.steamwar.fightsystem.states.FightState; + +import java.util.EnumSet; +import java.util.Set; + +public abstract class TimeoutWincondition extends Wincondition { + + private static TimeOverCountdown timeOverCountdown = null; + + protected TimeoutWincondition(Winconditions condition, Set enabled, String windescription) { + super(condition, enabled, windescription); + } + + protected TimeoutWincondition(Winconditions condition, String windescription) { + super(condition, EnumSet.of(FightState.RUNNING), windescription); + } + + protected abstract void timeOver(); + + @Override + public void enable() { + timeOverCountdown = new TimeOverCountdown(this::timeOver); + } + + @Override + public void disable() { + if(timeOverCountdown != null) + timeOverCountdown.disable(); + } + + public static TimeOverCountdown getTimeOverCountdown(){ + return timeOverCountdown; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java index 78b4645..bd265d9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -19,23 +19,66 @@ package de.steamwar.fightsystem.winconditions; +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; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import java.util.ArrayList; +import java.util.List; import java.util.Set; -abstract class Wincondition implements StateDependent { +public abstract class Wincondition implements StateDependent { + + protected static PercentWincondition percentWincondition = null; + protected static final List printableWinconditions = new ArrayList<>(); private final Set enabled; + private final String windescription; - Wincondition(boolean condition, Set enabled){ + protected Wincondition(Winconditions condition, Set enabled, String windescription){ + this(Config.ActiveWinconditions.contains(condition), enabled, windescription); + } + + protected Wincondition(boolean condition, Set enabled, String windescription){ this.enabled = enabled; + this.windescription = windescription; if(condition) FightState.registerStateDependent(this); } + protected void win(FightTeam team, String preteammessage, String postteammessage){ + win(team, preteammessage, postteammessage, null); + } + + protected void win(FightTeam team, String preteammessage, String postteammessage, String tiemessage){ + if(team != null){ + Bukkit.broadcastMessage(FightSystem.PREFIX + preteammessage + team.getColoredName() + postteammessage); + }else{ + Bukkit.broadcastMessage(FightSystem.PREFIX + tiemessage); + } + FightSystem.setSpectateState(team, windescription); + } + + protected FightTeam isTarget(Player player){ + FightTeam fightTeam = Fight.getPlayerTeam(player); + if(fightTeam == null) + return null; + + fightTeam.getFightPlayer(player).setOut(); + return fightTeam; + } + @Override public Set enabled(){ return enabled; } + + public static List getPrintableWinconditions(){ + return printableWinconditions; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 3f03582..d1c37d0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -19,20 +19,18 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionAllDead extends PlayerWincondition { +public class WinconditionAllDead extends ListenerWincondition { public WinconditionAllDead(){ - super(Config.AllDead); + super(Winconditions.ALL_DEAD, FightState.INGAME, "AllDead"); } @EventHandler @@ -46,14 +44,12 @@ public class WinconditionAllDead extends PlayerWincondition { } private void handleDeath(Player player, String message){ - if(!isTarget(player)) + FightTeam team = isTarget(player); + if(team == null) return; - FightTeam fightTeam = Fight.getPlayerTeam(player); - assert fightTeam != null; // Checked with isTarget - if(fightTeam.allPlayersOut()) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead"); + if(team.allPlayersOut()) { + win(Fight.getOpposite(team), "§cDer letzte Spieler aus ", message); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index 94b3726..c86092c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -19,20 +19,18 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.states.FightState; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionCaptainDead extends PlayerWincondition { +public class WinconditionCaptainDead extends ListenerWincondition { public WinconditionCaptainDead(){ - super(Config.CaptainDead); + super(Winconditions.CAPTAIN_DEAD, FightState.INGAME, "LeaderDead"); } @EventHandler @@ -46,14 +44,12 @@ public class WinconditionCaptainDead extends PlayerWincondition { } private void handleDeath(Player player, String message){ - if(!isTarget(player)) + FightTeam team = isTarget(player); + if(team == null) return; - FightTeam fightTeam = Fight.getPlayerTeam(player); - assert fightTeam != null; // Checked with isTarget - if(fightTeam.isPlayerLeader(player)) { - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead"); + if(team.isPlayerLeader(player)) { + win(Fight.getOpposite(team), "§cDer Leader von ", message); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index 74f1843..d400671 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -19,39 +19,26 @@ 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 de.steamwar.fightsystem.fight.FightTeam; -import java.util.EnumSet; - -public class WinconditionHeartRatioTimeout extends Wincondition { - - private TimeOverCountdown countdown; +public class WinconditionHeartRatioTimeout extends TimeoutWincondition { public WinconditionHeartRatioTimeout() { - super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING)); + super(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout"); } @Override - public void enable() { - countdown = new TimeOverCountdown(() -> { - double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); - double redHeartRatio = Fight.getRedTeam().getHeartRatio(); + protected void timeOver() { + double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); + double redHeartRatio = Fight.getRedTeam().getHeartRatio(); - if(blueHeartRatio > redHeartRatio) - FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout"); - else if(blueHeartRatio < redHeartRatio) - FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout"); - else - FightSystem.setSpectateState(null, "HeartTimeout"); - }); - } + FightTeam team = null; + if(blueHeartRatio > redHeartRatio) + team = Fight.getBlueTeam(); + else if(blueHeartRatio < redHeartRatio) + team = Fight.getRedTeam(); - @Override - public void disable(){ - countdown.disable(); + win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte mehr verbleibende Leben!", "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 2d4309d..7766081 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -20,60 +20,66 @@ package de.steamwar.fightsystem.winconditions; 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.utils.Region; -import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityExplodeEvent; import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; -public class WinconditionPercentSystem extends ListenerWincondition { +public class WinconditionPercentSystem extends ListenerWincondition implements PrintableWincondition, PercentWincondition { - private static double bluePercent = 0D; - private static double redPercent = 0D; + private static final int SCHEMATIC_SIZE = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); - private static int blueDestroyedBlocks; - private static int redDestroyedBlocks; - - private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); + private final Map teamMap = new HashMap<>(); public WinconditionPercentSystem() { - super(Config.PercentSystem, EnumSet.of(FightState.RUNNING)); + super(Winconditions.PERCENT_SYSTEM, EnumSet.of(FightState.RUNNING), "Percent"); + printableWinconditions.add(this); + percentWincondition = this; + teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); + teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); } @EventHandler public void handleEntityExplode(EntityExplodeEvent event) { - Entity entity = event.getEntity(); + teamMap.values().forEach(teamPercent -> teamPercent.check(event)); + } - //Team Blue - if(Region.isInRange(entity.getLocation(), Config.TeamBlueCornerX, Config.TeamBlueCornerY, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){ - blueDestroyedBlocks = blueDestroyedBlocks + event.blockList().size(); - double doubleBlueDestroyedBlocks = blueDestroyedBlocks; - double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize; - bluePercent = destroyPercent; - if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.getRedTeam(), "Percent"); + @Override + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%"; + } + + @Override + public double getPercent(FightTeam team) { + return teamMap.get(team).percent; + } + + private class TeamPercent { + + private final FightTeam team; + private double percent; + private int destroyedBlocks; + + private TeamPercent(FightTeam team) { + this.team = team; + } + + private void check(EntityExplodeEvent event) { + if(!Region.isInRange(event.getEntity().getLocation(), team.getCornerX(), team.getCornerY(), team.getCornerZ(), Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){ + return; } - //Team Red - }else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) { - redDestroyedBlocks = redDestroyedBlocks + event.blockList().size(); - double doubleRedDestroyedBlocks = redDestroyedBlocks; - double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize; - redPercent = destroyPercent; - if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.getBlueTeam(), "Percent"); + + destroyedBlocks += event.blockList().size(); + percent = (double)destroyedBlocks * 100 / SCHEMATIC_SIZE; + if(percent >= Config.PercentWin) { + win(Fight.getOpposite(team), "§cTeam ", " §chat den Gegnern"); } } } - - public static double getBluePercent() { - return bluePercent; - } - - public static double getRedPercent() { - return redPercent; - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java index 97d0c14..7cdd9d5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java @@ -1,40 +1,43 @@ +/* + 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.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 de.steamwar.fightsystem.fight.FightTeam; -import java.util.EnumSet; - -public class WinconditionPercentTimeout extends Wincondition { - - private static final String WINDESCRIPTION = "PercentTimeout"; - - private TimeOverCountdown countdown; +public class WinconditionPercentTimeout extends TimeoutWincondition { public WinconditionPercentTimeout() { - super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING)); + super(Winconditions.HEART_RATIO_TIMEOUT, "PercentTimeout"); } @Override - public void enable() { - countdown = new TimeOverCountdown(() -> { - double bluePercent = WinconditionPercentSystem.getBluePercent(); - double redPercent = WinconditionPercentSystem.getRedPercent(); + protected void timeOver() { + double bluePercent = Wincondition.percentWincondition.getPercent(Fight.getBlueTeam()); + double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam()); - 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(); + FightTeam team = null; + if(bluePercent > redPercent) + team = Fight.getRedTeam(); + else if(bluePercent < redPercent) + team = Fight.getBlueTeam(); + win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte weniger Schaden erlitten!", "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden!"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 6292b2e..beaa543 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -19,54 +19,67 @@ 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; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionPoints extends PlayerWincondition { +import java.util.HashMap; +import java.util.Map; - private static TeamPoints blue; - private static TeamPoints red; - private TimeOverCountdown countdown; +public class WinconditionPoints extends TimeoutWincondition implements PrintableWincondition, Listener { + + private final Map percentMap = new HashMap<>(); + private final Map teamMap = new HashMap<>(); public WinconditionPoints(){ - super(Config.Points); + super(Winconditions.POINTS, FightState.INGAME, "Points"); + + percentMap.put(Fight.getBlueTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getBlueTeam())); + percentMap.put(Fight.getRedTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getRedTeam())); + + teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam())); + teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam())); + printableWinconditions.add(this); } - public static TeamPoints getRed(){ - return red; - } + @Override + protected void timeOver() { + int redPoints = teamMap.get(Fight.getRedTeam()).getPoints(); + int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints(); - public static TeamPoints getBlue(){ - return blue; + FightTeam team = null; + if(redPoints > bluePoints) + team = Fight.getRedTeam(); + else if(redPoints < bluePoints) + team = Fight.getBlueTeam(); + + win(team, "§cDas Team ", " §chat mehr Punkte!", "§cBeide Teams haben gleich viele Punkte!"); } @Override public void enable() { - super.enable(); - blue = new TeamPoints(Fight.getRedTeam(), WinconditionRelativePercent.getBlue(), WinconditionRelativePercent.getRed()); - red = new TeamPoints(Fight.getBlueTeam(), WinconditionRelativePercent.getRed(), WinconditionRelativePercent.getBlue()); + Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); + teamMap.values().forEach(TeamPoints::enable); } @Override public void disable() { super.disable(); - if(countdown != null) - countdown.disable(); + HandlerList.unregisterAll(this); } @Override public void stateChange(FightState state){ if(state == FightState.RUNNING){ - countdown = new TimeOverCountdown(this::fightEnds); + super.enable(); } } @@ -81,73 +94,63 @@ public class WinconditionPoints extends PlayerWincondition { } private void handleDeath(Player player, String message){ - if(!isTarget(player)) + FightTeam team = isTarget(player); + if(team == null) return; - FightTeam fightTeam = Fight.getPlayerTeam(player); - TeamPoints enemy = getEnemyByTeam(fightTeam); - assert fightTeam != null; // Checked by isTarget - if(fightTeam.isPlayerLeader(player)) { + TeamPoints enemy = teamMap.get(Fight.getOpposite(team)); + if(team.isPlayerLeader(player)) { enemy.points += 500; - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getPrefix() + fightTeam.getColoredName() + message); - fightEnds(); - }else if(fightTeam.getPlayers().size() <= 5) + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + team.getColoredName() + message); + timeOver(); + }else if(team.getPlayers().size() <= 5) enemy.points += 300; else enemy.points += 200; } - private void fightEnds(){ - if(red.getPoints() > blue.getPoints()) - FightSystem.setSpectateState(blue.enemy, "Points"); - else if(red.getPoints() < blue.getPoints()) - FightSystem.setSpectateState(red.enemy, "Points"); - else - FightSystem.setSpectateState(null, "Points"); + @Override + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Punkte: " + teamMap.get(team).getPoints(); } - private TeamPoints getEnemyByTeam(FightTeam team){ - if(team == blue.enemy) - return blue; - else - return red; - } + private class TeamPoints { + private static final int MAX_POINTS = 2000; + + private final FightTeam team; - public static class TeamPoints { - private final FightTeam enemy; - private final WinconditionRelativePercent.TeamPercent enemyPercent; private double factor; - private static final int maxPoints = 2000; - private int points; - TeamPoints(FightTeam enemy, WinconditionRelativePercent.TeamPercent ownPercent, WinconditionRelativePercent.TeamPercent enemyPercent){ - this.enemy = enemy; - this.enemyPercent = enemyPercent; + TeamPoints(FightTeam team){ + this.team = team; points = 0; + } - //Prevent NPE - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () ->{ - if(enemyPercent.getBlockCount() < ownPercent.getBlockCount()) - this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte - else{ - double f = 10000.0 * ownPercent.getBlockCount() / enemyPercent.getBlockCount(); + public void enable() { + percentMap.get(team).enable(); + int ownBlocks = percentMap.get(team).getBlockCount(); + int enemyBlocks = percentMap.get(Fight.getOpposite(team)).getBlockCount(); - if(f > 10000) - f = 10000; - else if(f < 4000) - f = 4000; + if(enemyBlocks < ownBlocks) { + this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte + } else { + double f = 10000.0 * ownBlocks / enemyBlocks; - this.factor = f; - } - }); + if(f > 10000) + f = 10000; + else if(f < 4000) + f = 4000; + + this.factor = f; + } } public int getPoints(){ - int damagePoints = (int)(enemyPercent.getPercent() * factor); - if(damagePoints > maxPoints) - damagePoints = maxPoints; + int damagePoints = (int)(percentMap.get(Fight.getOpposite(team)).getPercent() * factor); + if(damagePoints > MAX_POINTS) + damagePoints = MAX_POINTS; return points + damagePoints; } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 6194b94..2355cbc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -30,31 +30,26 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.scheduler.BukkitTask; -import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; -public class WinconditionPumpkinTechKO extends Wincondition { +public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition { - private static int teamRedPumpkins = -1; - private static int teamBluePumpkins = -1; - private static final World WORLD = Bukkit.getWorlds().get(0); + private static final World world = Bukkit.getWorlds().get(0); private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); + + private final Map teamMap = new HashMap<>(); private BukkitTask task; - private static boolean running = false; public WinconditionPumpkinTechKO(){ - super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); - } - - public static int getTeamBluePumpkins() { - return teamBluePumpkins; - } - public static int getTeamRedPumpkins() { - return teamRedPumpkins; + super(Winconditions.PUMPKIN_TECH_KO, FightState.INGAME, "PumpkinTechKO"); + teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam())); + teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam())); } @Override public void enable() { - task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), WinconditionPumpkinTechKO::recursiveCheck, 0, 200); + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 0, 200); } @Override @@ -62,45 +57,38 @@ public class WinconditionPumpkinTechKO extends Wincondition { task.cancel(); } - private static void recursiveCheck(){ - if(running) - return; - running = true; - teamRedPumpkins = getPumpkins(Config.TeamRedCornerX, - Config.TeamRedCornerY, - Config.TeamRedCornerZ, - Config.TeamRedCornerX + Config.SchemsizeX, - Config.TeamRedCornerY + Config.SchemsizeY, - Config.TeamRedCornerZ + Config.SchemsizeZ); - teamBluePumpkins = getPumpkins(Config.TeamBlueCornerX, - Config.TeamBlueCornerY, - Config.TeamBlueCornerZ, - Config.TeamBlueCornerX + Config.SchemsizeX, - Config.TeamBlueCornerY + Config.SchemsizeY, - Config.TeamBlueCornerZ + Config.SchemsizeZ); - - checkKO(Fight.getRedTeam(), teamRedPumpkins); - checkKO(Fight.getBlueTeam(), teamBluePumpkins); - running = false; + private void check(){ + teamMap.values().forEach(TeamPumpkin::check); } - private static int getPumpkins(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ - int pumpkins = 0; - for(int x = minX; x <= maxX; x++) { - for(int y = minY; y <= maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { - if (WORLD.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) - pumpkins++; + @Override + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Kanonen: " + teamMap.get(team).pumpkins; + } + + private class TeamPumpkin { + private final FightTeam team; + + private int pumpkins; + + private TeamPumpkin (FightTeam team) { + this.team = team; + } + + private void check(){ + pumpkins = 0; + for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) { + for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) { + for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) { + if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) + pumpkins++; + } } } - } - return pumpkins; - } - private static void checkKO(FightTeam team, int pumpkins){ - if(pumpkins == 0){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO")); + if(pumpkins == 0) { + win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!"); + } } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index c8d762f..78cad8e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -21,7 +21,6 @@ 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; @@ -30,16 +29,12 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.scheduler.BukkitTask; -import java.util.Collections; -import java.util.EnumSet; -import java.util.HashSet; -import java.util.Set; +import java.util.*; -public class WinconditionRelativePercent extends Wincondition{ +public class WinconditionRelativePercent extends Wincondition implements PrintableWincondition, PercentWincondition { + private static final World world = Bukkit.getWorlds().get(0); private static final Set ignoredBlocks; - private static TeamPercent blue = null; - private static TeamPercent red = null; static{ Set ignored = new HashSet<>(); @@ -48,74 +43,78 @@ public class WinconditionRelativePercent extends Wincondition{ ignoredBlocks = Collections.unmodifiableSet(ignored); } + private final Map teamMap = new HashMap<>(); + public WinconditionRelativePercent(){ - super(Config.RelativePercent || Config.Points, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); - } - - public static TeamPercent getBlue(){ - if(blue == null) - blue = new TeamPercent(Fight.getBlueTeam()); - return blue; - } - - public static TeamPercent getRed(){ - if(red == null) - red = new TeamPercent(Fight.getRedTeam()); - return red; + super(Winconditions.RELATIVE_PERCENT, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "RelativePercent"); + teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); + teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); + printableWinconditions.add(this); + percentWincondition = this; } @Override public void enable() { - getBlue(); - getRed(); + teamMap.values().forEach(TeamPercent::enable); } @Override public void disable() { - blue.task.cancel(); - red.task.cancel(); + teamMap.values().forEach(teamPercent -> teamPercent.task.cancel()); + } + + @Override + public double getPercent(FightTeam team) { + return teamMap.get(team).getPercent(); + } + + @Override + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Schaden: " + (Math.round(100.0 * getPercent(team)) / 100.0) + "%"; } public static class TeamPercent { - private static final World world = Bukkit.getWorlds().get(0); private final FightTeam team; - private final int blockCount; - private final BukkitTask task; - private boolean running = false; + private int blockCount; + private BukkitTask task; private int currentBlocks; - private TeamPercent(FightTeam team){ + public TeamPercent(FightTeam team){ this.team = team; - this.blockCount = currentBlocks(); - this.currentBlocks = blockCount; - - task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { - if(running) - return; - running = true; - currentBlocks = currentBlocks(); - checkPercentDefeat(); - running = false; - }, 400, 400); + this.currentBlocks = 1; } - public double getPrintablePercent(){ - return Math.round(10000.0 * getPercent()) / 100.0; + public void enable(){ + blockCount = currentBlocks(); + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400); } - final int getBlockCount(){ + private void check(){ + currentBlocks = currentBlocks(); + + if(!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) + return; + + if(getPercent() >= Config.PercentWin){ + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); + FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"); + } + } + + public double getPercent(){ + if(currentBlocks > blockCount) + return 0; + return (blockCount - currentBlocks) * 100 / (double) blockCount; + } + + public int getBlockCount(){ return blockCount; } - double getPercent(){ - int blocksDestroyed = blockCount - currentBlocks; - return blocksDestroyed > 0 ? blocksDestroyed / (double) blockCount : 0; - } - private int currentBlocks(){ // Entern active - if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeOverCountdown.getRemainingTime()) + if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeoutWincondition.getTimeOverCountdown().getTimeLeft()) return currentBlocks; int blocks = 0; @@ -129,14 +128,5 @@ public class WinconditionRelativePercent extends Wincondition{ } return blocks; } - - private void checkPercentDefeat(){ - if(!Config.RelativePercent) - return; - if(getPercent() * 100 >= Config.PercentWin){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent")); - } - } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java similarity index 95% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java rename to FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index 1652e2d..b6a8b08 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -32,7 +32,7 @@ import org.bukkit.scheduler.BukkitTask; import java.util.EnumSet; -public class WinconditionTechKO extends ListenerWincondition { +public class WinconditionTimeTechKO extends ListenerWincondition { private static final int TECH_KO_TIME_IN_S = 90; private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10; @@ -51,8 +51,8 @@ public class WinconditionTechKO extends ListenerWincondition { /** * Works only for z-Axis fight direction for performance reasons */ - public WinconditionTechKO(){ - super(Config.TechKO, EnumSet.of(FightState.RUNNING)); + public WinconditionTimeTechKO(){ + super(Winconditions.TIME_TECH_KO, EnumSet.of(FightState.RUNNING), null); if(Config.TeamBluetoReddistanceZ > 0) { smallerZteam = Fight.getBlueTeam(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index 9143d22..4151852 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -19,28 +19,14 @@ 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.states.FightState; - -import java.util.EnumSet; - -public class WinconditionTimeout extends Wincondition { - - private TimeOverCountdown countdown; +public class WinconditionTimeout extends TimeoutWincondition { public WinconditionTimeout() { - super(Config.Timeout, EnumSet.of(FightState.RUNNING)); + super(Winconditions.TIMEOUT, "Timeout"); } @Override - public void enable() { - countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout")); - } - - @Override - public void disable() { - countdown.disable(); + protected void timeOver() { + win(null, null, null, "§cDie Zeit ist abgelaufen!"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index c3ec8d8..845aa25 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -30,32 +30,26 @@ import org.bukkit.World; import org.bukkit.scheduler.BukkitTask; import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; -public class WinconditionWaterTechKO extends Wincondition { +public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition { - private static int teamRedWater; - private static int teamBlueWater; private static final World WORLD = Bukkit.getWorlds().get(0); + private final Map teamMap = new HashMap<>(); private BukkitTask task; - private boolean running = false; public WinconditionWaterTechKO() { - super(Config.WaterTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); - } - - public static int getTeamBlueWater() { - return teamBlueWater; - } - - public static int getTeamRedWater() { - return teamRedWater; + super(Winconditions.WATER_TECH_KO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "WaterTechKO"); + teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam())); + teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam())); + printableWinconditions.add(this); } @Override public void enable() { - checkTask(); - task = Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), this::checkTask, 200, 200); + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 200, 200); } @Override @@ -63,47 +57,37 @@ public class WinconditionWaterTechKO extends Wincondition { task.cancel(); } - private void checkEmpty(FightTeam team, int teamWater){ - if(teamWater == 0){ - Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO")); + private void check() { + teamMap.values().forEach(TeamWater::check); + } + + @Override + public String getDisplay(FightTeam team) { + return team.getPrefix() + "Wasser: " + teamMap.get(team).water; + } + + private class TeamWater { + private final FightTeam team; + private int water; + + private TeamWater(FightTeam team) { + this.team = team; } - } - private void checkTask() { - if(running) - return; - running = true; - teamRedWater = calcWater( - Config.TeamRedCornerX, - Config.TeamRedCornerY, - Config.TeamRedCornerZ, - Config.TeamRedCornerX + Config.SchemsizeX, - Config.TeamRedCornerY + Config.SchemsizeY, - Config.TeamRedCornerZ + Config.SchemsizeZ); - teamBlueWater = calcWater( - Config.TeamBlueCornerX, - Config.TeamBlueCornerY, - Config.TeamBlueCornerZ, - Config.TeamBlueCornerX + Config.SchemsizeX, - Config.TeamBlueCornerY + Config.SchemsizeY, - Config.TeamBlueCornerZ + Config.SchemsizeZ); - - checkEmpty(Fight.getRedTeam(), teamRedWater); - checkEmpty(Fight.getBlueTeam(), teamBlueWater); - running = false; - } - - private int calcWater(int minX, int minY, int minZ, int maxX, int maxY, int maxZ){ - int teamWater = 0; - for(int x = minX; x <= maxX; x++) { - for(int y = minY; y <= maxY; y++) { - for (int z = minZ; z <= maxZ; z++) { - if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z))) - teamWater++; + private void check() { + water = 0; + for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) { + for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) { + for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) { + if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z))) + water++; + } } } + + if(water == 0){ + win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!"); + } } - return teamWater; } } From 7b085d8ee6cfa3c36078955c406d3a4fc9434af2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 12 Mar 2021 15:43:32 +0100 Subject: [PATCH 03/15] Refactor StateDependent Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider_12.java | 21 +- .../fightsystem/utils/TechHider_14.java | 137 ++++++++++--- .../fightsystem/utils/TechHider_15.java | 189 ++--------------- .../de/steamwar/fightsystem/ArenaMode.java | 28 +++ .../src/de/steamwar/fightsystem/Config.java | 58 +++--- .../fightsystem/utils/ITechHider.java | 5 +- .../de/steamwar/fightsystem/FightSystem.java | 52 +++-- .../fightsystem/commands/AcceptCommand.java | 8 +- .../fightsystem/commands/AkCommand.java | 8 +- .../fightsystem/commands/BasicCommand.java | 40 ---- .../fightsystem/commands/DeclineCommand.java | 8 +- .../fightsystem/commands/InviteCommand.java | 8 +- .../fightsystem/commands/KitCommand.java | 7 +- .../fightsystem/commands/LeaderCommand.java | 10 +- .../fightsystem/commands/LeaveCommand.java | 7 +- .../commands/LockschemCommand.java | 12 +- .../fightsystem/commands/ReadyCommand.java | 7 +- .../fightsystem/commands/RemoveCommand.java | 8 +- .../fightsystem/countdown/Countdown.java | 15 +- .../countdown/NoPlayersOnlineCountdown.java | 16 +- .../countdown/PreRunningCountdown.java | 18 +- .../countdown/PreSchemPasteCountdown.java | 20 +- .../countdown/SetupOverCountdown.java | 18 +- .../countdown/SpectateOverCountdown.java | 18 +- .../countdown/TechKOCountdown.java | 47 ----- .../countdown/TimeOverCountdown.java | 1 - .../de/steamwar/fightsystem/fight/Fight.java | 6 +- .../fightsystem/fight/FightSchematic.java | 19 +- .../steamwar/fightsystem/fight/FightTeam.java | 17 +- .../ArrowPickup.java} | 21 +- .../fightsystem/listener/ArrowStopper.java | 28 +-- .../fightsystem/listener/BasicListener.java | 37 +--- .../{PlayerChatListener.java => Chat.java} | 16 +- .../{CheckListener.java => Check.java} | 12 +- ...eListener.java => ConnectionListener.java} | 51 ++--- ...istener.java => DenyWorldInteraction.java} | 45 ++-- ...yDamageListener.java => EntityDamage.java} | 11 +- ...{EventJoinListener.java => EventJoin.java} | 11 +- .../{utils => listener}/FightScoreboard.java | 80 ++++---- .../listener/FoodLevelChangeListener.java | 50 ----- .../listener/GameplayListener.java | 50 ----- ...{HotbarGUIListener.java => HotbarGUI.java} | 11 +- ...DamageListener.java => InFightDamage.java} | 16 +- ...oryListener.java => InFightInventory.java} | 23 +-- .../{PlayerMoveListener.java => Move.java} | 14 +- ...ormalJoinListener.java => NormalJoin.java} | 11 +- .../fightsystem/listener/Permanent.java | 107 ++++++++++ .../listener/PersonalKitCreator.java | 26 +-- .../fightsystem/listener/PistonListener.java | 11 +- ...leLaunchListener.java => PrepareJoin.java} | 37 ++-- ...ankedJoinListener.java => RankedJoin.java} | 11 +- ...ventRecordListener.java => Recording.java} | 37 ++-- .../listener/ScoreboardListener.java | 26 --- .../fightsystem/listener/TestJoin.java | 55 +++++ .../fightsystem/listener/TestListener.java | 193 ------------------ .../fightsystem/listener/WaterRemover.java | 15 +- .../fightsystem/record/RecordSystem.java | 3 +- .../fightsystem/states/FightState.java | 32 +-- .../IStateDependent.java} | 36 ++-- .../fightsystem/states/StateDependent.java | 59 +++--- .../states/StateDependentCommand.java | 56 +++++ .../StateDependentCountdown.java} | 36 ++-- .../StateDependentListener.java} | 39 ++-- .../states/StateDependentTask.java | 67 ++++++ .../fightsystem/utils/EnterHandler.java | 4 +- .../fightsystem/utils/FightStatistics.java | 8 +- .../steamwar/fightsystem/utils/TechHider.java | 25 ++- .../EventTeamOffWincondition.java | 40 ++-- .../winconditions/PercentWincondition.java | 19 ++ .../RankedPlayerLeftWincondition.java | 11 +- .../winconditions/Wincondition.java | 45 ++-- .../winconditions/WinconditionAllDead.java | 9 +- .../WinconditionCaptainDead.java | 9 +- .../WinconditionHeartRatioTimeout.java | 11 +- .../WinconditionPercentSystem.java | 11 +- .../WinconditionPercentTimeout.java | 11 +- .../winconditions/WinconditionPoints.java | 65 +++--- .../WinconditionPumpkinTechKO.java | 19 +- .../WinconditionRelativePercent.java | 28 ++- .../winconditions/WinconditionTimeTechKO.java | 66 +++--- .../winconditions/WinconditionTimeout.java | 12 +- .../WinconditionWaterTechKO.java | 19 +- 82 files changed, 1181 insertions(+), 1372 deletions(-) create mode 100644 FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java rename FightSystem_Main/src/de/steamwar/fightsystem/{commands/UnavailableCommand.java => listener/ArrowPickup.java} (60%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{PlayerChatListener.java => Chat.java} (87%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{CheckListener.java => Check.java} (88%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{PlayerStateListener.java => ConnectionListener.java} (74%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{FreezeWorldStateListener.java => DenyWorldInteraction.java} (68%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{EntityDamageListener.java => EntityDamage.java} (81%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{EventJoinListener.java => EventJoin.java} (92%) rename FightSystem_Main/src/de/steamwar/fightsystem/{utils => listener}/FightScoreboard.java (55%) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/GameplayListener.java rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{HotbarGUIListener.java => HotbarGUI.java} (90%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{InFightDamageListener.java => InFightDamage.java} (83%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{InFightInventoryListener.java => InFightInventory.java} (89%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{PlayerMoveListener.java => Move.java} (92%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{NormalJoinListener.java => NormalJoin.java} (87%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{ProjectileLaunchListener.java => PrepareJoin.java} (52%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{RankedJoinListener.java => RankedJoin.java} (85%) rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{EventRecordListener.java => Recording.java} (90%) delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java rename FightSystem_Main/src/de/steamwar/fightsystem/{winconditions/ListenerWincondition.java => states/IStateDependent.java} (51%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java rename FightSystem_Main/src/de/steamwar/fightsystem/{winconditions/TimeoutWincondition.java => states/StateDependentCountdown.java} (50%) rename FightSystem_Main/src/de/steamwar/fightsystem/{listener/VersionDependentListener.java => states/StateDependentListener.java} (51%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java 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 1e76865..b8aba8f 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -31,9 +31,12 @@ import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.logging.Level; import static de.steamwar.fightsystem.utils.ITechHider.bypass; @@ -41,9 +44,19 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; class TechHider_12 { private TechHider_12(){} - private static final short obfuscateShift4 = (short)(Config.ObfuscateWith << 4); + static Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4); + } + return hiddenBlockIds; + } - static PacketAdapter chunkHider(){ + static int getObfuscateWith() { + return Material.matchMaterial(Config.ObfuscateWith).getId() << 4; + } + + static PacketAdapter chunkHider(Set hiddenBlockIds, int obfuscateWith){ return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { @@ -91,8 +104,8 @@ class TechHider_12 { int entry = ITechHider.readVarInt(data, i); i += ITechHider.readVarIntLength(data, i); - if(Config.HiddenBlocks.contains(entry >> 4)){ - entry = obfuscateShift4; + if(hiddenBlockIds.contains(entry)){ + entry = obfuscateWith; changed = true; } buffer.writeBytes(ITechHider.writeVarInt(entry)); 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 42f546e..fa86a3f 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java @@ -30,16 +30,41 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; +import net.minecraft.server.v1_14_R1.Block; +import net.minecraft.server.v1_14_R1.IBlockData; +import net.minecraft.server.v1_14_R1.IRegistry; +import net.minecraft.server.v1_14_R1.MinecraftKey; import org.bukkit.entity.Player; +import java.nio.ByteBuffer; +import java.nio.LongBuffer; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static de.steamwar.fightsystem.utils.ITechHider.bypass; public class TechHider_14 { private TechHider_14(){} - static PacketAdapter chunkHider(){ + static Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ + hiddenBlockIds.add(Block.getCombinedId(data)); + } + } + return hiddenBlockIds; + } + + static int getObfuscateWith() { + return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); + } + + static PacketAdapter chunkHider(Set hiddenBlockIds, int obfuscateWith){ + /* + * Bevor editing this function read and understand: https://wiki.vg/Chunk_Format + * */ return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override public void onPacketSending(PacketEvent e) { @@ -52,16 +77,9 @@ public class TechHider_14 { if(bypass(p, chunkX, chunkZ)) 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>> list = cached.getListNbtModifier(); + packet = packet.shallowClone(); + e.setPacket(packet); + StructureModifier>> list = packet.getListNbtModifier(); List> nmsTags = list.read(0); boolean changed = false; for(int i = nmsTags.size() - 1; i >= 0; i--){ @@ -78,30 +96,25 @@ public class TechHider_14 { } changed = false; - StructureModifier byteArray = cached.getByteArrays(); + StructureModifier byteArray = packet.getByteArrays(); int primaryBitMask = ints.read(2); - int numChunkSections = 0; - while(primaryBitMask != 0){ - numChunkSections += primaryBitMask & 1; - primaryBitMask >>= 1; - } - byte [] data = byteArray.read(0); + byte[] data = byteArray.read(0); ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); int i = 0; - while(numChunkSections > 0){ + int chunkY = 0; + while(primaryBitMask != 0){ + while((primaryBitMask & 1) == 0){ + primaryBitMask >>= 1; + chunkY++; + } + buffer.writeBytes(data, i, 2); // Block count i += 2; byte bitsPerBlock = data[i++]; buffer.writeByte(bitsPerBlock); - if(bitsPerBlock < 4) - bitsPerBlock = 4; - else if(bitsPerBlock > 8){ - bitsPerBlock = 14; - buffer.writeByte(data[++i]); - } - if(bitsPerBlock != 14){ + if(bitsPerBlock < 9){ int paletteLength = ITechHider.readVarInt(data, i); int paletteLengthLength = ITechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, paletteLengthLength); @@ -110,30 +123,48 @@ public class TechHider_14 { int blockId = ITechHider.readVarInt(data, i); int actPaletteLength = ITechHider.readVarIntLength(data, i); - if(Config.HiddenBlocks.contains(blockId)){ - byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith); - buffer.writeBytes(a); + if(hiddenBlockIds.contains(blockId)){ + buffer.writeBytes(ITechHider.writeVarInt(obfuscateWith)); changed = true; }else{ buffer.writeBytes(data, i, actPaletteLength); } i += actPaletteLength; } + + //We modify only the chunk palette for performance reasons int dataArrayLength = ITechHider.readVarInt(data, i); int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); i += dataArrayLengthLength; i += dataArrayLength * 8; }else{ + //Full Chunk/no palette, so the chunk has to be crawled through int dataArrayLength = ITechHider.readVarInt(data, i); int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength*8 + dataArrayLengthLength); + buffer.writeBytes(data, i, dataArrayLengthLength); i += dataArrayLengthLength; + + ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8); + VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); + + for(int pos = 0; pos < 4096; pos++){ + if(hiddenBlockIds.contains(values.get(pos))){ + changed = true; + values.set(pos, obfuscateWith); + } + } + + for(long l : values.backing) + buffer.writeLong(l); + i += dataArrayLength * 8; } - numChunkSections--; + + primaryBitMask >>= 1; + chunkY++; } - buffer.writeBytes(data, i, data.length - i); + buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why if(changed){ data = new byte[buffer.readableBytes()]; @@ -143,4 +174,46 @@ public class TechHider_14 { } }; } + + private static final class VariableValueArray { + private final long[] backing; + private final int bitsPerValue; + private final long valueMask; + + public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { + this.bitsPerValue = bitsPerEntry; + this.backing = new long[dataArrayLength]; + buffer.get(backing); + this.valueMask = (1L << this.bitsPerValue) - 1; + } + + public int get(int index) { + index *= bitsPerValue; + int i0 = index >> 6; + int i1 = index & 0x3f; + + long value = backing[i0] >>> i1; + + // The value is divided over two long values + if (i1 + bitsPerValue > 64) { + value |= backing[++i0] << 64 - i1; + } + + return (int) (value & valueMask); + } + + public void set(int index, int value) { + index *= bitsPerValue; + int i0 = index >> 6; + int i1 = index & 0x3f; + + backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; + int i2 = i1 + bitsPerValue; + // The value is divided over two long values + if (i2 > 64) { + i0++; + backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1; + } + } + } } 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 ca06d6c..dabe7a4 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java @@ -1,6 +1,6 @@ -/* +/* 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 @@ -19,182 +19,29 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.protocol.PacketType; -import com.comphenix.protocol.events.PacketAdapter; -import com.comphenix.protocol.events.PacketContainer; -import com.comphenix.protocol.events.PacketEvent; -import com.comphenix.protocol.reflect.StructureModifier; -import com.comphenix.protocol.wrappers.nbt.NbtBase; -import com.comphenix.protocol.wrappers.nbt.NbtCompound; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.IFightSystem; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.UnpooledByteBufAllocator; -import org.bukkit.entity.Player; +import net.minecraft.server.v1_15_R1.Block; +import net.minecraft.server.v1_15_R1.IBlockData; +import net.minecraft.server.v1_15_R1.IRegistry; +import net.minecraft.server.v1_15_R1.MinecraftKey; -import java.nio.ByteBuffer; -import java.nio.LongBuffer; -import java.util.List; +import java.util.HashSet; +import java.util.Set; -import static de.steamwar.fightsystem.utils.ITechHider.bypass; - -public class TechHider_15 { +class TechHider_15 { private TechHider_15(){} - static PacketAdapter chunkHider(){ - /* - * Bevor editing this function read and understand: https://wiki.vg/Chunk_Format - * */ - return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { - @Override - public void onPacketSending(PacketEvent e) { - PacketContainer packet = e.getPacket(); - StructureModifier ints = packet.getIntegers(); - - int chunkX = ints.read(0); - int chunkZ = ints.read(1); - Player p = e.getPlayer(); - if(bypass(p, chunkX, chunkZ)) - return; - - packet = packet.shallowClone(); - e.setPacket(packet); - StructureModifier>> list = packet.getListNbtModifier(); - List> nmsTags = list.read(0); - boolean changed = false; - for(int i = nmsTags.size() - 1; i >= 0; i--){ - NbtBase nbtBase = nmsTags.get(i); - assert nbtBase instanceof NbtCompound; - NbtCompound nbt = (NbtCompound) nbtBase; - if(Config.HiddenBlockEntities.contains(nbt.getString("id"))){ - nmsTags.remove(i); - changed = true; - } - } - if(changed){ - list.write(0, nmsTags); - } - - changed = false; - StructureModifier byteArray = packet.getByteArrays(); - int primaryBitMask = ints.read(2); - byte[] data = byteArray.read(0); - ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.directBuffer(data.length + 100); - int i = 0; - - int chunkY = 0; - while(primaryBitMask != 0){ - while((primaryBitMask & 1) == 0){ - primaryBitMask >>= 1; - chunkY++; - } - - buffer.writeBytes(data, i, 2); // Block count - i += 2; - byte bitsPerBlock = data[i++]; - buffer.writeByte(bitsPerBlock); - - if(bitsPerBlock < 9){ - int paletteLength = ITechHider.readVarInt(data, i); - int paletteLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, paletteLengthLength); - i += paletteLengthLength; - for(int actPaletteId = 0; actPaletteId < paletteLength; actPaletteId++){ - int blockId = ITechHider.readVarInt(data, i); - int actPaletteLength = ITechHider.readVarIntLength(data, i); - - if(Config.HiddenBlocks.contains(blockId)){ - byte[] a = ITechHider.writeVarInt(Config.ObfuscateWith); - buffer.writeBytes(a); - changed = true; - }else{ - buffer.writeBytes(data, i, actPaletteLength); - } - i += actPaletteLength; - } - - //We modify only the chunk palette for performance reasons - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLength * 8 + dataArrayLengthLength); - i += dataArrayLengthLength; - i += dataArrayLength * 8; - }else{ - //Full Chunk/no palette, so the chunk has to be crawled through - int dataArrayLength = ITechHider.readVarInt(data, i); - int dataArrayLengthLength = ITechHider.readVarIntLength(data, i); - buffer.writeBytes(data, i, dataArrayLengthLength); - i += dataArrayLengthLength; - - ByteBuffer source = ByteBuffer.wrap(data, i, dataArrayLength * 8); - VariableValueArray values = new VariableValueArray(bitsPerBlock, dataArrayLength, source.asLongBuffer()); - - for(int pos = 0; pos < 4096; pos++){ - if(Config.HiddenBlocks.contains(values.get(pos))){ - changed = true; - values.set(pos, Config.ObfuscateWith); - } - } - - for(long l : values.backing) - buffer.writeLong(l); - - i += dataArrayLength * 8; - } - - primaryBitMask >>= 1; - chunkY++; - } - buffer.writeBytes(data, i, data.length - i); // MC appends a 0 byte at the end if there is a full chunk, idk why - - if(changed){ - data = new byte[buffer.readableBytes()]; - buffer.readBytes(data); - byteArray.write(0, data); - } + static Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + for(IBlockData data : IRegistry.BLOCK.get(new MinecraftKey(tag)).getStates().a()){ + hiddenBlockIds.add(Block.getCombinedId(data)); } - }; + } + return hiddenBlockIds; } - private static final class VariableValueArray { - private final long[] backing; - private final int bitsPerValue; - private final long valueMask; - - public VariableValueArray(int bitsPerEntry, int dataArrayLength, LongBuffer buffer) { - this.bitsPerValue = bitsPerEntry; - this.backing = new long[dataArrayLength]; - buffer.get(backing); - this.valueMask = (1L << this.bitsPerValue) - 1; - } - - public int get(int index) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - long value = backing[i0] >>> i1; - - // The value is divided over two long values - if (i1 + bitsPerValue > 64) { - value |= backing[++i0] << 64 - i1; - } - - return (int) (value & valueMask); - } - - public void set(int index, int value) { - index *= bitsPerValue; - int i0 = index >> 6; - int i1 = index & 0x3f; - - backing[i0] = this.backing[i0] & ~(this.valueMask << i1) | (value & valueMask) << i1; - int i2 = i1 + bitsPerValue; - // The value is divided over two long values - if (i2 > 64) { - i0++; - backing[i0] = backing[i0] & -(1L << i2 - 64) | value >> 64 - i1; - } - } + static int getObfuscateWith() { + return Block.getCombinedId(IRegistry.BLOCK.get(new MinecraftKey(Config.ObfuscateWith)).getBlockData()); } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java new file mode 100644 index 0000000..8e8a58f --- /dev/null +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -0,0 +1,28 @@ +package de.steamwar.fightsystem; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +public enum ArenaMode { + NORMAL, + RANKED, + EVENT, + TEST, + CHECK, + PREPARE; + + public static final Set All = Collections.unmodifiableSet(EnumSet.allOf(ArenaMode.class)); + + public static final Set Normal = Collections.unmodifiableSet(EnumSet.of(NORMAL)); + public static final Set Check = Collections.unmodifiableSet(EnumSet.of(CHECK)); + public static final Set Event = Collections.unmodifiableSet(EnumSet.of(EVENT)); + public static final Set Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); + public static final Set Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED)); + public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); + + public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); + public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT))); + public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); + public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT)); +} diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 7152d59..4daa7e3 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -26,7 +26,6 @@ import de.steamwar.sql.Team; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.util.Vector; @@ -122,11 +121,9 @@ public class Config { //tech hider parameter public static final boolean TechhiderActive; - public static final Set HiddenBlocks; - public static final Set HiddenBlockTags; + public static final Set HiddenBlocks; public static final Set HiddenBlockEntities; - public static final int ObfuscateWith; - public static final String ObfuscateWithTag; + public static final String ObfuscateWith; //event parameter private static final int EventKampfID; @@ -138,6 +135,9 @@ public class Config { //check parameter public static final int CheckSchemID; + public static final int PrepareSchemID; + + public static final ArenaMode mode; //live recorder parameter public static final String spectateIP = "127.0.0.1"; @@ -209,25 +209,9 @@ public class Config { PersonalKits = config.getBoolean("Kits.PersonalKits"); ForbiddenItems = config.getStringList("Kits.ForbiddenItems"); - ConfigurationSection techhiderConfig = config.getConfigurationSection("Techhider.HiddenBlocks"); - Set blocks = new HashSet<>(); - Set blockTags = new HashSet<>(); - for(String key : techhiderConfig.getKeys(false)){ - blockTags.add(key); - if(techhiderConfig.isInt(key)) - blocks.add(techhiderConfig.getInt(key)); - else{ - List minmax = techhiderConfig.getIntegerList(key); // Entry 0: Minimum, Entry 1: Maximum - for(int i = minmax.get(0); i <= minmax.get(1); i++) - blocks.add(i); - } - - } - HiddenBlocks = Collections.unmodifiableSet(blocks); - HiddenBlockTags = Collections.unmodifiableSet(blockTags); + HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); - ObfuscateWith = config.getInt("Techhider.ObfuscateWith"); - ObfuscateWithTag = config.getString("Techhider.ObfuscateWithTag"); + ObfuscateWith = config.getString("Techhider.ObfuscateWithTag"); TechhiderActive = config.getBoolean("Techhider.Active"); if(schemsizeX < 0){ @@ -326,7 +310,7 @@ public class Config { TeamBlueRotate = teamBlueRotate; EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); - if(event()){ + if(EventKampfID >= 1){ EventFight eventFight = EventFight.get(EventKampfID); if(eventFight == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight"); @@ -389,22 +373,28 @@ public class Config { RedLeader = null; CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); + PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0")); Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); + + if(Ranked){ + mode = ArenaMode.RANKED; + }else if(CheckSchemID != 0){ + mode = ArenaMode.CHECK; + }else if(EventKampfID >= 1){ + mode = ArenaMode.EVENT; + }else if(EventKampfID == -1){ + mode = ArenaMode.TEST; + }else if(PrepareSchemID != 0){ + mode = ArenaMode.PREPARE; + }else{ + mode = ArenaMode.NORMAL; + } } - public static boolean event(){ - return EventKampfID >= 1; - } public static boolean test(){ return EventKampfID == -1; } - public static boolean check(){ - return CheckSchemID != 0; - } - public static boolean fixedTeams(){ - return event() || Ranked; - } public static boolean recording(){ - return event(); + return mode == ArenaMode.EVENT; } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index 4d1f185..e882d8a 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.utils; import com.comphenix.protocol.events.PacketContainer; import com.google.common.primitives.Bytes; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.fight.IFight; @@ -69,10 +70,10 @@ public class ITechHider { arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ); arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1; - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWithTag); + obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); - if(Config.event()) + if(Config.mode == ArenaMode.EVENT) threadMultiplier = 4; else threadMultiplier = 1; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 2eca2ee..62fea36 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -59,30 +59,29 @@ public class FightSystem extends JavaPlugin { Fight.init(); RecordSystem.init(); - new EntityDamageListener(); + new EntityDamage(); new WaterRemover(); - new FoodLevelChangeListener(); + new Permanent(); new PistonListener(); - new PlayerChatListener(); - new HotbarGUIListener(); - new PlayerMoveListener(); - new PlayerStateListener(); - new ProjectileLaunchListener(); - new InFightDamageListener(); - new InFightInventoryListener(); - new FreezeWorldStateListener(); - new EventJoinListener(); - new EventRecordListener(); - new CheckListener(); - new TestListener(); - new NormalJoinListener(); - new RankedJoinListener(); - new GameplayListener(); + new Chat(); + new HotbarGUI(); + new Move(); + new ConnectionListener(); + new InFightDamage(); + new InFightInventory(); + new DenyWorldInteraction(); + new EventJoin(); + new Recording(); + new Check(); + new PrepareJoin(); + new TestJoin(); + new NormalJoin(); + new RankedJoin(); new PersonalKitCreator(); - new ScoreboardListener(); + new FightScoreboard(); new ArrowStopper(); if(Core.getVersion() > 8) - new VersionDependentListener(); + new ArrowPickup(); new EnterHandler(); new TechHider(); @@ -127,15 +126,12 @@ public class FightSystem extends JavaPlugin { return; } - if(Config.event() || Config.Ranked) { + if(Config.mode == ArenaMode.EVENT) { setPreSchemState(); - }else if(Config.test()){ - if(Config.check()){ - Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); - } - - setPreSchemState(); - Bukkit.getScheduler().runTaskLater(this, FightSystem::setPostSchemState, 0); + }else if(Config.mode == ArenaMode.CHECK){ + Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); + }else if(Config.mode == ArenaMode.PREPARE) { + Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); } } @@ -189,7 +185,7 @@ public class FightSystem extends JavaPlugin { Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); } - if(Config.event()) { + if(Config.mode == ArenaMode.EVENT) { if (winFightTeam == null) getEventFight().setErgebnis(0); else if (winFightTeam.isBlue()) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java index 73bc815..0e23db4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AcceptCommand.java @@ -19,16 +19,18 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class AcceptCommand extends BasicCommand { +public class AcceptCommand implements CommandExecutor { public AcceptCommand() { - super(!Config.fixedTeams(), FightState.SETUP, "accept"); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "accept", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java index bb59238..d58d55c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/AkCommand.java @@ -19,19 +19,21 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Kit; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; 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 AkCommand extends BasicCommand { +public class AkCommand implements CommandExecutor { public AkCommand() { - super(Config.test(), FightState.ALL, "ak"); + new StateDependentCommand(ArenaMode.Test, FightState.All, "ak", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java deleted file mode 100644 index 7d88be7..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/BasicCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -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/DeclineCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java index 85580ad..3fa9906 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/DeclineCommand.java @@ -19,16 +19,18 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class DeclineCommand extends BasicCommand { +public class DeclineCommand implements CommandExecutor { public DeclineCommand() { - super(!Config.fixedTeams(), FightState.SETUP, "decline"); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "decline", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java index 1578d6c..e6bee2c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/InviteCommand.java @@ -19,16 +19,18 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class InviteCommand extends BasicCommand { +public class InviteCommand implements CommandExecutor { public InviteCommand() { - super(!Config.fixedTeams(), FightState.SETUP, "invite"); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "invite", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java index f7e1bf4..585262b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/KitCommand.java @@ -19,15 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class KitCommand extends BasicCommand { +public class KitCommand implements CommandExecutor { public KitCommand() { - super(true, FightState.SETUP, "kit"); + new StateDependentCommand(ArenaMode.All, FightState.Setup, "kit", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java index 487086e..84a9f73 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java @@ -19,20 +19,20 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.util.EnumSet; - -public class LeaderCommand extends BasicCommand { +public class LeaderCommand implements CommandExecutor { public LeaderCommand() { - super(!Config.fixedTeams(), Config.test() ? FightState.ALL : EnumSet.of(FightState.PRE_LEADER_SETUP), "leader"); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "leader", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java index 4eebee8..7e3327e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaveCommand.java @@ -19,15 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class LeaveCommand extends BasicCommand { +public class LeaveCommand implements CommandExecutor { public LeaveCommand() { - super(true, FightState.SETUP, "leave"); + new StateDependentCommand(ArenaMode.All, FightState.Setup, "leave", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index e947c27..6087608 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -19,22 +19,26 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; 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 extends BasicCommand { +public class LockschemCommand implements CommandExecutor { public LockschemCommand() { - super(true, FightState.ALL, "lockschem"); + new StateDependentCommand(ArenaMode.All, FightState.All, "lockschem", this); } @Override @@ -67,6 +71,10 @@ public class LockschemCommand extends BasicCommand { } Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal); player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!"); + FightPlayer leader = fightTeam.getLeader(); + if(leader != null){ + leader.sendMessage(FightSystem.PREFIX + "§cDeine Schematic wurde von " + player.getName() + " gesperrt!"); + } return false; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java index 708bcb6..4761ca5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/ReadyCommand.java @@ -19,15 +19,18 @@ package de.steamwar.fightsystem.commands; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class ReadyCommand extends BasicCommand { +public class ReadyCommand implements CommandExecutor { public ReadyCommand() { - super(true, FightState.SETUP, "ready"); + new StateDependentCommand(ArenaMode.AntiPrepare, FightState.PostSchemSetup, "ready", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java index bb9175d..29ba6d2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/RemoveCommand.java @@ -19,16 +19,18 @@ package de.steamwar.fightsystem.commands; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -public class RemoveCommand extends BasicCommand { +public class RemoveCommand implements CommandExecutor { public RemoveCommand() { - super(!Config.fixedTeams(), FightState.SETUP, "remove"); + new StateDependentCommand(ArenaMode.VariableTeams, FightState.Setup, "remove", this); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java index 5a649cf..cc3fc73 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.core.Core; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.listener.BasicListener; @@ -34,16 +33,18 @@ import org.bukkit.scheduler.BukkitTask; public abstract class Countdown { - protected int time; + private final int totalTime; private final Sound sound; private final boolean level; + protected int time; private BukkitTask task = null; - abstract String countdownCounting(); - abstract void countdownFinished(); + public abstract String countdownCounting(); + public abstract void countdownFinished(); - Countdown(int time, SWSound sound, boolean level) { + public Countdown(int time, SWSound sound, boolean level) { + this.totalTime = time; this.time = time; this.sound = getSound(sound); this.level = level; @@ -68,6 +69,7 @@ public abstract class Countdown { } public void enable() { + time = totalTime; task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20); } @@ -79,8 +81,7 @@ public abstract class Countdown { } private void broadcast(String message){ - if(Config.recording()) - RecordSystem.actionBar(message); + RecordSystem.actionBar(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) BasicListener.toActionbar(p, msg); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index 8af6e9f..8c81c7b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -19,20 +19,17 @@ package de.steamwar.fightsystem.countdown; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; import org.bukkit.Bukkit; -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 class NoPlayersOnlineCountdown extends Countdown { public NoPlayersOnlineCountdown() { super(Config.NoPlayerOnlineDuration, null, false); - FightState.registerStateDependent(this); + new StateDependentCountdown(ArenaMode.All, FightState.PreLeaderSetup, this); } @Override @@ -44,9 +41,4 @@ public class NoPlayersOnlineCountdown extends Countdown implements StateDependen 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 438390e..4506ace 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -19,20 +19,17 @@ package de.steamwar.fightsystem.countdown; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; -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 class PreRunningCountdown extends Countdown { public PreRunningCountdown() { super(Config.PreFightDuration, SWSound.BLOCK_NOTE_PLING, true); - FightState.registerStateDependent(this); + new StateDependentCountdown(ArenaMode.All, FightState.PreRunning, this); } @Override @@ -44,9 +41,4 @@ public class PreRunningCountdown extends Countdown implements StateDependent { 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 0088037..aace340 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java @@ -19,34 +19,26 @@ package de.steamwar.fightsystem.countdown; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; -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 class PreSchemPasteCountdown extends Countdown { public PreSchemPasteCountdown() { super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false); - FightState.registerStateDependent(this); + new StateDependentCountdown(ArenaMode.All, FightState.PreSchemSetup, this); } @Override - String countdownCounting() { + public String countdownCounting() { return "bis eine Public-Schematic gewählt wird!"; } @Override - void countdownFinished() { + public void countdownFinished() { FightSystem.setPostSchemState(); } - - @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 d01e6af..2a93915 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java @@ -19,24 +19,21 @@ package de.steamwar.fightsystem.countdown; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; -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 class SetupOverCountdown extends Countdown { public SetupOverCountdown() { super(Config.SetupDuration, null, false); - FightState.registerStateDependent(this); + new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this); } @Override - String countdownCounting() { + public String countdownCounting() { return "bis die Kits verteilt werden!"; } @@ -44,9 +41,4 @@ public class SetupOverCountdown extends Countdown implements StateDependent { 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 74e5abf..c9893b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -19,20 +19,17 @@ package de.steamwar.fightsystem.countdown; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; -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 class SpectateOverCountdown extends Countdown { public SpectateOverCountdown() { super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false); - FightState.registerStateDependent(this); + new StateDependentCountdown(ArenaMode.AntiTest, FightState.Spectate, this); } @Override @@ -44,9 +41,4 @@ public class SpectateOverCountdown extends Countdown implements StateDependent { 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 deleted file mode 100644 index f958f8a..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java +++ /dev/null @@ -1,47 +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.countdown; - -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import org.bukkit.Bukkit; - -public class TechKOCountdown extends Countdown { - - private final FightTeam team; - - public TechKOCountdown(FightTeam team, int countdownTime) { - super(countdownTime, SWSound.BLOCK_NOTE_PLING, false); - this.team = team; - enable(); - } - - @Override - final String countdownCounting() { - return "bis " + team.getColoredName() + " §feinen Schuss abgegeben haben muss!"; - } - - @Override - void countdownFinished() { - Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!"); - FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO"); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java index acb6d6f..96a6cab 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TimeOverCountdown.java @@ -30,7 +30,6 @@ public class TimeOverCountdown extends Countdown { public TimeOverCountdown(Runnable timeOver) { super(Config.TimeoutTime, SWSound.BLOCK_NOTE_BASS, false); this.timeOver = timeOver; - enable(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 5a062a8..761dcef 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -26,6 +26,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.PlayerInfoData; import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.FightSystem; @@ -92,8 +93,7 @@ public class Fight { } public static void playSound(Sound sound, float volume, float pitch) { - if(Config.recording()) - RecordSystem.soundAtPlayer(sound.name(), volume, pitch); + RecordSystem.soundAtPlayer(sound.name(), volume, pitch); //volume: max. 100, pitch: max. 2 Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } @@ -155,7 +155,7 @@ public class Fight { return 0; } - if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){ + if(Config.IgnorePublicOnly || ArenaMode.RankedEvent.contains(Config.mode)){ return 1000; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 4835b41..fcfa795 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -27,7 +27,7 @@ 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.states.IStateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; @@ -45,7 +45,7 @@ import java.util.Random; import java.util.Set; import java.util.logging.Level; -public class FightSchematic implements StateDependent { +public class FightSchematic implements IStateDependent { private final FightTeam team; private final int pasteX; @@ -91,11 +91,14 @@ public class FightSchematic implements StateDependent { @Override public Set enabled() { - return FightState.SCHEM; + return FightState.Schem; } @Override public void enable() { + if(FightState.getFightState() == FightState.SPECTATE) + return; + if(clipboard == null){ List publics = Schematic.getSchemsOfType(0, Config.SchematicType); if(publics.isEmpty()) @@ -104,12 +107,10 @@ public class FightSchematic implements StateDependent { setSchematic(publics.get(new Random().nextInt(publics.size()))); } - if(Config.recording()){ - if(team.isBlue()) - RecordSystem.blueSchem(schematic); - else - RecordSystem.redSchem(schematic); - } + if(team.isBlue()) + RecordSystem.blueSchem(schematic); + else + RecordSystem.redSchem(schematic); FreezeWorld freezer = new FreezeWorld(); DyeColor c = ColorConverter.chat2dye(team.getColor()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 265dee2..d5e9001 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -21,12 +21,14 @@ package de.steamwar.fightsystem.fight; import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.core.VersionedRunnable; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.FightScoreboard; +import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.inventory.SWItem; @@ -153,14 +155,16 @@ public class FightTeam implements IFightTeam{ team.addEntry(player.getName()); Fight.setPlayerGamemode(player, GameMode.SURVIVAL); + player.setHealth(20); + player.setFoodLevel(20); + BasicListener.setAttackSpeed(player); player.teleport(spawn); 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()) Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); - if(Config.recording()) - RecordSystem.playerJoins(player); + RecordSystem.playerJoins(player); TechHider.reloadChunks(player, chunksToReload); return fightPlayer; } @@ -180,8 +184,7 @@ public class FightTeam implements IFightTeam{ player.teleport(Config.SpecSpawn); if(!Config.test()) new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player); - if(Config.recording()) - RecordSystem.entityDespawns(player); + RecordSystem.entityDespawns(player); TechHider.reloadChunks(player, chunksToReload); } @@ -203,7 +206,7 @@ public class FightTeam implements IFightTeam{ if(!players.isEmpty()) { setLeader(players.values().iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); - }else if(!Config.event() && !Config.Ranked){ + }else if(!ArenaMode.RankedEvent.contains(Config.mode)){ FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); } return; @@ -226,7 +229,7 @@ public class FightTeam implements IFightTeam{ else inventory.setItem(1, new ItemBuilder(Material.AIR).build()); - if(!Config.event() && !Config.Ranked){ + if(!ArenaMode.RankedEvent.contains(Config.mode)){ inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java similarity index 60% rename from FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java index 63734df..b8d4693 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/UnavailableCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowPickup.java @@ -17,17 +17,18 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.commands; +package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; +import de.steamwar.core.Core; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; -public class UnavailableCommand implements CommandExecutor { - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar."); - return false; +public class ArrowPickup { + + public ArrowPickup() { + if(Core.getVersion() > 8){ + new StateDependentListener(ArenaMode.All, FightState.All, new PickupArrowListener_9()); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 7dcfc68..696d0e7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -20,27 +20,27 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.projectiles.ProjectileSource; -import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; -import java.util.EnumSet; +public class ArrowStopper implements Listener { -public class ArrowStopper extends BasicListener { - - private BukkitTask task; private static final Vector NULL_VECTOR = new Vector(0, 0, 0); private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; + public ArrowStopper() { - super(Config.TechhiderActive ? EnumSet.of(FightState.RUNNING) : EnumSet.noneOf(FightState.class)); + new StateDependentListener(Config.TechhiderActive, FightState.Running, this); + new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } private void run() { @@ -62,18 +62,6 @@ public class ArrowStopper extends BasicListener { } } - @Override - public void enable() { - super.enable(); - task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1); - } - - @Override - public void disable() { - super.disable(); - task.cancel(); - } - private boolean checkBlocks(Block start, Block end) { Block cursor = start; @@ -97,7 +85,7 @@ public class ArrowStopper extends BasicListener { } private boolean checkBlock(Block block) { - return Config.HiddenBlockTags.contains(block.getType().name()); + return Config.HiddenBlocks.contains(block.getType().name()); } private boolean invalidEntity(Arrow entity) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java index be70bc2..c572101 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java @@ -20,28 +20,14 @@ package de.steamwar.fightsystem.listener; import de.steamwar.core.VersionedRunnable; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; import net.md_5.bungee.api.chat.BaseComponent; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import java.util.Set; +public class BasicListener { + private BasicListener(){} -public abstract class BasicListener implements Listener, StateDependent { - - private final Set enabled; - - BasicListener(Set enabled){ - this.enabled = enabled; - FightState.registerStateDependent(this); - } - - boolean notFighting(Player p){ + public static boolean notFighting(Player p){ return Fight.getFightPlayer(p) == null; } @@ -55,22 +41,7 @@ public abstract class BasicListener implements Listener, StateDependent { new VersionedRunnable(() -> BasicListener_9.toChat(player, components), 9)); } - void setAttackSpeed(Player player){ + public static void setAttackSpeed(Player player){ VersionedRunnable.call(new VersionedRunnable(() -> BasicListener_9.setAttackSpeed(player), 9)); } - - @Override - public void enable(){ - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - } - - @Override - public void disable(){ - HandlerList.unregisterAll(this); - } - - @Override - public Set enabled() { - return enabled; - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java similarity index 87% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java index 394f109..8e89799 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Chat.java @@ -19,25 +19,26 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; 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.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; -import java.util.EnumSet; +public class Chat implements Listener { -public class PlayerChatListener extends BasicListener { - - public PlayerChatListener(){ - super(EnumSet.allOf(FightState.class)); + public Chat(){ + new StateDependentListener(ArenaMode.All, FightState.All, this); } @EventHandler @@ -63,10 +64,9 @@ public class PlayerChatListener extends BasicListener { } private void broadcastChat(String message) { - if (Config.recording()) - RecordSystem.chat(message); + RecordSystem.chat(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); for(Player p : Bukkit.getOnlinePlayers()) - toChat(p, msg); + BasicListener.toChat(p, msg); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Check.java similarity index 88% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/Check.java index 78f5e2b..0681294 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/CheckListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Check.java @@ -19,24 +19,26 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; -import java.util.EnumSet; import java.util.logging.Level; -public class CheckListener extends BasicListener { +public class Check implements Listener { - public CheckListener() { - super(Config.check() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + public Check() { + new StateDependentListener(ArenaMode.Check, FightState.All, this); } @EventHandler @@ -66,7 +68,7 @@ public class CheckListener extends BasicListener { Bukkit.getLogger().log(Level.SEVERE, player.getName() + " tried to use a copy command!"); } - private static boolean allowedToCheck(SteamwarUser user) { + private boolean allowedToCheck(SteamwarUser user) { return user.getUserGroup() == UserGroup.Supporter || user.getUserGroup() == UserGroup.Developer || user.getUserGroup() == UserGroup.Moderator || diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java similarity index 74% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java index a37fc22..196fb6c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.comms.packets.TablistNamePacket; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.Countdown; @@ -29,25 +30,22 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import java.util.EnumSet; +public class ConnectionListener implements Listener { -public class PlayerStateListener extends BasicListener{ - - public PlayerStateListener() { - super(EnumSet.allOf(FightState.class)); + public ConnectionListener() { + new StateDependentListener(ArenaMode.All, FightState.All, this); } @EventHandler(priority = EventPriority.HIGH) @@ -55,10 +53,6 @@ public class PlayerStateListener extends BasicListener{ event.setJoinMessage(null); Player player = event.getPlayer(); - player.setHealth(20); - player.setFoodLevel(20); - setAttackSpeed(player); - FightTeam fightTeam = Fight.getPlayerTeam(player); if (fightTeam == null) { @@ -77,6 +71,8 @@ public class PlayerStateListener extends BasicListener{ @EventHandler(priority = EventPriority.HIGH) public void handlePlayerDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + Player player = event.getEntity().getPlayer(); FightTeam fightTeam = Fight.getPlayerTeam(player); @@ -85,13 +81,11 @@ public class PlayerStateListener extends BasicListener{ assert player != null; Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!"); - event.setDeathMessage(null); fightTeam.getFightPlayer(player).setOut(); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(fightTeam.getSpawn()); Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); - if(Config.recording()) - RecordSystem.entityDespawns(player); + RecordSystem.entityDespawns(player); } @EventHandler(priority = EventPriority.HIGH) @@ -106,40 +100,19 @@ public class PlayerStateListener extends BasicListener{ if(FightState.setup()){ fightTeam.removePlayer(player); - if(Config.recording()) - RecordSystem.entityDespawns(player); + RecordSystem.entityDespawns(player); }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!"); fightTeam.getFightPlayer(player).setOut(); - if(Config.recording()) - RecordSystem.entityDespawns(player); + RecordSystem.entityDespawns(player); } } //Shutdown server if nobody online and its not an event server - if(!Config.event() && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player)))) + if(Config.mode != ArenaMode.EVENT && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player)))) FightSystem.shutdown(null); } - - @EventHandler - public void handlePlayerRespawn(PlayerRespawnEvent event) { - Player player = event.getPlayer(); - FightTeam team = Fight.getPlayerTeam(player); - if(team == null) - event.setRespawnLocation(Config.SpecSpawn); - else - event.setRespawnLocation(team.getSpawn()); - } - - @EventHandler - public void onTpGM3(PlayerTeleportEvent e) { - if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { - e.setCancelled(true); - toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); - e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!"); - } - } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java similarity index 68% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index 4206418..ca0d01c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FreezeWorldStateListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -19,40 +19,40 @@ package de.steamwar.fightsystem.listener; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; +import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryPickupItemEvent; -import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerKickEvent; -import java.util.EnumSet; +public class DenyWorldInteraction implements Listener { -public class FreezeWorldStateListener extends BasicListener { - - public FreezeWorldStateListener() { - super(Config.test() ? EnumSet.of(FightState.PRE_RUNNING) : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); + public DenyWorldInteraction() { + new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this); + new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this); } @EventHandler public void handleBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); event.setCancelled(true); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke abbauen!")); + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke abbauen!")); } @EventHandler public void handleBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); event.setCancelled(true); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke setzen!")); + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst derzeit keine Blöcke setzen!")); } @EventHandler @@ -60,18 +60,18 @@ public class FreezeWorldStateListener extends BasicListener { event.setCancelled(true); } - @EventHandler - public void onInventoryClick(InventoryClickEvent event) { - if(PersonalKitCreator.notInKitCreator(event.getWhoClicked())) - event.setCancelled(true); - } - @EventHandler public void handlePlayerKickEvent(PlayerKickEvent e){ if(e.getReason().contains("Flying is not enabled")) e.setCancelled(true); } + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if(PersonalKitCreator.notInKitCreator(event.getWhoClicked())) + event.setCancelled(true); + } + @EventHandler public void onInventoryDrag(InventoryDragEvent event) { if(PersonalKitCreator.notInKitCreator(event.getWhoClicked())) @@ -79,12 +79,11 @@ public class FreezeWorldStateListener extends BasicListener { } @EventHandler - public void onDropPickup(InventoryPickupItemEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onDropping(PlayerDropItemEvent e){ - e.setCancelled(true); + public void handleProjectileLaunch(ProjectileLaunchEvent event) { + event.setCancelled(true); + if(event.getEntity().getShooter() instanceof Player){ + Player player = (Player) event.getEntity().getShooter(); + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Kampfbeginn nutzen!")); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamage.java similarity index 81% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamage.java index b6c4fcf..fb9ae04 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityDamage.java @@ -19,17 +19,18 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import java.util.EnumSet; +public class EntityDamage implements Listener { -public class EntityDamageListener extends BasicListener { - - public EntityDamageListener() { - super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); + public EntityDamage() { + new StateDependentListener(ArenaMode.All, FightState.AntiRunning, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java similarity index 92% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index 6e60e5c..ca27151 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -19,25 +19,26 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.SteamwarUser; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.util.EnumSet; +public class EventJoin implements Listener { -public class EventJoinListener extends BasicListener { - - public EventJoinListener() { - super(Config.event() ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class)); + public EventJoin() { + new StateDependentListener(ArenaMode.Event, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java similarity index 55% rename from FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java index 5e92c7b..40c4c2e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FightScoreboard.java @@ -17,43 +17,50 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.utils; +package de.steamwar.fightsystem.listener; 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.ArenaMode; +import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.winconditions.*; +import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.winconditions.PrintableWincondition; +import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.scoreboard.SWScoreboard; import de.steamwar.scoreboard.ScoreboardCallback; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scoreboard.Scoreboard; import java.util.*; -public class FightScoreboard { - private FightScoreboard(){} +public class FightScoreboard implements Listener { private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); - private static int index = 0; - private static String title = ""; - private static final HashMap scores = new HashMap<>(); - static { - Bukkit.getScheduler().scheduleSyncRepeatingTask(FightSystem.getPlugin(), FightScoreboard::nextIndexDisplay, 0, 200); - } + private int index = 0; + private String title = ""; + private final HashMap scores = new HashMap<>(); public static Scoreboard getScoreboard() { - return Bukkit.getScoreboardManager().getMainScoreboard(); + return Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); } - public static void showScoreboard(Player p) { - SWScoreboard.createScoreboard(p, new ScoreboardCallback() { + public FightScoreboard(){ + new StateDependentListener(ArenaMode.All, FightState.All, this); + new StateDependentTask(ArenaMode.All, FightState.All, this::nextIndexDisplay, 0, 200); + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) { + SWScoreboard.createScoreboard(event.getPlayer(), new ScoreboardCallback() { @Override public HashMap getData() { return scores; @@ -66,11 +73,12 @@ public class FightScoreboard { }); } - public static void removeScoreboard(Player p) { - SWScoreboard.removeScoreboard(p); + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SWScoreboard.removeScoreboard(event.getPlayer()); } - private static void teamScoreboard(FightTeam fightTeam){ + private void teamScoreboard(FightTeam fightTeam){ setTitle(fightTeam.getColoredName()); fightTeam.getPlayers().forEach(fp -> { if(fp.isLiving()) @@ -78,35 +86,35 @@ public class FightScoreboard { }); } - private static void generalScoreboard(){ + private void generalScoreboard(){ setTitle("§eKampf"); - List scores = new ArrayList<>(); + List scoreList = new ArrayList<>(); - TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown(); + Countdown timeOverCountdown = Wincondition.getTimeOverCountdown(); if(timeOverCountdown != null){ int fightTime = timeOverCountdown.getTimeLeft(); if (fightTime >= 60) - scores.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s"); + scoreList.add("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s"); else - scores.add("§7Zeit: §a" + fightTime + "s"); + scoreList.add("§7Zeit: §a" + fightTime + "s"); } - scores.add("§7TPS: §e" + TPSWatcher.getTPS()); + scoreList.add("§7TPS: §e" + TPSWatcher.getTPS()); if(fullScoreboard.contains(FightState.getFightState())){ for(PrintableWincondition wincondition : Wincondition.getPrintableWinconditions()){ - scores.add(wincondition.getDisplay(Fight.getRedTeam())); - scores.add(wincondition.getDisplay(Fight.getBlueTeam())); + scoreList.add(wincondition.getDisplay(Fight.getRedTeam())); + scoreList.add(wincondition.getDisplay(Fight.getBlueTeam())); } } - int value = scores.size(); - for(String score : scores){ + int value = scoreList.size(); + for(String score : scoreList){ addScore(score, value--); } } - private static void nextIndexDisplay() { + private void nextIndexDisplay() { index++; if(index > 2) index = 0; @@ -122,15 +130,13 @@ public class FightScoreboard { generalScoreboard(); } - private static void setTitle(String t) { + private void setTitle(String t) { title = t; - if(Config.recording()) - RecordSystem.scoreboardTitle(t); + RecordSystem.scoreboardTitle(t); } - private static void addScore(String string, int i) { - if(Config.recording()) - RecordSystem.scoreboardData(string, i); + private void addScore(String string, int i) { scores.put(string, i); + RecordSystem.scoreboardData(string, i); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java deleted file mode 100644 index 3c82cc5..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/FoodLevelChangeListener.java +++ /dev/null @@ -1,50 +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 org.bukkit.event.EventHandler; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.bukkit.event.entity.SpawnerSpawnEvent; -import org.bukkit.event.weather.WeatherChangeEvent; - -import java.util.EnumSet; - -public class FoodLevelChangeListener extends BasicListener { - - public FoodLevelChangeListener() { - super(EnumSet.allOf(FightState.class)); - } - - @EventHandler - public void handleFoodLevelChange(FoodLevelChangeEvent event) { - event.setCancelled(true); - } - - @EventHandler - public void onWeatherChange(WeatherChangeEvent event){ - event.setCancelled(true); - } - - @EventHandler - public void onSpawnerSpawn(SpawnerSpawnEvent e){ - e.setCancelled(true); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/GameplayListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/GameplayListener.java deleted file mode 100644 index 0b6ef8d..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/GameplayListener.java +++ /dev/null @@ -1,50 +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 org.bukkit.event.EventHandler; -import org.bukkit.event.inventory.CraftItemEvent; -import org.bukkit.event.inventory.FurnaceSmeltEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; - -import java.util.EnumSet; - -public class GameplayListener extends BasicListener{ - - public GameplayListener() { - super(EnumSet.allOf(FightState.class)); - } - - @EventHandler - public void onSleep(PlayerBedEnterEvent e) { - e.setCancelled(true); - } - - @EventHandler - public void onCrafting(CraftItemEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onFurnace(FurnaceSmeltEvent e){ - e.setCancelled(true); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java similarity index 90% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java index f0a5732..2827c50 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUIListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/HotbarGUI.java @@ -19,22 +19,23 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.meta.ItemMeta; -import java.util.EnumSet; +public class HotbarGUI implements Listener { -public class HotbarGUIListener extends BasicListener { - - public HotbarGUIListener() { - super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); + public HotbarGUI() { + new StateDependentListener(ArenaMode.All, FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java similarity index 83% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java index b073645..d525e6c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamage.java @@ -19,22 +19,24 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; -import java.util.EnumSet; import java.util.Objects; -public class InFightDamageListener extends BasicListener { +public class InFightDamage implements Listener { - public InFightDamageListener() { - super(EnumSet.of(FightState.RUNNING)); + public InFightDamage() { + new StateDependentListener(ArenaMode.All, FightState.Running, this); } @EventHandler @@ -42,7 +44,7 @@ public class InFightDamageListener extends BasicListener { if(!(event.getEntity() instanceof Player)) return; - if(notFighting((Player)event.getEntity())) + if(BasicListener.notFighting((Player)event.getEntity())) event.setCancelled(true); } @@ -69,7 +71,7 @@ public class InFightDamageListener extends BasicListener { return; } - if(notFighting(damager)){ + if(BasicListener.notFighting(damager)){ event.setCancelled(true); //Damager is not fighting return; @@ -81,7 +83,7 @@ public class InFightDamageListener extends BasicListener { event.getDamager().setFireTicks(0); player.setFireTicks(0); } - toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); + BasicListener.toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); } if(player.getHealth() - event.getFinalDamage() <= 0){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java similarity index 89% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java index d20afba..c72a812 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventory.java @@ -19,28 +19,27 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Material; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; -import org.bukkit.event.inventory.InventoryPickupItemEvent; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; -import java.util.EnumSet; +public class InFightInventory implements Listener { -public class InFightInventoryListener extends BasicListener { - - public InFightInventoryListener() { - super(EnumSet.of(FightState.RUNNING)); + public InFightInventory() { + new StateDependentListener(ArenaMode.All, FightState.Running, this); } @EventHandler @@ -77,16 +76,6 @@ public class InFightInventoryListener extends BasicListener { } } - @EventHandler - public void onDropPickup(InventoryPickupItemEvent e){ - e.setCancelled(true); - } - - @EventHandler - public void onDropping(PlayerDropItemEvent e){ - e.setCancelled(true); - } - @EventHandler public void onBlockBreak(BlockBreakEvent event) { Inventory inventory = event.getPlayer().getInventory(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java similarity index 92% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java index f05c79b..026a8e9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java @@ -19,11 +19,13 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; 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.StateDependentListener; import de.steamwar.fightsystem.utils.Region; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -31,19 +33,19 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; -import java.util.EnumSet; import java.util.logging.Level; -public class PlayerMoveListener extends BasicListener { +public class Move implements Listener { private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen"; private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; private static final String DENY_ENTERN = "§cDu darfst nicht entern"; - public PlayerMoveListener() { - super(EnumSet.allOf(FightState.class)); + public Move() { + new StateDependentListener(ArenaMode.All, FightState.All, this); } @EventHandler @@ -108,7 +110,7 @@ public class PlayerMoveListener extends BasicListener { if(to.getY() <= Config.underArenaBorder) { if(player.getGameMode() == GameMode.SPECTATOR || team == null) reset(event, DENY_ARENA); - else if(FightState.getFightState().infight()) + else if(FightState.infight()) player.damage(2); else if(!Config.GroundWalkable) player.teleport(team.getSpawn()); @@ -120,6 +122,6 @@ public class PlayerMoveListener extends BasicListener { private void reset(PlayerMoveEvent event, String message){ Player player = event.getPlayer(); player.teleport(event.getFrom()); - toActionbar(player, TextComponent.fromLegacyText(message)); + BasicListener.toActionbar(player, TextComponent.fromLegacyText(message)); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java similarity index 87% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java index 7006e78..b6a39ae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java @@ -19,21 +19,22 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; 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.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.util.EnumSet; +public class NormalJoin implements Listener { -public class NormalJoinListener extends BasicListener { - - public NormalJoinListener() { - super(Config.event() || Config.test() || Config.Ranked ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP)); + public NormalJoin() { + new StateDependentListener(ArenaMode.Normal, FightState.PreLeaderSetup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java new file mode 100644 index 0000000..7a98a71 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java @@ -0,0 +1,107 @@ +/* + 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.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.SpawnerSpawnEvent; +import org.bukkit.event.inventory.CraftItemEvent; +import org.bukkit.event.inventory.FurnaceSmeltEvent; +import org.bukkit.event.inventory.InventoryPickupItemEvent; +import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerDropItemEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.weather.WeatherChangeEvent; + +public class Permanent implements Listener { + + public Permanent() { + new StateDependentListener(ArenaMode.All, FightState.All, this); + } + + @EventHandler + public void handleFoodLevelChange(FoodLevelChangeEvent event) { + event.setCancelled(true); + } + + @EventHandler + public void onWeatherChange(WeatherChangeEvent event){ + event.setCancelled(true); + } + + @EventHandler + public void onSpawnerSpawn(SpawnerSpawnEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onSleep(PlayerBedEnterEvent e) { + e.setCancelled(true); + } + + @EventHandler + public void onCrafting(CraftItemEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onFurnace(FurnaceSmeltEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onDropPickup(InventoryPickupItemEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onDropping(PlayerDropItemEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void handlePlayerRespawn(PlayerRespawnEvent event) { + Player player = event.getPlayer(); + FightTeam team = Fight.getPlayerTeam(player); + if(team == null) + event.setRespawnLocation(Config.SpecSpawn); + else + event.setRespawnLocation(team.getSpawn()); + } + + @EventHandler + public void onTpGM3(PlayerTeleportEvent e) { + if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { + e.setCancelled(true); + BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); + e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!"); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index 132a60c..320ef75 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -25,6 +25,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.Kit; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.sql.PersonalKit; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; @@ -32,6 +33,7 @@ import org.bukkit.GameMode; import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; @@ -39,18 +41,24 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.inventory.ItemStack; -import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.Objects; -public class PersonalKitCreator extends BasicListener { +public class PersonalKitCreator implements Listener { private static final Map openKitCreators = new HashMap<>(); - private static final EnumSet enabled = Config.PersonalKits ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.noneOf(FightState.class); public PersonalKitCreator(){ - super(enabled); + new StateDependentListener(Config.PersonalKits, FightState.Setup, this){ + @Override + public void disable(){ + while(!openKitCreators.isEmpty()){ + openKitCreators.values().iterator().next().close(); + } + super.disable(); + } + }; } public static void openKitCreator(Player player, PersonalKit kit){ @@ -58,21 +66,13 @@ public class PersonalKitCreator extends BasicListener { new InventoryBackup(player, kit); new Kit(kit).loadToPlayer(player); player.setGameMode(GameMode.CREATIVE); - toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!")); + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§eInventar zum Anpassen des Kits öffnen§8!")); } public static boolean notInKitCreator(HumanEntity player){ return !openKitCreators.containsKey(player); } - @Override - public void disable(){ - while(!openKitCreators.isEmpty()){ - openKitCreators.values().iterator().next().close(); - } - super.disable(); - } - @EventHandler public void onInventoryClick(InventoryClickEvent e){ if(!openKitCreators.containsKey(e.getWhoClicked())) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index 3ff094f..ddb784a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -21,22 +21,21 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.Region; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPistonExtendEvent; import org.bukkit.event.block.BlockPistonRetractEvent; -import java.util.EnumSet; - -public class PistonListener extends BasicListener { +public class PistonListener implements Listener { public PistonListener() { //Wenn Entern aktiv ist, sollen Raketen etc. entern können - super(Config.EnterStages.isEmpty() - ? EnumSet.allOf(FightState.class) - : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); + new StateDependentListener(Config.EnterStages.isEmpty(), FightState.All, this); + new StateDependentListener(!Config.EnterStages.isEmpty(), FightState.Setup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java similarity index 52% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java index f5881eb..e5a3735 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ProjectileLaunchListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java @@ -1,6 +1,6 @@ -/* +/* 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 @@ -19,26 +19,35 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; -import net.md_5.bungee.api.chat.TextComponent; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.ProjectileLaunchEvent; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; -import java.util.EnumSet; +public class PrepareJoin implements Listener { -public class ProjectileLaunchListener extends BasicListener { - - public ProjectileLaunchListener() { - super(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP, FightState.PRE_RUNNING, FightState.SPECTATE)); + public PrepareJoin() { + new StateDependentListener(ArenaMode.Prepare, FightState.All, this); } @EventHandler - public void handleProjectileLaunch(ProjectileLaunchEvent event) { - event.setCancelled(true); - if(event.getEntity().getShooter() instanceof Player){ - Player player = (Player) event.getEntity().getShooter(); - toActionbar(player, TextComponent.fromLegacyText("§cDu darfst den Bogen erst nach Fightbeginn nutzen!")); + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + FightTeam team = Fight.getPlayerTeam(player); + + if (team == null) { + Fight.getBlueTeam().addMember(player); + } + + if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) { + FightSystem.setPreSchemState(); + FightSystem.setPostSchemState(); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java similarity index 85% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java index dc767dc..36abfe0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java @@ -19,20 +19,21 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import java.util.EnumSet; +public class RankedJoin implements Listener { -public class RankedJoinListener extends BasicListener { - - public RankedJoinListener() { - super(!Config.event() && Config.Ranked ? EnumSet.of(FightState.PRE_SCHEM_SETUP) : EnumSet.noneOf(FightState.class)); + public RankedJoin() { + new StateDependentListener(ArenaMode.Ranked, FightState.PreLeaderSetup, this); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java similarity index 90% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index c45428c..d1ef4fc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventRecordListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -26,12 +26,14 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.*; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.entity.TNTPrimed; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.EntitySpawnEvent; @@ -43,16 +45,29 @@ import org.bukkit.event.player.*; import org.bukkit.event.server.BroadcastMessageEvent; import org.bukkit.inventory.ItemStack; -import java.util.EnumSet; import java.util.Random; -public class EventRecordListener extends BasicListener { +public class Recording implements Listener { private static final int AIR = 0; private static final Random random = new Random(); - public EventRecordListener() { - super(Config.recording() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); + public Recording() { + new StateDependentListener(Config.recording(), FightState.All, this){ + @Override + public void stateChange(FightState state) { + if(state == FightState.PRE_RUNNING) { + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + setKitItems(Fight.getBlueTeam()); + setKitItems(Fight.getRedTeam()); + }, 1); + }else if(state == FightState.SPECTATE){ + despawnTeam(Fight.getRedTeam()); + despawnTeam(Fight.getBlueTeam()); + despawnTNT(); + } + } + }; } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -170,20 +185,6 @@ public class EventRecordListener extends BasicListener { } } - @Override - public void stateChange(FightState state) { - if(state == FightState.PRE_RUNNING) { - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - setKitItems(Fight.getBlueTeam()); - setKitItems(Fight.getRedTeam()); - }, 1); - }else if(state == FightState.SPECTATE){ - despawnTeam(Fight.getRedTeam()); - despawnTeam(Fight.getBlueTeam()); - despawnTNT(); - } - } - private void setKitItems(FightTeam team){ if(FightState.getFightState() != FightState.PRE_RUNNING) return; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java deleted file mode 100644 index 49722fd..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ScoreboardListener.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.utils.FightScoreboard; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -import java.util.EnumSet; - -public class ScoreboardListener extends BasicListener { - - public ScoreboardListener() { - super(EnumSet.allOf(FightState.class)); - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent event) { - FightScoreboard.showScoreboard(event.getPlayer()); - } - - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - FightScoreboard.removeScoreboard(event.getPlayer()); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java new file mode 100644 index 0000000..66cc993 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java @@ -0,0 +1,55 @@ +/* + 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.ArenaMode; +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.StateDependentListener; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class TestJoin implements Listener { + + public TestJoin() { + new StateDependentListener(ArenaMode.Test, FightState.All, this); + } + + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + FightTeam fightTeam = Fight.getPlayerTeam(player); + + if (fightTeam == null && (!Fight.getRedTeam().hasTeamLeader() || !Fight.getBlueTeam().hasTeamLeader())) { + player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader"); + } + + player.setOp(true); + + if(FightState.getFightState() == FightState.PRE_LEADER_SETUP){ + FightSystem.setPreSchemState(); + FightSystem.setPostSchemState(); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java deleted file mode 100644 index f73f887..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestListener.java +++ /dev/null @@ -1,193 +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.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.countdown.NoPlayersOnlineCountdown; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; - -import java.util.EnumSet; - -public class TestListener extends BasicListener { - - private NoPlayersOnlineCountdown countdown; - - public TestListener() { - super(Config.test() ? EnumSet.allOf(FightState.class) : EnumSet.noneOf(FightState.class)); - if(Config.test()) - countdown = new NoPlayersOnlineCountdown(); - } - - @EventHandler - public void handlePlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if (fightTeam == null && (!Fight.getRedTeam().hasTeamLeader() || !Fight.getBlueTeam().hasTeamLeader())) { - player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader"); - } - - if(countdown != null){ - countdown.disable(); - countdown = null; - } - - player.setOp(true); - /*PermissionAttachment attachment = player.addAttachment(FightSystem.getPlugin()); - attachment.setPermission("fawe.permpack.basic", true); - attachment.setPermission("minecraft.command.gamemode", true); - attachment.setPermission("minecraft.command.tp", true); - attachment.setPermission("worldedit.navigation.jumpto.tool", true); - attachment.setPermission("worldedit.navigation.thru.tool", true); - attachment.setPermission("worldedit.navigation.jumpto.tool", true); - attachment.setPermission("worldedit.navigation.thru.tool", true); - attachment.setPermission("worldedit.biome.info", true); - attachment.setPermission("worldedit.biome.set", true); - attachment.setPermission("worldedit.biome.list", true); - attachment.setPermission("worldedit.chunkinfo", true); - attachment.setPermission("worldedit.listchunks", true); - attachment.setPermission("worldedit.clipboard.cut", true); - attachment.setPermission("worldedit.clipboard.paste", true); - attachment.setPermission("worldedit.schematic.formats", true); - attachment.setPermission("worldedit.schematic.load", true); - attachment.setPermission("worldedit.schematic.list", true); - attachment.setPermission("worldedit.schematic.save", true); - attachment.setPermission("worldedit.clipboard.clear", true); - attachment.setPermission("worldedit.clipboard.copy", true); - attachment.setPermission("worldedit.clipboard.lazycopy", true); - attachment.setPermission("worldedit.clipboard.place", true); - attachment.setPermission("worldedit.clipboard.download", true); - attachment.setPermission("worldedit.clipboard.flip", true); - attachment.setPermission("worldedit.clipboard.rotate", true); - attachment.setPermission("worldedit.help", true); - attachment.setPermission("worldedit.global-mask", true); - attachment.setPermission("worldedit.global-transform", true); - attachment.setPermission("worldedit.generation.cylinder", true); - attachment.setPermission("worldedit.generation.sphere", true); - attachment.setPermission("worldedit.generation.forest", true); - attachment.setPermission("worldedit.generation.pumpkins", true); - attachment.setPermission("worldedit.generation.pyramid", true); - attachment.setPermission("worldedit.generation.shape", true); - attachment.setPermission("worldedit.biome.set", true); - attachment.setPermission("worldedit.history.undo", true); - attachment.setPermission("worldedit.history.redo", true); - attachment.setPermission("worldedit.history.rollback", true); - attachment.setPermission("worldedit.navigation.unstuck", true); - attachment.setPermission("worldedit.navigation.ascend", true); - attachment.setPermission("worldedit.navigation.descend", true); - attachment.setPermission("worldedit.navigation.ceiling", true); - attachment.setPermission("worldedit.navigation.thru.command", true); - attachment.setPermission("worldedit.navigation.jumpto.command", true); - attachment.setPermission("worldedit.navigation.up", true); - attachment.setPermission("worldedit.region.hollow", true); - attachment.setPermission("worldedit.region.line", true); - attachment.setPermission("worldedit.region.curve", true); - attachment.setPermission("worldedit.region.overlay", true); - attachment.setPermission("worldedit.region.center", true); - attachment.setPermission("worldedit.region.naturalize", true); - attachment.setPermission("worldedit.region.walls", true); - attachment.setPermission("worldedit.region.faces", true); - attachment.setPermission("worldedit.region.smooth", true); - attachment.setPermission("worldedit.region.move", true); - attachment.setPermission("worldedit.region.forest", true); - attachment.setPermission("worldedit.region.replace", true); - attachment.setPermission("worldedit.region.stack", true); - attachment.setPermission("worldedit.region.set", true); - attachment.setPermission("worldedit.selection.pos", true); - attachment.setPermission("worldedit.selection.chunk", true); - attachment.setPermission("worldedit.selection.hpos", true); - attachment.setPermission("worldedit.wand", true); - attachment.setPermission("worldedit.wand.toggle", true); - attachment.setPermission("worldedit.selection.contract", true); - attachment.setPermission("worldedit.selection.outset", true); - attachment.setPermission("worldedit.selection.inset", true); - attachment.setPermission("worldedit.analysis.distr", true); - attachment.setPermission("worldedit.analysis.count", true); - attachment.setPermission("worldedit.selection.size", true); - attachment.setPermission("worldedit.selection.expand", true); - attachment.setPermission("worldedit.selection.shift", true); - attachment.setPermission("worldedit.snapshots.list", true); - attachment.setPermission("worldedit.superpickaxe", true); - attachment.setPermission("worldedit.superpickaxe.area", true); - attachment.setPermission("worldedit.superpickaxe.recursive", true); - attachment.setPermission("worldedit.brush.blendball", true); - attachment.setPermission("worldedit.brush.erode", true); - attachment.setPermission("worldedit.brush.pull", true); - attachment.setPermission("worldedit.brush.circle", true); - attachment.setPermission("worldedit.brush.recursive", true); - attachment.setPermission("worldedit.brush.line", true); - attachment.setPermission("worldedit.brush.spline", true); - attachment.setPermission("worldedit.brush.surfacespline", true); - attachment.setPermission("worldedit.brush.shatter", true); - attachment.setPermission("worldedit.brush.stencil", true); - attachment.setPermission("worldedit.brush.height", true); - attachment.setPermission("worldedit.brush.layer", true); - attachment.setPermission("worldedit.brush.populateschematic", true); - attachment.setPermission("worldedit.brush.scatter", true); - attachment.setPermission("worldedit.brush.splatter", true); - attachment.setPermission("worldedit.brush.scattercommand", true); - attachment.setPermission("worldedit.brush.copy", true); - attachment.setPermission("worldedit.brush.command", true); - attachment.setPermission("worldedit.brush.apply", true); - attachment.setPermission("worldedit.brush.sphere", true); - attachment.setPermission("worldedit.brush.cylinder", true); - attachment.setPermission("worldedit.brush.clipboard", true); - attachment.setPermission("worldedit.brush.smooth", true); - attachment.setPermission("worldedit.brush.ex", true); - attachment.setPermission("worldedit.brush.gravity", true); - attachment.setPermission("worldedit.brush.options.range", true); - attachment.setPermission("worldedit.brush.options.material", true); - attachment.setPermission("worldedit.brush.options.size", true); - attachment.setPermission("worldedit.brush.options.mask", true); - attachment.setPermission("worldedit.brush.options.smask", true); - attachment.setPermission("worldedit.brush.options.transform", true); - attachment.setPermission("worldedit.brush.options.scroll", true); - attachment.setPermission("worldedit.brush.options.visualize", true); - attachment.setPermission("worldedit.tool.deltree", true); - attachment.setPermission("worldedit.tool.farwand", true); - attachment.setPermission("worldedit.tool.lrbuild", true); - attachment.setPermission("worldedit.tool.info", true); - attachment.setPermission("worldedit.tool.tree", true); - attachment.setPermission("worldedit.tool.replacer", true); - attachment.setPermission("worldedit.tool.data-cycler", true); - attachment.setPermission("worldedit.tool.flood-fill", true); - attachment.setPermission("worldedit.tool.inspect", true); - attachment.setPermission("worldedit.fill.recursive", true); - attachment.setPermission("worldedit.drain", true); - attachment.setPermission("worldedit.fixlava", true); - attachment.setPermission("worldedit.fixwater", true); - attachment.setPermission("worldedit.removeabove", true); - attachment.setPermission("worldedit.removebelow", true); - attachment.setPermission("worldedit.removenear", true); - attachment.setPermission("worldedit.replacenear", true); - attachment.setPermission("worldedit.snow", true); - attachment.setPermission("worldedit.thaw", true); - attachment.setPermission("worldedit.green", true); - attachment.setPermission("worldedit.extinguish", true); - attachment.setPermission("worldedit.calc", true); - attachment.setPermission("worldedit.fill", true);*/ - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index 1895673..ffa9409 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -20,21 +20,22 @@ package de.steamwar.fightsystem.listener; import de.steamwar.core.VersionedCallable; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -import java.util.EnumSet; - -public class WaterRemover extends BasicListener { +public class WaterRemover implements Listener { private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY; public WaterRemover() { - super(EnumSet.of(FightState.RUNNING)); + new StateDependentListener(ArenaMode.All, FightState.Running, this); } @EventHandler @@ -54,7 +55,8 @@ public class WaterRemover extends BasicListener { private void checkBlock(Block b) { //checks for water and removes it, if present - if(!VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8), + if(!VersionedCallable.call( + new VersionedCallable<>(() -> WaterRemover_8.removeWater(b), 8), new VersionedCallable<>(() -> WaterRemover_14.removeWater(b), 14))) return; @@ -69,7 +71,8 @@ public class WaterRemover extends BasicListener { } public static boolean isWater(Block block){ - return VersionedCallable.call(new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8), + return VersionedCallable.call( + new VersionedCallable<>(() -> WaterRemover_8.isWater(block), 8), new VersionedCallable<>(() -> WaterRemover_14.isWater(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 ce7b19b..b13e818 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.record; import de.steamwar.core.VersionedCallable; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; @@ -48,7 +49,7 @@ public class RecordSystem { if (Config.SpectateSystem) new SpectateConnection(); new FileRecorder(); - if(Config.event()) + if(Config.mode == ArenaMode.EVENT) teamIds(Config.EventTeamBlueID, Config.EventTeamRedID); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index fc6e52f..fdc32ac 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -19,10 +19,7 @@ package de.steamwar.fightsystem.states; -import java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.*; public enum FightState { PRE_LEADER_SETUP, @@ -32,19 +29,28 @@ public enum FightState { RUNNING, SPECTATE; - 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)); + public static final Set All = Collections.unmodifiableSet(EnumSet.allOf(FightState.class)); - private static final Map stateDependentFeatures = new HashMap<>(); + public static final Set PreLeaderSetup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP)); + public static final Set PreSchemSetup = Collections.unmodifiableSet(EnumSet.of(PRE_SCHEM_SETUP)); + public static final Set PostSchemSetup = Collections.unmodifiableSet(EnumSet.of(POST_SCHEM_SETUP)); + public static final Set PreRunning = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING)); + public static final Set Running = Collections.unmodifiableSet(EnumSet.of(RUNNING)); + public static final Set Spectate = Collections.unmodifiableSet(EnumSet.of(SPECTATE)); + + public static final Set Setup = Collections.unmodifiableSet(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP)); + public static final Set Ingame = Collections.unmodifiableSet(EnumSet.of(PRE_RUNNING, RUNNING)); + public static final Set Schem = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PRE_LEADER_SETUP, PRE_SCHEM_SETUP))); + public static final Set AntiRunning = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RUNNING))); + + private static final Map stateDependentFeatures = new HashMap<>(); private static FightState fightState = PRE_LEADER_SETUP; public static FightState getFightState() { return fightState; } - public static void registerStateDependent(StateDependent stateDependent){ + public static void registerStateDependent(IStateDependent stateDependent){ if(stateDependent.enabled().isEmpty()) return; boolean enabled = stateDependent.enabled().contains(fightState); @@ -56,7 +62,7 @@ public enum FightState { public static void setFightState(FightState state){ fightState = state; - for(Map.Entry feature : stateDependentFeatures.entrySet()){ + for(Map.Entry feature : stateDependentFeatures.entrySet()){ //Enable feature if should be enabled and currently disabled if(feature.getKey().enabled().contains(fightState)){ if(!feature.getValue()){ @@ -75,11 +81,11 @@ public enum FightState { } public static boolean setup(){ - return SETUP.contains(fightState); + return Setup.contains(fightState); } public static boolean ingame(){ - return INGAME.contains(fightState); + return Ingame.contains(fightState); } public static boolean infight(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java similarity index 51% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java rename to FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java index 2eaf446..a9465dc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/ListenerWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java @@ -17,39 +17,29 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.winconditions; - -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.states.FightState; -import org.bukkit.Bukkit; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; +package de.steamwar.fightsystem.states; import java.util.Set; -abstract class ListenerWincondition extends Wincondition implements Listener { +public interface IStateDependent { - protected ListenerWincondition(Winconditions condition, Set enabled, String windescription){ - super(condition, enabled, windescription); - } - - protected ListenerWincondition(boolean condition, Set enabled, String windescription) { - super(condition, enabled, windescription); - } + /** + * @return returns a set containing + */ + Set enabled(); /** * Enables the state dependent object */ - @Override - public void enable(){ - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - } + void enable(); /** * Disables the state dependent object */ - @Override - public void disable(){ - HandlerList.unregisterAll(this); - } + void disable(); + + /** + * On state change when enabled + */ + default void stateChange(FightState state){} } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java index 44051d5..9b17b43 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java @@ -1,45 +1,32 @@ -/* - 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.states; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.winconditions.Winconditions; + import java.util.Set; -public interface StateDependent { +public abstract class StateDependent implements IStateDependent { - /** - * @return returns a set containing - */ - Set enabled(); + private final Set enabled; - /** - * Enables the state dependent object - */ - void enable(); + protected StateDependent(Winconditions wincondition, Set states){ + this(Config.ActiveWinconditions.contains(wincondition), states); + } - /** - * Disables the state dependent object - */ - void disable(); + protected StateDependent(Set mode, Set states){ + this(mode.contains(Config.mode), states); + } - /** - * On state change when enabled - */ - default void stateChange(FightState state){} + protected StateDependent(boolean enabled, Set states){ + this.enabled = states; + + if(enabled) + FightState.registerStateDependent(this); + } + + @Override + public Set enabled() { + return enabled; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java new file mode 100644 index 0000000..03bcf29 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java @@ -0,0 +1,56 @@ +/* + 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.states; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; + +import java.util.Set; + +public class StateDependentCommand extends StateDependent { + + private static final CommandExecutor unavailible = (sender, cmd, s, strings) -> { + sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar."); + return false; + }; + + private final PluginCommand command; + private final CommandExecutor executor; + + public StateDependentCommand(Set mode, Set states, String name, CommandExecutor executor) { + super(mode, states); + this.executor = executor; + this.command = FightSystem.getPlugin().getCommand(name); + assert command != null; + disable(); + } + + @Override + public void enable() { + command.setExecutor(executor); + } + + @Override + public void disable() { + command.setExecutor(unavailible); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java similarity index 50% rename from FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java rename to FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java index 9529474..57bc00b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/TimeoutWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java @@ -17,40 +17,40 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.winconditions; +package de.steamwar.fightsystem.states; -import de.steamwar.fightsystem.countdown.TimeOverCountdown; -import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.winconditions.Winconditions; -import java.util.EnumSet; import java.util.Set; -public abstract class TimeoutWincondition extends Wincondition { +public class StateDependentCountdown extends StateDependent { - private static TimeOverCountdown timeOverCountdown = null; + private final Countdown countdown; - protected TimeoutWincondition(Winconditions condition, Set enabled, String windescription) { - super(condition, enabled, windescription); + public StateDependentCountdown(Set mode, Set states, Countdown countdown) { + super(mode, states); + this.countdown = countdown; } - protected TimeoutWincondition(Winconditions condition, String windescription) { - super(condition, EnumSet.of(FightState.RUNNING), windescription); + public StateDependentCountdown(Winconditions wincondition, Set states, Countdown countdown) { + super(Config.ActiveWinconditions.contains(wincondition), states); + this.countdown = countdown; } - protected abstract void timeOver(); + public Countdown getCountdown(){ + return countdown; + } @Override public void enable() { - timeOverCountdown = new TimeOverCountdown(this::timeOver); + countdown.enable(); } @Override public void disable() { - if(timeOverCountdown != null) - timeOverCountdown.disable(); - } - - public static TimeOverCountdown getTimeOverCountdown(){ - return timeOverCountdown; + countdown.disable(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/VersionDependentListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java similarity index 51% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/VersionDependentListener.java rename to FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java index 9197091..8a34a3e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/VersionDependentListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java @@ -1,6 +1,6 @@ -/* +/* 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 @@ -17,39 +17,44 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.states; -import de.steamwar.core.Core; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.winconditions.Winconditions; import org.bukkit.Bukkit; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; -import java.util.*; +import java.util.Set; -public class VersionDependentListener extends BasicListener { +public class StateDependentListener extends StateDependent{ - private static final List listeners = new ArrayList<>(); + private final Listener listener; - static { - if(Core.getVersion() > 8) - listeners.add(new PickupArrowListener_9()); + public StateDependentListener(Winconditions wincondition, Set states, Listener listener){ + super(Config.ActiveWinconditions.contains(wincondition), states); + this.listener = listener; } - public VersionDependentListener() { - super(EnumSet.allOf(FightState.class)); + public StateDependentListener(boolean enabled, Set states, Listener listener){ + super(enabled, states); + this.listener = listener; + } + + public StateDependentListener(Set mode, Set states, Listener listener) { + super(mode, states); + this.listener = listener; } @Override public void enable() { - for(Listener listener : listeners) - Bukkit.getPluginManager().registerEvents(listener, FightSystem.getPlugin()); + Bukkit.getPluginManager().registerEvents(listener, FightSystem.getPlugin()); } @Override public void disable() { - for(Listener listener : listeners) - HandlerList.unregisterAll(listener); + HandlerList.unregisterAll(listener); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java new file mode 100644 index 0000000..cc219a8 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java @@ -0,0 +1,67 @@ +/* + 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.states; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.winconditions.Winconditions; +import org.bukkit.Bukkit; +import org.bukkit.scheduler.BukkitTask; + +import java.util.Set; + +public class StateDependentTask extends StateDependent { + + private final Runnable runnable; + private final long delay; + private final long period; + + private BukkitTask task = null; + + public StateDependentTask(Winconditions wincondition, Set states, Runnable runnable, long delay, long period){ + this(Config.ActiveWinconditions.contains(wincondition), states, runnable, delay, period); + } + + public StateDependentTask(boolean enabled, Set states, Runnable runnable, long delay, long period){ + super(enabled, states); + this.runnable = runnable; + this.delay = delay; + this.period = period; + } + + public StateDependentTask(Set mode, Set states, Runnable runnable, long delay, long period) { + super(mode, states); + this.runnable = runnable; + this.delay = delay; + this.period = period; + } + + @Override + public void enable() { + task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), runnable, delay, period); + } + + @Override + public void disable() { + task.cancel(); + } + +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java index a6b480d..d4250e2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -25,12 +25,12 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.IStateDependent; import java.util.EnumSet; import java.util.Set; -public class EnterHandler implements StateDependent { +public class EnterHandler implements IStateDependent { private static final Set enabled = EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING); public EnterHandler(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index a65d25b..d2207af 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -21,11 +21,11 @@ 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.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.winconditions.TimeoutWincondition; +import de.steamwar.fightsystem.winconditions.Wincondition; import de.steamwar.sql.Elo; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; @@ -78,7 +78,7 @@ public class FightStatistics { } int remainingTime = 0; - TimeOverCountdown timeOverCountdown = TimeoutWincondition.getTimeOverCountdown(); + Countdown timeOverCountdown = Wincondition.getTimeOverCountdown(); if(timeOverCountdown != null){ remainingTime = timeOverCountdown.getTimeLeft(); } @@ -95,7 +95,7 @@ public class FightStatistics { Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } - if(Config.Ranked && !Config.event()){ + if(Config.Ranked){ int blueElo = Elo.getElo(blueLeader.getId(), gameMode); int redElo = Elo.getElo(redLeader.getId(), gameMode); double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 0391143..a766300 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -37,7 +37,7 @@ 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 de.steamwar.fightsystem.states.IStateDependent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.entity.Player; @@ -46,7 +46,7 @@ import java.util.*; import static de.steamwar.fightsystem.utils.ITechHider.bypass; -public class TechHider implements StateDependent { +public class TechHider implements IStateDependent { private static final boolean DISABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; @@ -59,10 +59,21 @@ public class TechHider implements StateDependent { enabled = DISABLED ? EnumSet.noneOf(FightState.class) : EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP)); + + Set hiddenBlockIds = VersionedCallable.call( + new VersionedCallable<>(Collections::emptySet, 8), + new VersionedCallable<>(TechHider_12::getHiddenBlockIds, 12), + new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), + new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); + int obfuscateWith = VersionedCallable.call( + new VersionedCallable<>(() -> 0, 8), + new VersionedCallable<>(TechHider_12::getObfuscateWith, 12), + new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), + new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + 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)); + new VersionedCallable<>(() -> TechHider_12.chunkHider(hiddenBlockIds, obfuscateWith), 12), + new VersionedCallable<>(() -> TechHider_14.chunkHider(hiddenBlockIds, obfuscateWith), 14)); if(DISABLED) return; @@ -144,7 +155,7 @@ public class TechHider implements StateDependent { boolean changed = false; for(MultiBlockChangeInfo mbci : changes){ WrappedBlockData block = mbci.getData(); - if(Config.HiddenBlockTags.contains(block.getType().name())){ + if(Config.HiddenBlocks.contains(block.getType().name())){ changed = true; block.setType(ITechHider.obfuscateMaterial); mbci.setData(block); @@ -178,7 +189,7 @@ public class TechHider implements StateDependent { e.setPacket(cached); StructureModifier blockStructure = cached.getBlockData(); WrappedBlockData block = blockStructure.read(0); - if(Config.HiddenBlockTags.contains(block.getType().name())){ + if(Config.HiddenBlocks.contains(block.getType().name())){ block.setType(ITechHider.obfuscateMaterial); blockStructure.write(0, block); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index 638cabe..ca74fdb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -19,37 +19,37 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; -import java.util.EnumSet; - -public class EventTeamOffWincondition extends Wincondition { +public class EventTeamOffWincondition extends Wincondition{ public EventTeamOffWincondition(){ - super(Config.event(), EnumSet.of(FightState.PRE_RUNNING), "TeamOffline"); - } + super("TeamOffline", "§cDas Team ", " §cist offline!", "§cBeide Teams sind offline!"); + new StateDependent(ArenaMode.Event, FightState.PreRunning) { + @Override + public void enable() { + if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){ + win(null); + }else{ + teamOff(Fight.getBlueTeam()); + teamOff(Fight.getRedTeam()); + } + } - @Override - public void enable() { - if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){ - win(null, null, null, "§cBeide Teams sind offline!"); - }else{ - teamOff(Fight.getBlueTeam()); - teamOff(Fight.getRedTeam()); - } - } - - @Override - public void disable() { - //Team off is a one time trigger + @Override + public void disable() { + //Team off is a one time trigger + } + }; } private void teamOff(FightTeam team){ if(team.allPlayersOut()){ - win(Fight.getOpposite(team), "§cDas Team ", " §cist offline!"); + win(Fight.getOpposite(team)); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java index 4997c13..eacac0b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -1,3 +1,22 @@ +/* + 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.winconditions; import de.steamwar.fightsystem.fight.FightTeam; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java index 371ee08..17b71d1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java @@ -19,18 +19,21 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; -public class RankedPlayerLeftWincondition extends ListenerWincondition{ +public class RankedPlayerLeftWincondition extends Wincondition implements Listener { public RankedPlayerLeftWincondition(){ - super(Config.Ranked, FightState.INGAME, "LeaderQuit"); + super("LeaderQuit", "§cDer Leader von ", " §chat den Kampf verlassen!"); + new StateDependentListener(ArenaMode.Ranked, FightState.Setup, this); } @EventHandler @@ -41,7 +44,7 @@ public class RankedPlayerLeftWincondition extends ListenerWincondition{ return; if(team.isPlayerLeader(player)) { - win(Fight.getOpposite(team), "§cDer Leader von ", " §chat den Kampf verlassen!"); + win(Fight.getOpposite(team)); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java index bd265d9..f24d7a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -19,43 +19,53 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; -import java.util.Set; -public abstract class Wincondition implements StateDependent { +public abstract class Wincondition { protected static PercentWincondition percentWincondition = null; + protected static StateDependentCountdown timeOverCountdown = null; protected static final List printableWinconditions = new ArrayList<>(); - private final Set enabled; private final String windescription; + private final String preteammessage; + private final String postteammessage; + private final String tiemessage; - protected Wincondition(Winconditions condition, Set enabled, String windescription){ - this(Config.ActiveWinconditions.contains(condition), enabled, windescription); + protected Wincondition(String windescription, String tiemessage) { + this(windescription, null, null, tiemessage); } - protected Wincondition(boolean condition, Set enabled, String windescription){ - this.enabled = enabled; + protected Wincondition(String windescription, String preteammessage, String postteammessage) { + this(windescription, preteammessage, postteammessage, null); + } + + protected Wincondition(String windescription, String preteammessage, String postteammessage, String tiemessage) { this.windescription = windescription; - if(condition) - FightState.registerStateDependent(this); + this.preteammessage = preteammessage; + this.tiemessage = tiemessage; + this.postteammessage = postteammessage; } - protected void win(FightTeam team, String preteammessage, String postteammessage){ - win(team, preteammessage, postteammessage, null); + public static Countdown getTimeOverCountdown(){ + return timeOverCountdown.getCountdown(); } - protected void win(FightTeam team, String preteammessage, String postteammessage, String tiemessage){ + protected void win(FightTeam team, String postteammessage){ + Bukkit.broadcastMessage(FightSystem.PREFIX + tiemessage + team.getColoredName() + postteammessage); + FightSystem.setSpectateState(team, windescription); + } + + protected void win(FightTeam team){ if(team != null){ Bukkit.broadcastMessage(FightSystem.PREFIX + preteammessage + team.getColoredName() + postteammessage); }else{ @@ -73,11 +83,6 @@ public abstract class Wincondition implements StateDependent { return fightTeam; } - @Override - public Set enabled(){ - return enabled; - } - public static List getPrintableWinconditions(){ return printableWinconditions; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index d1c37d0..4a07ab0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -22,15 +22,18 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionAllDead extends ListenerWincondition { +public class WinconditionAllDead extends Wincondition implements Listener { public WinconditionAllDead(){ - super(Winconditions.ALL_DEAD, FightState.INGAME, "AllDead"); + super("AllDead", "§cDer letzte Spieler aus "); + new StateDependentListener(Winconditions.ALL_DEAD, FightState.Ingame, this); } @EventHandler @@ -49,7 +52,7 @@ public class WinconditionAllDead extends ListenerWincondition { return; if(team.allPlayersOut()) { - win(Fight.getOpposite(team), "§cDer letzte Spieler aus ", message); + win(Fight.getOpposite(team), message); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index c86092c..1e91204 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -22,15 +22,18 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; -public class WinconditionCaptainDead extends ListenerWincondition { +public class WinconditionCaptainDead extends Wincondition implements Listener { public WinconditionCaptainDead(){ - super(Winconditions.CAPTAIN_DEAD, FightState.INGAME, "LeaderDead"); + super("LeaderDead", "§cDer Leader von "); + new StateDependentListener(Winconditions.CAPTAIN_DEAD, FightState.Ingame, this); } @EventHandler @@ -49,7 +52,7 @@ public class WinconditionCaptainDead extends ListenerWincondition { return; if(team.isPlayerLeader(player)) { - win(Fight.getOpposite(team), "§cDer Leader von ", message); + win(Fight.getOpposite(team), message); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index d400671..efdeb78 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -19,16 +19,19 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCountdown; -public class WinconditionHeartRatioTimeout extends TimeoutWincondition { +public class WinconditionHeartRatioTimeout extends Wincondition { public WinconditionHeartRatioTimeout() { - super(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout"); + super("HeartTimeout", "§cDie Zeit ist abgelaufen, und Team ", " §chatte mehr verbleibende Leben!", "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!"); + timeOverCountdown = new StateDependentCountdown(Winconditions.HEART_RATIO_TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); } - @Override protected void timeOver() { double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); double redHeartRatio = Fight.getRedTeam().getHeartRatio(); @@ -39,6 +42,6 @@ public class WinconditionHeartRatioTimeout extends TimeoutWincondition { else if(blueHeartRatio < redHeartRatio) team = Fight.getRedTeam(); - win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte mehr verbleibende Leben!", "§cDie Zeit ist abgelaufen, und beide Teams hatten die gleiche Anzahl an verbleibenden Leben!"); + win(team); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 7766081..be7f867 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -23,26 +23,29 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.Region; import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; -import java.util.EnumSet; import java.util.HashMap; import java.util.Map; -public class WinconditionPercentSystem extends ListenerWincondition implements PrintableWincondition, PercentWincondition { +public class WinconditionPercentSystem extends Wincondition implements Listener, PrintableWincondition, PercentWincondition { private static final int SCHEMATIC_SIZE = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); private final Map teamMap = new HashMap<>(); public WinconditionPercentSystem() { - super(Winconditions.PERCENT_SYSTEM, EnumSet.of(FightState.RUNNING), "Percent"); + super("Percent", "§cTeam ", " §chat den Gegnern"); printableWinconditions.add(this); percentWincondition = this; teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); + + new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this); } @EventHandler @@ -78,7 +81,7 @@ public class WinconditionPercentSystem extends ListenerWincondition implements P destroyedBlocks += event.blockList().size(); percent = (double)destroyedBlocks * 100 / SCHEMATIC_SIZE; if(percent >= Config.PercentWin) { - win(Fight.getOpposite(team), "§cTeam ", " §chat den Gegnern"); + win(Fight.getOpposite(team)); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java index 7cdd9d5..d98f79d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java @@ -19,16 +19,19 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.countdown.TimeOverCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCountdown; -public class WinconditionPercentTimeout extends TimeoutWincondition { +public class WinconditionPercentTimeout extends Wincondition { public WinconditionPercentTimeout() { - super(Winconditions.HEART_RATIO_TIMEOUT, "PercentTimeout"); + super("PercentTimeout", "§cDie Zeit ist abgelaufen, und Team ", " §chatte weniger Schaden erlitten!", "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden!"); + timeOverCountdown = new StateDependentCountdown(Winconditions.PERCENT_TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); } - @Override protected void timeOver() { double bluePercent = Wincondition.percentWincondition.getPercent(Fight.getBlueTeam()); double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam()); @@ -38,6 +41,6 @@ public class WinconditionPercentTimeout extends TimeoutWincondition { team = Fight.getRedTeam(); else if(bluePercent < redPercent) team = Fight.getBlueTeam(); - win(team, "§cDie Zeit ist abgelaufen, und Team ", " §chatte weniger Schaden erlitten!", "§cDie Zeit ist abgelaufen, und beide Teams hatten gleichen Schaden!"); + win(team); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index beaa543..3fa6a78 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -20,13 +20,16 @@ package de.steamwar.fightsystem.winconditions; 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; +import de.steamwar.fightsystem.states.StateDependent; +import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -34,23 +37,32 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; import java.util.Map; -public class WinconditionPoints extends TimeoutWincondition implements PrintableWincondition, Listener { +public class WinconditionPoints extends Wincondition implements PrintableWincondition, Listener { - private final Map percentMap = new HashMap<>(); private final Map teamMap = new HashMap<>(); public WinconditionPoints(){ - super(Winconditions.POINTS, FightState.INGAME, "Points"); - - percentMap.put(Fight.getBlueTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getBlueTeam())); - percentMap.put(Fight.getRedTeam(), new WinconditionRelativePercent.TeamPercent(Fight.getRedTeam())); + super("Points", "§cDas Team ", " §chat mehr Punkte!", "§cBeide Teams haben gleich viele Punkte!"); teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam())); printableWinconditions.add(this); + + new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this); + timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver)); + new StateDependent(Winconditions.POINTS, FightState.Ingame){ + @Override + public void enable() { + teamMap.values().forEach(TeamPoints::enable); + } + + @Override + public void disable() { + teamMap.values().forEach(TeamPoints::disable); + } + }; } - @Override protected void timeOver() { int redPoints = teamMap.get(Fight.getRedTeam()).getPoints(); int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints(); @@ -61,26 +73,7 @@ public class WinconditionPoints extends TimeoutWincondition implements Printable else if(redPoints < bluePoints) team = Fight.getBlueTeam(); - win(team, "§cDas Team ", " §chat mehr Punkte!", "§cBeide Teams haben gleich viele Punkte!"); - } - - @Override - public void enable() { - Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin()); - teamMap.values().forEach(TeamPoints::enable); - } - - @Override - public void disable() { - super.disable(); - HandlerList.unregisterAll(this); - } - - @Override - public void stateChange(FightState state){ - if(state == FightState.RUNNING){ - super.enable(); - } + win(team); } @EventHandler @@ -119,19 +112,21 @@ public class WinconditionPoints extends TimeoutWincondition implements Printable private static final int MAX_POINTS = 2000; private final FightTeam team; + private final WinconditionRelativePercent.TeamPercent percent; private double factor; private int points; TeamPoints(FightTeam team){ this.team = team; - points = 0; + this.percent = new WinconditionRelativePercent.TeamPercent(team); + this.points = 0; } public void enable() { - percentMap.get(team).enable(); - int ownBlocks = percentMap.get(team).getBlockCount(); - int enemyBlocks = percentMap.get(Fight.getOpposite(team)).getBlockCount(); + percent.enable(); + int ownBlocks = percent.getBlockCount(); + int enemyBlocks = teamMap.get(Fight.getOpposite(team)).percent.getBlockCount(); if(enemyBlocks < ownBlocks) { this.factor = 10000; //Original mit 20 (20% = 0.2 ergeben 2000 Punkte @@ -147,8 +142,12 @@ public class WinconditionPoints extends TimeoutWincondition implements Printable } } + public void disable(){ + percent.disable(); + } + public int getPoints(){ - int damagePoints = (int)(percentMap.get(Fight.getOpposite(team)).getPercent() * factor); + int damagePoints = (int)(teamMap.get(Fight.getOpposite(team)).percent.getPercent() * factor); if(damagePoints > MAX_POINTS) damagePoints = MAX_POINTS; return points + damagePoints; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 2355cbc..4e6e9bf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -20,15 +20,14 @@ package de.steamwar.fightsystem.winconditions; 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.StateDependentTask; import de.steamwar.inventory.SWItem; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; -import org.bukkit.scheduler.BukkitTask; import java.util.HashMap; import java.util.Map; @@ -39,24 +38,14 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable private static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); private final Map teamMap = new HashMap<>(); - private BukkitTask task; public WinconditionPumpkinTechKO(){ - super(Winconditions.PUMPKIN_TECH_KO, FightState.INGAME, "PumpkinTechKO"); + super("PumpkinTechKO", "§cDas Team ", " §cist Tech K.O.!"); + new StateDependentTask(Winconditions.PUMPKIN_TECH_KO, FightState.Ingame, this::check, 0, 200); teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam())); teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam())); } - @Override - public void enable() { - task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 0, 200); - } - - @Override - public void disable() { - task.cancel(); - } - private void check(){ teamMap.values().forEach(TeamPumpkin::check); } @@ -87,7 +76,7 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable } if(pumpkins == 0) { - win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!"); + win(Fight.getOpposite(team)); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 78cad8e..4285b1f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -24,6 +24,7 @@ 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; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -46,21 +47,22 @@ public class WinconditionRelativePercent extends Wincondition implements Printab private final Map teamMap = new HashMap<>(); public WinconditionRelativePercent(){ - super(Winconditions.RELATIVE_PERCENT, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "RelativePercent"); + super("RelativePercent", null); teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); printableWinconditions.add(this); percentWincondition = this; - } + new StateDependent(Winconditions.RELATIVE_PERCENT, FightState.Running){ + @Override + public void enable() { + teamMap.values().forEach(TeamPercent::enable); + } - @Override - public void enable() { - teamMap.values().forEach(TeamPercent::enable); - } - - @Override - public void disable() { - teamMap.values().forEach(teamPercent -> teamPercent.task.cancel()); + @Override + public void disable() { + teamMap.values().forEach(TeamPercent::disable); + } + }; } @Override @@ -90,6 +92,10 @@ public class WinconditionRelativePercent extends Wincondition implements Printab task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 400, 400); } + public void disable(){ + task.cancel(); + } + private void check(){ currentBlocks = currentBlocks(); @@ -114,7 +120,7 @@ public class WinconditionRelativePercent extends Wincondition implements Printab private int currentBlocks(){ // Entern active - if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - TimeoutWincondition.getTimeOverCountdown().getTimeLeft()) + if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - Wincondition.getTimeOverCountdown().getTimeLeft()) return currentBlocks; int blocks = 0; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index b6a8b08..b0481fd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -20,19 +20,17 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.countdown.TechKOCountdown; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.countdown.SWSound; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.entity.TNTPrimed; -import org.bukkit.scheduler.BukkitTask; -import java.util.EnumSet; - -public class WinconditionTimeTechKO extends ListenerWincondition { +public class WinconditionTimeTechKO extends Wincondition { private static final int TECH_KO_TIME_IN_S = 90; private static final int TECH_KO_HALF_TIME = TECH_KO_TIME_IN_S*10; @@ -46,13 +44,12 @@ public class WinconditionTimeTechKO extends ListenerWincondition { private int biggerZtime = TECH_KO_HALF_TIME; private TechKOCountdown smallerZcountdown = null; private TechKOCountdown biggerZcountdown = null; - private BukkitTask task; /** * Works only for z-Axis fight direction for performance reasons */ public WinconditionTimeTechKO(){ - super(Winconditions.TIME_TECH_KO, EnumSet.of(FightState.RUNNING), null); + super("TechKO", "", " §chat den Gegner Tech K.O. gesetzt!"); if(Config.TeamBluetoReddistanceZ > 0) { smallerZteam = Fight.getBlueTeam(); @@ -61,26 +58,21 @@ public class WinconditionTimeTechKO extends ListenerWincondition { smallerZteam = Fight.getRedTeam(); biggerZteam = Fight.getBlueTeam(); } - } - @Override - public void enable() { - super.enable(); - task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::run, 1, 1); - } - - @Override - public void disable() { - super.disable(); - if(smallerZcountdown != null){ - smallerZcountdown.disable(); - smallerZcountdown = null; - } - if(biggerZcountdown != null){ - biggerZcountdown.disable(); - biggerZcountdown = null; - } - task.cancel(); + new StateDependentTask(Winconditions.TIME_TECH_KO, FightState.Running, this::run, 1, 1){ + @Override + public void disable() { + super.disable(); + if(smallerZcountdown != null){ + smallerZcountdown.disable(); + smallerZcountdown = null; + } + if(biggerZcountdown != null){ + biggerZcountdown.disable(); + biggerZcountdown = null; + } + } + }; } private void run(){ @@ -111,4 +103,24 @@ public class WinconditionTimeTechKO extends ListenerWincondition { smallerZtime--; biggerZtime--; } + + private class TechKOCountdown extends Countdown { + private final FightTeam team; + + public TechKOCountdown(FightTeam team, int countdownTime) { + super(countdownTime, SWSound.BLOCK_NOTE_PLING, false); + this.team = team; + super.enable(); + } + + @Override + public final String countdownCounting() { + return "bis " + team.getColoredName() + " §feinen Schuss abgegeben haben muss!"; + } + + @Override + public void countdownFinished() { + win(Fight.getOpposite(team)); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index 4151852..93f9cdb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -19,14 +19,18 @@ package de.steamwar.fightsystem.winconditions; -public class WinconditionTimeout extends TimeoutWincondition { +import de.steamwar.fightsystem.countdown.TimeOverCountdown; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCountdown; + +public class WinconditionTimeout extends Wincondition { public WinconditionTimeout() { - super(Winconditions.TIMEOUT, "Timeout"); + super("Timeout", "§cDie Zeit ist abgelaufen!"); + timeOverCountdown = new StateDependentCountdown(Winconditions.TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); } - @Override protected void timeOver() { - win(null, null, null, "§cDie Zeit ist abgelaufen!"); + win(null); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 845aa25..fcd7c9a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -20,16 +20,14 @@ package de.steamwar.fightsystem.winconditions; 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.states.StateDependentTask; import org.bukkit.Bukkit; import org.bukkit.World; -import org.bukkit.scheduler.BukkitTask; -import java.util.EnumSet; import java.util.HashMap; import java.util.Map; @@ -38,23 +36,14 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi private static final World WORLD = Bukkit.getWorlds().get(0); private final Map teamMap = new HashMap<>(); - private BukkitTask task; public WinconditionWaterTechKO() { - super(Winconditions.WATER_TECH_KO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING), "WaterTechKO"); + super("WaterTechKO", "§cDas Team ", " §cwurde Tech K.O. gesetzt!"); teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam())); printableWinconditions.add(this); - } - @Override - public void enable() { - task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::check, 200, 200); - } - - @Override - public void disable() { - task.cancel(); + new StateDependentTask(Winconditions.WATER_TECH_KO, FightState.Ingame, this::check, 200, 200); } private void check() { @@ -86,7 +75,7 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi } if(water == 0){ - win(Fight.getOpposite(team), "§cDas Team ", " §cist Tech K.O.!"); + win(Fight.getOpposite(team)); } } } From 9098a26aa9e36da35301faf7a09c0a5be6147286 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 14:49:43 +0100 Subject: [PATCH 04/15] Refactoring + Arena reset Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/ArenaMode.java | 4 +- .../src/de/steamwar/fightsystem/Config.java | 13 ++ .../fightsystem/utils/ITechHider.java | 47 +------ .../de/steamwar/fightsystem/utils/Region.java | 101 ++++++++++++++ .../de/steamwar/fightsystem/FightSystem.java | 33 +++-- .../fightsystem/commands/Commands.java | 6 +- .../de/steamwar/fightsystem/commands/GUI.java | 2 +- .../fightsystem/commands/LeaderCommand.java | 4 +- .../commands/LockschemCommand.java | 6 +- .../countdown/EventSpectateCountdown.java | 44 ++++++ ...Countdown.java => PostSchemCountdown.java} | 4 +- ...eCountdown.java => PreSchemCountdown.java} | 4 +- .../countdown/SpectateOverCountdown.java | 6 +- .../de/steamwar/fightsystem/fight/Fight.java | 8 +- .../fightsystem/fight/FightSchematic.java | 21 +-- .../steamwar/fightsystem/fight/FightTeam.java | 76 +++++------ .../fightsystem/fight/FightWorld.java | 49 +++++++ .../fightsystem/listener/ArenaBorder.java | 72 ++++++++++ .../listener/ConnectionListener.java | 118 ---------------- .../fightsystem/listener/EventJoin.java | 2 +- .../fightsystem/listener/IngameDeath.java | 77 +++++++++++ .../steamwar/fightsystem/listener/Move.java | 127 ------------------ .../fightsystem/listener/NormalJoin.java | 6 +- .../fightsystem/listener/Permanent.java | 63 ++++++--- .../fightsystem/listener/PistonListener.java | 17 +-- .../{PrepareJoin.java => PrepareSchem.java} | 12 +- .../fightsystem/listener/Recording.java | 27 ++-- .../fightsystem/listener/SetupQuit.java | 50 +++++++ .../fightsystem/listener/Shutdown.java | 43 ++++++ .../fightsystem/listener/TeamArea.java | 73 ++++++++++ .../fightsystem/listener/TestJoin.java | 2 +- .../fightsystem/states/FightState.java | 9 +- .../fightsystem/states/IStateDependent.java | 5 - .../fightsystem/utils/FightStatistics.java | 31 +++-- .../de/steamwar/fightsystem/utils/Region.java | 55 -------- .../steamwar/fightsystem/utils/TechHider.java | 8 +- .../WinconditionPercentSystem.java | 3 +- 37 files changed, 714 insertions(+), 514 deletions(-) create mode 100644 FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java rename FightSystem_Main/src/de/steamwar/fightsystem/countdown/{SetupOverCountdown.java => PostSchemCountdown.java} (94%) rename FightSystem_Main/src/de/steamwar/fightsystem/countdown/{PreSchemPasteCountdown.java => PreSchemCountdown.java} (93%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java rename FightSystem_Main/src/de/steamwar/fightsystem/listener/{PrepareJoin.java => PrepareSchem.java} (88%) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java delete mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/Region.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index 8e8a58f..5235c96 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -22,7 +22,9 @@ public enum ArenaMode { public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); - public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT))); + public static final Set AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT))); public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); + public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT))); public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT)); + public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 4daa7e3..10e9ed6 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem; +import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; @@ -50,6 +51,12 @@ public class Config { public static final List EnterStages; //arena parameter + public static final Region BluePasteRegion; + public static final Region RedPasteRegion; + public static final Region BlueExtendRegion; + public static final Region RedExetendRegion; + public static final Region ArenaRegion; + public static final int SchemsizeX; public static final int SchemsizeY; public static final int SchemsizeZ; @@ -309,6 +316,12 @@ public class Config { TeamRedRotate = teamRedRotate; TeamBlueRotate = teamBlueRotate; + RedPasteRegion = new Region(TeamRedCornerX, TeamRedCornerY, TeamRedCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ); + BluePasteRegion = new Region(TeamBlueCornerX, TeamBlueCornerY, TeamBlueCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ); + RedExetendRegion = new Region(TeamRedCornerX, underArenaBorder, TeamRedCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic); + BlueExtendRegion = new Region(TeamBlueCornerX, underArenaBorder, TeamBlueCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic); + ArenaRegion = new Region(ArenaMinX, underArenaBorder, ArenaMinZ, ArenaMaxX - ArenaMinX, upperArenaBorder - underArenaBorder, ArenaMaxZ - ArenaMinZ); + EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ EventFight eventFight = EventFight.get(EventKampfID); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index e882d8a..b545be5 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -41,35 +41,8 @@ public class ITechHider { static final Map packetCache = new HashMap<>(); static final Material obfuscateMaterial; static final int threadMultiplier; - static final int arenaMinX; - static final int arenaMaxX; - static final int arenaMinZ; - static final int arenaMaxZ; - - private static final int blueMinX; - private static final int blueMaxX; - private static final int blueMinZ; - private static final int blueMaxZ; - private static final int redMinX; - private static final int redMaxX; - private static final int redMinZ; - private static final int redMaxZ; static{ - int areaExtension = Config.EnterStages.isEmpty() ? Config.BorderFromSchematic : 0; - blueMinX = ITechHider.posToChunk(Config.TeamBlueCornerX - areaExtension); - blueMaxX = ITechHider.posToChunk(Config.TeamBlueCornerX + Config.SchemsizeX + areaExtension) + 1; - blueMinZ = ITechHider.posToChunk(Config.TeamBlueCornerZ - areaExtension); - blueMaxZ = ITechHider.posToChunk(Config.TeamBlueCornerZ + Config.SchemsizeZ + areaExtension) + 1; - redMinX = ITechHider.posToChunk(Config.TeamRedCornerX - areaExtension); - redMaxX = ITechHider.posToChunk(Config.TeamRedCornerX + Config.SchemsizeX + areaExtension) + 1; - redMinZ = ITechHider.posToChunk(Config.TeamRedCornerZ - areaExtension); - redMaxZ = ITechHider.posToChunk(Config.TeamRedCornerZ + Config.SchemsizeZ + areaExtension) + 1; - arenaMinX = ITechHider.posToChunk(Config.ArenaMinX); - arenaMaxX = ITechHider.posToChunk(Config.ArenaMaxX) + 1; - arenaMinZ = ITechHider.posToChunk(Config.ArenaMinZ); - arenaMaxZ = ITechHider.posToChunk(Config.ArenaMaxZ) + 1; - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); @@ -85,27 +58,15 @@ public class ITechHider { IFightTeam ft = IFight.getPlayerTeam(p); if(ft == null){ - //Außerhalb der Arena - return arenaMinX > chunkX || - chunkX > arenaMaxX || - arenaMinZ > chunkZ || - chunkZ > arenaMaxZ; + return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); }else if(ft.isBlue()){ - return ft.canPlayerEntern(p) || - redMinX > chunkX || - chunkX > redMaxX || - redMinZ > chunkZ || - chunkZ > redMaxZ; + return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); }else{ - return ft.canPlayerEntern(p) || - blueMinX > chunkX || - chunkX > blueMaxX || - blueMinZ > chunkZ || - chunkZ > blueMaxZ; + return ft.canPlayerEntern(p) || Config.RedExetendRegion.chunkOutside(chunkX, chunkZ); } } - static int posToChunk(int c){ + public static int posToChunk(int c){ int chunk = c / 16; if(c<0) chunk--; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java new file mode 100644 index 0000000..bcfeb27 --- /dev/null +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -0,0 +1,101 @@ +package de.steamwar.fightsystem.utils; + +import org.bukkit.Location; +import org.bukkit.block.Block; + +import java.util.function.ObjIntConsumer; + +public class Region { + + private final int minX; + private final int minY; + private final int minZ; + private final int maxX; + private final int maxY; + private final int maxZ; + + public Region(int minX, int minY, int minZ, int sizeX, int maxY, int sizeZ, int extendX, int extendZ) { + this(minX - extendX, minY, minZ - extendZ, + minX + sizeX + extendX, maxY, minZ + sizeZ + extendZ); + } + + public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { + this.minX = minX; + this.minY = minY; + this.minZ = minZ; + this.maxX = minX + sizeX; + this.maxY = minY + sizeY; + this.maxZ = minZ + sizeZ; + } + + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + public int getMinZ() { + return minZ; + } + + public int getMaxX() { + return maxX; + } + + public int getMaxY() { + return maxY; + } + + public int getMaxZ() { + return maxZ; + } + + public int getMinChunkX(){ + return ITechHider.posToChunk(minX); + } + + public int getMaxChunkX(){ + return ITechHider.posToChunk(maxX); + } + + public int getMinChunkZ(){ + return ITechHider.posToChunk(minZ); + } + + public int getMaxChunkZ(){ + return ITechHider.posToChunk(maxZ); + } + + public boolean chunkOutside(int cX, int cZ) { + return getMinChunkX() > cX || cX > getMaxChunkX() || + getMinChunkZ() > cZ || cZ > getMaxChunkZ(); + } + + public void forEachChunk(ObjIntConsumer executor) { + for(int x = getMinChunkX(); x <= getMaxChunkX(); x++) + for(int z = getMinChunkZ(); z <= getMaxChunkZ(); z++) + executor.accept(x, z); + } + + public boolean in2dRegion(Location location){ + return minX <= location.getX() && location.getX() < maxX && minZ <= location.getZ() && location.getZ() <= maxZ; + } + + public boolean inRegion(Location location){ + return in2dRegion(location) && minY < location.getY() && location.getY() < maxY; + } + + public boolean playerInRegion(Location location){ + return in2dRegion(location) && minY < location.getY() && location.getY() + 1.8 < maxY; + } + + public boolean in2dRegion(Block block){ + return minX <= block.getX() && block.getX() < maxX && minZ <= block.getZ() && block.getZ() <= maxZ; + } + + public boolean inRegion(Block block){ + return in2dRegion(block) && minY <= block.getY() && block.getY() < maxY; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 62fea36..f64bdcb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -26,6 +26,7 @@ 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.fight.FightWorld; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.record.Recorder; @@ -65,15 +66,18 @@ public class FightSystem extends JavaPlugin { new PistonListener(); new Chat(); new HotbarGUI(); - new Move(); - new ConnectionListener(); + new ArenaBorder(); + new TeamArea(); + new IngameDeath(); new InFightDamage(); new InFightInventory(); new DenyWorldInteraction(); new EventJoin(); new Recording(); new Check(); - new PrepareJoin(); + new Shutdown(); + new SetupQuit(); + new PrepareSchem(); new TestJoin(); new NormalJoin(); new RankedJoin(); @@ -85,6 +89,7 @@ public class FightSystem extends JavaPlugin { new EnterHandler(); new TechHider(); + new FightWorld(); new WinconditionAllDead(); new WinconditionCaptainDead(); @@ -101,10 +106,11 @@ public class FightSystem extends JavaPlugin { new WinconditionPercentTimeout(); new NoPlayersOnlineCountdown(); - new PreSchemPasteCountdown(); - new SetupOverCountdown(); + new PreSchemCountdown(); + new PostSchemCountdown(); new PreRunningCountdown(); new SpectateOverCountdown(); + new EventSpectateCountdown(); new LeaveCommand(); new KitCommand(); @@ -122,16 +128,14 @@ public class FightSystem extends JavaPlugin { CommandInjector.injectCommand(new GamemodeCommand()); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to replace commands", e); - Bukkit.shutdown(); - return; } if(Config.mode == ArenaMode.EVENT) { setPreSchemState(); }else if(Config.mode == ArenaMode.CHECK){ - Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); + Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.CheckSchemID)); }else if(Config.mode == ArenaMode.PREPARE) { - Fight.getBlueTeam().setNotPastingSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); + Fight.getBlueTeam().setSchem(Schematic.getSchemFromDB(Config.PrepareSchemID)); } } @@ -140,15 +144,18 @@ public class FightSystem extends JavaPlugin { Recorder.closeAll(); } + + + public static void setPreLeaderState() { + FightState.setFightState(FightState.PRE_LEADER_SETUP); + } + public static void setPreSchemState() { FightState.setFightState(FightState.PRE_SCHEM_SETUP); } public static void setPostSchemState() { FightState.setFightState(FightState.POST_SCHEM_SETUP); - - Fight.getBlueTeam().pasteSchematic(); - Fight.getRedTeam().pasteSchematic(); } public static void setPreRunningState() { @@ -177,8 +184,6 @@ public class FightSystem extends JavaPlugin { Fight.getRedTeam().teleportToSpawn(); Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear()); - Bukkit.broadcastMessage(" "); - if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); } else { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index 39f9995..beed415 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -106,9 +106,8 @@ public class Commands { if(team == null) return; - FightPlayer leader = team.getLeader(); p.sendMessage(FightSystem.PREFIX + "§aDu bist Team " + team.getColoredName() + " §abeigetreten!"); - leader.sendMessage(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist deinem Team beigetreten!"); + team.broadcast(FightSystem.PREFIX + "§aDer Spieler §e" + p.getName() + " §aist dem Team beigetreten!"); team.addMember(p); } @@ -120,9 +119,8 @@ public class Commands { if(team == null) return; - FightPlayer leader = team.getLeader(); p.sendMessage(FightSystem.PREFIX + "§aDu hast die Einladung von " + team.getColoredName() + " §aabgelehnt!"); - leader.sendMessage(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat deine Einladung abgelehnt!"); + team.broadcast(FightSystem.PREFIX + "§cDer Spieler §e" + p.getName() + " §chat die Einladung abgelehnt!"); team.getInvited().remove(p); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index 3babf48..9efade8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -184,7 +184,7 @@ public class GUI { if(fightTeam == null) return; if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP) - fightTeam.setSchematic(s); + fightTeam.pasteSchem(s); p.closeInventory(); }); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java index 84a9f73..e0b03c2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java @@ -43,9 +43,9 @@ public class LeaderCommand implements CommandExecutor { if(args.length == 0){ if(Fight.getFightPlayer(player) == null){ - if(!Fight.getBlueTeam().hasTeamLeader()) + if(Fight.getBlueTeam().isLeaderless()) Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player)); - else if(!Fight.getRedTeam().hasTeamLeader()) + else if(Fight.getRedTeam().isLeaderless()) Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player)); else player.sendMessage(FightSystem.PREFIX + "§cEs sind bereits 2 Teamleader vorhanden"); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java index 6087608..6070d12 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LockschemCommand.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; @@ -71,10 +70,7 @@ public class LockschemCommand implements CommandExecutor { } Schematic.getSchemFromDB(fightTeam.getSchematic()).setSchemType(SchematicType.Normal); player.sendMessage(FightSystem.PREFIX + "Schematic von " + fightTeam.getColoredName() + " §cgesperrt!"); - FightPlayer leader = fightTeam.getLeader(); - if(leader != null){ - leader.sendMessage(FightSystem.PREFIX + "§cDeine Schematic wurde von " + player.getName() + " gesperrt!"); - } + fightTeam.broadcast(FightSystem.PREFIX + "§cDie Schematic wurde von " + player.getName() + " gesperrt!"); return false; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java new file mode 100644 index 0000000..abaa890 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EventSpectateCountdown.java @@ -0,0 +1,44 @@ +/* + 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.countdown; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCountdown; + +public class EventSpectateCountdown extends Countdown { + + public EventSpectateCountdown() { + super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false); + new StateDependentCountdown(ArenaMode.Event, FightState.Spectate, this); + } + + @Override + public String countdownCounting() { + return "bis der Server gestoppt wird!"; + } + + @Override + public void countdownFinished() { + FightSystem.shutdown(null); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java similarity index 94% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java rename to FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index 2a93915..a388fbd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SetupOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -25,9 +25,9 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; -public class SetupOverCountdown extends Countdown { +public class PostSchemCountdown extends Countdown { - public SetupOverCountdown() { + public PostSchemCountdown() { super(Config.SetupDuration, null, false); new StateDependentCountdown(ArenaMode.AntiTest, FightState.PostSchemSetup, this); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java similarity index 93% rename from FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java rename to FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index aace340..e0084a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemPasteCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -25,9 +25,9 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; -public class PreSchemPasteCountdown extends Countdown { +public class PreSchemCountdown extends Countdown { - public PreSchemPasteCountdown() { + public PreSchemCountdown() { super(Config.PreSchemPasteDuration, SWSound.BLOCK_NOTE_PLING, false); new StateDependentCountdown(ArenaMode.All, FightState.PreSchemSetup, this); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index c9893b4..8280f03 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -29,16 +29,16 @@ public class SpectateOverCountdown extends Countdown { public SpectateOverCountdown() { super(Config.SpectatorDuration, SWSound.BLOCK_NOTE_PLING, false); - new StateDependentCountdown(ArenaMode.AntiTest, FightState.Spectate, this); + new StateDependentCountdown(ArenaMode.Restartable, FightState.Spectate, this); } @Override public String countdownCounting() { - return "bis der Server gestoppt wird!"; + return "bis die Arena zurückgesetzt wird!"; } @Override public void countdownFinished() { - FightSystem.shutdown(null); + FightSystem.setPreLeaderState(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 761dcef..cc3a16e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -42,8 +42,8 @@ import java.util.logging.Level; public class Fight { private Fight(){} - 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); + private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExetendRegion, Config.TeamRedRotate, false, Config.RedLeader); + private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.TeamBlueRotate, true, Config.BlueLeader); public static void init(){ IFight.init(redTeam, blueTeam); @@ -159,8 +159,8 @@ public class Fight { return 1000; } - if(redTeam.getLeader() == null || redTeam.getLeader().getPlayer() == null || - blueTeam.getLeader() == null || blueTeam.getLeader().getPlayer() == null){ + + if(redTeam.getLeader() == null || blueTeam.getLeader() == null){ return 1000; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index fcfa795..7b4c1ae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -22,12 +22,13 @@ 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.ArenaMode; 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.IStateDependent; +import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ColorConverter; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; @@ -42,10 +43,9 @@ 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 IStateDependent { +public class FightSchematic extends StateDependent { private final FightTeam team; private final int pasteX; @@ -60,6 +60,7 @@ public class FightSchematic implements IStateDependent { private int schematic = 0; public FightSchematic(FightTeam team, int pasteX, int pasteY, int pasteZ, int cornerX, int cornerY, int cornerZ, boolean rotate) { + super(ArenaMode.All, FightState.Schem); this.team = team; this.pasteX = pasteX; this.pasteY = pasteY; @@ -68,7 +69,6 @@ public class FightSchematic implements IStateDependent { this.cornerY = cornerY; this.cornerZ = cornerZ; this.rotate = rotate; - FightState.registerStateDependent(this); } public boolean hasSchematic(){ @@ -89,11 +89,6 @@ public class FightSchematic implements IStateDependent { } } - @Override - public Set enabled() { - return FightState.Schem; - } - @Override public void enable() { if(FightState.getFightState() == FightState.SPECTATE) @@ -107,6 +102,12 @@ public class FightSchematic implements IStateDependent { setSchematic(publics.get(new Random().nextInt(publics.size()))); } + if(!ArenaMode.Test.contains(Config.mode)){ + FightPlayer leader = team.getLeader(); + if(leader != null) + leader.getPlayer().getInventory().clear(0); + } + if(team.isBlue()) RecordSystem.blueSchem(schematic); else @@ -175,7 +176,7 @@ public class FightSchematic implements IStateDependent { @Override public void disable() { - //TODO: Reset team area + team.teleportToSpawn(); } private static class FreezeWorld implements Listener { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index d5e9001..5e03e88 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -30,6 +30,7 @@ import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.utils.ItemBuilder; +import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.TechHider; import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; @@ -59,27 +60,20 @@ public class FightTeam implements IFightTeam{ private final boolean blue; private final Location spawn; - 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 final Region schemRegion; + private final Region extendRegion; - public FightTeam(String name, String prefix, Location spawn, int cornerX, int cornerY, int cornerZ, boolean rotate, boolean blue, UUID designatedLeader) { + public FightTeam(String name, String prefix, Location spawn, Region schemRegion, Region extendRegion, boolean rotate, boolean blue, UUID designatedLeader) { this.spawn = spawn; - this.pasteX = cornerX + Config.SchemsizeX/2; - this.pasteY = cornerY; - this.pasteZ = cornerZ + Config.SchemsizeZ/2; + this.schemRegion = schemRegion; + this.extendRegion = extendRegion; + int pasteX = schemRegion.getMinX() + Config.SchemsizeX / 2; + int pasteY = schemRegion.getMinY(); + int pasteZ = schemRegion.getMinZ() + Config.SchemsizeZ / 2; this.name = name; this.prefix = prefix; this.ready = false; - this.rotate = rotate; - this.cornerX = cornerX; - this.cornerY = cornerY; - this.cornerZ = cornerZ; - this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, cornerX, cornerY, cornerZ, rotate); + this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, schemRegion.getMinX(), schemRegion.getMinY(), schemRegion.getMinZ(), rotate); this.blue = blue; this.designatedLeader = designatedLeader; color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); @@ -94,20 +88,28 @@ public class FightTeam implements IFightTeam{ team.setAllowFriendlyFire(false); } + public Region getSchemRegion() { + return schemRegion; + } + + public Region getExtendRegion() { + return extendRegion; + } + public final int getCornerX() { - return cornerX; + return schemRegion.getMinX(); } public final int getCornerY() { - return cornerY; + return schemRegion.getMinY(); } public final int getCornerZ() { - return cornerZ; + return schemRegion.getMinZ(); } public boolean canbeLeader(Player p){ - return !hasTeamLeader() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); + return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } public void teleportToSpawn(){ @@ -172,24 +174,24 @@ public class FightTeam implements IFightTeam{ public void removePlayer(Player player) { FightPlayer fightPlayer = getFightPlayer(player); - final List chunksToReload = TechHider.prepareChunkReload(player); + List chunksToReload = TechHider.prepareChunkReload(player); players.remove(player); team.removeEntry(player.getName()); - fightPlayer.getPlayer().getInventory().clear(); - if(fightPlayer.equals(leader) && FightState.setup()) + if(fightPlayer.equals(leader)) setLeader(null); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); - if(!Config.test()) + player.getInventory().clear(); + if(!ArenaMode.Test.contains(Config.mode)) new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player); RecordSystem.entityDespawns(player); TechHider.reloadChunks(player, chunksToReload); } - public boolean hasTeamLeader() { - return leader != null; + public boolean isLeaderless() { + return leader == null; } @Override @@ -207,7 +209,7 @@ public class FightTeam implements IFightTeam{ setLeader(players.values().iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); }else if(!ArenaMode.RankedEvent.contains(Config.mode)){ - FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); + FightSystem.setPreLeaderState(); } return; } @@ -248,27 +250,19 @@ public class FightTeam implements IFightTeam{ return ready; } - public void pasteSchematic(){ - if(!Config.test() && leader != null) - leader.getPlayer().getInventory().clear(0); - } + public void pasteSchem(Schematic schematic){ + setSchem(schematic); - public void setSchematic(Schematic schematic){ - setNotPastingSchem(schematic); - broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); - - if(!Config.test()) - leader.getPlayer().getInventory().clear(0); - - if(Config.test()) - pasteSchematic(); + if(ArenaMode.Test.contains(Config.mode)) + this.schematic.enable(); else if(Fight.getOpposite(this).hasSchematic()){ FightSystem.setPostSchemState(); } } - public void setNotPastingSchem(Schematic schematic){ + public void setSchem(Schematic schematic){ this.schematic.setSchematic(schematic); + broadcast(FightSystem.PREFIX + "§7Das §e" + Config.GameName + " " + schematic.getSchemName() + " §7wird für den Kampf verwendet!"); } public boolean hasSchematic(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java new file mode 100644 index 0000000..6245c59 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -0,0 +1,49 @@ +package de.steamwar.fightsystem.fight; + +import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; +import net.minecraft.server.v1_15_R1.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.WorldCreator; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.Player; + +public class FightWorld extends StateDependent { + + private final World world = Bukkit.getWorlds().get(0); + + public FightWorld() { + super(ArenaMode.Restartable, FightState.Schem); + } + + @Override + public void enable() { + //unused + } + + @Override + public void disable() { + World backup = new WorldCreator(world.getName() + "/backup").createWorld(); + assert backup != null; + Config.ArenaRegion.forEachChunk((x, z) -> resetChunk(backup, x, z)); + Bukkit.unloadWorld(backup, false); + } + + private void resetChunk(World backup, int x, int z){ + Chunk chunk = ((CraftWorld) world).getHandle().getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + chunk.heightMap.clear(); + chunk.heightMap.putAll(backupChunk.heightMap); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java new file mode 100644 index 0000000..4a92fc8 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -0,0 +1,72 @@ +/* + 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.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +public class ArenaBorder implements Listener { + + public ArenaBorder() { + new StateDependentListener(ArenaMode.All, FightState.All, this); + } + + @EventHandler + public void arenaBorder(PlayerMoveEvent event){ + Player player = event.getPlayer(); + Location to = event.getTo(); + assert to != null; + + if(!Config.ArenaRegion.in2dRegion(to)){ + reset(event); + return; + } + + FightTeam team = Fight.getPlayerTeam(player); + if(team == null || player.getGameMode() == GameMode.SPECTATOR) + return; + + if(to.getY() <= Config.underArenaBorder) { + if(FightState.infight()) + player.damage(2); + else if(!Config.GroundWalkable) + player.teleport(team.getSpawn()); + }else if(to.getY() + 1.8 <= Config.upperArenaBorder){ + reset(event); + } + } + + private void reset(PlayerMoveEvent event){ + Player player = event.getPlayer(); + player.teleport(event.getFrom()); + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§cDu darfst die Arena nicht verlassen")); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java deleted file mode 100644 index 196fb6c..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ConnectionListener.java +++ /dev/null @@ -1,118 +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.comms.packets.TablistNamePacket; -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.countdown.Countdown; -import de.steamwar.fightsystem.countdown.SWSound; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.record.RecordSystem; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.sql.SteamwarUser; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerQuitEvent; - -public class ConnectionListener implements Listener { - - public ConnectionListener() { - new StateDependentListener(ArenaMode.All, FightState.All, this); - } - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerJoin(PlayerJoinEvent event) { - event.setJoinMessage(null); - - Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if (fightTeam == null) { - Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - player.teleport(Config.SpecSpawn); - if(!Config.test()) - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5); - } else { - player.teleport(fightTeam.getSpawn()); - if(FightState.setup()) - Fight.setPlayerGamemode(player, GameMode.SURVIVAL); - else - Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - } - } - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerDeath(PlayerDeathEvent event) { - event.setDeathMessage(null); - - Player player = event.getEntity().getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if(fightTeam == null) - return; - - assert player != null; - Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + fightTeam.getPrefix() + player.getName() + " §cist gestorben!"); - fightTeam.getFightPlayer(player).setOut(); - Fight.setPlayerGamemode(player, GameMode.SPECTATOR); - player.teleport(fightTeam.getSpawn()); - Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); - RecordSystem.entityDespawns(player); - } - - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerQuit(PlayerQuitEvent event) { - event.setQuitMessage(null); - - Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - if(fightTeam == null) - return; - - if(FightState.setup()){ - fightTeam.removePlayer(player); - - RecordSystem.entityDespawns(player); - }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!"); - fightTeam.getFightPlayer(player).setOut(); - - RecordSystem.entityDespawns(player); - } - } - - //Shutdown server if nobody online and its not an event server - if(Config.mode != ArenaMode.EVENT && (Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(player)))) - FightSystem.shutdown(null); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index ca27151..d56405b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -81,7 +81,7 @@ public class EventJoin implements Listener { if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){ FightPlayer fp = team.addMember(player); - if(!team.hasTeamLeader()) + if(team.isLeaderless()) team.setLeader(fp); return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java new file mode 100644 index 0000000..6bf1074 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -0,0 +1,77 @@ +/* + 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.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.countdown.SWSound; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.record.RecordSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class IngameDeath implements Listener { + + public IngameDeath() { + new StateDependentListener(ArenaMode.All, FightState.Ingame, this); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + + Player player = event.getEntity(); + FightTeam team = Fight.getPlayerTeam(player); + + if(team == null) + return; + + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §cist gestorben!"); + Fight.playSound(Countdown.getSound(SWSound.ENTITY_WITHER_DEATH), 100.0F, 1.0F); + team.getFightPlayer(player).setOut(); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + + Player player = event.getPlayer(); + FightTeam team = Fight.getPlayerTeam(player); + if(team == null) + return; + + FightPlayer fightPlayer = team.getFightPlayer(player); + if(fightPlayer.isLiving()) { + Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Spieler " + team.getPrefix() + player.getName() + " §chat den Kampf verlassen!"); + team.getFightPlayer(player).setOut(); + RecordSystem.entityDespawns(player); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java deleted file mode 100644 index 026a8e9..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Move.java +++ /dev/null @@ -1,127 +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.ArenaMode; -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.StateDependentListener; -import de.steamwar.fightsystem.utils.Region; -import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; - -import java.util.logging.Level; - -public class Move implements Listener { - - private static final String DENY_ARENA = "§cDu darfst die Arena nicht verlassen"; - private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; - private static final String DENY_ENTERN = "§cDu darfst nicht entern"; - - public Move() { - new StateDependentListener(ArenaMode.All, FightState.All, this); - } - - @EventHandler - public void teamAreas(PlayerMoveEvent event) { - Player player = event.getPlayer(); - if(player == FightSystem.getEventLeiter() || Config.test()) - return; - - Location to = event.getTo(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - assert to != null; - boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; - - boolean inBlueArea = inArenaY && Region.isIn2DRange(to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); - boolean inRedArea = inArenaY && Region.isIn2DRange(to, Config.TeamRedCornerX, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic); - - if(inBlueArea){ - if(fightTeam == null) - reset(event, DENY_TEAM); - else if(fightTeam == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player))) - reset(event, DENY_ENTERN); - else - return; // Is allowed in area - checkInInnerArea(event.getPlayer(), to, Config.TeamBlueCornerX, Config.TeamBlueCornerZ); - }else if(inRedArea){ - if(fightTeam == null) - reset(event, DENY_TEAM); - else if(fightTeam == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !fightTeam.canPlayerEntern(player))) - reset(event, DENY_ENTERN); - else - return; // Is allowed in area - checkInInnerArea(event.getPlayer(), to, Config.TeamRedCornerX, Config.TeamRedCornerZ); - }else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player)) - reset(event, DENY_ENTERN); - } - - private void checkInInnerArea(Player player, Location to, int teamCornerX, int teamCornerZ){ - boolean inArenaY = to.getY() + 1.8 <= Config.TeamBlueCornerY + Config.SchemsizeY; - boolean inArea = inArenaY && Region.isIn2DRange(to, teamCornerX, teamCornerZ, Config.SchemsizeX, Config.SchemsizeZ, 0); - if(inArea && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension - player.kickPlayer(null); - Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); - } - } - - @EventHandler - public void arenaBorder(PlayerMoveEvent event){ - Player player = event.getPlayer(); - Location to = event.getTo(); - - //Check in Arena - assert to != null; - if(!Region.isIn2DRegion(to, Config.ArenaMinX, Config.ArenaMinZ, Config.ArenaMaxX, Config.ArenaMaxZ)){ - reset(event, DENY_ARENA); - return; - } - - FightTeam team = Fight.getPlayerTeam(player); - boolean inArenaY = to.getY() + 1.8 <= Config.upperArenaBorder; - - if(to.getY() <= Config.underArenaBorder) { - if(player.getGameMode() == GameMode.SPECTATOR || team == null) - reset(event, DENY_ARENA); - else if(FightState.infight()) - player.damage(2); - else if(!Config.GroundWalkable) - player.teleport(team.getSpawn()); - }else if(team != null && !inArenaY){ - reset(event, DENY_ARENA); - } - } - - private void reset(PlayerMoveEvent event, String message){ - Player player = event.getPlayer(); - player.teleport(event.getFrom()); - BasicListener.toActionbar(player, TextComponent.fromLegacyText(message)); - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java index b6a39ae..264a242 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java @@ -23,6 +23,7 @@ import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; @@ -50,8 +51,9 @@ public class NormalJoin implements Listener { } } - if(Fight.getRedTeam().hasTeamLeader() && Fight.getBlueTeam().hasTeamLeader() - && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) { + FightPlayer redLeader = Fight.getRedTeam().getLeader(); + FightPlayer blueLeader = Fight.getBlueTeam().getLeader(); + if(redLeader != null && blueLeader != null && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) { FightSystem.setPreSchemState(); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java index 7a98a71..51dbd8f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Permanent.java @@ -19,26 +19,30 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.fightsystem.ArenaMode; 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.StateDependentListener; +import de.steamwar.sql.SteamwarUser; import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; -import org.bukkit.event.player.PlayerBedEnterEvent; -import org.bukkit.event.player.PlayerDropItemEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.player.*; import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.world.WorldLoadEvent; public class Permanent implements Listener { @@ -46,6 +50,39 @@ public class Permanent implements Listener { new StateDependentListener(ArenaMode.All, FightState.All, this); } + @EventHandler + public void handlePlayerRespawn(PlayerRespawnEvent event){ + Player player = event.getPlayer(); + Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + + FightTeam team = Fight.getPlayerTeam(player); + event.setRespawnLocation(team == null ? Config.SpecSpawn : team.getSpawn()); + } + + @EventHandler + public void onTpGM3(PlayerTeleportEvent e) { + if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { + e.setCancelled(true); + BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); + e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!"); + } + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerJoin(PlayerJoinEvent event) { + event.setJoinMessage(null); + + Player player = event.getPlayer(); + FightTeam fightTeam = Fight.getPlayerTeam(player); + + if (fightTeam == null) { + Fight.setPlayerGamemode(player, GameMode.SPECTATOR); + player.teleport(Config.SpecSpawn); + if(!ArenaMode.Test.contains(Config.mode)) + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player), 5); + } + } + @EventHandler public void handleFoodLevelChange(FoodLevelChangeEvent event) { event.setCancelled(true); @@ -87,21 +124,7 @@ public class Permanent implements Listener { } @EventHandler - public void handlePlayerRespawn(PlayerRespawnEvent event) { - Player player = event.getPlayer(); - FightTeam team = Fight.getPlayerTeam(player); - if(team == null) - event.setRespawnLocation(Config.SpecSpawn); - else - event.setRespawnLocation(team.getSpawn()); - } - - @EventHandler - public void onTpGM3(PlayerTeleportEvent e) { - if (e.getCause() == PlayerTeleportEvent.TeleportCause.SPECTATE) { - e.setCancelled(true); - BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst diese Teleportfunktion nicht benutzen!")); - e.getPlayer().kickPlayer("§cDu darfst diese Teleportfunktion nicht benutzen!"); - } + public void onWorldLoad(WorldLoadEvent e) { + e.getWorld().setAutoSave(false); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index ddb784a..00c8e0e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -22,7 +22,6 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.fightsystem.utils.Region; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.event.EventHandler; @@ -40,13 +39,9 @@ public class PistonListener implements Listener { @EventHandler public void handlePistonExtend(BlockPistonExtendEvent e){ - BlockFace b = e.getDirection(); + BlockFace b = e.getDirection().getOppositeFace(); for(Block block : e.getBlocks()){ - if( - block.getY() > Config.upperArenaBorder || - (!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) && - !Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic)) - ){ + if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))){ e.setCancelled(true); return; } @@ -55,13 +50,9 @@ public class PistonListener implements Listener { @EventHandler public void handlePistonRetract(BlockPistonRetractEvent e){ - BlockFace b = e.getDirection(); + BlockFace b = e.getDirection().getOppositeFace(); for(Block block : e.getBlocks()){ - if( - block.getY() > Config.upperArenaBorder || - (!Region.isIn2DRange(block.getLocation(), Config.TeamBlueCornerX + b.getModX(), Config.TeamBlueCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic) && - !Region.isIn2DRange(block.getLocation(), Config.TeamRedCornerX + b.getModX(), Config.TeamRedCornerZ + b.getModZ(), Config.SchemsizeX, Config.SchemsizeZ, Config.BorderFromSchematic)) - ){ + if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))) { e.setCancelled(true); return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java similarity index 88% rename from FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java rename to FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java index e5a3735..3852681 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -30,10 +30,16 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -public class PrepareJoin implements Listener { +public class PrepareSchem implements Listener { - public PrepareJoin() { - new StateDependentListener(ArenaMode.Prepare, FightState.All, this); + public PrepareSchem() { + new StateDependentListener(ArenaMode.Prepare, FightState.Setup, this){ + @Override + public void disable() { + super.disable(); + //TODO + } + }; } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index d1ef4fc..fdcb5cd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.*; import org.bukkit.entity.EntityType; @@ -53,19 +54,21 @@ public class Recording implements Listener { private static final Random random = new Random(); public Recording() { - new StateDependentListener(Config.recording(), FightState.All, this){ + new StateDependentListener(Config.recording(), FightState.All, this); + new StateDependent(Config.recording(), FightState.Ingame){ @Override - public void stateChange(FightState state) { - if(state == FightState.PRE_RUNNING) { - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - setKitItems(Fight.getBlueTeam()); - setKitItems(Fight.getRedTeam()); - }, 1); - }else if(state == FightState.SPECTATE){ - despawnTeam(Fight.getRedTeam()); - despawnTeam(Fight.getBlueTeam()); - despawnTNT(); - } + public void enable() { + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { + setKitItems(Fight.getBlueTeam()); + setKitItems(Fight.getRedTeam()); + }, 1); + } + + @Override + public void disable() { + despawnTeam(Fight.getRedTeam()); + despawnTeam(Fight.getBlueTeam()); + despawnTNT(); } }; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java new file mode 100644 index 0000000..15776f3 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java @@ -0,0 +1,50 @@ +/* + 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.ArenaMode; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class SetupQuit implements Listener { + + public SetupQuit(){ + new StateDependentListener(ArenaMode.All, FightState.Setup, this); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerQuit(PlayerQuitEvent event) { + event.setQuitMessage(null); + + Player player = event.getPlayer(); + FightTeam team = Fight.getPlayerTeam(player); + if(team == null) + return; + + team.removePlayer(player); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java new file mode 100644 index 0000000..be3e243 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Shutdown.java @@ -0,0 +1,43 @@ +/* + 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.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class Shutdown implements Listener { + + public Shutdown(){ + new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this); + } + + @EventHandler(priority = EventPriority.HIGH) + public void handlePlayerQuit(PlayerQuitEvent event) { + //Shutdown server if nobody online and its not an event server + if(Bukkit.getOnlinePlayers().isEmpty() || (Bukkit.getOnlinePlayers().size() == 1 && Bukkit.getOnlinePlayers().contains(event.getPlayer()))) + Bukkit.shutdown(); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java new file mode 100644 index 0000000..d1fc8e3 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -0,0 +1,73 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.ArenaMode; +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.StateDependentListener; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.Bukkit; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; + +import java.util.logging.Level; + +public class TeamArea implements Listener { + + private static final String DENY_TEAM = "§cDu darfst nicht zu den Teams"; + private static final String DENY_ENTERN = "§cDu darfst nicht entern"; + + public TeamArea() { + new StateDependentListener(ArenaMode.AntiTest, FightState.All, this); + } + + @EventHandler + public void teamAreas(PlayerMoveEvent event) { + Player player = event.getPlayer(); + if(player == FightSystem.getEventLeiter()) + return; + + Location to = event.getTo(); + assert to != null; + + FightTeam team = Fight.getPlayerTeam(player); + + if(Config.BlueExtendRegion.playerInRegion(to)){ + if(team == null) + reset(event, DENY_TEAM); + else if(team == Fight.getRedTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player))) + reset(event, DENY_ENTERN); + else + return; // Is allowed in area + checkInInnerArea(event.getPlayer(), to, Fight.getBlueTeam()); + }else if(Config.RedExetendRegion.playerInRegion(to)){ + if(team == null) + reset(event, DENY_TEAM); + else if(team == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player))) + reset(event, DENY_ENTERN); + else + return; // Is allowed in area + checkInInnerArea(event.getPlayer(), to, Fight.getRedTeam()); + }else if(team != null && player.getGameMode() != GameMode.SPECTATOR && !team.canPlayerEntern(player)) + reset(event, DENY_ENTERN); + } + + private void checkInInnerArea(Player player, Location to, FightTeam team){ + if(team.getSchemRegion().playerInRegion(to) && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension + player.kickPlayer(null); + Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); + } + } + + private void reset(PlayerMoveEvent event, String message){ + Player player = event.getPlayer(); + player.teleport(event.getFrom()); + BasicListener.toActionbar(player, TextComponent.fromLegacyText(message)); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java index 66cc993..a8fd0eb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TestJoin.java @@ -41,7 +41,7 @@ public class TestJoin implements Listener { Player player = event.getPlayer(); FightTeam fightTeam = Fight.getPlayerTeam(player); - if (fightTeam == null && (!Fight.getRedTeam().hasTeamLeader() || !Fight.getBlueTeam().hasTeamLeader())) { + if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) { player.sendMessage(FightSystem.PREFIX + "§7Werde zum Teamleader mit §8/§eleader"); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index fdc32ac..b99fa84 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -64,12 +64,9 @@ public enum FightState { 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); + if(feature.getKey().enabled().contains(fightState) && !feature.getValue()){ + feature.getKey().enable(); + feature.setValue(true); } //Disable feature if should be disabled and currently enabled diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java index a9465dc..1d9f170 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/IStateDependent.java @@ -37,9 +37,4 @@ public interface IStateDependent { * Disables the state dependent object */ void disable(); - - /** - * On state change when enabled - */ - default void stateChange(FightState state){} } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index d2207af..ade520e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -41,7 +41,7 @@ public class FightStatistics { private FightStatistics(){} private static Timestamp starttime = Timestamp.from(Instant.now()); - private static int K = 20; + private static final int K = 20; public static void start(){ starttime = Timestamp.from(Instant.now()); @@ -49,10 +49,14 @@ public class FightStatistics { public static void saveStats(FightTeam winner, String windescription){ String gameMode = Config.SchematicType.toDB(); - if(!Fight.getBlueTeam().hasTeamLeader() || !Fight.getRedTeam().hasTeamLeader()) - return; - SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); - SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); + + int blueLeader = 0; + int redLeader = 0; + if(Fight.getBlueTeam().getLeader() != null) + blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()).getId(); + if(Fight.getRedTeam().getLeader() != null) + redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()).getId(); + int win = 0; double blueResult; if(winner == Fight.getBlueTeam()) { @@ -65,7 +69,8 @@ public class FightStatistics { blueResult = 0.5; } - Integer blueSchem, redSchem; + Integer blueSchem; + Integer redSchem; try{ blueSchem = Schematic.getSchemFromDB(Fight.getBlueTeam().getSchematic()).getSchemID(); }catch(SecurityException e){ @@ -85,7 +90,7 @@ public class FightStatistics { try { int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime, - blueLeader.getId(), redLeader.getId(), blueSchem, redSchem, win, windescription); + blueLeader, redLeader, blueSchem, redSchem, win, windescription); for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) savePlayerStats(fp, fightId); @@ -96,16 +101,16 @@ public class FightStatistics { } if(Config.Ranked){ - int blueElo = Elo.getElo(blueLeader.getId(), gameMode); - int redElo = Elo.getElo(redLeader.getId(), gameMode); + int blueElo = Elo.getElo(blueLeader, gameMode); + int redElo = Elo.getElo(redLeader, gameMode); double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation)); int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); - Elo.setElo(blueLeader.getId(), gameMode, newBlueElo); - Elo.setElo(redLeader.getId(), gameMode, newRedElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + blueLeader.getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + redLeader.getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo); + Elo.setElo(blueLeader, gameMode, newBlueElo); + Elo.setElo(redLeader, gameMode, newRedElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + Fight.getBlueTeam().getLeader().getPlayer().getName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + Fight.getRedTeam().getLeader().getPlayer().getName() + "§8: §7" + redElo + "§8»§e" + newRedElo); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/Region.java deleted file mode 100644 index 721658c..0000000 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/Region.java +++ /dev/null @@ -1,55 +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.utils; - -import org.bukkit.Location; - -public class Region { - - private Region(){} - - public static boolean isInRange(Location location, int minX, int minY, int minZ, int xRange, int yRange, int zRange, int margin) { - return isInRegion(location, minX, minY, minZ, minX + xRange, minY + yRange, minZ + zRange, margin); - } - - public static boolean isInRegion(Location location, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int margin) { - return isIn2DRegion(location, minX, minZ, maxX, maxZ, margin) && inRange(location.getBlockY(), minY, maxY, margin); - } - - public static boolean isIn2DRange(Location location, int minX, int minZ, int xRange, int zRange, int margin){ - return isIn2DRegion(location, minX, minZ, minX + xRange, minZ + zRange, margin); - } - - private static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ, int margin){ - return inRange(location.getBlockX(), minX, maxX, margin) && inRange(location.getBlockZ(), minZ, maxZ, margin); - } - - public static boolean isIn2DRegion(Location location, int minX, int minZ, int maxX, int maxZ){ - return inRange(location.getBlockX(), minX, maxX) && inRange(location.getBlockZ(), minZ, maxZ); - } - - private static boolean inRange(double value, int min, int max, int margin){ - return inRange(value, min-margin, max+margin); - } - - private static boolean inRange(double value, int min, int max){ - return min <= value && value <= max; - } -} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index a766300..fb1f633 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -232,10 +232,10 @@ public class TechHider implements IStateDependent { if(DISABLED) return Collections.emptyList(); List chunksToReload = new ArrayList<>(); - for(int x = ITechHider.arenaMinX; x <= ITechHider.arenaMaxX; x++) - for(int z = ITechHider.arenaMinZ; z <= ITechHider.arenaMaxZ; z++) - if(!bypass(p, x, z)) - chunksToReload.add(new ChunkPos(x, z)); + Config.ArenaRegion.forEachChunk((x, z) -> { + if(!bypass(p, x, z)) + chunksToReload.add(new ChunkPos(x, z)); + }); return chunksToReload; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index be7f867..3f903c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -24,7 +24,6 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.fightsystem.utils.Region; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityExplodeEvent; @@ -74,7 +73,7 @@ public class WinconditionPercentSystem extends Wincondition implements Listener, } private void check(EntityExplodeEvent event) { - if(!Region.isInRange(event.getEntity().getLocation(), team.getCornerX(), team.getCornerY(), team.getCornerZ(), Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)){ + if(!team.getExtendRegion().inRegion(event.getEntity().getLocation())){ return; } From 9b65277c6667b0027c6cbb828951910191e02ec4 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Mar 2021 17:25:13 +0100 Subject: [PATCH 05/15] Full resettable + config simplification Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam_12.java | 9 +- .../fightsystem/fight/FightTeam_14.java | 7 +- .../fightsystem/fight/FightTeam_8.java | 6 +- .../src/de/steamwar/fightsystem/Config.java | 146 +++++++----------- .../fightsystem/utils/ITechHider.java | 22 +-- .../de/steamwar/fightsystem/utils/Region.java | 23 +++ .../de/steamwar/fightsystem/FightSystem.java | 28 +--- .../fightsystem/commands/LeaderCommand.java | 4 +- .../de/steamwar/fightsystem/fight/Fight.java | 9 +- .../fightsystem/fight/FightPlayer.java | 4 +- .../fightsystem/fight/FightSchematic.java | 67 ++++---- .../steamwar/fightsystem/fight/FightTeam.java | 137 +++++++++++----- .../fightsystem/listener/ArenaBorder.java | 4 +- .../fightsystem/listener/EventJoin.java | 5 +- .../fightsystem/listener/NormalJoin.java | 4 +- .../listener/PersonalKitCreator.java | 18 +-- .../fightsystem/listener/PistonListener.java | 4 +- .../fightsystem/listener/RankedJoin.java | 4 +- .../fightsystem/listener/TeamArea.java | 2 +- .../fightsystem/listener/WaterRemover.java | 2 +- .../fightsystem/record/RecordSystem.java | 4 +- .../steamwar/fightsystem/utils/TechHider.java | 27 +++- .../WinconditionPercentSystem.java | 6 +- .../WinconditionPumpkinTechKO.java | 13 +- .../WinconditionRelativePercent.java | 18 +-- .../WinconditionWaterTechKO.java | 13 +- 26 files changed, 287 insertions(+), 299 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java index c6138b0..5d382d9 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam_12.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.regions.CuboidRegion; -import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.utils.Region; import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; @@ -54,10 +54,9 @@ class FightTeam_12 { @SuppressWarnings("deprecation") - static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ - FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); - Vector corner = new Vector(cornerX, cornerY, cornerZ); - CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ)); + static void replaceTeamColor(EditSession e, DyeColor c, Region r){ + FightTeam_8.replaceTeamColor(e, c, r); + CuboidRegion region = new CuboidRegion(new Vector(r.getMinX(), r.getMinY(), r.getMinZ()), new Vector(r.getMaxX(), r.getMaxY(), r.getMaxZ())); try { e.replaceBlocks(region, CONCRETE_SET, new BaseBlock(CONCRETE.getId(), c.getWoolData())); e.replaceBlocks(region, CONCRETE_POWDER_SET, new BaseBlock(CONCRETE_POWDER.getId(), c.getWoolData())); 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 ed35380..867a0f6 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java @@ -33,6 +33,7 @@ import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.utils.Region; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -61,10 +62,8 @@ class FightTeam_14 { team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); } - static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ - BlockVector3 corner3 = BlockVector3.at(cornerX, cornerY, cornerZ); - BlockVector3 schemsize3 = BlockVector3.at(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ); - CuboidRegion region = new CuboidRegion(corner3, corner3.add(schemsize3)); + static void replaceTeamColor(EditSession e, DyeColor c, Region r){ + CuboidRegion region = new CuboidRegion(BlockVector3.at(r.getMinX(), r.getMinY(), r.getMinZ()), BlockVector3.at(r.getMaxX(), r.getMaxY(), r.getMaxZ())); try { e.replaceBlocks(region, WOOL_SET, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_wool")).getDefaultState().toBaseBlock()); e.replaceBlocks(region, CARPET_SET, Objects.requireNonNull(BlockTypes.get(c.name().toLowerCase() + "_carpet")).getDefaultState().toBaseBlock()); 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 0752e85..26aceec 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -32,6 +32,7 @@ import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.utils.Region; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; @@ -72,9 +73,8 @@ class FightTeam_8 { } @SuppressWarnings("deprecation") - static void replaceTeamColor(EditSession e, DyeColor c, int cornerX, int cornerY, int cornerZ){ - Vector corner = new Vector(cornerX, cornerY, cornerZ); - CuboidRegion region = new CuboidRegion(corner, corner.add(Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ)); + static void replaceTeamColor(EditSession e, DyeColor c, Region r){ + CuboidRegion region = new CuboidRegion(new Vector(r.getMinX(), r.getMinY(), r.getMinZ()), new Vector(r.getMaxX(), r.getMaxY(), r.getMaxZ())); try { e.replaceBlocks(region, WOOL_SET, new BaseBlock(WOOL.getId(), c.getWoolData())); e.replaceBlocks(region, CLAY_SET, new BaseBlock(CLAY.getId(), c.getWoolData())); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 10e9ed6..a34a405 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -54,39 +54,20 @@ public class Config { public static final Region BluePasteRegion; public static final Region RedPasteRegion; public static final Region BlueExtendRegion; - public static final Region RedExetendRegion; + public static final Region RedExtendRegion; public static final Region ArenaRegion; - public static final int SchemsizeX; - public static final int SchemsizeY; - public static final int SchemsizeZ; - public static final int TeamBlueCornerX; - public static final int TeamBlueCornerY; - public static final int TeamBlueCornerZ; - private static final int TeamBluePasteX; - private static final int TeamBluePasteZ; public static final Location TeamBlueSpawn; - public static final int TeamRedCornerX; - public static final int TeamRedCornerY; - public static final int TeamRedCornerZ; - private static final int TeamRedPasteX; - private static final int TeamRedPasteZ; public static final Location TeamRedSpawn; + public static final Location SpecSpawn; + private static final int TeamBluetoReddistanceX; private static final int TeamBluetoReddistanceY; public static final int TeamBluetoReddistanceZ; - public static final Location SpecSpawn; - public static final int underArenaBorder; + public static final int BorderFromSchematic; - public static final int upperArenaBorder; public static final boolean AlignWater; public static final int WaterDepth; - private static final int Schem2BorderX; - private static final int Schem2BorderZ; - public static final int ArenaMinX; - public static final int ArenaMinZ; - public static final int ArenaMaxX; - public static final int ArenaMaxZ; public static final boolean GroundWalkable; //schematic parameter @@ -94,10 +75,9 @@ public class Config { public static final boolean OnlyPublicSchematics; public static final boolean IgnorePublicOnly; public static final de.steamwar.sql.SchematicType SchematicType; - public static final boolean TeamRedRotate; - public static final boolean TeamBlueRotate; - public static final boolean ReplaceObsidian; - public static final boolean ReplaceBedrock; + public static final boolean RedRotate; + public static final boolean BlueRotate; + public static final boolean ReplaceObsidianBedrock; public static final boolean ReplaceWithBlockupdates; //team parameter @@ -180,9 +160,9 @@ public class Config { TeamBluetoReddistanceX = worldconfig.getInt("Arena.TeamBluetoReddistance.x"); TeamBluetoReddistanceY = worldconfig.getInt("Arena.TeamBluetoReddistance.y"); TeamBluetoReddistanceZ = worldconfig.getInt("Arena.TeamBluetoReddistance.z"); - Schem2BorderX = config.getInt("Arena.Schem2Border.x"); - Schem2BorderZ = config.getInt("Arena.Schem2Border.z"); - underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); + int schem2BorderX = config.getInt("Arena.Schem2Border.x"); + int schem2BorderZ = config.getInt("Arena.Schem2Border.z"); + int underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); BorderFromSchematic = config.getInt("Arena.BorderFromSchematic"); AlignWater = worldconfig.getBoolean("Arena.AlignWater"); WaterDepth = worldconfig.getInt("Arena.WaterDepth"); @@ -195,14 +175,13 @@ public class Config { SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly"); boolean rotate = config.getBoolean("Schematic.Rotate"); - ReplaceObsidian = config.getBoolean("Schematic.ReplaceObsidian"); - ReplaceBedrock = config.getBoolean("Schematic.ReplaceBedrock"); + ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock"); ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates"); GameName = config.getString("Output.GameName"); TeamChatDetection = config.getString("Output.TeamChatDetection"); - ActiveWinconditions = config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet()); + ActiveWinconditions = Collections.unmodifiableSet(config.getStringList("WinConditions").stream().map(Winconditions::valueOf).collect(Collectors.toSet())); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); @@ -214,7 +193,7 @@ public class Config { MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); PersonalKits = config.getBoolean("Kits.PersonalKits"); - ForbiddenItems = config.getStringList("Kits.ForbiddenItems"); + ForbiddenItems = Collections.unmodifiableList(config.getStringList("Kits.ForbiddenItems")); HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); @@ -222,88 +201,81 @@ public class Config { TechhiderActive = config.getBoolean("Techhider.Active"); if(schemsizeX < 0){ - SchemsizeX = -schemsizeX; - TeamBlueCornerX = teamBlueCornerX - SchemsizeX; - }else{ - SchemsizeX = schemsizeX; - TeamBlueCornerX = teamBlueCornerX; + schemsizeX = -schemsizeX; + teamBlueCornerX = teamBlueCornerX - schemsizeX; } if(schemsizeY < 0){ - SchemsizeY = -schemsizeY; - TeamBlueCornerY = teamBlueCornerY - SchemsizeY; - }else{ - SchemsizeY = schemsizeY; - TeamBlueCornerY = teamBlueCornerY; + schemsizeY = -schemsizeY; + teamBlueCornerY = teamBlueCornerY - schemsizeY; } if(schemsizeZ < 0){ - SchemsizeZ = -schemsizeZ; - TeamBlueCornerZ = teamBlueCornerZ - SchemsizeZ; - }else{ - SchemsizeZ = schemsizeZ; - TeamBlueCornerZ = teamBlueCornerZ; + schemsizeZ = -schemsizeZ; + teamBlueCornerZ = teamBlueCornerZ - schemsizeZ; } - upperArenaBorder = TeamBlueCornerY + SchemsizeY + BorderFromSchematic; - TeamRedCornerX = TeamBluetoReddistanceX + TeamBlueCornerX; - TeamRedCornerY = TeamBluetoReddistanceY + TeamBlueCornerY; - TeamRedCornerZ = TeamBluetoReddistanceZ + TeamBlueCornerZ; + int teamRedCornerX = TeamBluetoReddistanceX + teamBlueCornerX; + int teamRedCornerY = TeamBluetoReddistanceY + teamBlueCornerY; + int teamRedCornerZ = TeamBluetoReddistanceZ + teamBlueCornerZ; - TeamBluePasteX = TeamBlueCornerX + SchemsizeX / 2; - TeamBluePasteZ = TeamBlueCornerZ + SchemsizeZ / 2; - TeamRedPasteX = TeamBluePasteX + TeamBluetoReddistanceX; - TeamRedPasteZ = TeamBluePasteZ + TeamBluetoReddistanceZ; + int teamBluePasteX = teamBlueCornerX + schemsizeX / 2; + int teamBluePasteZ = teamBlueCornerZ + schemsizeZ / 2; + int teamRedPasteX = teamBluePasteX + TeamBluetoReddistanceX; + int teamRedPasteZ = teamBluePasteZ + TeamBluetoReddistanceZ; World world = Bukkit.getWorlds().get(0); TeamBlueSpawn = new Location(world, - TeamBluePasteX + 0.5 + teamBlueSpawnOffsetX, - TeamBlueCornerY + 0.5 + teamBlueSpawnOffsetY, - TeamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ); + teamBluePasteX + 0.5 + teamBlueSpawnOffsetX, + teamBlueCornerY + 0.5 + teamBlueSpawnOffsetY, + teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ); TeamRedSpawn = new Location(world, - TeamRedPasteX + 0.5 - teamBlueSpawnOffsetX, - TeamRedCornerY + 0.5 + teamBlueSpawnOffsetY, - TeamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); + teamRedPasteX + 0.5 - teamBlueSpawnOffsetX, + teamRedCornerY + 0.5 + teamBlueSpawnOffsetY, + teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); + + SpecSpawn = new Location(world, + teamBluePasteX + TeamBluetoReddistanceX/2.0, + teamBlueCornerY + TeamBluetoReddistanceY/2.0 + schemsizeY/2.0, + teamBluePasteZ + TeamBluetoReddistanceZ/2.0); Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector()); double pitch = Math.toDegrees(v1.angle(v1.clone().setY(0))); double yaw = Math.toDegrees(v1.clone().setY(0).angle(new Vector(0, 0, 1))); - double pitchInverted = pitch * -1; - double yawInverted = yaw + 180; - TeamBlueSpawn.setYaw((float) yawInverted); + TeamBlueSpawn.setYaw((float) yaw + 180); TeamBlueSpawn.setPitch((float) pitch); TeamRedSpawn.setYaw((float) yaw); - TeamRedSpawn.setPitch((float) pitchInverted); + TeamRedSpawn.setPitch((float) pitch * -1); - SpecSpawn = new Location(world, - TeamBluePasteX + TeamBluetoReddistanceX/2.0, - TeamBlueCornerY + TeamBluetoReddistanceY/2.0 + SchemsizeY/2.0, - TeamBluePasteZ + TeamBluetoReddistanceZ/2.0); boolean teamRedRotate; boolean teamBlueRotate; + int arenaMinX; + int arenaMaxX; + int arenaMinZ; + int arenaMaxZ; if(TeamBluetoReddistanceX > 0){ - ArenaMinX = TeamBlueCornerX - Schem2BorderX; - ArenaMaxX = TeamRedCornerX + SchemsizeX + Schem2BorderX; + arenaMinX = teamBlueCornerX - schem2BorderX; + arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX; teamRedRotate = true; teamBlueRotate = false; }else{ - ArenaMinX = TeamRedCornerX - Schem2BorderX; - ArenaMaxX = TeamBlueCornerX + SchemsizeX + Schem2BorderX; + arenaMinX = teamRedCornerX - schem2BorderX; + arenaMaxX = teamBlueCornerX + schemsizeX + schem2BorderX; teamRedRotate = false; teamBlueRotate = true; } if(TeamBluetoReddistanceZ > 0){ - ArenaMinZ = TeamBlueCornerZ - Schem2BorderZ; - ArenaMaxZ = TeamRedCornerZ + SchemsizeZ + Schem2BorderZ; + arenaMinZ = teamBlueCornerZ - schem2BorderZ; + arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ; teamRedRotate = true; teamBlueRotate = false; }else{ - ArenaMinZ = TeamRedCornerZ - Schem2BorderZ; - ArenaMaxZ = TeamBlueCornerZ + SchemsizeZ + Schem2BorderZ; + arenaMinZ = teamRedCornerZ - schem2BorderZ; + arenaMaxZ = teamBlueCornerZ + schemsizeZ + schem2BorderZ; if(TeamBluetoReddistanceZ != 0){ teamRedRotate = false; teamBlueRotate = true; @@ -313,14 +285,16 @@ public class Config { teamRedRotate = false; teamBlueRotate = false; } - TeamRedRotate = teamRedRotate; - TeamBlueRotate = teamBlueRotate; + RedRotate = teamRedRotate; + BlueRotate = teamBlueRotate; - RedPasteRegion = new Region(TeamRedCornerX, TeamRedCornerY, TeamRedCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ); - BluePasteRegion = new Region(TeamBlueCornerX, TeamBlueCornerY, TeamBlueCornerZ, SchemsizeX, SchemsizeY, SchemsizeZ); - RedExetendRegion = new Region(TeamRedCornerX, underArenaBorder, TeamRedCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic); - BlueExtendRegion = new Region(TeamBlueCornerX, underArenaBorder, TeamBlueCornerZ, SchemsizeX, upperArenaBorder, SchemsizeZ, BorderFromSchematic, BorderFromSchematic); - ArenaRegion = new Region(ArenaMinX, underArenaBorder, ArenaMinZ, ArenaMaxX - ArenaMinX, upperArenaBorder - underArenaBorder, ArenaMaxZ - ArenaMinZ); + RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); + BluePasteRegion = new Region(teamBlueCornerX, teamBlueCornerY, teamBlueCornerZ, schemsizeX, schemsizeY, schemsizeZ); + + RedExtendRegion = new Region(teamRedCornerX, underArenaBorder, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, BorderFromSchematic, BorderFromSchematic); + BlueExtendRegion = new Region(teamBlueCornerX, underArenaBorder, teamBlueCornerZ, schemsizeX, schemsizeY, schemsizeZ, BorderFromSchematic, BorderFromSchematic); + int upperArenaBorder = teamBlueCornerY + schemsizeY + BorderFromSchematic; + ArenaRegion = new Region(arenaMinX, underArenaBorder, arenaMinZ, arenaMaxX - arenaMinX, upperArenaBorder - underArenaBorder, arenaMaxZ - arenaMinZ); EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index b545be5..572b888 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -19,39 +19,19 @@ package de.steamwar.fightsystem.utils; -import com.comphenix.protocol.events.PacketContainer; import com.google.common.primitives.Bytes; -import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.fight.IFight; import de.steamwar.fightsystem.fight.IFightTeam; -import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class ITechHider { private ITechHider (){} - static final Map packetCache = new HashMap<>(); - static final Material obfuscateMaterial; - static final int threadMultiplier; - - static{ - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); - Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); - - if(Config.mode == ArenaMode.EVENT) - threadMultiplier = 4; - else - threadMultiplier = 1; - } - static boolean bypass(Player p, int chunkX, int chunkZ){ if(p == IFightSystem.getEventLeiter()) return true; @@ -62,7 +42,7 @@ public class ITechHider { }else if(ft.isBlue()){ return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); }else{ - return ft.canPlayerEntern(p) || Config.RedExetendRegion.chunkOutside(chunkX, chunkZ); + return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index bcfeb27..14c66f6 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.utils; +import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.Location; import org.bukkit.block.Block; @@ -79,6 +80,28 @@ public class Region { executor.accept(x, z); } + public void forEach(TriConsumer executor) { + for(int x = minX; x < maxX; x++) { + for(int y = minY; y < maxY; y++) { + for (int z = minZ; z <= maxZ; z++) { + executor.accept(x, y, z); + } + } + } + } + + public int volume(){ + return (maxX - minX) * (maxY - minY) * (maxZ - minZ); + } + + public int centerX() { + return (maxX - minX) / 2 + minX; + } + + public int centerZ() { + return (maxZ - minZ) / 2 + minZ; + } + public boolean in2dRegion(Location location){ return minX <= location.getX() && location.getX() < maxX && minZ <= location.getZ() && location.getZ() <= maxZ; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index f64bdcb..d145f55 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -24,9 +24,9 @@ import de.steamwar.core.Core; import de.steamwar.fightsystem.commands.*; 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.fight.FightWorld; +import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.record.Recorder; @@ -38,7 +38,6 @@ import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; -import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -144,10 +143,11 @@ public class FightSystem extends JavaPlugin { Recorder.closeAll(); } - - public static void setPreLeaderState() { FightState.setFightState(FightState.PRE_LEADER_SETUP); + + Fight.getBlueTeam().reset(); + Fight.getRedTeam().reset(); } public static void setPreSchemState() { @@ -161,12 +161,7 @@ public class FightSystem extends JavaPlugin { public static void setPreRunningState() { FightState.setFightState(FightState.PRE_RUNNING); - Fight.getBlueTeam().loadKits(); - Fight.getRedTeam().loadKits(); - setAllPlayersGM(GameMode.SURVIVAL); Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); - - Fight.replaceSync(); } public static void setRunningState() { @@ -179,11 +174,6 @@ public class FightSystem extends JavaPlugin { public static void setSpectateState(FightTeam winFightTeam, String windescription) { FightState.setFightState(FightState.SPECTATE); - setAllPlayersGM(GameMode.SPECTATOR); - Fight.getBlueTeam().teleportToSpawn(); - Fight.getRedTeam().teleportToSpawn(); - Bukkit.getOnlinePlayers().forEach(player -> player.getInventory().clear()); - if(winFightTeam != null) { Bukkit.broadcastMessage(PREFIX + "§aDas Team " + winFightTeam.getColoredName() + " §ahat gewonnen!"); } else { @@ -223,14 +213,4 @@ public class FightSystem extends JavaPlugin { public static void shutdown(String reason){ IFightSystem.shutdown(reason); } - - private static void setAllPlayersGM(GameMode gm) { - for(FightPlayer fightPlayer: Fight.getBlueTeam().getPlayers()){ - Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm); - } - for(FightPlayer fightPlayer: Fight.getRedTeam().getPlayers()){ - Fight.setPlayerGamemode(fightPlayer.getPlayer(), gm); - } - } - } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java index e0b03c2..19d7874 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/LeaderCommand.java @@ -44,9 +44,9 @@ public class LeaderCommand implements CommandExecutor { if(args.length == 0){ if(Fight.getFightPlayer(player) == null){ if(Fight.getBlueTeam().isLeaderless()) - Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player)); + Fight.getBlueTeam().addMember(player); else if(Fight.getRedTeam().isLeaderless()) - Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player)); + Fight.getRedTeam().addMember(player); else player.sendMessage(FightSystem.PREFIX + "§cEs sind bereits 2 Teamleader vorhanden"); }else diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index cc3a16e..93178c9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -42,8 +42,8 @@ import java.util.logging.Level; public class Fight { private Fight(){} - private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExetendRegion, Config.TeamRedRotate, false, Config.RedLeader); - private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.TeamBlueRotate, true, Config.BlueLeader); + private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); + private static final FightTeam blueTeam = new FightTeam(Config.TeamBlueName, Config.TeamBlueColor, Config.TeamBlueSpawn, Config.BluePasteRegion, Config.BlueExtendRegion, Config.BlueRotate, true, Config.BlueLeader); public static void init(){ IFight.init(redTeam, blueTeam); @@ -106,11 +106,6 @@ public class Fight { return null; } - public static void replaceSync() { - redTeam.replaceSync(); - blueTeam.replaceSync(); - } - public static void setPlayerGamemode(Player player, GameMode gameMode) { player.setGameMode(gameMode); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java index ea37ce4..f0c59bf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -54,9 +54,7 @@ public class FightPlayer { public void setOut() { isOut = true; - if(enternCountdown != null){ - enternCountdown.disable(); - } + stopEnternCountdown(); } public void setEnternCountdown(EnternCountdown countdown){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index 7b4c1ae..a4c2ec2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -30,6 +30,7 @@ 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.fightsystem.utils.Region; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.Schematic; import org.bukkit.*; @@ -48,26 +49,16 @@ import java.util.logging.Level; public class FightSchematic extends 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 Region region; 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) { - super(ArenaMode.All, FightState.Schem); + public FightSchematic(FightTeam team, boolean rotate) { + super(ArenaMode.All, FightState.PostSchemSetup); this.team = team; - this.pasteX = pasteX; - this.pasteY = pasteY; - this.pasteZ = pasteZ; - this.cornerX = cornerX; - this.cornerY = cornerY; - this.cornerZ = cornerZ; + this.region = team.getSchemRegion(); this.rotate = rotate; } @@ -89,6 +80,11 @@ public class FightSchematic extends StateDependent { } } + public void reset(){ + schematic = 0; + clipboard = null; + } + @Override public void enable() { if(FightState.getFightState() == FightState.SPECTATE) @@ -119,22 +115,22 @@ public class FightSchematic extends StateDependent { try { VersionedRunnable.call(new VersionedRunnable(() -> { try { - EditSession e = FightTeam_8.pasteSchematic(clipboard, pasteX, pasteY, pasteZ, rotate); - FightTeam_8.replaceTeamColor(e, c, cornerX, cornerY, cornerZ); + EditSession e = FightTeam_8.pasteSchematic(clipboard, region.centerX(), region.getMinY(), region.centerZ(), rotate); + FightTeam_8.replaceTeamColor(e, c, region); } 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); + EditSession e = FightTeam_8.pasteSchematic(clipboard, region.centerX(), region.getMinY(), region.centerZ(), rotate); + FightTeam_12.replaceTeamColor(e, c, region); } 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); + EditSession e = FightTeam_14.pasteSchematic(clipboard, region.centerX(), region.getMinY(), region.centerZ(), rotate); + FightTeam_14.replaceTeamColor(e, c, region); } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { throw new SecurityException("Error pasting arena in schematic", ex); } @@ -148,35 +144,30 @@ public class FightSchematic extends StateDependent { Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), team::teleportToSpawn, 40); } - public void replaceSync(boolean replace, Material target, Material replacement){ - if(!replace) + @Override + public void disable() { + if(!Config.ReplaceObsidianBedrock) 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); - } - } - } + replaceSync(Material.OBSIDIAN, Material.TNT); + replaceSync(Material.BEDROCK, Material.SLIME_BLOCK); if(!Config.ReplaceWithBlockupdates) HandlerList.unregisterAll(freezer); } - @Override - public void disable() { - team.teleportToSpawn(); + private void replaceSync(Material target, Material replacement){ + World world = Bukkit.getWorlds().get(0); + + region.forEach((x, y, z) -> { + Block block = world.getBlockAt(x, y, z); + if(block.getType() == target) + block.setType(replacement); + }); } private static class FreezeWorld implements Listener { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 5e03e88..859bf10 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -29,6 +29,7 @@ import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.RecordSystem; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.listener.FightScoreboard; +import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.ItemBuilder; import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.TechHider; @@ -48,14 +49,14 @@ import java.util.*; public class FightTeam implements IFightTeam{ private FightPlayer leader; - private final UUID designatedLeader; + private UUID designatedLeader; private final Map players = new HashMap<>(); private boolean ready; private final Set invited = new HashSet<>(); private final String name; private final String prefix; private final ChatColor color; - private FightSchematic schematic; + private final FightSchematic schematic; private final Team team; private final boolean blue; @@ -67,16 +68,16 @@ public class FightTeam implements IFightTeam{ this.spawn = spawn; this.schemRegion = schemRegion; this.extendRegion = extendRegion; - int pasteX = schemRegion.getMinX() + Config.SchemsizeX / 2; - int pasteY = schemRegion.getMinY(); - int pasteZ = schemRegion.getMinZ() + Config.SchemsizeZ / 2; this.name = name; this.prefix = prefix; this.ready = false; - this.schematic = new FightSchematic(this, pasteX, pasteY, pasteZ, schemRegion.getMinX(), schemRegion.getMinY(), schemRegion.getMinZ(), rotate); this.blue = blue; this.designatedLeader = designatedLeader; - color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); + this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); + this.schematic = new FightSchematic(this, rotate); + new KitLoader(); + new SpectateHandler(); + if(FightScoreboard.getScoreboard().getTeam(name) == null) team = FightScoreboard.getScoreboard().registerNewTeam(name); else @@ -96,18 +97,6 @@ public class FightTeam implements IFightTeam{ return extendRegion; } - public final int getCornerX() { - return schemRegion.getMinX(); - } - - public final int getCornerY() { - return schemRegion.getMinY(); - } - - public final int getCornerZ() { - return schemRegion.getMinZ(); - } - public boolean canbeLeader(Player p){ return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } @@ -145,11 +134,41 @@ public class FightTeam implements IFightTeam{ return false; } + public void reset(){ + schematic.reset(); + invited.clear(); + Set playerSet = new HashSet<>(players.keySet()); + for(Player player : playerSet){ + if(!player.isOnline()) + removePlayer(player); + } + FightPlayer leaderBackup = leader; + playerSet.removeIf(player -> !player.isOnline()); + players.clear(); + leader = null; + + if(leaderBackup != null){ + playerSet.remove(leaderBackup.getPlayer()); + addMember(leaderBackup.getPlayer()); + } + + playerSet.forEach(this::addMember); + + if(isLeaderless()){ + for(Player player : Bukkit.getOnlinePlayers()){ + if(Fight.getPlayerTeam(player) == null && canbeLeader(player)){ + addMember(player); + break; + } + } + } + } + public void broadcast(String message) { players.forEach((player, fp) -> player.sendMessage(message)); } - public FightPlayer addMember(Player player) { + public void addMember(Player player) { final List chunksToReload = TechHider.prepareChunkReload(player); FightPlayer fightPlayer = new FightPlayer(player, this); players.put(player, fightPlayer); @@ -168,7 +187,9 @@ public class FightTeam implements IFightTeam{ Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), prefix + player.getName()).send(player), 5); RecordSystem.playerJoins(player); TechHider.reloadChunks(player, chunksToReload); - return fightPlayer; + + if(isLeaderless()) + setLeader(fightPlayer); } public void removePlayer(Player player) { @@ -181,13 +202,16 @@ public class FightTeam implements IFightTeam{ if(fightPlayer.equals(leader)) setLeader(null); + RecordSystem.entityDespawns(player); Fight.setPlayerGamemode(player, GameMode.SPECTATOR); player.teleport(Config.SpecSpawn); player.getInventory().clear(); - if(!ArenaMode.Test.contains(Config.mode)) - new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player); - RecordSystem.entityDespawns(player); - TechHider.reloadChunks(player, chunksToReload); + + if(player.isOnline()){ + if(!ArenaMode.Test.contains(Config.mode)) + new TablistNamePacket(SteamwarUser.get(player.getUniqueId()).getId(), "§7" + player.getName()).send(player); + TechHider.reloadChunks(player, chunksToReload); + } } public boolean isLeaderless() { @@ -203,9 +227,11 @@ public class FightTeam implements IFightTeam{ return leader; } - public void setLeader(FightPlayer leader) { - if (leader == null){ - if(!players.isEmpty()) { + private void setLeader(FightPlayer leader) { + if (leader == null) { + if (FightState.getFightState() == FightState.PRE_LEADER_SETUP){ + this.leader = null; + }else if(!players.isEmpty()) { setLeader(players.values().iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); }else if(!ArenaMode.RankedEvent.contains(Config.mode)){ @@ -213,10 +239,10 @@ public class FightTeam implements IFightTeam{ } return; } - if (!PersonalKitCreator.notInKitCreator(leader.getPlayer())) - leader.getPlayer().closeInventory(); + PersonalKitCreator.closeIfInKitCreator(leader.getPlayer()); this.leader = leader; + designatedLeader = null; if(ready) setReady(false); @@ -328,18 +354,6 @@ public class FightTeam implements IFightTeam{ return currentHearts / maximumHearts; } - public void loadKits(){ - for(FightPlayer fightPlayer : players.values()) { - fightPlayer.getPlayer().getInventory().clear(); - fightPlayer.getKit().loadToPlayer(fightPlayer.getPlayer()); - } - } - - 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){ VersionedRunnable.call(new VersionedRunnable(() -> FightTeam_8.setTeamColor(team, color), 8), new VersionedRunnable(() -> FightTeam_9.setTeamColor(team, color), 9), @@ -350,4 +364,43 @@ public class FightTeam implements IFightTeam{ public ChatColor getColor() { return color; } + + private class KitLoader extends StateDependent { + private KitLoader() { + super(ArenaMode.All, FightState.Ingame); + } + + @Override + public void enable() { + for(FightPlayer fightPlayer : players.values()) { + Player player = fightPlayer.getPlayer(); + PersonalKitCreator.closeIfInKitCreator(player); + + player.getInventory().clear(); + Fight.setPlayerGamemode(player, GameMode.SURVIVAL); + fightPlayer.getKit().loadToPlayer(player); + } + } + + @Override + public void disable() { + players.values().forEach(fightPlayer -> fightPlayer.getPlayer().getInventory().clear()); + } + } + + private class SpectateHandler extends StateDependent { + private SpectateHandler() { + super(ArenaMode.All, FightState.Spectate); + } + + @Override + public void enable() { + players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SPECTATOR)); + } + + @Override + public void disable() { + players.values().forEach(fightPlayer -> Fight.setPlayerGamemode(fightPlayer.getPlayer(), GameMode.SURVIVAL)); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java index 4a92fc8..989e8ac 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -54,12 +54,12 @@ public class ArenaBorder implements Listener { if(team == null || player.getGameMode() == GameMode.SPECTATOR) return; - if(to.getY() <= Config.underArenaBorder) { + if(to.getY() <= Config.ArenaRegion.getMinY()) { if(FightState.infight()) player.damage(2); else if(!Config.GroundWalkable) player.teleport(team.getSpawn()); - }else if(to.getY() + 1.8 <= Config.upperArenaBorder){ + }else if(to.getY() + 1.8 <= Config.ArenaRegion.getMaxY()){ reset(event); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index d56405b..9bc3b71 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -23,7 +23,6 @@ import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; @@ -80,9 +79,7 @@ public class EventJoin implements Listener { } if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){ - FightPlayer fp = team.addMember(player); - if(team.isLeaderless()) - team.setLeader(fp); + team.addMember(player); return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java index 264a242..a7e3937 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java @@ -45,9 +45,9 @@ public class NormalJoin implements Listener { if (fightTeam == null) { if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) { - Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player)); + Fight.getBlueTeam().addMember(player); }else if(Fight.getRedTeam().canbeLeader(player)) { - Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player)); + Fight.getRedTeam().addMember(player); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java index 320ef75..3007ee1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PersonalKitCreator.java @@ -50,15 +50,7 @@ public class PersonalKitCreator implements Listener { private static final Map openKitCreators = new HashMap<>(); public PersonalKitCreator(){ - new StateDependentListener(Config.PersonalKits, FightState.Setup, this){ - @Override - public void disable(){ - while(!openKitCreators.isEmpty()){ - openKitCreators.values().iterator().next().close(); - } - super.disable(); - } - }; + new StateDependentListener(Config.PersonalKits, FightState.Setup, this); } public static void openKitCreator(Player player, PersonalKit kit){ @@ -73,6 +65,14 @@ public class PersonalKitCreator implements Listener { return !openKitCreators.containsKey(player); } + public static void closeIfInKitCreator(HumanEntity player){ + InventoryBackup backup = openKitCreators.get(player); + if(backup == null) + return; + + backup.close(); + } + @EventHandler public void onInventoryClick(InventoryClickEvent e){ if(!openKitCreators.containsKey(e.getWhoClicked())) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index 00c8e0e..bfb7a16 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -41,7 +41,7 @@ public class PistonListener implements Listener { public void handlePistonExtend(BlockPistonExtendEvent e){ BlockFace b = e.getDirection().getOppositeFace(); for(Block block : e.getBlocks()){ - if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))){ + if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExtendRegion.inRegion(block.getRelative(b))){ e.setCancelled(true); return; } @@ -52,7 +52,7 @@ public class PistonListener implements Listener { public void handlePistonRetract(BlockPistonRetractEvent e){ BlockFace b = e.getDirection().getOppositeFace(); for(Block block : e.getBlocks()){ - if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExetendRegion.inRegion(block.getRelative(b))) { + if(Config.BlueExtendRegion.inRegion(block.getRelative(b)) && Config.RedExtendRegion.inRegion(block.getRelative(b))) { e.setCancelled(true); return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java index 36abfe0..49ec963 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoin.java @@ -43,9 +43,9 @@ public class RankedJoin implements Listener { if (fightTeam == null) { if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) { - Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player)); + Fight.getBlueTeam().addMember(player); }else if(Fight.getRedTeam().canbeLeader(player)) { - Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player)); + Fight.getRedTeam().addMember(player); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java index d1fc8e3..017adaf 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -46,7 +46,7 @@ public class TeamArea implements Listener { else return; // Is allowed in area checkInInnerArea(event.getPlayer(), to, Fight.getBlueTeam()); - }else if(Config.RedExetendRegion.playerInRegion(to)){ + }else if(Config.RedExtendRegion.playerInRegion(to)){ if(team == null) reset(event, DENY_TEAM); else if(team == Fight.getBlueTeam() && (player.getGameMode() == GameMode.SPECTATOR || !team.canPlayerEntern(player))) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index ffa9409..cb24bc1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -32,7 +32,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class WaterRemover implements Listener { - private static final int MIN_Y = Config.AlignWater ? Config.TeamBlueCornerY + Config.WaterDepth : Config.TeamBlueCornerY; + private static final int MIN_Y = Config.BluePasteRegion.getMinY() + (Config.AlignWater ? Config.WaterDepth : 0); public WaterRemover() { new StateDependentListener(ArenaMode.All, FightState.Running, this); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java index b13e818..87a5ba2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/record/RecordSystem.java @@ -168,8 +168,8 @@ public class RecordSystem { public static synchronized void blockChange(Block block){ int blockState = blockToId(block); - int shortX = block.getX() - Config.ArenaMinX; - int shortZ = block.getZ() - Config.ArenaMinZ; + int shortX = block.getX() - Config.ArenaRegion.getMinX(); + int shortZ = block.getZ() - Config.ArenaRegion.getMinZ(); if((short)blockState == blockState && shortX > 0 && shortX < 256 && shortZ > 0 && shortZ < 256){ //Short block packet Recorder.rByte(0x33); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index fb1f633..8168229 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -33,6 +33,7 @@ import com.comphenix.protocol.wrappers.WrappedBlockData; import de.steamwar.core.Core; import de.steamwar.core.VersionedCallable; import de.steamwar.core.events.ChunkListener; +import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.IFightSystem; @@ -40,6 +41,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.IStateDependent; import org.bukkit.Bukkit; import org.bukkit.GameMode; +import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.*; @@ -52,7 +54,10 @@ public class TechHider implements IStateDependent { private final Set enabled; private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); + private final Map packetCache = new HashMap<>(); + private final Material obfuscateMaterial; private final PacketAdapter chunkHider; + private final int threadMultiplier; public TechHider(){ FightState.registerStateDependent(this); @@ -71,13 +76,21 @@ public class TechHider implements IStateDependent { new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); + obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), new VersionedCallable<>(() -> TechHider_12.chunkHider(hiddenBlockIds, obfuscateWith), 12), new VersionedCallable<>(() -> TechHider_14.chunkHider(hiddenBlockIds, obfuscateWith), 14)); + if(Config.mode == ArenaMode.EVENT) + threadMultiplier = 4; + else + threadMultiplier = 1; + if(DISABLED) return; + Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); + if(Core.getVersion() > 8){ protocolManager.addPacketListener(new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Client.USE_ITEM) { @Override @@ -114,7 +127,7 @@ public class TechHider implements IStateDependent { protocolManager.addPacketListener(updateBlockEntity); } if(chunkHider != null) { - protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(ITechHider.threadMultiplier * 4); + protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(threadMultiplier * 4); } } @@ -141,14 +154,14 @@ public class TechHider implements IStateDependent { if(bypass(p, pos.getChunkX(), pos.getChunkZ())) return; - PacketContainer cached = ITechHider.packetCache.get(packet); + PacketContainer cached = packetCache.get(packet); if(cached != null){ e.setPacket(cached); return; } cached = packet.shallowClone(); - ITechHider.packetCache.put(packet, cached); + packetCache.put(packet, cached); e.setPacket(cached); StructureModifier blockStructure = cached.getMultiBlockChangeInfoArrays(); MultiBlockChangeInfo[] changes = blockStructure.read(0).clone(); @@ -157,7 +170,7 @@ public class TechHider implements IStateDependent { WrappedBlockData block = mbci.getData(); if(Config.HiddenBlocks.contains(block.getType().name())){ changed = true; - block.setType(ITechHider.obfuscateMaterial); + block.setType(obfuscateMaterial); mbci.setData(block); } } @@ -178,19 +191,19 @@ public class TechHider implements IStateDependent { if(bypass(p, ITechHider.posToChunk(pos.getX()), ITechHider.posToChunk(pos.getZ()))) return; - PacketContainer cached = ITechHider.packetCache.get(packet); + PacketContainer cached = packetCache.get(packet); if(cached != null){ e.setPacket(cached); return; } cached = packet.deepClone(); - ITechHider.packetCache.put(packet, cached); + packetCache.put(packet, cached); e.setPacket(cached); StructureModifier blockStructure = cached.getBlockData(); WrappedBlockData block = blockStructure.read(0); if(Config.HiddenBlocks.contains(block.getType().name())){ - block.setType(ITechHider.obfuscateMaterial); + block.setType(obfuscateMaterial); blockStructure.write(0, block); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 3f903c0..baed79b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -33,8 +33,6 @@ import java.util.Map; public class WinconditionPercentSystem extends Wincondition implements Listener, PrintableWincondition, PercentWincondition { - private static final int SCHEMATIC_SIZE = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); - private final Map teamMap = new HashMap<>(); public WinconditionPercentSystem() { @@ -65,11 +63,13 @@ public class WinconditionPercentSystem extends Wincondition implements Listener, private class TeamPercent { private final FightTeam team; + private final int volume; private double percent; private int destroyedBlocks; private TeamPercent(FightTeam team) { this.team = team; + this.volume = team.getSchemRegion().volume(); } private void check(EntityExplodeEvent event) { @@ -78,7 +78,7 @@ public class WinconditionPercentSystem extends Wincondition implements Listener, } destroyedBlocks += event.blockList().size(); - percent = (double)destroyedBlocks * 100 / SCHEMATIC_SIZE; + percent = (double)destroyedBlocks * 100 / volume; if(percent >= Config.PercentWin) { win(Fight.getOpposite(team)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 4e6e9bf..fb1fcb0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; @@ -66,14 +65,10 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable private void check(){ pumpkins = 0; - for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) { - for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) { - for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) { - if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) - pumpkins++; - } - } - } + team.getSchemRegion().forEach((x, y, z) -> { + if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) + pumpkins++; + }); if(pumpkins == 0) { win(Fight.getOpposite(team)); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 4285b1f..c6aeedc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -97,7 +97,7 @@ public class WinconditionRelativePercent extends Wincondition implements Printab } private void check(){ - currentBlocks = currentBlocks(); + currentBlocks(); if(!Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)) return; @@ -123,16 +123,12 @@ public class WinconditionRelativePercent extends Wincondition implements Printab if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Config.TimeoutTime - Wincondition.getTimeOverCountdown().getTimeLeft()) return currentBlocks; - int blocks = 0; - for(int x = team.getCornerX(); x < team.getCornerX() + Config.SchemsizeX; x++){ - for(int y = team.getCornerY(); y < team.getCornerY() + Config.SchemsizeY; y++){ - for(int z = team.getCornerZ(); z < team.getCornerZ() + Config.SchemsizeZ; z++){ - if(!ignoredBlocks.contains(world.getBlockAt(x,y,z).getType())) - blocks++; - } - } - } - return blocks; + currentBlocks = 0; + team.getSchemRegion().forEach((x, y, z) -> { + if(!ignoredBlocks.contains(world.getBlockAt(x,y,z).getType())) + currentBlocks++; + }); + return currentBlocks; } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index fcd7c9a..4516630 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -19,7 +19,6 @@ package de.steamwar.fightsystem.winconditions; -import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.WaterRemover; @@ -65,14 +64,10 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi private void check() { water = 0; - for(int x = team.getCornerX(); x <= team.getCornerX() + Config.SchemsizeX; x++) { - for(int y = team.getCornerY(); y <= team.getCornerY() + Config.SchemsizeY; y++) { - for (int z = team.getCornerZ(); z <= team.getCornerZ() + Config.SchemsizeZ; z++) { - if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z))) - water++; - } - } - } + team.getExtendRegion().forEach((x, y, z) -> { + if (WaterRemover.isWater(WORLD.getBlockAt(x, y, z))) + water++; + }); if(water == 0){ win(Fight.getOpposite(team)); From ce5cbf9969711528f2ef4a68817c1dbaca8502d6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Mar 2021 16:42:45 +0100 Subject: [PATCH 06/15] Adding skip, techhider improvements... Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam_14.java | 47 ++++++++- .../fightsystem/utils/TechHider_14.java | 15 ++- .../fightsystem/utils/TechHider_15.java | 15 ++- .../fightsystem/fight/FightTeam_8.java | 50 ++++++++-- .../src/de/steamwar/fightsystem/Config.java | 98 +++++++++---------- .../de/steamwar/fightsystem/IFightSystem.java | 18 ---- .../de/steamwar/fightsystem/utils/Region.java | 5 +- .../de/steamwar/fightsystem/FightSystem.java | 27 +++-- .../fightsystem/commands/Commands.java | 8 ++ .../de/steamwar/fightsystem/commands/GUI.java | 14 +++ .../fightsystem/commands/SkipCommand.java | 27 +++++ .../fightsystem/commands/StateCommand.java | 26 +++++ .../fightsystem/countdown/Countdown.java | 25 +++++ .../fightsystem/fight/FightSchematic.java | 6 +- .../steamwar/fightsystem/fight/FightTeam.java | 21 +++- .../fightsystem/listener/EventJoin.java | 51 ++++++---- .../fightsystem/listener/PrepareSchem.java | 42 +++++++- .../fightsystem/listener/TeamArea.java | 2 +- .../fightsystem/listener/WaterRemover.java | 2 +- .../states/OneShotStateDependent.java | 25 +++++ .../steamwar/fightsystem/utils/TechHider.java | 35 +++++++ .../winconditions/WinconditionTimeTechKO.java | 2 +- FightSystem_Main/src/plugin.yml | 4 +- 23 files changed, 442 insertions(+), 123 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java 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 867a0f6..46d9c9d 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightTeam_14.java @@ -22,8 +22,13 @@ package de.steamwar.fightsystem.fight; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; @@ -39,14 +44,17 @@ import de.steamwar.sql.Schematic; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.scoreboard.Team; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Collections; import java.util.Objects; import java.util.Set; -class FightTeam_14 { +public class FightTeam_14 { private FightTeam_14(){} private static final Set WOOL_SET = Collections.singleton(Objects.requireNonNull(BlockTypes.PINK_WOOL).getDefaultState().toBaseBlock()); @@ -78,8 +86,8 @@ class FightTeam_14 { e.flushSession(); } - 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); + static EditSession pasteSchematic(Clipboard clipboard, Region region, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { + BlockVector3 paste = BlockVector3.at(region.centerX(), region.getMinY(), region.centerZ()); World w = new BukkitWorld(Bukkit.getWorlds().get(0)); BlockVector3 dimensions = clipboard.getDimensions(); @@ -93,7 +101,7 @@ class FightTeam_14 { v = paste.subtract(dimensions.getX()/2, 0, dimensions.getZ()/2).subtract(offset); } - if(Config.AlignWater){ + if(Config.WaterDepth != 0){ BlockVector3 it = clipboard.getMinimumPoint(); int depth = 0; while(!clipboard.getBlock(it).getBlockType().getMaterial().isAir()){ @@ -110,4 +118,35 @@ class FightTeam_14 { e.flushSession(); return e; } + + public static boolean checkPistonMoving(Block block){ + return block.getType() == Material.MOVING_PISTON; + } + + public static void saveSchem(Schematic schem, Region region) { + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + BlockVector3 min = BlockVector3.at(region.getMinX(), region.getMinY(), region.getMinZ()); + CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ())); + BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); + EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); + + ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min); + forwardExtentCopy.setCopyingEntities(false); + try{ + Operations.complete(forwardExtentCopy); + }catch(WorldEditException e){ + throw new IllegalStateException(e); + } + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try { + ClipboardWriter writer = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(outputStream); + writer.write(clipboard); + writer.close(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + schem.saveFromBytes(outputStream.toByteArray(), true); + } } 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 fa86a3f..39546ec 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/TechHider_14.java @@ -30,10 +30,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; -import net.minecraft.server.v1_14_R1.Block; -import net.minecraft.server.v1_14_R1.IBlockData; -import net.minecraft.server.v1_14_R1.IRegistry; -import net.minecraft.server.v1_14_R1.MinecraftKey; +import net.minecraft.server.v1_14_R1.*; import org.bukkit.entity.Player; import java.nio.ByteBuffer; @@ -54,6 +51,16 @@ public class TechHider_14 { hiddenBlockIds.add(Block.getCombinedId(data)); } } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : Block.REGISTRY_ID){ + if(data.p() == water){ + hiddenBlockIds.add(Block.getCombinedId(data)); + } + } + } + return hiddenBlockIds; } 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 dabe7a4..e5d5e03 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/TechHider_15.java @@ -20,10 +20,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; -import net.minecraft.server.v1_15_R1.Block; -import net.minecraft.server.v1_15_R1.IBlockData; -import net.minecraft.server.v1_15_R1.IRegistry; -import net.minecraft.server.v1_15_R1.MinecraftKey; +import net.minecraft.server.v1_15_R1.*; import java.util.HashSet; import java.util.Set; @@ -38,6 +35,16 @@ class TechHider_15 { hiddenBlockIds.add(Block.getCombinedId(data)); } } + + if(Config.HiddenBlocks.contains("water")){ + Fluid water = FluidTypes.WATER.a(false); + for(IBlockData data : Block.REGISTRY_ID){ + if(data.getFluid() == water){ + hiddenBlockIds.add(Block.getCombinedId(data)); + } + } + } + return hiddenBlockIds; } 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 26aceec..83655e6 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam_8.java @@ -19,13 +19,14 @@ package de.steamwar.fightsystem.fight; -import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; +import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; @@ -39,13 +40,15 @@ import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.DyeColor; import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.scoreboard.Team; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Collections; import java.util.Set; -class FightTeam_8 { +public class FightTeam_8 { private FightTeam_8(){} @SuppressWarnings("deprecation") @@ -87,10 +90,10 @@ class FightTeam_8 { e.flushQueue(); } - static EditSession pasteSchematic(Clipboard clipboard, int pasteX, int pasteY, int pasteZ, boolean rotate) throws Schematic.WrongVersionException, IOException, NoClipboardException { + static EditSession pasteSchematic(Clipboard clipboard, Region paste, 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); + Vector v = new Vector(paste.centerX(), paste.getMinY(), paste.centerZ()); Vector offset = clipboard.getMinimumPoint().subtract(clipboard.getOrigin()); AffineTransform aT = new AffineTransform(); if(rotate){ @@ -100,7 +103,7 @@ class FightTeam_8 { v = v.subtract(dimensions.getX()/2 - dimensions.getX()%2, 0, dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); } - if(Config.AlignWater){ + if(Config.WaterDepth != 0){ Vector it = clipboard.getMinimumPoint(); int depth = 0; while(!clipboard.getBlock(it).isAir()){ @@ -117,4 +120,35 @@ class FightTeam_8 { e.flushQueue(); return e; } + + public static boolean checkPistonMoving(Block block){ + return block.getType() == Material.PISTON_MOVING_PIECE; + } + + public static void saveSchem(Schematic schem, Region region) { + World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + Vector min = new Vector(region.getMinX(), region.getMinY(), region.getMinZ()); + CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ())); + BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); + EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(w, -1); + + ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, cuboidRegion, clipboard, min); + forwardExtentCopy.setCopyingEntities(false); + try{ + Operations.complete(forwardExtentCopy); + }catch(WorldEditException e){ + throw new IllegalStateException(e); + } + + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try { + ClipboardWriter writer = ClipboardFormat.SCHEMATIC.getWriter(outputStream); + writer.write(clipboard, w.getWorldData()); + writer.close(); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + schem.saveFromBytes(outputStream.toByteArray(), false); + } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index a34a405..29a84bf 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -61,12 +61,11 @@ public class Config { public static final Location TeamRedSpawn; public static final Location SpecSpawn; - private static final int TeamBluetoReddistanceX; - private static final int TeamBluetoReddistanceY; - public static final int TeamBluetoReddistanceZ; + private static final int BlueToRedX; + private static final int BlueToRedY; + public static final int BlueToRedZ; - public static final int BorderFromSchematic; - public static final boolean AlignWater; + public static final int PreperationArea; public static final int WaterDepth; public static final boolean GroundWalkable; @@ -77,6 +76,7 @@ public class Config { public static final de.steamwar.sql.SchematicType SchematicType; public static final boolean RedRotate; public static final boolean BlueRotate; + public static final boolean PasteAligned; public static final boolean ReplaceObsidianBedrock; public static final boolean ReplaceWithBlockupdates; @@ -134,14 +134,14 @@ public class Config { if(!new File(IFightSystem.getPlugin().getDataFolder(), System.getProperty("config", "config.yml")).exists()) { IFightSystem.getPlugin().saveDefaultConfig(); Bukkit.getLogger().log(Level.SEVERE, "Arenaconfig fehlt!"); - IFightSystem.shutdown(null); + Bukkit.shutdown(); } FileConfiguration config = IFightSystem.getPlugin().getConfig(); File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), config.getString("Arenaconfig", "config.yml")); if(!worldConfigFile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); - IFightSystem.shutdown(null); + Bukkit.shutdown(); } FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); @@ -151,30 +151,30 @@ public class Config { PreFightDuration = config.getInt("Times.PreFightDuration"); SpectatorDuration = config.getInt("Times.SpectatorDuration"); + int underBorder = worldconfig.getInt("UnderBorder"); + int blueCornerX = worldconfig.getInt("BlueCorner.x"); + int blueCornerY = worldconfig.getInt("BlueCorner.y"); + int blueCornerZ = worldconfig.getInt("BlueCorner.z"); + BlueToRedX = worldconfig.getInt("BlueToRed.x"); + BlueToRedY = worldconfig.getInt("BlueToRed.y"); + BlueToRedZ = worldconfig.getInt("BlueToRed.z"); + double teamBlueSpawnOffsetX = worldconfig.getDouble("SpawnOffset.x"); + double teamBlueSpawnOffsetY = worldconfig.getDouble("SpawnOffset.y"); + double teamBlueSpawnOffsetZ = worldconfig.getDouble("SpawnOffset.z"); + WaterDepth = config.getInt("Arena.WaterDepth"); 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"); int schem2BorderX = config.getInt("Arena.Schem2Border.x"); int schem2BorderZ = config.getInt("Arena.Schem2Border.z"); - int underArenaBorder = worldconfig.getInt("Arena.underArenaBorder"); - BorderFromSchematic = config.getInt("Arena.BorderFromSchematic"); - AlignWater = worldconfig.getBoolean("Arena.AlignWater"); - WaterDepth = worldconfig.getInt("Arena.WaterDepth"); + PreperationArea = config.getInt("Arena.BorderFromSchematic"); GroundWalkable = config.getBoolean("Arena.GroundWalkable"); - double teamBlueSpawnOffsetX = worldconfig.getDouble("Arena.SpawnOffset.x"); - double teamBlueSpawnOffsetY = worldconfig.getDouble("Arena.SpawnOffset.y"); - double teamBlueSpawnOffsetZ = worldconfig.getDouble("Arena.SpawnOffset.z"); RanksEnabled = config.getBoolean("Schematic.RanksEnabled"); SchematicType = de.steamwar.sql.SchematicType.fromDB(config.getString("Schematic.SchematicType")); IgnorePublicOnly = config.getBoolean("Schematic.IgnorePublicOnly"); boolean rotate = config.getBoolean("Schematic.Rotate"); + PasteAligned = config.getBoolean("Schematic.PasteAligned"); ReplaceObsidianBedrock = config.getBoolean("Schematic.ReplaceObsidianBedrock"); ReplaceWithBlockupdates = config.getBoolean("Schematic.ReplaceWithBlockupdates"); @@ -202,32 +202,32 @@ public class Config { if(schemsizeX < 0){ schemsizeX = -schemsizeX; - teamBlueCornerX = teamBlueCornerX - schemsizeX; + blueCornerX = blueCornerX - schemsizeX; } if(schemsizeY < 0){ schemsizeY = -schemsizeY; - teamBlueCornerY = teamBlueCornerY - schemsizeY; + blueCornerY = blueCornerY - schemsizeY; } if(schemsizeZ < 0){ schemsizeZ = -schemsizeZ; - teamBlueCornerZ = teamBlueCornerZ - schemsizeZ; + blueCornerZ = blueCornerZ - schemsizeZ; } - int teamRedCornerX = TeamBluetoReddistanceX + teamBlueCornerX; - int teamRedCornerY = TeamBluetoReddistanceY + teamBlueCornerY; - int teamRedCornerZ = TeamBluetoReddistanceZ + teamBlueCornerZ; + int teamRedCornerX = BlueToRedX + blueCornerX; + int teamRedCornerY = BlueToRedY + blueCornerY; + int teamRedCornerZ = BlueToRedZ + blueCornerZ; - int teamBluePasteX = teamBlueCornerX + schemsizeX / 2; - int teamBluePasteZ = teamBlueCornerZ + schemsizeZ / 2; - int teamRedPasteX = teamBluePasteX + TeamBluetoReddistanceX; - int teamRedPasteZ = teamBluePasteZ + TeamBluetoReddistanceZ; + int teamBluePasteX = blueCornerX + schemsizeX / 2; + int teamBluePasteZ = blueCornerZ + schemsizeZ / 2; + int teamRedPasteX = teamBluePasteX + BlueToRedX; + int teamRedPasteZ = teamBluePasteZ + BlueToRedZ; World world = Bukkit.getWorlds().get(0); TeamBlueSpawn = new Location(world, teamBluePasteX + 0.5 + teamBlueSpawnOffsetX, - teamBlueCornerY + 0.5 + teamBlueSpawnOffsetY, + blueCornerY + 0.5 + teamBlueSpawnOffsetY, teamBluePasteZ + 0.5 + teamBlueSpawnOffsetZ); TeamRedSpawn = new Location(world, @@ -236,9 +236,9 @@ public class Config { teamRedPasteZ + 0.5 - teamBlueSpawnOffsetZ); SpecSpawn = new Location(world, - teamBluePasteX + TeamBluetoReddistanceX/2.0, - teamBlueCornerY + TeamBluetoReddistanceY/2.0 + schemsizeY/2.0, - teamBluePasteZ + TeamBluetoReddistanceZ/2.0); + teamBluePasteX + BlueToRedX /2.0, + blueCornerY + BlueToRedY /2.0 + schemsizeY/2.0, + teamBluePasteZ + BlueToRedZ /2.0); Vector v1 = TeamBlueSpawn.toVector().subtract(TeamRedSpawn.toVector()); double pitch = Math.toDegrees(v1.angle(v1.clone().setY(0))); @@ -257,26 +257,26 @@ public class Config { int arenaMaxX; int arenaMinZ; int arenaMaxZ; - if(TeamBluetoReddistanceX > 0){ - arenaMinX = teamBlueCornerX - schem2BorderX; + if(BlueToRedX > 0){ + arenaMinX = blueCornerX - schem2BorderX; arenaMaxX = teamRedCornerX + schemsizeX + schem2BorderX; teamRedRotate = true; teamBlueRotate = false; }else{ arenaMinX = teamRedCornerX - schem2BorderX; - arenaMaxX = teamBlueCornerX + schemsizeX + schem2BorderX; + arenaMaxX = blueCornerX + schemsizeX + schem2BorderX; teamRedRotate = false; teamBlueRotate = true; } - if(TeamBluetoReddistanceZ > 0){ - arenaMinZ = teamBlueCornerZ - schem2BorderZ; + if(BlueToRedZ > 0){ + arenaMinZ = blueCornerZ - schem2BorderZ; arenaMaxZ = teamRedCornerZ + schemsizeZ + schem2BorderZ; teamRedRotate = true; teamBlueRotate = false; }else{ arenaMinZ = teamRedCornerZ - schem2BorderZ; - arenaMaxZ = teamBlueCornerZ + schemsizeZ + schem2BorderZ; - if(TeamBluetoReddistanceZ != 0){ + arenaMaxZ = blueCornerZ + schemsizeZ + schem2BorderZ; + if(BlueToRedZ != 0){ teamRedRotate = false; teamBlueRotate = true; } @@ -289,19 +289,19 @@ public class Config { BlueRotate = teamBlueRotate; RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); - BluePasteRegion = new Region(teamBlueCornerX, teamBlueCornerY, teamBlueCornerZ, schemsizeX, schemsizeY, schemsizeZ); + BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); - RedExtendRegion = new Region(teamRedCornerX, underArenaBorder, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, BorderFromSchematic, BorderFromSchematic); - BlueExtendRegion = new Region(teamBlueCornerX, underArenaBorder, teamBlueCornerZ, schemsizeX, schemsizeY, schemsizeZ, BorderFromSchematic, BorderFromSchematic); - int upperArenaBorder = teamBlueCornerY + schemsizeY + BorderFromSchematic; - ArenaRegion = new Region(arenaMinX, underArenaBorder, arenaMinZ, arenaMaxX - arenaMinX, upperArenaBorder - underArenaBorder, arenaMaxZ - arenaMinZ); + RedExtendRegion = new Region(teamRedCornerX, underBorder, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea); + BlueExtendRegion = new Region(blueCornerX, underBorder, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea); + int upperArenaBorder = blueCornerY + schemsizeY + PreperationArea; + ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, upperArenaBorder - underBorder, arenaMaxZ - arenaMinZ); EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ EventFight eventFight = EventFight.get(EventKampfID); if(eventFight == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load EventFight"); - IFightSystem.shutdown(null); + Bukkit.shutdown(); } assert eventFight != null; @@ -310,7 +310,7 @@ public class Config { if(team1 == null || team2 == null){ Bukkit.getLogger().log(Level.SEVERE, "Failed to load Team"); - IFightSystem.shutdown(null); + Bukkit.shutdown(); } assert team1 != null; @@ -379,7 +379,7 @@ public class Config { } public static boolean test(){ - return EventKampfID == -1; + return ArenaMode.Test.contains(ArenaMode.TEST); } public static boolean recording(){ return mode == ArenaMode.EVENT; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java index be18926..5725381 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java @@ -20,7 +20,6 @@ package de.steamwar.fightsystem; import de.steamwar.sql.EventFight; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -50,21 +49,4 @@ public class IFightSystem { public static Player getEventLeiter(){ return eventLeiter; } - - public static void shutdown(String reason){ - if(reason != null) - Bukkit.broadcastMessage(reason); - //Staggered kick to prevent lobby overloading - kickNext(); - } - - private static void kickNext(){ - if(Bukkit.getOnlinePlayers().isEmpty()){ - Bukkit.shutdown(); - return; - } - - Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); - Bukkit.getScheduler().runTaskLater(plugin, IFightSystem::kickNext, 10); - } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index 14c66f6..9375b0c 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -1,6 +1,5 @@ package de.steamwar.fightsystem.utils; -import org.apache.logging.log4j.util.TriConsumer; import org.bukkit.Location; import org.bukkit.block.Block; @@ -121,4 +120,8 @@ public class Region { public boolean inRegion(Block block){ return in2dRegion(block) && minY <= block.getY() && block.getY() < maxY; } + + public interface TriConsumer{ + void accept(T x, V y, U z); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index d145f55..2611d88 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -31,6 +31,7 @@ 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.OneShotStateDependent; import de.steamwar.fightsystem.utils.EnterHandler; import de.steamwar.fightsystem.utils.FightStatistics; import de.steamwar.fightsystem.utils.TechHider; @@ -121,6 +122,12 @@ public class FightSystem extends JavaPlugin { new AkCommand(); new LeaderCommand(); new LockschemCommand(); + new StateCommand(); + new SkipCommand(); + + new OneShotStateDependent(ArenaMode.All, FightState.PreRunning, () -> Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!")); + new OneShotStateDependent(ArenaMode.All, FightState.Running, () -> Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!")); + new OneShotStateDependent(ArenaMode.AntiTest, FightState.Running, FightStatistics::start); try { CommandRemover.removeAll("gamemode"); @@ -160,15 +167,10 @@ public class FightSystem extends JavaPlugin { public static void setPreRunningState() { FightState.setFightState(FightState.PRE_RUNNING); - - Bukkit.broadcastMessage(PREFIX + "§aDer Kampf beginnt!"); } public static void setRunningState() { FightState.setFightState(FightState.RUNNING); - - FightStatistics.start(); - Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } public static void setSpectateState(FightTeam winFightTeam, String windescription) { @@ -211,6 +213,19 @@ public class FightSystem extends JavaPlugin { } public static void shutdown(String reason){ - IFightSystem.shutdown(reason); + if(reason != null) + Bukkit.broadcastMessage(reason); + //Staggered kick to prevent lobby overloading + kickNext(); + } + + private static void kickNext(){ + if(Bukkit.getOnlinePlayers().isEmpty()){ + Bukkit.shutdown(); + return; + } + + Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); + Bukkit.getScheduler().runTaskLater(plugin, FightSystem::kickNext, 10); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index beed415..94ad0fb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -88,6 +88,14 @@ public class Commands { } static void toggleReady(Player p){ + FightTeam fightTeam = checkGetTeam(p); + if(fightTeam == null || checkGetLeader(p) == null) + return; + + fightTeam.skip(); + } + + static void toggleSkip(Player p){ if(checkSetup(p)) return; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java index 9efade8..0b960b0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/GUI.java @@ -67,6 +67,20 @@ public class GUI { inv.open(); } + public static void state(Player p){ + SWInventory inv = new SWInventory(p, 9, "Kampfstatus"); + inv.setItem(0, Material.GLASS, "§7PRE_LEADER_SETUP", (ClickType click) -> FightSystem.setPreLeaderState()); + inv.setItem(1, Material.GLASS, "§7PRE_SCHEM_SETUP", (ClickType click) -> FightSystem.setPreSchemState()); + inv.setItem(2, Material.GLASS, "§7POST_SCHEM_SETUP", (ClickType click) -> FightSystem.setPostSchemState()); + inv.setItem(3, Material.GLASS, "§ePRE_RUNNING", (ClickType click) -> FightSystem.setPreRunningState()); + inv.setItem(4, Material.GLASS, "§eRUNNING", (ClickType click) -> FightSystem.setRunningState()); + inv.setItem(5, Material.GLASS, "§7SPECTATE Blue", (ClickType click) -> FightSystem.setSpectateState(Fight.getBlueTeam(), "operator")); + inv.setItem(6, Material.GLASS, "§7SPECTATE Red", (ClickType click) -> FightSystem.setSpectateState(Fight.getRedTeam(), "operator")); + inv.setItem(7, Material.GLASS, "§7SPECTATE Tie", (ClickType click) -> FightSystem.setSpectateState(null, "operator")); + inv.setCallback(-999, (ClickType click) -> p.closeInventory()); + inv.open(); + } + public static void chooseInvitation(Player p){ List> players = SWListInv.createPlayerList(p.getUniqueId()); players.removeIf(swItemUUIDPair -> Fight.getFightPlayer(Bukkit.getPlayer(swItemUUIDPair.getObject())) != null); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java new file mode 100644 index 0000000..97a6de5 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java @@ -0,0 +1,27 @@ +package de.steamwar.fightsystem.commands; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class SkipCommand implements CommandExecutor { + + public SkipCommand() { + new StateDependentCommand(ArenaMode.AntiPrepare, FightState.Running, "skip", this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) { + return false; + } + Player player = (Player) sender; + + Commands.toggleSkip(player); + return false; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java new file mode 100644 index 0000000..8d29c46 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java @@ -0,0 +1,26 @@ +package de.steamwar.fightsystem.commands; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentCommand; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class StateCommand implements CommandExecutor { + + public StateCommand() { + new StateDependentCommand(ArenaMode.Test, FightState.All, "state", this); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) { + return false; + } + + GUI.state((Player) sender); + 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 cc3fc73..1b9cd6e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -31,8 +31,13 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import java.util.ArrayList; +import java.util.List; + public abstract class Countdown { + private static final List currentCountdowns = new ArrayList<>(); + private final int totalTime; private final Sound sound; private final boolean level; @@ -71,15 +76,35 @@ public abstract class Countdown { public void enable() { time = totalTime; task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::count, 20, 20); + currentCountdowns.add(this); } public void disable() { if(task != null){ task.cancel(); + currentCountdowns.remove(this); task = null; } } + public static void skip(){ + if(currentCountdowns.isEmpty()) + return; + + int smallestTime = currentCountdowns.get(0).time; + for(Countdown countdown : currentCountdowns){ + if(countdown.time < smallestTime) + smallestTime = countdown.time; + } + + smallestTime--; + for(Countdown countdown : currentCountdowns){ + countdown.time -= smallestTime; + } + + Bukkit.broadcastMessage(FightSystem.PREFIX + "§aBeide Teams waren damit einverstanden, zum nächsten Event zu beschleunigen!"); + } + private void broadcast(String message){ RecordSystem.actionBar(message); BaseComponent[] msg = TextComponent.fromLegacyText(message); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index a4c2ec2..c0f857c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -115,21 +115,21 @@ public class FightSchematic extends StateDependent { try { VersionedRunnable.call(new VersionedRunnable(() -> { try { - EditSession e = FightTeam_8.pasteSchematic(clipboard, region.centerX(), region.getMinY(), region.centerZ(), rotate); + EditSession e = FightTeam_8.pasteSchematic(clipboard, region, rotate); FightTeam_8.replaceTeamColor(e, c, region); } 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, region.centerX(), region.getMinY(), region.centerZ(), rotate); + EditSession e = FightTeam_8.pasteSchematic(clipboard, region, rotate); FightTeam_12.replaceTeamColor(e, c, region); } 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, region.centerX(), region.getMinY(), region.centerZ(), rotate); + EditSession e = FightTeam_14.pasteSchematic(clipboard, region, rotate); FightTeam_14.replaceTeamColor(e, c, region); } catch (Schematic.WrongVersionException | IOException | NoClipboardException ex) { throw new SecurityException("Error pasting arena in schematic", ex); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 859bf10..7e67e09 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -24,6 +24,7 @@ import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.BasicListener; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.RecordSystem; @@ -48,11 +49,11 @@ import java.util.*; public class FightTeam implements IFightTeam{ - private FightPlayer leader; private UUID designatedLeader; + private FightPlayer leader; private final Map players = new HashMap<>(); - private boolean ready; private final Set invited = new HashSet<>(); + private final String name; private final String prefix; private final ChatColor color; @@ -60,6 +61,9 @@ public class FightTeam implements IFightTeam{ private final Team team; private final boolean blue; + private boolean ready; + private boolean skip; + private final Location spawn; private final Region schemRegion; private final Region extendRegion; @@ -71,6 +75,7 @@ public class FightTeam implements IFightTeam{ this.name = name; this.prefix = prefix; this.ready = false; + this.skip = false; this.blue = blue; this.designatedLeader = designatedLeader; this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("§", "")); @@ -315,6 +320,18 @@ public class FightTeam implements IFightTeam{ } } + public void skip(){ + this.skip = !skip; + if(skip){ + broadcast(FightSystem.PREFIX + "§aEuer Team ist nun bereit, zum nächsten Event zu beschleunigen!"); + if(Fight.getOpposite(this).skip || Config.test()){ + Countdown.skip(); + } + }else{ + broadcast(FightSystem.PREFIX + "§cEuer Team ist nicht mehr bereit, zum nächsten Event zu beschleunigen!"); + } + } + public Set getInvited() { return invited; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index 9bc3b71..0efb2a2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -37,7 +37,7 @@ import org.bukkit.event.player.PlayerQuitEvent; public class EventJoin implements Listener { public EventJoin() { - new StateDependentListener(ArenaMode.Event, FightState.Setup, this); + new StateDependentListener(ArenaMode.Event, FightState.All, this); } @EventHandler @@ -58,29 +58,32 @@ public class EventJoin implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + //player.setResourcePack("https://steamwar.de/antixray.zip"); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - FightTeam team = null; - if(user.getTeam() == Config.EventTeamBlueID) - team = Fight.getBlueTeam(); - else if(user.getTeam() == Config.EventTeamRedID) - team = Fight.getRedTeam(); - - if(Config.BothTeamsPublic){ - if(Fight.getRedTeam().getPlayers().size() < Fight.getBlueTeam().getPlayers().size()) - team = Fight.getRedTeam(); - else + if(FightState.Setup.contains(FightState.getFightState())){ + FightTeam team = null; + if(user.getTeam() == Config.EventTeamBlueID) team = Fight.getBlueTeam(); - }else if(team == null){ - if(Config.EventTeamRedID == 0) + else if(user.getTeam() == Config.EventTeamRedID) team = Fight.getRedTeam(); - else if(Config.EventTeamBlueID == 0) - team = Fight.getBlueTeam(); - } - if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){ - team.addMember(player); - return; + if(Config.BothTeamsPublic){ + if(Fight.getRedTeam().getPlayers().size() < Fight.getBlueTeam().getPlayers().size()) + team = Fight.getRedTeam(); + else + team = Fight.getBlueTeam(); + }else if(team == null){ + if(Config.EventTeamRedID == 0) + team = Fight.getRedTeam(); + else if(Config.EventTeamBlueID == 0) + team = Fight.getBlueTeam(); + } + + if(team != null && team.getPlayers().size() < Config.MaximumTeamMembers){ + team.addMember(player); + return; + } } if(user.getId() == FightSystem.getEventFight().getKampfleiter()){ @@ -98,4 +101,14 @@ public class EventJoin implements Listener { if(player == FightSystem.getEventLeiter()) FightSystem.setEventLeiter(null); } + + /*@EventHandler + public void onResourcepack(PlayerResourcePackStatusEvent e){ + if(e.getStatus() == PlayerResourcePackStatusEvent.Status.ACCEPTED || e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) + return; + + Player player = e.getPlayer(); + player.sendMessage(FightSystem.PREFIX + "§cAuf Eventserver kann nur mit dem SteamWar-Resourcepack beigetreten werden"); + player.kickPlayer(null); + }*/ } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java index 3852681..fbdccca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -19,12 +19,21 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.core.VersionedCallable; +import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; +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.fight.FightTeam_14; +import de.steamwar.fightsystem.fight.FightTeam_8; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.Region; +import de.steamwar.sql.Schematic; +import org.bukkit.Bukkit; +import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -37,7 +46,38 @@ public class PrepareSchem implements Listener { @Override public void disable() { super.disable(); - //TODO + Region region = Fight.getBlueTeam().getExtendRegion(); + World world = Bukkit.getWorlds().get(0); + + Schematic schem; + try{ + schem = Schematic.getSchemFromDB(Config.PrepareSchemID); + }catch(SecurityException e){ + FightSystem.shutdown(FightSystem.PREFIX + "§cAnscheinend wurde die auszufahrende Schematic gelöscht, Einsenden wird abgebrochen."); + return; + } + + try{ + region.forEach((x, y, z) -> { + if(VersionedCallable.call( + new VersionedCallable<>(() -> FightTeam_8.checkPistonMoving(world.getBlockAt(x, y, z)), 8), + new VersionedCallable<>(() -> FightTeam_14.checkPistonMoving(world.getBlockAt(x, y, z)), 14))){ + FightSystem.shutdown(FightSystem.PREFIX + "§cIm Teambereich wurden sich noch bewegende Pistons gefunden, Einsenden wird abgebrochen."); + throw new IllegalStateException(); + } + }); + }catch (IllegalStateException e){ + return; + } + + try{ + VersionedRunnable.call( + new VersionedRunnable(() -> FightTeam_8.saveSchem(schem, region), 8), + new VersionedRunnable(() -> FightTeam_14.saveSchem(schem, region), 14)); + }catch(IllegalStateException e){ + FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen."); + return; + } } }; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java index 017adaf..b7873a0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -59,7 +59,7 @@ public class TeamArea implements Listener { } private void checkInInnerArea(Player player, Location to, FightTeam team){ - if(team.getSchemRegion().playerInRegion(to) && Config.BorderFromSchematic >= 5){ // Preventing false positives due to small extension + if(team.getSchemRegion().playerInRegion(to) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension player.kickPlayer(null); Bukkit.getLogger().log(Level.SEVERE, player.getName() + " ist in einen Teambereich eingedrungen."); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java index cb24bc1..40ae32e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -32,7 +32,7 @@ import org.bukkit.event.entity.EntityExplodeEvent; public class WaterRemover implements Listener { - private static final int MIN_Y = Config.BluePasteRegion.getMinY() + (Config.AlignWater ? Config.WaterDepth : 0); + private static final int MIN_Y = Config.BluePasteRegion.getMinY() + Config.WaterDepth; public WaterRemover() { new StateDependentListener(ArenaMode.All, FightState.Running, this); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java new file mode 100644 index 0000000..46d719e --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java @@ -0,0 +1,25 @@ +package de.steamwar.fightsystem.states; + +import de.steamwar.fightsystem.ArenaMode; + +import java.util.Set; + +public class OneShotStateDependent extends StateDependent{ + + private final Runnable runnable; + + public OneShotStateDependent(Set mode, Set states, Runnable runnable) { + super(mode, states); + this.runnable = runnable; + } + + @Override + public void enable() { + runnable.run(); + } + + @Override + public void disable() { + //Do nothing, oneshot + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 8168229..1cf0331 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -126,6 +126,9 @@ public class TechHider implements IStateDependent { if(Core.getVersion() > 8) { protocolManager.addPacketListener(updateBlockEntity); } + if(Core.getVersion() > 12) { + protocolManager.addPacketListener(blockBreakHider); + } if(chunkHider != null) { protocolManager.getAsynchronousManager().registerAsyncHandler(chunkHider).start(threadMultiplier * 4); } @@ -139,6 +142,9 @@ public class TechHider implements IStateDependent { if(Core.getVersion() > 8) { protocolManager.removePacketListener(updateBlockEntity); } + if(Core.getVersion() > 12) { + protocolManager.removePacketListener(blockBreakHider); + } if(chunkHider != null) { protocolManager.getAsynchronousManager().unregisterAsyncHandler(chunkHider); } @@ -223,6 +229,35 @@ public class TechHider implements IStateDependent { } }; + private final PacketAdapter blockBreakHider = new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.BLOCK_BREAK) { + @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 = packetCache.get(packet); + if(cached != null){ + e.setPacket(cached); + return; + } + + cached = packet.deepClone(); + packetCache.put(packet, cached); + e.setPacket(cached); + StructureModifier blockStructure = cached.getBlockData(); + WrappedBlockData block = blockStructure.read(0); + if(Config.HiddenBlocks.contains(block.getType().name())){ + block.setType(obfuscateMaterial); + blockStructure.write(0, block); + } + } + }; + private final PacketAdapter updateBlockEntity = new PacketAdapter(FightSystem.getPlugin(), PacketType.Play.Server.TILE_ENTITY_DATA) { @Override public void onPacketSending(PacketEvent event) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index b0481fd..c03bf25 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -51,7 +51,7 @@ public class WinconditionTimeTechKO extends Wincondition { public WinconditionTimeTechKO(){ super("TechKO", "", " §chat den Gegner Tech K.O. gesetzt!"); - if(Config.TeamBluetoReddistanceZ > 0) { + if(Config.BlueToRedZ > 0) { smallerZteam = Fight.getBlueTeam(); biggerZteam = Fight.getRedTeam(); }else{ diff --git a/FightSystem_Main/src/plugin.yml b/FightSystem_Main/src/plugin.yml index 265d3cf..0d4346a 100644 --- a/FightSystem_Main/src/plugin.yml +++ b/FightSystem_Main/src/plugin.yml @@ -17,4 +17,6 @@ commands: kit: remove: leader: - lockschem: \ No newline at end of file + lockschem: + state: + skip: \ No newline at end of file From aeaced502a3c42f1319079f211650dad640650e3 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 23 Mar 2021 19:54:05 +0100 Subject: [PATCH 07/15] Update default config Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 3 +- FightSystem_Main/src/config.yml | 212 +++++++++++------- .../countdown/NoPlayersOnlineCountdown.java | 21 +- 3 files changed, 157 insertions(+), 79 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 29a84bf..3db29fe 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -161,6 +161,7 @@ public class Config { double teamBlueSpawnOffsetX = worldconfig.getDouble("SpawnOffset.x"); double teamBlueSpawnOffsetY = worldconfig.getDouble("SpawnOffset.y"); double teamBlueSpawnOffsetZ = worldconfig.getDouble("SpawnOffset.z"); + WaterDepth = config.getInt("Arena.WaterDepth"); int schemsizeX = config.getInt("Arena.Schemsize.x"); int schemsizeY = config.getInt("Arena.Schemsize.y"); @@ -197,7 +198,7 @@ public class Config { HiddenBlocks = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlocks"))); HiddenBlockEntities = Collections.unmodifiableSet(new HashSet<>(config.getStringList("Techhider.HiddenBlockEntities"))); - ObfuscateWith = config.getString("Techhider.ObfuscateWithTag"); + ObfuscateWith = config.getString("Techhider.ObfuscateWith"); TechhiderActive = config.getBoolean("Techhider.Active"); if(schemsizeX < 0){ diff --git a/FightSystem_Main/src/config.yml b/FightSystem_Main/src/config.yml index 7b64223..ed8dafb 100644 --- a/FightSystem_Main/src/config.yml +++ b/FightSystem_Main/src/config.yml @@ -1,90 +1,150 @@ Times: - NoPlayersOnlineDuration: 300 + # Time in seconds the server stops after starting if nobody joins + NoPlayersOnlineDuration: 30 + # Time in seconds the team leaders have to choose their schematic PreSchemPasteDuration: 120 + # Time in seconds for preparing SetupDuration: 300 + # Time in seconds the final countdown is long PreFightDuration: 30 + # Time in seconds to spectate the arena after the fight SpectatorDuration: 30 + +Arena: + # The amount of blocks the schematics should be pasted under the surface + WaterDepth: 0 + # The size of the schematics + Schemsize: + x: 0 + y: 0 + z: 0 + # The outer border of the arena, measured in blocks around the schematic areas + Schem2Border: + x: 0 + z: 0 + # The size of the team areas are expanded around the schematics + BorderFromSchematic: 0 + # If ground walkable, teams can walk below the lower arena border during setup + GroundWalkable: true + Schematic: - OnlyPublicSchematics: false + # If the rank system for the schematics should be enabled + RanksEnabled: false + # The schematic type that can be chosen in this arena SchematicType: normal + # If the schematics should be rotated during pasting Rotate: true - ReplaceObsidian: false - ReplaceBedrock: false + # If only public schematics are allowed + OnlyPublicSchematics: false + # If the public only force should be completly disabled + IgnorePublicOnly: false + # If obsidian and bedrock should be replaced during PRE_RUNNING + ReplaceObsidianBedrock: false + # If the replacement should happen with blockupdates + ReplaceWithBlockupdates: false + Output: + # Name of the "Red" team TeamRedName: Rot + # Color prefix of the "Red" team TeamRedPrefix: '§c' + # Name of the "Blue" team TeamBlueName: Blau + # Color of the "Blue" team TeamBluePrefix: '§3' - GameName: War* + # The name of the gamemode presented to the players + GameName: NoGear + # The prefix used for team chats TeamChatDetection: + + +# The list of active winconditions WinConditions: - Timeout: true - AllDead: true - CaptainDead: false - PercentSystem: false - RelativePercent: false - Points: false - Entern: false - TechKO: false - WaterTechKO: false - HeartRatioTimeout: false - PumpkinTechKO: false + - TIMEOUT + # - HEART_RATIO_TIMEOUT + # - PERCENT_TIMEOUT + + - ALL_DEAD + # - CAPTAIN_DEAD + + # - PERCENT_SYSTEM + # - RELATIVE_PERCENT + # - POINTS + + - WATER_TECH_KO + # - TIME_TECH_KO + # - PUMPKIN_TECH_KO + WinConditionParams: + # The time of any of the timeout winconditions in seconds TimeoutTime: 1200 - EnterPhaseBegin: 600 + # The percentage when any of the percent winconditions limits or triggers a win PercentWin: 5.0 + # Blocks ignored by the percent winconditions IgnoredBlocks: - AIR - WATER - TNT - OBSIDIAN + Kits: + # The kit file for this configuration + File: kits.yml + # The default kit for team members MemberDefault: default + # The default kit for team leaders LeaderDefault: default + # If the personal kit system is active PersonalKits: false + # Items that are not allowed in the personal kit ForbiddenItems: [] + +# A list of integers containing the waiting time of this enter stage in the fight +EnterStages: [] + Techhider: - ObfuscateWith: 121 - ObfuscateWithTag: ENDER_STONE + # if the techhider is active + Active: true + # Which block the techhider replaces to. + ObfuscateWith: end_stone + # A list of all hidden blocks. "water" results in the hiding of all waterlogged blocks as well. HiddenBlocks: - BEDROCK: 7 - WATER: 8 - STATIONARY_WATER: 9 - NOTE_BLOCK: 25 - DETECTOR_RAIL: 28 - PISTON_BASE: 33 - PISTON_EXTENSION: 34 - PISTON_STICKY_BASE: 29 - POWERED_RAIL: 27 - TNT: 46 - OBSIDIAN: 49 - CHEST: 54 - REDSTONE_WIRE: 55 - STONE_PLATE: 70 - IRON_DOOR_BLOCK: 71 - WOOD_PLATE: 72 - REDSTONE_TORCH_OFF: 75 - REDSTONE_TORCH_ON: 76 - STONE_BUTTON: 77 - DIODE_BLOCK_OFF: 93 - DIODE_BLOCK_ON: 94 - BREWING_STAND: 117 - TRIPWIRE_HOOK: 131 - TRIPWIRE: 132 - WOOD_BUTTON: 143 - TRAPPED_CHEST: 146 - GOLD_PLATE: 147 - IRON_PLATE: 148 - REDSTONE_COMPARATOR_OFF: 149 - REDSTONE_COMPARATOR_ON: 150 - REDSTONE_BLOCK: 152 - HOPPER: 154 - ACTIVATOR_RAIL: 157 - DROPPER: 158 - SLIME_BLOCK: 165 - IRON_TRAPDOOR: 167 - OBSERVER: 218 - LEVER: 69 + - water + - note_block + - powered_rail + - detector_rail + - piston + - piston_head + - sticky_piston + - tnt + - chest + - trapped_chest + - redstone_wire + - stone_pressure_plate + - iron_door + - oak_pressure_plate + - spruce_pressure_plate + - birch_pressure_plate + - jungle_pressure_plate + - acacia_pressure_plate + - dark_oak_pressure_plate + - redstone_torch + - redstone_wall_torch + - repeater + - brewing_stand + - tripwire_hook + - tripwire + - heavy_weighted_pressure_plate + - light_weighted_pressure_plate + - comparator + - redstone_block + - hopper + - activator_rail + - dropper + - slime_block + - observer + - honey_block + - lever + # The block entities that are hidden (contents of blocks) HiddenBlockEntites: - minecraft:sign - minecraft:dispenser @@ -98,22 +158,22 @@ Techhider: - minecraft:jukebox - minecraft:comparator -# Muss in config.yml des Weltordners gesetzt werden -Arena: - Schemsize: - x: 0 - y: 0 - z: 0 - TeamBlueCorner: - x: 0 - y: 0 - z: 0 - TeamBluetoReddistance: - x: 0 - y: 0 - z: 0 - Schem2Border: - x: 0 - z: 0 - underArenaBorder: 0 - BorderFromSchematic: 0 \ No newline at end of file +# The following configuration must be in the Worldforlder/config.yml +# +# # The lower arena border under which players get damage +# UnderBorder: +# # The lowest corner in all axis of the blue team schematic area +# BlueCorner: +# x: 0 +# y: 0 +# z: 0 +# # The offset between the lowest corner of the blue area and the lowest corner of the red area +# BlueToRed: +# x: 0 +# y: 0 +# z: 0 +# # The offset the teams spawn relative to the center of their area +# SpawnOffset: +# x: 0 +# y: 0 +# z: 0 \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java index 8c81c7b..fc8ed95 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/NoPlayersOnlineCountdown.java @@ -23,13 +23,25 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; +import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; -public class NoPlayersOnlineCountdown extends Countdown { +public class NoPlayersOnlineCountdown extends Countdown implements Listener { public NoPlayersOnlineCountdown() { super(Config.NoPlayerOnlineDuration, null, false); - new StateDependentCountdown(ArenaMode.All, FightState.PreLeaderSetup, this); + + new StateDependentListener(ArenaMode.All, FightState.PreLeaderSetup, this); + new StateDependentCountdown(ArenaMode.All, FightState.PreLeaderSetup, this){ + @Override + public void enable() { + if(Bukkit.getOnlinePlayers().isEmpty()) + super.enable(); + } + }; } @Override @@ -37,6 +49,11 @@ public class NoPlayersOnlineCountdown extends Countdown { return "bis der Server gestoppt wird!"; } + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + disable(); + } + @Override public void countdownFinished() { Bukkit.getServer().shutdown(); From e9987079056ddc6cb89c794e2685656c24d02741 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Mar 2021 10:18:00 +0100 Subject: [PATCH 08/15] =?UTF-8?q?Bugfixes=20noch=20und=20n=C3=B6cher!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 11 ++++--- .../fightsystem/utils/ITechHider.java | 4 +-- .../de/steamwar/fightsystem/utils/Region.java | 26 ++++++++------- .../fightsystem/commands/Commands.java | 7 ++-- .../fightsystem/fight/FightSchematic.java | 7 +++- .../steamwar/fightsystem/fight/FightTeam.java | 25 +++++++++----- .../fightsystem/fight/FightWorld.java | 1 + .../fightsystem/listener/ArenaBorder.java | 2 +- .../fightsystem/listener/NormalJoin.java | 8 ----- .../fightsystem/listener/Recording.java | 2 +- .../fightsystem/listener/SetupQuit.java | 3 +- .../states/OneShotStateDependent.java | 1 + .../fightsystem/states/StateDependent.java | 6 +++- .../states/StateDependentCommand.java | 1 + .../states/StateDependentCountdown.java | 2 ++ .../states/StateDependentListener.java | 3 ++ .../states/StateDependentTask.java | 2 ++ .../steamwar/fightsystem/utils/TechHider.java | 33 +++++++------------ .../EventTeamOffWincondition.java | 2 +- .../winconditions/Wincondition.java | 2 ++ .../WinconditionPercentSystem.java | 6 ++-- .../winconditions/WinconditionPoints.java | 7 ++-- .../WinconditionPumpkinTechKO.java | 7 +++- .../WinconditionRelativePercent.java | 8 +++-- .../WinconditionWaterTechKO.java | 5 ++- 25 files changed, 105 insertions(+), 76 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 3db29fe..f8da8bc 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -289,13 +289,14 @@ public class Config { RedRotate = teamRedRotate; BlueRotate = teamBlueRotate; + int arenaYSize = schemsizeY + PreperationArea; + RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); - RedExtendRegion = new Region(teamRedCornerX, underBorder, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea); - BlueExtendRegion = new Region(blueCornerX, underBorder, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea); - int upperArenaBorder = blueCornerY + schemsizeY + PreperationArea; - ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, upperArenaBorder - underBorder, arenaMaxZ - arenaMinZ); + RedExtendRegion = new Region(teamRedCornerX, underBorder, teamRedCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea); + BlueExtendRegion = new Region(blueCornerX, underBorder, blueCornerZ, schemsizeX, arenaYSize, schemsizeZ, PreperationArea, PreperationArea); + ArenaRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, arenaYSize, arenaMaxZ - arenaMinZ); EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ @@ -380,7 +381,7 @@ public class Config { } public static boolean test(){ - return ArenaMode.Test.contains(ArenaMode.TEST); + return ArenaMode.Test.contains(mode); } public static boolean recording(){ return mode == ArenaMode.EVENT; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index 572b888..ade4044 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -40,9 +40,9 @@ public class ITechHider { if(ft == null){ return Config.ArenaRegion.chunkOutside(chunkX, chunkZ); }else if(ft.isBlue()){ - return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); - }else{ return ft.canPlayerEntern(p) || Config.RedExtendRegion.chunkOutside(chunkX, chunkZ); + }else{ + return ft.canPlayerEntern(p) || Config.BlueExtendRegion.chunkOutside(chunkX, chunkZ); } } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index 9375b0c..d9df230 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -14,9 +14,9 @@ public class Region { private final int maxY; private final int maxZ; - public Region(int minX, int minY, int minZ, int sizeX, int maxY, int sizeZ, int extendX, int extendZ) { + public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendZ) { this(minX - extendX, minY, minZ - extendZ, - minX + sizeX + extendX, maxY, minZ + sizeZ + extendZ); + sizeX + extendX * 2, sizeY, sizeZ + extendZ * 2); } public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { @@ -52,20 +52,24 @@ public class Region { return maxZ; } - public int getMinChunkX(){ - return ITechHider.posToChunk(minX); + public double posToChunk(int pos){ + return pos / 16.0; } - public int getMaxChunkX(){ - return ITechHider.posToChunk(maxX); + private int getMinChunkX(){ + return (int) Math.floor(posToChunk(minX)); } - public int getMinChunkZ(){ - return ITechHider.posToChunk(minZ); + private int getMaxChunkX(){ + return (int) Math.ceil(posToChunk(maxX)); } - public int getMaxChunkZ(){ - return ITechHider.posToChunk(maxZ); + private int getMinChunkZ(){ + return (int) Math.floor(posToChunk(minZ)); + } + + private int getMaxChunkZ(){ + return (int) Math.ceil(posToChunk(maxZ)); } public boolean chunkOutside(int cX, int cZ) { @@ -110,7 +114,7 @@ public class Region { } public boolean playerInRegion(Location location){ - return in2dRegion(location) && minY < location.getY() && location.getY() + 1.8 < maxY; + return in2dRegion(location) && minY <= location.getY() && location.getY() + 1.8 < maxY; } public boolean in2dRegion(Block block){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index 94ad0fb..973440a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -96,9 +96,6 @@ public class Commands { } static void toggleSkip(Player p){ - if(checkSetup(p)) - return; - FightTeam fightTeam = checkGetTeam(p); if(fightTeam == null || checkGetLeader(p) == null) return; @@ -213,8 +210,10 @@ public class Commands { Kit k = null; if(Config.PersonalKits){ PersonalKit kit = PersonalKit.get(SteamwarUser.get(p.getUniqueId()).getId(), Config.SchematicType.toDB(), kitName); - if(kit != null) + if(kit != null){ kit.setInUse(); + k = new Kit(kit); + } }else{ k = Kit.getKitByName(kitName); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java index c0f857c..7a76a2c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -60,10 +60,11 @@ public class FightSchematic extends StateDependent { this.team = team; this.region = team.getSchemRegion(); this.rotate = rotate; + register(); } public boolean hasSchematic(){ - return clipboard == null; + return clipboard != null; } public int getId(){ @@ -109,6 +110,10 @@ public class FightSchematic extends StateDependent { else RecordSystem.redSchem(schematic); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::paste); + } + + private void paste(){ FreezeWorld freezer = new FreezeWorld(); DyeColor c = ColorConverter.chat2dye(team.getColor()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 7e67e09..e7fcacc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -140,15 +140,18 @@ public class FightTeam implements IFightTeam{ } public void reset(){ + skip = false; + ready = false; schematic.reset(); invited.clear(); + Set playerSet = new HashSet<>(players.keySet()); for(Player player : playerSet){ - if(!player.isOnline()) + if(!Bukkit.getOnlinePlayers().contains(player)) removePlayer(player); } FightPlayer leaderBackup = leader; - playerSet.removeIf(player -> !player.isOnline()); + playerSet.removeIf(player -> !Bukkit.getOnlinePlayers().contains(player)); players.clear(); leader = null; @@ -183,6 +186,7 @@ public class FightTeam implements IFightTeam{ Fight.setPlayerGamemode(player, GameMode.SURVIVAL); player.setHealth(20); player.setFoodLevel(20); + player.getInventory().clear(); BasicListener.setAttackSpeed(player); player.teleport(spawn); if(Kit.getAvailableKits(false).size() > 1 || Config.PersonalKits) @@ -234,13 +238,12 @@ public class FightTeam implements IFightTeam{ private void setLeader(FightPlayer leader) { if (leader == null) { - if (FightState.getFightState() == FightState.PRE_LEADER_SETUP){ - this.leader = null; - }else if(!players.isEmpty()) { + this.leader = null; + if(!players.isEmpty()) { setLeader(players.values().iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); - }else if(!ArenaMode.RankedEvent.contains(Config.mode)){ - FightSystem.setPreLeaderState(); + }else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){ + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1); } return; } @@ -271,6 +274,10 @@ public class FightTeam implements IFightTeam{ 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()); + + if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){ + FightSystem.setPreSchemState(); + } } public Collection getPlayers() { @@ -284,7 +291,7 @@ public class FightTeam implements IFightTeam{ public void pasteSchem(Schematic schematic){ setSchem(schematic); - if(ArenaMode.Test.contains(Config.mode)) + if(Config.test()) this.schematic.enable(); else if(Fight.getOpposite(this).hasSchematic()){ FightSystem.setPostSchemState(); @@ -385,6 +392,7 @@ public class FightTeam implements IFightTeam{ private class KitLoader extends StateDependent { private KitLoader() { super(ArenaMode.All, FightState.Ingame); + register(); } @Override @@ -408,6 +416,7 @@ public class FightTeam implements IFightTeam{ private class SpectateHandler extends StateDependent { private SpectateHandler() { super(ArenaMode.All, FightState.Spectate); + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java index 6245c59..0ae81ef 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -18,6 +18,7 @@ public class FightWorld extends StateDependent { public FightWorld() { super(ArenaMode.Restartable, FightState.Schem); + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java index 989e8ac..d0ceee8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -59,7 +59,7 @@ public class ArenaBorder implements Listener { player.damage(2); else if(!Config.GroundWalkable) player.teleport(team.getSpawn()); - }else if(to.getY() + 1.8 <= Config.ArenaRegion.getMaxY()){ + }else if(to.getY() + 1.8 > Config.ArenaRegion.getMaxY()){ reset(event); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java index a7e3937..c8c08c4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoin.java @@ -21,9 +21,7 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; 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.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; @@ -50,11 +48,5 @@ public class NormalJoin implements Listener { Fight.getRedTeam().addMember(player); } } - - FightPlayer redLeader = Fight.getRedTeam().getLeader(); - FightPlayer blueLeader = Fight.getBlueTeam().getLeader(); - if(redLeader != null && blueLeader != null && (Fight.getRedTeam().getLeader().getPlayer() == player || Fight.getBlueTeam().getLeader().getPlayer() == player)) { - FightSystem.setPreSchemState(); - } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java index fdcb5cd..1e5c287 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/Recording.java @@ -70,7 +70,7 @@ public class Recording implements Listener { despawnTeam(Fight.getBlueTeam()); despawnTNT(); } - }; + }.register(); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java index 15776f3..e4360dd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/SetupQuit.java @@ -26,7 +26,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; @@ -36,7 +35,7 @@ public class SetupQuit implements Listener { new StateDependentListener(ArenaMode.All, FightState.Setup, this); } - @EventHandler(priority = EventPriority.HIGH) + @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { event.setQuitMessage(null); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java index 46d719e..6093d58 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java @@ -11,6 +11,7 @@ public class OneShotStateDependent extends StateDependent{ public OneShotStateDependent(Set mode, Set states, Runnable runnable) { super(mode, states); this.runnable = runnable; + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java index 9b17b43..be9d0eb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java @@ -9,6 +9,7 @@ import java.util.Set; public abstract class StateDependent implements IStateDependent { private final Set enabled; + private final boolean register; protected StateDependent(Winconditions wincondition, Set states){ this(Config.ActiveWinconditions.contains(wincondition), states); @@ -20,8 +21,11 @@ public abstract class StateDependent implements IStateDependent { protected StateDependent(boolean enabled, Set states){ this.enabled = states; + this.register = enabled; + } - if(enabled) + public void register(){ + if(register) FightState.registerStateDependent(this); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java index 03bcf29..a0da55a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java @@ -42,6 +42,7 @@ public class StateDependentCommand extends StateDependent { this.command = FightSystem.getPlugin().getCommand(name); assert command != null; disable(); + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java index 57bc00b..dd205cc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCountdown.java @@ -33,11 +33,13 @@ public class StateDependentCountdown extends StateDependent { public StateDependentCountdown(Set mode, Set states, Countdown countdown) { super(mode, states); this.countdown = countdown; + register(); } public StateDependentCountdown(Winconditions wincondition, Set states, Countdown countdown) { super(Config.ActiveWinconditions.contains(wincondition), states); this.countdown = countdown; + register(); } public Countdown getCountdown(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java index 8a34a3e..f5cfffc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentListener.java @@ -36,16 +36,19 @@ public class StateDependentListener extends StateDependent{ public StateDependentListener(Winconditions wincondition, Set states, Listener listener){ super(Config.ActiveWinconditions.contains(wincondition), states); this.listener = listener; + register(); } public StateDependentListener(boolean enabled, Set states, Listener listener){ super(enabled, states); this.listener = listener; + register(); } public StateDependentListener(Set mode, Set states, Listener listener) { super(mode, states); this.listener = listener; + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java index cc219a8..950fbcb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentTask.java @@ -45,6 +45,7 @@ public class StateDependentTask extends StateDependent { this.runnable = runnable; this.delay = delay; this.period = period; + register(); } public StateDependentTask(Set mode, Set states, Runnable runnable, long delay, long period) { @@ -52,6 +53,7 @@ public class StateDependentTask extends StateDependent { this.runnable = runnable; this.delay = delay; this.period = period; + register(); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index 1cf0331..e7933fc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -38,7 +38,7 @@ 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.IStateDependent; +import de.steamwar.fightsystem.states.StateDependent; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -48,11 +48,10 @@ import java.util.*; import static de.steamwar.fightsystem.utils.ITechHider.bypass; -public class TechHider implements IStateDependent { +public class TechHider extends StateDependent { - private static final boolean DISABLED = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; + private static final boolean enabled = !Config.OnlyPublicSchematics && !Config.test() && Config.TechhiderActive; - private final Set enabled; private final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); private final Map packetCache = new HashMap<>(); private final Material obfuscateMaterial; @@ -60,10 +59,7 @@ public class TechHider implements IStateDependent { private final int threadMultiplier; public TechHider(){ - FightState.registerStateDependent(this); - enabled = DISABLED - ? EnumSet.noneOf(FightState.class) - : EnumSet.complementOf(EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP)); + super(enabled, FightState.Schem); Set hiddenBlockIds = VersionedCallable.call( new VersionedCallable<>(Collections::emptySet, 8), @@ -76,7 +72,7 @@ public class TechHider implements IStateDependent { new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); - obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith); + obfuscateMaterial = Material.getMaterial(Config.ObfuscateWith.toUpperCase()); chunkHider = VersionedCallable.call(new VersionedCallable<>(() -> null, 8), new VersionedCallable<>(() -> TechHider_12.chunkHider(hiddenBlockIds, obfuscateWith), 12), new VersionedCallable<>(() -> TechHider_14.chunkHider(hiddenBlockIds, obfuscateWith), 14)); @@ -86,9 +82,6 @@ public class TechHider implements IStateDependent { else threadMultiplier = 1; - if(DISABLED) - return; - Bukkit.getScheduler().runTaskTimer(IFightSystem.getPlugin(), packetCache::clear, 1, 1); if(Core.getVersion() > 8){ @@ -111,11 +104,7 @@ public class TechHider implements IStateDependent { e.setCancelled(true); } }); - } - - @Override - public Set enabled() { - return enabled; + register(); } @Override @@ -174,7 +163,7 @@ public class TechHider implements IStateDependent { boolean changed = false; for(MultiBlockChangeInfo mbci : changes){ WrappedBlockData block = mbci.getData(); - if(Config.HiddenBlocks.contains(block.getType().name())){ + if(Config.HiddenBlocks.contains(block.getType().name().toLowerCase())){ changed = true; block.setType(obfuscateMaterial); mbci.setData(block); @@ -208,7 +197,7 @@ public class TechHider implements IStateDependent { e.setPacket(cached); StructureModifier blockStructure = cached.getBlockData(); WrappedBlockData block = blockStructure.read(0); - if(Config.HiddenBlocks.contains(block.getType().name())){ + if(Config.HiddenBlocks.contains(block.getType().name().toLowerCase())){ block.setType(obfuscateMaterial); blockStructure.write(0, block); } @@ -251,7 +240,7 @@ public class TechHider implements IStateDependent { e.setPacket(cached); StructureModifier blockStructure = cached.getBlockData(); WrappedBlockData block = blockStructure.read(0); - if(Config.HiddenBlocks.contains(block.getType().name())){ + if(Config.HiddenBlocks.contains(block.getType().name().toLowerCase())){ block.setType(obfuscateMaterial); blockStructure.write(0, block); } @@ -277,7 +266,7 @@ public class TechHider implements IStateDependent { }; public static List prepareChunkReload(Player p){ - if(DISABLED) + if(enabled) return Collections.emptyList(); List chunksToReload = new ArrayList<>(); Config.ArenaRegion.forEachChunk((x, z) -> { @@ -288,7 +277,7 @@ public class TechHider implements IStateDependent { } public static void reloadChunks(Player p, List chunksToReload){ - if(DISABLED) + if(enabled) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { for(ChunkPos chunk : chunksToReload){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index ca74fdb..1e3941b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -44,7 +44,7 @@ public class EventTeamOffWincondition extends Wincondition{ public void disable() { //Team off is a one time trigger } - }; + }.register(); } 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 f24d7a8..984fe29 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -57,6 +57,8 @@ public abstract class Wincondition { } public static Countdown getTimeOverCountdown(){ + if(timeOverCountdown == null) + return null; return timeOverCountdown.getCountdown(); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index baed79b..5e6a838 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -37,12 +37,14 @@ public class WinconditionPercentSystem extends Wincondition implements Listener, public WinconditionPercentSystem() { super("Percent", "§cTeam ", " §chat den Gegnern"); - printableWinconditions.add(this); - percentWincondition = this; teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); new StateDependentListener(Winconditions.PERCENT_SYSTEM, FightState.Running, this); + if(Config.ActiveWinconditions.contains(Winconditions.PERCENT_SYSTEM)){ + printableWinconditions.add(this); + percentWincondition = this; + } } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 3fa6a78..46caf0e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -19,6 +19,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; @@ -46,7 +47,6 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam())); - printableWinconditions.add(this); new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this); timeOverCountdown = new StateDependentCountdown(Winconditions.POINTS, FightState.Running, new TimeOverCountdown(this::timeOver)); @@ -60,7 +60,10 @@ public class WinconditionPoints extends Wincondition implements PrintableWincond public void disable() { teamMap.values().forEach(TeamPoints::disable); } - }; + }.register(); + if(Config.ActiveWinconditions.contains(Winconditions.POINTS)){ + printableWinconditions.add(this); + } } protected void timeOver() { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index fb1fcb0..187502d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; @@ -40,9 +41,13 @@ public class WinconditionPumpkinTechKO extends Wincondition implements Printable public WinconditionPumpkinTechKO(){ super("PumpkinTechKO", "§cDas Team ", " §cist Tech K.O.!"); - new StateDependentTask(Winconditions.PUMPKIN_TECH_KO, FightState.Ingame, this::check, 0, 200); teamMap.put(Fight.getRedTeam(), new TeamPumpkin(Fight.getRedTeam())); teamMap.put(Fight.getBlueTeam(), new TeamPumpkin(Fight.getBlueTeam())); + + new StateDependentTask(Winconditions.PUMPKIN_TECH_KO, FightState.Ingame, this::check, 0, 200); + if(Config.ActiveWinconditions.contains(Winconditions.PUMPKIN_TECH_KO)){ + printableWinconditions.add(this); + } } private void check(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index c6aeedc..ba8c35b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -50,8 +50,6 @@ public class WinconditionRelativePercent extends Wincondition implements Printab super("RelativePercent", null); teamMap.put(Fight.getBlueTeam(), new TeamPercent(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamPercent(Fight.getRedTeam())); - printableWinconditions.add(this); - percentWincondition = this; new StateDependent(Winconditions.RELATIVE_PERCENT, FightState.Running){ @Override public void enable() { @@ -62,7 +60,11 @@ public class WinconditionRelativePercent extends Wincondition implements Printab public void disable() { teamMap.values().forEach(TeamPercent::disable); } - }; + }.register(); + if(Config.ActiveWinconditions.contains(Winconditions.RELATIVE_PERCENT)){ + printableWinconditions.add(this); + percentWincondition = this; + } } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 4516630..a95ebb5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.listener.WaterRemover; @@ -40,9 +41,11 @@ public class WinconditionWaterTechKO extends Wincondition implements PrintableWi super("WaterTechKO", "§cDas Team ", " §cwurde Tech K.O. gesetzt!"); teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam())); teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam())); - printableWinconditions.add(this); new StateDependentTask(Winconditions.WATER_TECH_KO, FightState.Ingame, this::check, 200, 200); + if(Config.ActiveWinconditions.contains(Winconditions.WATER_TECH_KO)){ + printableWinconditions.add(this); + } } private void check() { From 5d71169690e962546734aee46a683641d1700d5c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Mar 2021 11:21:17 +0100 Subject: [PATCH 09/15] Fix multiversioning Signed-off-by: Lixfel --- .../fightsystem/fight/FightWorld_10.java | 47 ++++++++++++++++++ .../fightsystem/fight/FightWorld_12.java | 28 +++++++++++ .../fightsystem/fight/FightWorld_14.java | 48 +++++++++++++++++++ .../fightsystem/fight/FightWorld_15.java | 48 +++++++++++++++++++ .../fightsystem/fight/FightWorld_8.java | 47 ++++++++++++++++++ .../fightsystem/fight/FightWorld_9.java | 47 ++++++++++++++++++ .../fightsystem/commands/Commands.java | 4 +- .../fightsystem/fight/FightWorld.java | 42 ++++++++++------ 8 files changed, 294 insertions(+), 17 deletions(-) create mode 100644 FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java create mode 100644 FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java create mode 100644 FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java create mode 100644 FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java create mode 100644 FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java diff --git a/FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java b/FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java new file mode 100644 index 0000000..3b81471 --- /dev/null +++ b/FightSystem_10/src/de/steamwar/fightsystem/fight/FightWorld_10.java @@ -0,0 +1,47 @@ +/* + 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.events.ChunkListener; +import net.minecraft.server.v1_10_R1.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_10_R1.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_10 { + private FightWorld_10(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_10_R1.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java new file mode 100644 index 0000000..8df8227 --- /dev/null +++ b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java @@ -0,0 +1,28 @@ +package de.steamwar.fightsystem.fight; + +import de.steamwar.core.events.ChunkListener; +import net.minecraft.server.v1_12_R1.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_12_R1.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_12 { + private FightWorld_12(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_12_R1.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java new file mode 100644 index 0000000..0cff188 --- /dev/null +++ b/FightSystem_14/src/de/steamwar/fightsystem/fight/FightWorld_14.java @@ -0,0 +1,48 @@ +/* + 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.events.ChunkListener; +import net.minecraft.server.v1_14_R1.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_14_R1.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_14 { + private FightWorld_14(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_14_R1.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + chunk.heightMap.clear(); + chunk.heightMap.putAll(backupChunk.heightMap); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java b/FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java new file mode 100644 index 0000000..cac3956 --- /dev/null +++ b/FightSystem_15/src/de/steamwar/fightsystem/fight/FightWorld_15.java @@ -0,0 +1,48 @@ +/* + 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.events.ChunkListener; +import net.minecraft.server.v1_15_R1.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_15 { + private FightWorld_15(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_15_R1.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + chunk.heightMap.clear(); + chunk.heightMap.putAll(backupChunk.heightMap); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java new file mode 100644 index 0000000..e341167 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/fight/FightWorld_8.java @@ -0,0 +1,47 @@ +/* + 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.events.ChunkListener; +import net.minecraft.server.v1_8_R3.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_8 { + private FightWorld_8(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); + w.h.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java b/FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java new file mode 100644 index 0000000..06bdcc5 --- /dev/null +++ b/FightSystem_9/src/de/steamwar/fightsystem/fight/FightWorld_9.java @@ -0,0 +1,47 @@ +/* + 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.events.ChunkListener; +import net.minecraft.server.v1_9_R2.Chunk; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.craftbukkit.v1_9_R2.CraftWorld; +import org.bukkit.entity.Player; + +class FightWorld_9 { + private FightWorld_9(){} + + static void resetChunk(World world, World backup, int x, int z){ + net.minecraft.server.v1_9_R2.World w = ((CraftWorld) world).getHandle(); + Chunk chunk = w.getChunkAt(x, z); + Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); + + System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); + System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); + w.tileEntityListTick.removeAll(chunk.tileEntities.values()); + w.tileEntityList.removeAll(chunk.tileEntities.values()); + chunk.tileEntities.clear(); + chunk.tileEntities.putAll(backupChunk.tileEntities); + for(Player p : Bukkit.getOnlinePlayers()){ + ChunkListener.sendChunk(p, x, z); + } + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java index 973440a..26bed7c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/Commands.java @@ -92,7 +92,7 @@ public class Commands { if(fightTeam == null || checkGetLeader(p) == null) return; - fightTeam.skip(); + fightTeam.setReady(!fightTeam.isReady()); } static void toggleSkip(Player p){ @@ -100,7 +100,7 @@ public class Commands { if(fightTeam == null || checkGetLeader(p) == null) return; - fightTeam.setReady(!fightTeam.isReady()); + fightTeam.skip(); } static void acceptInvitation(Player p){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java index 0ae81ef..8b99fdc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -1,16 +1,32 @@ +/* + 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.events.ChunkListener; +import de.steamwar.core.VersionedRunnable; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import net.minecraft.server.v1_15_R1.Chunk; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.craftbukkit.v1_15_R1.CraftWorld; -import org.bukkit.entity.Player; public class FightWorld extends StateDependent { @@ -35,16 +51,12 @@ public class FightWorld extends StateDependent { } private void resetChunk(World backup, int x, int z){ - Chunk chunk = ((CraftWorld) world).getHandle().getChunkAt(x, z); - Chunk backupChunk = ((CraftWorld) backup).getHandle().getChunkAt(x, z); - - System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); - chunk.tileEntities.clear(); - chunk.tileEntities.putAll(backupChunk.tileEntities); - chunk.heightMap.clear(); - chunk.heightMap.putAll(backupChunk.heightMap); - for(Player p : Bukkit.getOnlinePlayers()){ - ChunkListener.sendChunk(p, x, z); - } + VersionedRunnable.call( + new VersionedRunnable(() -> FightWorld_8.resetChunk(world, backup, x, z), 8), + new VersionedRunnable(() -> FightWorld_9.resetChunk(world, backup, x, z), 9), + new VersionedRunnable(() -> FightWorld_10.resetChunk(world, backup, x, z), 10), + new VersionedRunnable(() -> FightWorld_12.resetChunk(world, backup, x, z), 12), + new VersionedRunnable(() -> FightWorld_14.resetChunk(world, backup, x, z), 14), + new VersionedRunnable(() -> FightWorld_15.resetChunk(world, backup, x, z), 15)); } } From 3e646f3b00c98fe1f9c5a24190edb41921edb5dc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Mar 2021 11:32:41 +0100 Subject: [PATCH 10/15] Fix headers Signed-off-by: Lixfel --- .../fightsystem/fight/FightWorld_12.java | 19 +++++++++++++++++++ .../de/steamwar/fightsystem/ArenaMode.java | 19 +++++++++++++++++++ .../de/steamwar/fightsystem/utils/Region.java | 19 +++++++++++++++++++ .../fightsystem/commands/SkipCommand.java | 19 +++++++++++++++++++ .../fightsystem/commands/StateCommand.java | 19 +++++++++++++++++++ .../fightsystem/listener/TeamArea.java | 19 +++++++++++++++++++ .../states/OneShotStateDependent.java | 19 +++++++++++++++++++ 7 files changed, 133 insertions(+) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java index 8df8227..f4a7d6c 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightWorld_12.java @@ -1,3 +1,22 @@ +/* + 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.events.ChunkListener; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java index 5235c96..84e1a2c 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/ArenaMode.java @@ -1,3 +1,22 @@ +/* + 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; import java.util.Collections; diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index d9df230..c180214 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -1,3 +1,22 @@ +/* + 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.utils; import org.bukkit.Location; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java index 97a6de5..4b7c5c2 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/SkipCommand.java @@ -1,3 +1,22 @@ +/* + 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.commands; import de.steamwar.fightsystem.ArenaMode; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java index 8d29c46..8299a8c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/commands/StateCommand.java @@ -1,3 +1,22 @@ +/* + 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.commands; import de.steamwar.fightsystem.ArenaMode; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java index b7873a0..3f8bb97 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -1,3 +1,22 @@ +/* + 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.ArenaMode; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java index 6093d58..564415b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/OneShotStateDependent.java @@ -1,3 +1,22 @@ +/* + 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.states; import de.steamwar.fightsystem.ArenaMode; From 687ef93adf29f3d74c3b29345bf811f18f155306 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Mar 2021 11:45:18 +0100 Subject: [PATCH 11/15] Fix Schempreparation Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/PrepareSchem.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java index fbdccca..b0c3301 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -78,6 +78,9 @@ public class PrepareSchem implements Listener { FightSystem.shutdown(FightSystem.PREFIX + "§cDie Schematic konnte nicht gespeichert werden, Einsenden wird abgebrochen."); return; } + + schem.setSchemType(Config.SchematicType.checkType()); + FightSystem.shutdown(FightSystem.PREFIX + "§aDie Schematic wird nun zeitnah von einem Teammitglied überprüft"); } }; } From 68a2067b88ee97be15a2018f17e45cc0a79e75e0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Mar 2021 13:49:21 +0100 Subject: [PATCH 12/15] Fix Techhider 1.8 - 1.10 Signed-off-by: Lixfel --- .../fightsystem/utils/TechHider_12.java | 14 ------- .../fightsystem/utils/TechHider_8.java | 42 +++++++++++++++++++ .../steamwar/fightsystem/utils/TechHider.java | 6 +-- 3 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java 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 b8aba8f..4286cd5 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/TechHider_12.java @@ -31,10 +31,8 @@ import de.steamwar.fightsystem.IFightSystem; import io.netty.buffer.ByteBuf; import io.netty.buffer.UnpooledByteBufAllocator; import org.bukkit.Bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; -import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; @@ -44,18 +42,6 @@ import static de.steamwar.fightsystem.utils.ITechHider.bypass; class TechHider_12 { private TechHider_12(){} - static Set getHiddenBlockIds() { - Set hiddenBlockIds = new HashSet<>(); - for(String tag : Config.HiddenBlocks){ - hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4); - } - return hiddenBlockIds; - } - - static int getObfuscateWith() { - return Material.matchMaterial(Config.ObfuscateWith).getId() << 4; - } - static PacketAdapter chunkHider(Set hiddenBlockIds, int obfuscateWith){ return new PacketAdapter(IFightSystem.getPlugin(), PacketType.Play.Server.MAP_CHUNK) { @Override diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java new file mode 100644 index 0000000..ccf7943 --- /dev/null +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/TechHider_8.java @@ -0,0 +1,42 @@ +/* + 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.utils; + +import de.steamwar.fightsystem.Config; +import org.bukkit.Material; + +import java.util.HashSet; +import java.util.Set; + +class TechHider_8 { + private TechHider_8(){} + + static Set getHiddenBlockIds() { + Set hiddenBlockIds = new HashSet<>(); + for(String tag : Config.HiddenBlocks){ + hiddenBlockIds.add(Material.matchMaterial(tag).getId() << 4); + } + return hiddenBlockIds; + } + + static int getObfuscateWith() { + return Material.matchMaterial(Config.ObfuscateWith).getId() << 4; + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java index e7933fc..68f897a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/TechHider.java @@ -62,13 +62,11 @@ public class TechHider extends StateDependent { super(enabled, FightState.Schem); Set hiddenBlockIds = VersionedCallable.call( - new VersionedCallable<>(Collections::emptySet, 8), - new VersionedCallable<>(TechHider_12::getHiddenBlockIds, 12), + new VersionedCallable<>(TechHider_8::getHiddenBlockIds, 8), new VersionedCallable<>(TechHider_14::getHiddenBlockIds, 14), new VersionedCallable<>(TechHider_15::getHiddenBlockIds, 15)); int obfuscateWith = VersionedCallable.call( - new VersionedCallable<>(() -> 0, 8), - new VersionedCallable<>(TechHider_12::getObfuscateWith, 12), + new VersionedCallable<>(TechHider_8::getObfuscateWith, 8), new VersionedCallable<>(TechHider_14::getObfuscateWith, 14), new VersionedCallable<>(TechHider_15::getObfuscateWith, 15)); From f69e86454143afb1b291a026c5eb1dcd8d33ae72 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 27 Mar 2021 17:57:51 +0100 Subject: [PATCH 13/15] Bugfixes Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 +- .../de/steamwar/fightsystem/utils/Region.java | 3 +++ .../fightsystem/states/StateDependent.java | 19 +++++++++++++++++++ .../states/StateDependentCommand.java | 4 ++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index f8da8bc..704c78c 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -289,7 +289,7 @@ public class Config { RedRotate = teamRedRotate; BlueRotate = teamBlueRotate; - int arenaYSize = schemsizeY + PreperationArea; + int arenaYSize = blueCornerY - underBorder + schemsizeY + PreperationArea; RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java index c180214..470b8d0 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/Region.java @@ -19,10 +19,12 @@ package de.steamwar.fightsystem.utils; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import java.util.function.ObjIntConsumer; +import java.util.logging.Level; public class Region { @@ -39,6 +41,7 @@ public class Region { } public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { + Bukkit.getLogger().log(Level.INFO, minX + " " + minY + " " + minZ + " " + sizeX + " " + sizeY + " " + sizeZ); this.minX = minX; this.minY = minY; this.minZ = minZ; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java index be9d0eb..e20c4fb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependent.java @@ -1,3 +1,22 @@ +/* + 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.states; import de.steamwar.fightsystem.ArenaMode; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java index a0da55a..b2e63fb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/StateDependentCommand.java @@ -28,7 +28,7 @@ import java.util.Set; public class StateDependentCommand extends StateDependent { - private static final CommandExecutor unavailible = (sender, cmd, s, strings) -> { + private static final CommandExecutor unavailable = (sender, cmd, s, strings) -> { sender.sendMessage(FightSystem.PREFIX + "§cDieser Befehl ist zu diesem Kampfzeitpunkt nicht verfügbar."); return false; }; @@ -52,6 +52,6 @@ public class StateDependentCommand extends StateDependent { @Override public void disable() { - command.setExecutor(unavailible); + command.setExecutor(unavailable); } } From 947afe7e1f2e5e82f734e3131606704b0698d732 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 30 Mar 2021 18:59:12 +0200 Subject: [PATCH 14/15] Fixes Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/fight/Fight.java | 8 ++--- .../fightsystem/listener/EventJoin.java | 11 ------ .../fightsystem/listener/ResourcePack.java | 35 +++++++++++++++++++ 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 93178c9..dd56cf4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -58,14 +58,12 @@ public class Fight { } public static FightTeam getOpposite(FightTeam fightTeam) { - if(fightTeam == null){ - throw new IllegalArgumentException(); - } - if(fightTeam == redTeam) return blueTeam; - else + else if(fightTeam == blueTeam) return redTeam; + + throw new IllegalArgumentException(); } public static FightTeam getInvitedTeam(Player player){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java index 0efb2a2..55195dc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -58,7 +58,6 @@ public class EventJoin implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - //player.setResourcePack("https://steamwar.de/antixray.zip"); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(FightState.Setup.contains(FightState.getFightState())){ @@ -101,14 +100,4 @@ public class EventJoin implements Listener { if(player == FightSystem.getEventLeiter()) FightSystem.setEventLeiter(null); } - - /*@EventHandler - public void onResourcepack(PlayerResourcePackStatusEvent e){ - if(e.getStatus() == PlayerResourcePackStatusEvent.Status.ACCEPTED || e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) - return; - - Player player = e.getPlayer(); - player.sendMessage(FightSystem.PREFIX + "§cAuf Eventserver kann nur mit dem SteamWar-Resourcepack beigetreten werden"); - player.kickPlayer(null); - }*/ } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java new file mode 100644 index 0000000..c4ae576 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/ResourcePack.java @@ -0,0 +1,35 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentListener; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerResourcePackStatusEvent; + +public class ResourcePack implements Listener { + + public ResourcePack(){ + new StateDependentListener(ArenaMode.Event, FightState.All, this); + } + + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + player.setResourcePack("https://steamwar.de/antixray.zip"); + } + + @EventHandler + public void onResourcepack(PlayerResourcePackStatusEvent e){ + if(e.getStatus() == PlayerResourcePackStatusEvent.Status.ACCEPTED || e.getStatus() == PlayerResourcePackStatusEvent.Status.SUCCESSFULLY_LOADED) + return; + + Player player = e.getPlayer(); + player.sendMessage(FightSystem.PREFIX + "§cAuf Eventserver kann nur mit dem SteamWar-Resourcepack beigetreten werden"); + player.sendMessage(FightSystem.PREFIX + "§cDa du abgelehnt hast, musst du nun in der Serverliste erstmal wieder Ressourcenpakete von SteamWar aktivieren."); + player.kickPlayer(null); + } +} From f9ab14a2e36757598f5a38249586cbac9c11eaf0 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 30 Mar 2021 19:38:56 +0200 Subject: [PATCH 15/15] Fix order Signed-off-by: Lixfel --- FightSystem_API/src/de/steamwar/fightsystem/Config.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 704c78c..06b2d83 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -369,12 +369,12 @@ public class Config { mode = ArenaMode.RANKED; }else if(CheckSchemID != 0){ mode = ArenaMode.CHECK; + }else if(PrepareSchemID != 0){ + mode = ArenaMode.PREPARE; }else if(EventKampfID >= 1){ mode = ArenaMode.EVENT; }else if(EventKampfID == -1){ mode = ArenaMode.TEST; - }else if(PrepareSchemID != 0){ - mode = ArenaMode.PREPARE; }else{ mode = ArenaMode.NORMAL; }