From 4d9e6bbb9d0992729787b34d5f2f254db7aeee88 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 9 Apr 2022 16:14:03 +0200 Subject: [PATCH 1/2] Refactoring some things Signed-off-by: Lixfel --- .../utils/CraftbukkitWrapper10.java | 4 +- .../utils/CraftbukkitWrapper12.java | 4 +- .../utils/WorldOfColorWrapper12.java | 2 +- .../fightsystem/utils/BlockIdWrapper14.java | 2 +- .../utils/CraftbukkitWrapper14.java | 4 +- .../utils/FlatteningWrapper14.java | 2 +- .../fightsystem/utils/WorldeditWrapper14.java | 6 +- .../fightsystem/utils/BlockIdWrapper15.java | 2 +- .../utils/CraftbukkitWrapper15.java | 4 +- .../fightsystem/utils/BlockIdWrapper18.java | 2 +- .../utils/CraftbukkitWrapper18.java | 4 +- .../fightsystem/utils/BlockIdWrapper8.java | 2 +- .../fightsystem/utils/BountifulWrapper8.java | 2 +- .../utils/CraftbukkitWrapper8.java | 4 +- .../fightsystem/utils/FlatteningWrapper8.java | 2 +- .../utils/WorldOfColorWrapper8.java | 2 +- .../fightsystem/utils/WorldeditWrapper8.java | 8 +- .../fightsystem/utils/BountifulWrapper9.java | 2 +- .../utils/CraftbukkitWrapper9.java | 4 +- .../src/de/steamwar/fightsystem/Config.java | 17 ++-- .../de/steamwar/fightsystem/FightSystem.java | 50 ++--------- .../de/steamwar/fightsystem/commands/GUI.java | 19 +++-- .../fightsystem/commands/GamemodeCommand.java | 2 +- .../fightsystem/commands/LeaderCommand.java | 19 +++-- .../fightsystem/commands/WinCommand.java | 16 ++-- .../countdown/PostSchemCountdown.java | 3 +- .../countdown/PreRunningCountdown.java | 3 +- .../countdown/PreSchemCountdown.java | 3 +- .../countdown/SpectateOverCountdown.java | 3 +- .../fightsystem/event/HellsBells.java | 11 +-- .../de/steamwar/fightsystem/event/Meteor.java | 9 +- .../de/steamwar/fightsystem/fight/Fight.java | 14 +++- .../fightsystem/fight/FightSchematic.java | 8 +- .../steamwar/fightsystem/fight/FightTeam.java | 26 +++--- .../fightsystem/fight/FightWorld.java | 18 ++-- .../fightsystem/listener/ArrowStopper.java | 16 ++-- .../steamwar/fightsystem/listener/Chat.java | 2 +- .../fightsystem/listener/ClickAnalyzer.java | 4 +- .../fightsystem/listener/EventJoin.java | 15 +--- .../fightsystem/listener/NormalJoin.java | 15 ++-- .../fightsystem/listener/PrepareSchem.java | 11 +-- .../fightsystem/listener/Recording.java | 29 +++---- .../fightsystem/listener/TeamArea.java | 5 +- .../fightsystem/listener/TestJoin.java | 6 +- .../fightsystem/listener/WaterRemover.java | 9 +- .../fightsystem/record/FileRecorder.java | 3 +- .../fightsystem/record/PacketProcessor.java | 9 +- .../steamwar/fightsystem/record/Recorder.java | 3 +- .../fightsystem/utils/BlockIdWrapper.java | 18 ++-- .../fightsystem/utils/BountifulWrapper.java | 38 ++++----- .../fightsystem/utils/BungeeFightInfo.java | 2 +- .../fightsystem/utils/CraftbukkitWrapper.java | 18 ++-- .../fightsystem/utils/EnterHandler.java | 6 +- .../fightsystem/utils/FightStatistics.java | 10 +-- .../fightsystem/utils/FlatteningWrapper.java | 28 +++---- .../fightsystem/utils/ItemBuilder.java | 2 +- .../steamwar/fightsystem/utils/TechHider.java | 2 +- .../utils/WorldOfColorWrapper.java | 16 ++-- .../fightsystem/utils/WorldeditWrapper.java | 20 ++--- .../EventTeamOffWincondition.java | 30 ++----- .../winconditions/PercentWincondition.java | 9 +- .../winconditions/Wincondition.java | 15 ++++ ...terTechKO.java => WinconditionBlocks.java} | 56 ++++++------- ...ava => WinconditionComparisonTimeout.java} | 29 ++----- .../WinconditionPercentTimeout.java | 49 ----------- .../winconditions/WinconditionPoints.java | 14 +--- .../WinconditionPumpkinTechKO.java | 84 ------------------- .../winconditions/WinconditionTimeTechKO.java | 9 +- 68 files changed, 310 insertions(+), 555 deletions(-) rename FightSystem_Core/src/de/steamwar/fightsystem/winconditions/{WinconditionWaterTechKO.java => WinconditionBlocks.java} (54%) rename FightSystem_Core/src/de/steamwar/fightsystem/winconditions/{WinconditionHeartRatioTimeout.java => WinconditionComparisonTimeout.java} (52%) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java diff --git a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java index 6e421a9..d43e00c 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper10 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_10_R1.World w = ((CraftWorld) world).getHandle(); @@ -71,7 +71,7 @@ public class CraftbukkitWrapper10 implements CraftbukkitWrapper.ICraftbukkitWrap } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java index d980c1c..a637867 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper12 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_12_R1.World w = ((CraftWorld) world).getHandle(); @@ -71,7 +71,7 @@ public class CraftbukkitWrapper12 implements CraftbukkitWrapper.ICraftbukkitWrap } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); } } diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java index b8f46e4..876feb8 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java @@ -27,7 +27,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; -public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper { +public class WorldOfColorWrapper12 implements WorldOfColorWrapper { @Override public void setTeamColor(Team team, ChatColor color) { team.setColor(color); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java index 78101c3..e2a8bff 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/BlockIdWrapper14.java @@ -30,7 +30,7 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; -public class BlockIdWrapper14 implements BlockIdWrapper.IBlockIdWrapper { +public class BlockIdWrapper14 implements BlockIdWrapper { @Override public int blockToId(Block block) { return net.minecraft.server.v1_14_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java index c53bfe5..54e5ff9 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper14 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_14_R1.World w = ((CraftWorld) world).getHandle(); @@ -72,7 +72,7 @@ public class CraftbukkitWrapper14 implements CraftbukkitWrapper.ICraftbukkitWrap } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream(); } } diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java index 239c774..ff3a1a9 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java @@ -32,7 +32,7 @@ import org.bukkit.inventory.meta.ItemMeta; import java.util.Objects; -public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper { +public class FlatteningWrapper14 implements FlatteningWrapper { @Override public DyeColor getSilver() { return DyeColor.LIGHT_GRAY; diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java index 402c587..4ee7a4d 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/WorldeditWrapper14.java @@ -40,9 +40,9 @@ import com.sk89q.worldedit.session.ClipboardHolder; 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.FightSystem; import de.steamwar.sql.SchematicNode; -import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.util.Vector; @@ -56,7 +56,7 @@ import java.util.Map; import java.util.Objects; import java.util.zip.GZIPInputStream; -public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { +public class WorldeditWrapper14 implements WorldeditWrapper { private static final Map colorBlocks = new HashMap<>(); @@ -123,7 +123,7 @@ public class WorldeditWrapper14 implements WorldeditWrapper.IWorldeditWrapper { @Override public void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException { - World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + World w = new BukkitWorld(Config.world); BlockVector3 min = BlockVector3.at(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, BlockVector3.at(region.getMaxX(), region.getMaxY(), region.getMaxZ()).subtract(BlockVector3.ONE)); BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java index c88034f..9ec0283 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/BlockIdWrapper15.java @@ -30,7 +30,7 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; -public class BlockIdWrapper15 implements BlockIdWrapper.IBlockIdWrapper { +public class BlockIdWrapper15 implements BlockIdWrapper { @Override public int blockToId(Block block) { return net.minecraft.server.v1_15_R1.Block.REGISTRY_ID.getId(((CraftBlock)block).getNMS()); diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java index 6d7b376..2fe700e 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper15 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_15_R1.World w = ((CraftWorld) world).getHandle(); @@ -72,7 +72,7 @@ public class CraftbukkitWrapper15 implements CraftbukkitWrapper.ICraftbukkitWrap } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entitiesById.values().stream(); } } diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java index 5b5cc19..243aa24 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/BlockIdWrapper18.java @@ -37,7 +37,7 @@ import java.util.HashSet; import java.util.Objects; import java.util.Set; -public class BlockIdWrapper18 implements BlockIdWrapper.IBlockIdWrapper { +public class BlockIdWrapper18 implements BlockIdWrapper { @Override public int blockToId(Block block) { diff --git a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java index 8fd5f23..de77d54 100644 --- a/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java +++ b/FightSystem_18/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper18.java @@ -35,7 +35,7 @@ import java.util.Set; import java.util.stream.Stream; import java.util.stream.StreamSupport; -public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper18 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { @@ -65,7 +65,7 @@ public class CraftbukkitWrapper18 implements CraftbukkitWrapper.ICraftbukkitWrap } @Override - public Stream tntIterator() { + public Stream entityIterator() { return StreamSupport.stream(((CraftWorld) Config.world).getHandle().H().a().spliterator(), false); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java index 865c4a7..da5d971 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BlockIdWrapper8.java @@ -27,7 +27,7 @@ import org.bukkit.block.Block; import java.util.HashSet; import java.util.Set; -public class BlockIdWrapper8 implements BlockIdWrapper.IBlockIdWrapper { +public class BlockIdWrapper8 implements BlockIdWrapper { @Override @SuppressWarnings("deprecation") public int blockToId(Block block) { diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index 9ca288c..4b08cf2 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -38,7 +38,7 @@ import org.bukkit.scoreboard.Team; import java.util.*; -public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { +public class BountifulWrapper8 implements BountifulWrapper { public BountifulWrapper8() { EntityEnderDragon dragon = new EntityEnderDragon(null); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java index deb612c..07d75e9 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper8.java @@ -34,7 +34,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper8 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_8_R3.World w = ((CraftWorld) world).getHandle(); @@ -68,7 +68,7 @@ public class CraftbukkitWrapper8 implements CraftbukkitWrapper.ICraftbukkitWrapp } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java index 5b6ed8d..b88cca2 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java @@ -29,7 +29,7 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -public class FlatteningWrapper8 implements FlatteningWrapper.IFlatteningWrapper { +public class FlatteningWrapper8 implements FlatteningWrapper { @Override public DyeColor getSilver() { return DyeColor.SILVER; diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java index 96e8665..68e4f66 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java @@ -26,7 +26,7 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; -public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper { +public class WorldOfColorWrapper8 implements WorldOfColorWrapper { @Override public void setTeamColor(Team team, ChatColor color) { team.setPrefix("ยง" + color.getChar()); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java index 3d7fb2a..c8588f4 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldeditWrapper8.java @@ -37,9 +37,9 @@ import com.sk89q.worldedit.math.transform.AffineTransform; 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.FightSystem; import de.steamwar.sql.SchematicNode; -import org.bukkit.Bukkit; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Material; @@ -55,7 +55,7 @@ import java.util.Set; import java.util.zip.GZIPInputStream; @SuppressWarnings("deprecation") -public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { +public class WorldeditWrapper8 implements WorldeditWrapper { protected static final int COLOR_TO_REPLACE = DyeColor.PINK.getWoolData(); protected static final Set colorBlocks = new HashSet<>(); @@ -117,12 +117,12 @@ public class WorldeditWrapper8 implements WorldeditWrapper.IWorldeditWrapper { @Override public Clipboard loadChar(String charName) throws IOException { - return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Bukkit.getWorlds().get(0)).getWorldData()); + return new SchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schematic"))))).read(new BukkitWorld(Config.world).getWorldData()); } @Override public void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException { - World w = new BukkitWorld(Bukkit.getWorlds().get(0)); + World w = new BukkitWorld(Config.world); Vector min = new Vector(region.getMinX(), minY, region.getMinZ()); CuboidRegion cuboidRegion = new CuboidRegion(w, min, new Vector(region.getMaxX(), region.getMaxY(), region.getMaxZ()).subtract(Vector.ONE)); BlockArrayClipboard clipboard = new BlockArrayClipboard(cuboidRegion); diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index cbf3207..27e6e28 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -45,7 +45,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { +public class BountifulWrapper9 implements BountifulWrapper { private static final Class enumHand = Reflection.getClass("{nms.world}.EnumHand"); private static final Object mainHand = enumHand.getEnumConstants()[0]; diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java index f1ace08..0873f8a 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java @@ -35,7 +35,7 @@ import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; -public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapper { +public class CraftbukkitWrapper9 implements CraftbukkitWrapper { @Override public void resetChunk(World world, World backup, int x, int z) { net.minecraft.server.v1_9_R2.World w = ((CraftWorld) world).getHandle(); @@ -71,7 +71,7 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper.ICraftbukkitWrapp } @Override - public Stream tntIterator() { + public Stream entityIterator() { return ((CraftWorld) Config.world).getHandle().entityList.stream(); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 020687c..0bc6775 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -23,6 +23,7 @@ import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.winconditions.Winconditions; import de.steamwar.sql.Event; import de.steamwar.sql.EventFight; +import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.Team; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -30,6 +31,7 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; import org.bukkit.util.Vector; import java.io.File; @@ -118,6 +120,7 @@ public class Config { //event parameter private static final int EventKampfID; + public static final EventFight EventKampf; public static final int EventTeamBlueID; public static final int EventTeamRedID; public static final boolean BothTeamsPublic; @@ -144,7 +147,7 @@ public class Config { } FileConfiguration config = YamlConfiguration.loadConfiguration(new File(FightSystem.getPlugin().getDataFolder(), configFile)); - File worldConfigFile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); + File worldConfigFile = new File(world.getWorldFolder(), "config.yml"); if(!worldConfigFile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Weltconfig fehlt!"); Bukkit.shutdown(); @@ -232,8 +235,6 @@ public class Config { int teamRedPasteX = teamBluePasteX + BlueToRedX; int teamRedPasteZ = teamBluePasteZ + BlueToRedZ; - World world = Bukkit.getWorlds().get(0); - TeamBlueSpawn = new Location(world, teamBluePasteX + 0.5 + teamBlueSpawnOffsetX, blueCornerY + 0.5 + teamBlueSpawnOffsetY, @@ -332,8 +333,7 @@ public class Config { EventTeamBlueID = team1.getTeamId(); EventTeamRedID = team2.getTeamId(); BothTeamsPublic = EventTeamRedID == 0 && EventTeamBlueID == 0; - - FightSystem.setEventFight(eventFight); + EventKampf = eventFight; Event event = Event.get(eventFight.getEventID()); if(BothTeamsPublic) { @@ -353,6 +353,7 @@ public class Config { OnlyPublicSchematics = config.getBoolean("Schematic.OnlyPublicSchematics", false); EventTeamBlueID = 0; EventTeamRedID = 0; + EventKampf = null; BothTeamsPublic = true; MaximumTeamMembers = Integer.MAX_VALUE; LiveReplay = false; @@ -397,4 +398,10 @@ public class Config { public static boolean blueNegZ(){ return BlueToRedZ > 0; } + + public static boolean isReferee(Player player) { + if(EventKampf == null) + return false; + return SteamwarUser.get(player.getUniqueId()).getId() == EventKampf.getKampfleiter(); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 4d6acb8..6466e21 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -35,17 +35,13 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; -import de.steamwar.sql.EventFight; import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; -import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class FightSystem extends JavaPlugin { private static FightSystem plugin; - private static EventFight eventFight; - private static Player eventLeiter; private Message message; private FightTeam lastWinner; @@ -103,17 +99,17 @@ public class FightSystem extends JavaPlugin { new WinconditionAllDead(); new WinconditionCaptainDead(); - new WinconditionPumpkinTechKO(); - new WinconditionWaterTechKO(); + new WinconditionBlocks(Winconditions.WATER_TECH_KO, "WaterTechKO", "BAR_WATER", FlatteningWrapper.impl::isWater); + new WinconditionBlocks(Winconditions.PUMPKIN_TECH_KO, "PumpkinTechKO", "BAR_CANNONS", block -> block.getType() == WinconditionBlocks.PUMPKIN_LANTERN); new WinconditionPercentSystem(); new WinconditionBlacklistPercent(); new WinconditionWhitelistPercent(); new WinconditionPoints(); new WinconditionTimeout(); - new WinconditionHeartRatioTimeout(); new WinconditionTimeTechKO(); new EventTeamOffWincondition(); - new WinconditionPercentTimeout(); + new WinconditionComparisonTimeout(Winconditions.HEART_RATIO_TIMEOUT, "HeartTimeout", "WIN_MORE_HEALTH", FightTeam::getHeartRatio); + new WinconditionComparisonTimeout(Winconditions.PERCENT_TIMEOUT, "PercentTimeout", "WIN_LESS_DAMAGE", team -> -Wincondition.getPercentWincondition().getPercent(team)); new HellsBells(); new Meteor(); @@ -150,7 +146,7 @@ public class FightSystem extends JavaPlugin { FileSource.startReplay(); if(Config.mode == ArenaMode.EVENT) { - setPreSchemState(); + FightState.setFightState(FightState.PRE_SCHEM_SETUP); }else if(Config.mode == ArenaMode.CHECK){ Fight.getBlueTeam().setSchem(SchematicNode.getSchematicNode(Config.CheckSchemID)); }else if(Config.mode == ArenaMode.PREPARE) { @@ -163,26 +159,6 @@ public class FightSystem extends JavaPlugin { GlobalRecorder.getInstance().close(); } - 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); - } - - public static void setPreRunningState() { - FightState.setFightState(FightState.PRE_RUNNING); - } - - public static void setRunningState() { - FightState.setFightState(FightState.RUNNING); - } - public static void setSpectateState(FightTeam winFightTeam, String winreason, String subtitle, Object... params) { plugin.lastWinner = winFightTeam; plugin.lastWinreason = winreason; @@ -191,22 +167,6 @@ public class FightSystem extends JavaPlugin { FightState.setFightState(FightState.SPECTATE); } - public static void setEventLeiter(Player el){ - eventLeiter = el; - } - - public static Player getEventLeiter(){ - return eventLeiter; - } - - public static EventFight getEventFight(){ - return eventFight; - } - - public static void setEventFight(EventFight ef){ - eventFight = ef; - } - public static FightSystem getPlugin() { return plugin; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 0f56b0a..5b04b80 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -69,14 +69,17 @@ public class GUI { public static void state(Player p){ SWInventory inv = new SWInventory(p, 9, msg.parse("STATE_TITLE", p)); - inv.setItem(0, Material.GLASS, msg.parse("STATE_PRE_LEADER_SETUP", p), (ClickType click) -> FightSystem.setPreLeaderState()); - inv.setItem(1, Material.GLASS, msg.parse("STATE_PRE_SCHEM_SETUP", p), (ClickType click) -> FightSystem.setPreSchemState()); - inv.setItem(2, Material.GLASS, msg.parse("STATE_POST_SCHEM_SETUP", p), (ClickType click) -> FightSystem.setPostSchemState()); - inv.setItem(3, Material.GLASS, msg.parse("STATE_PRE_RUNNING", p), (ClickType click) -> FightSystem.setPreRunningState()); - inv.setItem(4, Material.GLASS, msg.parse("STATE_RUNNING", p), (ClickType click) -> FightSystem.setRunningState()); - inv.setItem(5, Material.GLASS, msg.parse("STATE_SPECTATE_WIN", p, Fight.getBlueTeam().getColoredName()), (ClickType click) -> FightSystem.setSpectateState(Fight.getBlueTeam(), "operator", "WIN_FIGHTLEADER")); - inv.setItem(6, Material.GLASS, msg.parse("STATE_SPECTATE_WIN", p, Fight.getRedTeam().getColoredName()), (ClickType click) -> FightSystem.setSpectateState(Fight.getRedTeam(), "operator", "WIN_FIGHTLEADER")); - inv.setItem(7, Material.GLASS, msg.parse("STATE_SPECTATE_TIE", p), (ClickType click) -> FightSystem.setSpectateState(null, "operator", "WIN_FIGHTLEADER")); + int i = 0; + for(FightState state : FightState.values()) { + if(state == FightState.SPECTATE) + continue; + + inv.setItem(i++, Material.GLASS, msg.parse("STATE_" + state.name(), p), click -> FightState.setFightState(state)); + } + for(FightTeam team : Fight.teams()) { + inv.setItem(i++, Material.GLASS, msg.parse("STATE_SPECTATE_WIN", p, team.getColoredName()), click -> FightSystem.setSpectateState(team, "operator", "WIN_FIGHTLEADER")); + } + inv.setItem(i, Material.GLASS, msg.parse("STATE_SPECTATE_TIE", p), click -> FightSystem.setSpectateState(null, "operator", "WIN_FIGHTLEADER")); inv.setCallback(-999, (ClickType click) -> p.closeInventory()); inv.open(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java index dc7b306..0cde5ac 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java @@ -64,7 +64,7 @@ public class GamemodeCommand extends BukkitCommand { Player p = (Player) sender; - if (!(Config.test() || p == FightSystem.getEventLeiter())) { + if (!(Config.test() || Config.isReferee(p))) { FightSystem.getMessage().sendPrefixless("GAMEMODE_NOT_ALLOWED", p, ChatMessageType.ACTION_BAR); return false; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java index bfc46b8..4933fac 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LeaderCommand.java @@ -22,6 +22,7 @@ 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.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; import net.md_5.bungee.api.ChatMessageType; @@ -42,16 +43,18 @@ public class LeaderCommand implements CommandExecutor { return false; Player player = (Player) sender; - if(Fight.getFightPlayer(player) == null){ - if(Fight.getBlueTeam().isLeaderless()) - Fight.getBlueTeam().addMember(player); - else if(Fight.getRedTeam().isLeaderless()) - Fight.getRedTeam().addMember(player); - else - FightSystem.getMessage().sendPrefixless("LEADER_FULL", player, ChatMessageType.ACTION_BAR); - }else + if(Fight.getFightPlayer(player) != null) { FightSystem.getMessage().sendPrefixless("ALREADY_IN_TEAM", player, ChatMessageType.ACTION_BAR); + return false; + } + for(FightTeam team : Fight.teams()) { + if(team.canbeLeader(player)) { + team.addMember(player); + return false; + } + } + FightSystem.getMessage().sendPrefixless("LEADER_FULL", player, ChatMessageType.ACTION_BAR); return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java index 979a181..d522a8e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java @@ -1,8 +1,10 @@ package de.steamwar.fightsystem.commands; 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.StateDependentCommand; import net.md_5.bungee.api.ChatMessageType; @@ -24,7 +26,7 @@ public class WinCommand implements CommandExecutor { } Player p = (Player) sender; - if (p != FightSystem.getEventLeiter()) { + if (!Config.isReferee(p)) { FightSystem.getMessage().sendPrefixless("NOT_FIGHTLEADER", p, ChatMessageType.ACTION_BAR); return false; } @@ -36,10 +38,14 @@ public class WinCommand implements CommandExecutor { if(args[0].equalsIgnoreCase("tie")){ FightSystem.setSpectateState(null, "Referee", "WIN_FIGHTLEADER"); - }else if(args[0].equalsIgnoreCase(Fight.getBlueTeam().getName())){ - FightSystem.setSpectateState(Fight.getBlueTeam(), "Referee", "WIN_FIGHTLEADER"); - }else if(args[0].equalsIgnoreCase(Fight.getRedTeam().getName())){ - FightSystem.setSpectateState(Fight.getRedTeam(), "Referee", "WIN_FIGHTLEADER"); + return false; + } + + for(FightTeam team : Fight.teams()) { + if(args[0].equalsIgnoreCase(team.getName())){ + FightSystem.setSpectateState(team, "Referee", "WIN_FIGHTLEADER"); + return false; + } } return false; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java index 0f7147e..877dfe0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PostSchemCountdown.java @@ -21,7 +21,6 @@ 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; import de.steamwar.fightsystem.utils.Message; @@ -35,6 +34,6 @@ public class PostSchemCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.setPreRunningState(); + FightState.setFightState(FightState.PRE_RUNNING); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java index 87984b1..17684a7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreRunningCountdown.java @@ -21,7 +21,6 @@ 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; import de.steamwar.fightsystem.utils.Message; @@ -36,6 +35,6 @@ public class PreRunningCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.setRunningState(); + FightState.setFightState(FightState.RUNNING); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java index b88378f..4200eb6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/PreSchemCountdown.java @@ -21,7 +21,6 @@ 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; import de.steamwar.fightsystem.utils.Message; @@ -36,6 +35,6 @@ public class PreSchemCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.setPostSchemState(); + FightState.setFightState(FightState.POST_SCHEM_SETUP); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java index 0290647..7e1b6eb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/SpectateOverCountdown.java @@ -21,7 +21,6 @@ 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; import de.steamwar.fightsystem.utils.Message; @@ -36,6 +35,6 @@ public class SpectateOverCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.setPreLeaderState(); + FightState.setFightState(FightState.PRE_LEADER_SETUP); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java index 80a7f7b..4b61b8f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/HellsBells.java @@ -29,8 +29,6 @@ import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.winconditions.Winconditions; import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitTask; @@ -45,7 +43,6 @@ public class HellsBells { public static final Random random = new Random(); - private final World world = Bukkit.getWorlds().get(0); private final int xLength = Config.RedExtendRegion.getMaxX() - Config.RedExtendRegion.getMinX(); private final int zLength = Config.RedExtendRegion.getMaxZ() - Config.RedExtendRegion.getMinZ(); private State current = State.PRE; @@ -100,13 +97,13 @@ public class HellsBells { currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { for (int w = 0; w < width; w++) { if (direction.isNorthOrWest()) { - world.spawnEntity(redStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); + Config.world.spawnEntity(redStart.addAndToLocation(Config.world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); + Config.world.spawnEntity(blueStart.addAndToLocation(Config.world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } else { - world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); + Config.world.spawnEntity(redStart.addAndToLocation(Config.world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); + Config.world.spawnEntity(blueStart.addAndToLocation(Config.world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT); } } if (length.addAndGet(-2) <= 0) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/event/Meteor.java b/FightSystem_Core/src/de/steamwar/fightsystem/event/Meteor.java index 158620b..3f3115d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/event/Meteor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/event/Meteor.java @@ -30,11 +30,9 @@ import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.fightsystem.winconditions.Winconditions; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Fireball; import org.bukkit.entity.LargeFireball; import org.bukkit.entity.TNTPrimed; -import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.scheduler.BukkitTask; @@ -52,7 +50,6 @@ public class Meteor implements Listener { public static final Random random = new Random(); private final Vector vector = new Vector(0, -1, 0); - private final World world = Bukkit.getWorlds().get(0); private final int xLength = Config.RedExtendRegion.getMaxX() - Config.RedExtendRegion.getMinX(); private final int zLength = Config.RedExtendRegion.getMaxZ() - Config.RedExtendRegion.getMinZ(); private Meteor.State current = Meteor.State.PRE; @@ -86,7 +83,7 @@ public class Meteor implements Listener { //@EventHandler public void explode(ProjectileHitEvent event) { if (event.getEntity() instanceof Fireball) { - TNTPrimed tnt = world.spawn(event.getEntity().getLocation(), TNTPrimed.class); + TNTPrimed tnt = Config.world.spawn(event.getEntity().getLocation(), TNTPrimed.class); tnt.setVelocity(new Vector(0, 0, 0)); tnt.setFuseTicks(0); tnt.setYield(((Fireball) event.getEntity()).getYield()); @@ -113,13 +110,13 @@ public class Meteor implements Listener { vector.setX(random.nextDouble() - 0.5); vector.setZ(random.nextDouble() - 0.5); - LargeFireball fireballRed = world.spawn(redStart.toLocation(world), LargeFireball.class); + LargeFireball fireballRed = Config.world.spawn(redStart.toLocation(Config.world), LargeFireball.class); fireballRed.setDirection(vector); fireballRed.setBounce(false); fireballRed.setIsIncendiary(false); fireballRed.setYield(current.explosionSize); - LargeFireball fireballBlue = world.spawn(blueStart.toLocation(world), LargeFireball.class); + LargeFireball fireballBlue = Config.world.spawn(blueStart.toLocation(Config.world), LargeFireball.class); vector.setZ(vector.getZ() * -1); fireballBlue.setDirection(vector); fireballBlue.setBounce(false); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index a62ea3f..5c2b0ee 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -33,14 +33,18 @@ import org.bukkit.GameMode; import org.bukkit.Sound; import org.bukkit.entity.Player; -import java.util.Collections; -import java.util.List; +import java.util.*; public class Fight { private Fight(){} 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); + private static final Collection teams = new HashSet<>(); + static { + teams.add(redTeam); + teams.add(blueTeam); + } public static FightTeam getPlayerTeam(Player player) { if(redTeam.isPlayerInTeam(player)) @@ -87,6 +91,10 @@ public class Fight { return blueTeam; } + public static Collection teams() { + return teams; + } + public static FightTeam getUnrotated() { return Config.BlueRotate ? Fight.getRedTeam() : Fight.getBlueTeam(); } @@ -117,7 +125,7 @@ public class Fight { } } - if(FightSystem.getEventLeiter() == player || Config.test()) + if(Config.test() || Config.isReferee(player)) return; Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java index b0d6b8e..6dd1cdc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightSchematic.java @@ -133,7 +133,7 @@ public class FightSchematic extends StateDependent { Vector dims = WorldeditWrapper.impl.getDimensions(clipboard); WorldeditWrapper.impl.pasteClipboard( clipboard, - new Location(Bukkit.getWorlds().get(0), region.centerX(), region.getMinY(), region.centerZ()), + new Location(Config.world, region.centerX(), region.getMinY(), region.centerZ()), new Vector( Config.PasteAligned && Config.BlueToRedX != 0 ? region.getSizeX()/2.0 - dims.getBlockX() : -dims.getBlockX()/2.0, Config.WaterDepth != 0 ? Config.WaterDepth - WorldeditWrapper.impl.getWaterDepth(clipboard) : 0, @@ -191,17 +191,15 @@ public class FightSchematic extends StateDependent { length -= 1; AffineTransform aT = new AffineTransform().rotateY(rotate ? 180 : 0); - Location base = new Location(Bukkit.getWorlds().get(0), region.centerX(), team.getExtendRegion().getMaxY(), region.centerZ()); + Location base = new Location(Config.world, region.centerX(), team.getExtendRegion().getMaxY(), region.centerZ()); for(int i = 0; i < characters.length; i++){ WorldeditWrapper.impl.pasteClipboard(characters[i], base, new Vector(offsets[i] - length/2, 0, -region.getSizeZ()/2), aT); } } 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); + Block block = Config.world.getBlockAt(x, y, z); if(block.getType() == target) block.setType(replacement); }); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index eac082b..8071f7c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -217,8 +217,8 @@ public class FightTeam { BountifulWrapper.impl.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(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build()); - player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributs().setDisplayName(FightSystem.getMessage().parse("RESPAWN", player)).build()); + player.getInventory().setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build()); + player.getInventory().setItem(7, new ItemBuilder(Material.BEACON).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("RESPAWN", player)).build()); GlobalRecorder.getInstance().playerJoins(player); TechHider.reloadChunks(player, chunksToReload, false); @@ -268,7 +268,7 @@ public class FightTeam { if(!players.isEmpty()) { setLeader(players.values().iterator().next(), false); }else if(FightState.getFightState() != FightState.PRE_LEADER_SETUP && !ArenaMode.RankedEvent.contains(Config.mode)){ - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), FightSystem::setPreLeaderState, 1); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> FightState.setFightState(FightState.PRE_LEADER_SETUP), 1); } } @@ -295,22 +295,22 @@ public class FightTeam { Player player = leader.getPlayer(); Inventory inventory = leader.getPlayer().getInventory(); if (Kit.getAvailableKits(true).size() > 1 || Config.PersonalKits) - inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build()); + inventory.setItem(1, new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_KIT", player)).build()); else inventory.setItem(1, new ItemBuilder(Material.AIR).build()); if(!ArenaMode.RankedEvent.contains(Config.mode)){ - inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName(FightSystem.getMessage().parse("INVITE_PLAYERS", player)).build()); - inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName(FightSystem.getMessage().parse("REMOVE_PLAYERS", player)).build()); + inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("INVITE_PLAYERS", player)).build()); + inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributes().setDisplayName(FightSystem.getMessage().parse("REMOVE_PLAYERS", player)).build()); } - inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", player)).build()); + inventory.setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", player)).build()); if(Config.test() || FightState.getFightState() != FightState.POST_SCHEM_SETUP) - inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_SCHEMATIC", player, Config.GameName)).build()); + inventory.setItem(0, new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("CHOOSE_SCHEMATIC", player, Config.GameName)).build()); if(FightState.getFightState() == FightState.PRE_LEADER_SETUP && !Fight.getOpposite(this).isLeaderless()){ - FightSystem.setPreSchemState(); + FightState.setFightState(FightState.PRE_SCHEM_SETUP); } } @@ -340,7 +340,7 @@ public class FightTeam { if(Config.test()) this.schematic.enable(); else if(Fight.getOpposite(this).schematic.hasSchematic()){ - FightSystem.setPostSchemState(); + FightState.setFightState(FightState.POST_SCHEM_SETUP); } } @@ -363,12 +363,12 @@ public class FightTeam { this.ready = ready; if(ready) { - l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributs().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName(FightSystem.getMessage().parse("TEAM_READY", l)).build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).setDisplayName(FightSystem.getMessage().parse("TEAM_READY", l)).build()); broadcast("TEAM_READY"); if(Fight.getOpposite(this).isReady() || ArenaMode.SoloLeader.contains(Config.mode)) - FightSystem.setPreRunningState(); + FightState.setFightState(FightState.PRE_RUNNING); } else { - l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributs().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", l)).build()); + l.getInventory().setItem(4, new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).setDisplayName(FightSystem.getMessage().parse("TEAM_NOT_READY", l)).build()); broadcast("TEAM_NOT_READY"); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java index 6afe6a3..914a138 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.fight; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; @@ -28,13 +29,11 @@ import de.steamwar.fightsystem.utils.FlatteningWrapper; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; -import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; public class FightWorld extends StateDependent { - private static final World world = Bukkit.getWorlds().get(0); private static final boolean paper = Bukkit.getVersion().contains("git-Paper"); public static boolean isPaper(){ @@ -58,22 +57,21 @@ public class FightWorld extends StateDependent { public static void forceLoad(){ Config.ArenaRegion.forEachChunk((cX, cZ) -> { - world.loadChunk(cX, cZ); - FlatteningWrapper.impl.forceLoadChunk(world, cX, cZ); + Config.world.loadChunk(cX, cZ); + FlatteningWrapper.impl.forceLoadChunk(Config.world, cX, cZ); }); } public static void resetWorld(){ - for(Entity entity : world.getEntities()){ - if(entity.getType() != EntityType.PLAYER && (!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(entity.getLocation()))) { + Recording.iterateOverEntities(entity -> true, entity -> { + if(entity.getType() != EntityType.PLAYER && (!Config.ArenaLeaveable || Config.ArenaRegion.inRegion(entity.getLocation()))) entity.remove(); - } - } + }); - World backup = new WorldCreator(world.getName() + "/backup").createWorld(); + World backup = new WorldCreator(Config.world.getName() + "/backup").createWorld(); assert backup != null; Config.ArenaRegion.forEachChunk((x, z) -> { - CraftbukkitWrapper.impl.resetChunk(world, backup, x, z); + CraftbukkitWrapper.impl.resetChunk(Config.world, backup, x, z); for(Player p : Bukkit.getOnlinePlayers()) { de.steamwar.core.CraftbukkitWrapper.impl.sendChunk(p, x, z); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 5e51e65..61317ea 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -19,11 +19,11 @@ package de.steamwar.fightsystem.listener; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.WorldOfColorWrapper; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; @@ -41,10 +41,12 @@ public class ArrowStopper { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } + private static final Class entityArrow = Reflection.getClass("{nms.world.entity.projectile}.EntityArrow"); private void run() { - for (Arrow arrow : Bukkit.getWorlds().get(0).getEntitiesByClass(Arrow.class)) { + Recording.iterateOverEntities(entityArrow::isInstance, entity -> { + Arrow arrow = (Arrow) entity; if (invalidEntity(arrow)) - continue; + return; Location prevLocation = arrow.getLocation().toVector().subtract(arrow.getVelocity()).toLocation(arrow.getWorld()); if (arrow.getTicksLived() == 0){ @@ -52,12 +54,12 @@ public class ArrowStopper { if(projSource instanceof Player) prevLocation = ((Player) arrow.getShooter()).getEyeLocation(); else - continue; + return; } if (checkBlocks(arrow.getLocation().getBlock(), prevLocation.getBlock())) { arrow.remove(); } - } + }); } private boolean checkBlocks(Block start, Block end) { @@ -95,8 +97,4 @@ public class ArrowStopper { WorldOfColorWrapper.impl.isInBlock(entity) || entity.getVelocity().equals(NULL_VECTOR); } - - public interface IArrowStopper { - boolean isInBlock(Arrow e); - } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java index c562a60..9becb1f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Chat.java @@ -54,7 +54,7 @@ public class Chat implements Listener { } else { broadcastChat("PARTICIPANT_CHAT", teamName, player.getName(), message); } - }else if(player == FightSystem.getEventLeiter()){ + }else if(Config.isReferee(player)){ broadcastChat("FIGHTLEADER_CHAT", player.getName(), message); }else{ broadcastChat("SPECTATOR_CHAT", player.getName(), message); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java index df67914..dbc5b07 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ClickAnalyzer.java @@ -19,8 +19,8 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.io.*; @@ -32,7 +32,7 @@ public class ClickAnalyzer { static { try { - output = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(Bukkit.getWorlds().get(0).getWorldFolder(), "clicks.csv")))); + output = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(Config.world.getWorldFolder(), "clicks.csv")))); } catch (FileNotFoundException e) { throw new SecurityException(e); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java index dc31e1e..6630bec 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/EventJoin.java @@ -32,7 +32,6 @@ 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; public class EventJoin implements Listener { @@ -49,7 +48,7 @@ public class EventJoin implements Listener { SteamwarUser user = SteamwarUser.get(player.getUniqueId()); if(user.getTeam() == Config.EventTeamBlueID || user.getTeam() == Config.EventTeamRedID || - user.getId() == FightSystem.getEventFight().getKampfleiter()) + Config.isReferee(player)) return; event.disallow(PlayerLoginEvent.Result.KICK_OTHER, FightSystem.getMessage().parse("NO_PARTICIPANT", player)); @@ -60,10 +59,8 @@ public class EventJoin implements Listener { Player player = event.getPlayer(); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(user.getId() == FightSystem.getEventFight().getKampfleiter()){ - FightSystem.setEventLeiter(player); + if(Config.isReferee(player)) return; - } if(FightState.Setup.contains(FightState.getFightState())){ FightTeam team = null; @@ -93,12 +90,4 @@ public class EventJoin implements Listener { if(Config.LiveReplay) player.kickPlayer(FightSystem.getMessage().parse("NO_PARTICIPANT", player)); } - - @EventHandler - public void handlePlayerLeave(PlayerQuitEvent event){ - Player player = event.getPlayer(); - - if(player == FightSystem.getEventLeiter()) - FightSystem.setEventLeiter(null); - } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java index c8c08c4..371ae75 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/NormalJoin.java @@ -20,7 +20,6 @@ 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; @@ -39,14 +38,12 @@ public class NormalJoin implements Listener { @EventHandler public void handlePlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); + if (Fight.getPlayerTeam(player) != null) + return; - if (fightTeam == null) { - if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) { - Fight.getBlueTeam().addMember(player); - }else if(Fight.getRedTeam().canbeLeader(player)) { - Fight.getRedTeam().addMember(player); - } - } + FightTeam team = Fight.teams().stream().filter(t -> player.getUniqueId().equals(t.getDesignatedLeader())).findAny( // Player is designated leader of a team + ).orElse(Fight.teams().stream().filter(t -> t.canbeLeader(player)).findAny().orElse(null)); // Else search empty team + if(team != null) + team.addMember(player); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java index c411a48..288eda7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/PrepareSchem.java @@ -33,7 +33,6 @@ import de.steamwar.fightsystem.utils.Region; import de.steamwar.fightsystem.utils.WorldeditWrapper; import de.steamwar.sql.SchematicNode; import org.bukkit.Bukkit; -import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -50,9 +49,8 @@ public class PrepareSchem implements Listener { public PrepareSchem() { new OneShotStateDependent(ArenaMode.Prepare, FightState.PostSchemSetup, () -> Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { stationaryMovingPistons.clear(); - World world = Bukkit.getWorlds().get(0); Fight.getUnrotated().getSchemRegion().forEach((x, y, z) -> { - if(FlatteningWrapper.impl.checkPistonMoving(world.getBlockAt(x, y, z))) + if(FlatteningWrapper.impl.checkPistonMoving(Config.world.getBlockAt(x, y, z))) stationaryMovingPistons.add(new Vector(x, y, z)); }); }, 1)); @@ -61,7 +59,6 @@ public class PrepareSchem implements Listener { @Override public void disable() { super.disable(); - World world = Bukkit.getWorlds().get(0); Region region = Fight.getUnrotated().getExtendRegion(); int minY = Fight.getUnrotated().getSchemRegion().getMinY(); @@ -76,7 +73,7 @@ public class PrepareSchem implements Listener { try{ region.forEach((x, y, z) -> { - if(FlatteningWrapper.impl.checkPistonMoving(world.getBlockAt(x, y, z)) && !stationaryMovingPistons.contains(new Vector(x, y, z))){ + if(FlatteningWrapper.impl.checkPistonMoving(Config.world.getBlockAt(x, y, z)) && !stationaryMovingPistons.contains(new Vector(x, y, z))){ FightSystem.getMessage().broadcast("PREPARE_ACTIVE_PISTON"); Bukkit.shutdown(); throw new IllegalStateException(); @@ -116,8 +113,8 @@ public class PrepareSchem implements Listener { } if(FightState.getFightState() == FightState.PRE_LEADER_SETUP) { - FightSystem.setPreSchemState(); - FightSystem.setPostSchemState(); + FightState.setFightState(FightState.PRE_SCHEM_SETUP); + FightState.setFightState(FightState.POST_SCHEM_SETUP); } schemExists(SchematicNode.getSchematicNode(Config.PrepareSchemID)); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index c68906c..7cec941 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -34,11 +34,9 @@ import de.steamwar.fightsystem.utils.*; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.entity.Entity; 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; @@ -50,12 +48,13 @@ import org.bukkit.event.player.*; import org.bukkit.inventory.ItemStack; import java.util.Random; +import java.util.function.Consumer; +import java.util.function.Predicate; public class Recording implements Listener { private static final int AIR = 0; private static final Random random = new Random(); - private static final World world = Bukkit.getWorlds().get(0); public static ItemStack disarmNull(ItemStack stack){ if(stack == null) @@ -68,22 +67,24 @@ public class Recording implements Listener { return fp == null || !fp.isLiving() || FightState.getFightState() == FightState.SPECTATE; } + public static final Class primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed"); + private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); + public static void iterateOverEntities(Predicate filter, Consumer consumer) { + CraftbukkitWrapper.impl.entityIterator().filter(filter).map(entity -> (Entity) getBukkitEntity.invoke(entity)).forEach(consumer); + } + public Recording() { new StateDependentListener(ArenaMode.AntiReplay, FightState.All, this); new StateDependentListener(ArenaMode.AntiReplay, FightState.All, BountifulWrapper.impl.newHandSwapRecorder()); new StateDependent(ArenaMode.AntiReplay, FightState.Ingame){ @Override public void enable() { - Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> { - setKitItems(Fight.getBlueTeam()); - setKitItems(Fight.getRedTeam()); - }, 1); + Bukkit.getScheduler().runTaskLater(FightSystem.getPlugin(), () -> Fight.teams().forEach(Recording.this::setKitItems), 1); } @Override public void disable() { - despawnTeam(Fight.getRedTeam()); - despawnTeam(Fight.getBlueTeam()); + Fight.teams().forEach(Recording.this::despawnTeam); despawnTNT(); } }.register(); @@ -106,14 +107,11 @@ public class Recording implements Listener { if(FightState.getFightState() == FightState.SPECTATE || !GlobalRecorder.getInstance().recording()) return; - CraftbukkitWrapper.impl.tntIterator().filter(primedTnt::isInstance).forEach(this::trackEntity); + iterateOverEntities(primedTnt::isInstance, this::trackEntity); }, 1, 1); } - private static final Class primedTnt = Reflection.getClass("{nms.world.entity.item}.EntityTNTPrimed"); - private static final Reflection.MethodInvoker getBukkitEntity = Reflection.getTypedMethod(Reflection.getClass("{nms.world.entity}.Entity"), "getBukkitEntity", null); - private void trackEntity(Object e) { - Entity entity = (Entity) getBukkitEntity.invoke(e); + private void trackEntity(Entity entity) { GlobalRecorder.getInstance().entityMoves(entity); GlobalRecorder.getInstance().entitySpeed(entity); } @@ -297,7 +295,6 @@ public class Recording implements Listener { } private void despawnTNT(){ - for(TNTPrimed tnt : Bukkit.getWorlds().get(0).getEntitiesByClass(TNTPrimed.class)) - GlobalRecorder.getInstance().entityDespawns(tnt); + iterateOverEntities(primedTnt::isInstance, GlobalRecorder.getInstance()::entityDespawns); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java index 2dfaf34..44aef93 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -54,12 +54,11 @@ public class TeamArea implements Listener { @EventHandler public void teamAreas(PlayerMoveEvent event) { Player player = event.getPlayer(); - if(player == FightSystem.getEventLeiter()) + if(Config.isReferee(player)) return; FightTeam team = Fight.getPlayerTeam(player); - checkInTeamRegion(event, Fight.getBlueTeam(), player, team); - checkInTeamRegion(event, Fight.getRedTeam(), player, team); + Fight.teams().forEach(t -> checkInTeamRegion(event, t, player, team)); } @EventHandler diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java index faa7109..dc65ffd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TestJoin.java @@ -49,15 +49,15 @@ public class TestJoin implements Listener { return; } - if (fightTeam == null && (Fight.getRedTeam().isLeaderless() || Fight.getBlueTeam().isLeaderless())) { + if (fightTeam == null && Fight.teams().stream().anyMatch(team -> team.canbeLeader(player))) { FightSystem.getMessage().send("TEST_BECOME_LEADER", player); } player.setOp(true); if(FightState.getFightState() == FightState.PRE_LEADER_SETUP){ - FightSystem.setPreSchemState(); - FightSystem.setPostSchemState(); + FightState.setFightState(FightState.PRE_SCHEM_SETUP); + FightState.setFightState(FightState.POST_SCHEM_SETUP); } } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index d555ad0..a7097fb 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -60,11 +60,10 @@ public class WaterRemover implements Listener { return; Location location = event.getLocation(); - if (Config.BlueExtendRegion.inRegion(location)) { - tnt.put(event.getEntity().getEntityId(), Fight.getBlueTeam()); - } else if (Config.RedExtendRegion.inRegion(location)) { - tnt.put(event.getEntity().getEntityId(), Fight.getRedTeam()); - } + Fight.teams().forEach(team -> { + if(team.getExtendRegion().inRegion(location)) + tnt.put(event.getEntity().getEntityId(), team); + }); } @EventHandler diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java index 136c07e..67d39bc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -22,14 +22,13 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import org.bukkit.Bukkit; import java.io.*; import java.util.zip.GZIPOutputStream; public class FileRecorder extends StateDependent implements Recorder { - private static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "recording.recording"); + private static final File file = new File(Config.world.getWorldFolder(), "recording.recording"); private DataOutputStream outputStream; public static File getFile() { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index b24d0bc..f94c3ed 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -39,7 +39,6 @@ import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Sound; -import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.scheduler.BukkitTask; @@ -50,8 +49,6 @@ import java.util.logging.Level; public class PacketProcessor { - private static final World world = Bukkit.getWorlds().get(0); - private static PacketProcessor currentProcessor = null; public static PacketProcessor currentReplay() { @@ -348,7 +345,7 @@ public class PacketProcessor { if(!Config.ArenaRegion.in2dRegion(x, z)) return; //Outside of the arena - execSync(() -> BlockIdWrapper.impl.setBlock(world, x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); + execSync(() -> BlockIdWrapper.impl.setBlock(Config.world, x, y, z, TechHider.ENABLED && hiddenBlockIds.contains(blockState) ? obfuscateWith : blockState)); } private void particle() throws IOException { @@ -364,7 +361,7 @@ public class PacketProcessor { double finalX = x; double finalZ = z; - execSync(() -> BountifulWrapper.impl.spawnParticle(world, particleName, finalX + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), finalZ + Config.ArenaRegion.getMinZ())); + execSync(() -> BountifulWrapper.impl.spawnParticle(Config.world, particleName, finalX + Config.ArenaRegion.getMinX(), y + Config.BluePasteRegion.getMinY(), finalZ + Config.ArenaRegion.getMinZ())); } private void sound() throws IOException { @@ -388,7 +385,7 @@ public class PacketProcessor { Sound sound = Sound.valueOf(soundName); - execSync(() -> WorldOfColorWrapper.impl.playSound(new Location(world, x, y, z), sound, soundCategory, volume, pitch)); + execSync(() -> WorldOfColorWrapper.impl.playSound(new Location(Config.world, x, y, z), sound, soundCategory, volume, pitch)); } private void soundAtPlayer() throws IOException { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java index 7fc6618..eb31336 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/Recorder.java @@ -53,8 +53,7 @@ public interface Recorder { } arenaInfo(); - enableTeam(Fight.getBlueTeam()); - enableTeam(Fight.getRedTeam()); + Fight.teams().forEach(this::enableTeam); } default void enableTeam(FightTeam team){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java index 4d262e5..f9e65e7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BlockIdWrapper.java @@ -26,18 +26,14 @@ import org.bukkit.block.Block; import java.util.Set; -public class BlockIdWrapper { - private BlockIdWrapper() {} +public interface BlockIdWrapper { + BlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final IBlockIdWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + int blockToId(Block block); + void setBlock(World world, int x, int y, int z, int blockState); - public interface IBlockIdWrapper { - int blockToId(Block block); - void setBlock(World world, int x, int y, int z, int blockState); + Set getHiddenBlockIds(); + int getObfuscateWith(); - Set getHiddenBlockIds(); - int getObfuscateWith(); - - Object getPose(boolean sneaking); - } + Object getPose(boolean sneaking); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index 5149f87..e40939e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -29,33 +29,29 @@ import org.bukkit.scoreboard.Team; import java.util.UUID; -public class BountifulWrapper { - private BountifulWrapper() {} +public interface BountifulWrapper { + BountifulWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final IBountifulWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + boolean mainHand(Object packet); + boolean bowInHand(boolean mainHand, Player p); - public interface IBountifulWrapper { - boolean mainHand(Object packet); - boolean bowInHand(boolean mainHand, Player p); + void setAttackSpeed(Player player); - void setAttackSpeed(Player player); + void setNametagVisibility(Team team); - void setNametagVisibility(Team team); + Listener newDenyArrowPickupListener(); + Listener newDenyHandSwapListener(); - Listener newDenyArrowPickupListener(); - Listener newDenyHandSwapListener(); + void recordHandItems(Player player); + Listener newHandSwapRecorder(); - void recordHandItems(Player player); - Listener newHandSwapRecorder(); + void spawnParticle(World world, String particleName, double x, double y, double z); - void spawnParticle(World world, String particleName, double x, double y, double z); + Object getDataWatcherObject(int index, Class type); + Object getDataWatcherItem(Object dataWatcherObject, Object value); + void setTeleportPacketPosition(Object packet, double x, double y, double z); + void setSpawnPacketUUID(Object packet, UUID uuid); + void setNamedSpawnPosition(Object packet, double x, double y, double z); - Object getDataWatcherObject(int index, Class type); - Object getDataWatcherItem(Object dataWatcherObject, Object value); - void setTeleportPacketPosition(Object packet, double x, double y, double z); - void setSpawnPacketUUID(Object packet, UUID uuid); - void setNamedSpawnPosition(Object packet, double x, double y, double z); - - void sendBar(Player player, FightTeam team, double progress, String text); - } + void sendBar(Player player, FightTeam team, double progress, String text); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java index f9ebb3c..cae8b77 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BungeeFightInfo.java @@ -44,7 +44,7 @@ public class BungeeFightInfo { return; new FightInfoPacket( - Bukkit.getWorlds().get(0).getName(), + Config.world.getName(), Config.SchematicType.toDB(), "", Fight.getBlueTeam().getColoredName(), diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java index 5df31ee..1771d79 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper.java @@ -28,17 +28,13 @@ import org.bukkit.inventory.ItemStack; import java.util.stream.Stream; -public class CraftbukkitWrapper { - private CraftbukkitWrapper() {} +public interface CraftbukkitWrapper { + CraftbukkitWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final ICraftbukkitWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + void resetChunk(World world, World backup, int x, int z); + void sendResourcePack(Player player, String pack, String sha1); + float headRotation(Entity e); + boolean hasItems(ItemStack stack); - public interface ICraftbukkitWrapper { - void resetChunk(World world, World backup, int x, int z); - void sendResourcePack(Player player, String pack, String sha1); - float headRotation(Entity e); - boolean hasItems(ItemStack stack); - - Stream tntIterator(); - } + Stream entityIterator(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java index 01b12dd..cec63a4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -43,14 +43,12 @@ public class EnterHandler implements IStateDependent { @Override public void enable() { - registerTeam(Fight.getBlueTeam()); - registerTeam(Fight.getRedTeam()); + Fight.teams().forEach(this::registerTeam); } @Override public void disable() { - unregisterTeam(Fight.getBlueTeam()); - unregisterTeam(Fight.getRedTeam()); + Fight.teams().forEach(this::unregisterTeam); } private void registerTeam(FightTeam team){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index f1e6e25..52a2a26 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -68,11 +68,11 @@ public class FightStatistics { private void setEventResult() { if (FightSystem.getLastWinner() == null) - FightSystem.getEventFight().setErgebnis(0); + Config.EventKampf.setErgebnis(0); else if (FightSystem.getLastWinner().isBlue()) - FightSystem.getEventFight().setErgebnis(1); + Config.EventKampf.setErgebnis(1); else - FightSystem.getEventFight().setErgebnis(2); + Config.EventKampf.setErgebnis(2); } private void disable() { @@ -110,7 +110,7 @@ public class FightStatistics { } try { - int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime, + int fightId = create(gameMode, Config.world.getName(), starttime, remainingTime, blueLeader, redLeader, blueSchem, redSchem, win, windescription); for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) @@ -119,7 +119,7 @@ public class FightStatistics { savePlayerStats(fp, fightId); if (ArenaMode.Event.contains(Config.mode)) { - FightSystem.getEventFight().setFight(fightId); + Config.EventKampf.setFight(fightId); } try { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java index 34c4c4f..57a9b27 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java @@ -28,28 +28,24 @@ import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -public class FlatteningWrapper { - private FlatteningWrapper() {} +public interface FlatteningWrapper { + FlatteningWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final IFlatteningWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + DyeColor getSilver(); - public interface IFlatteningWrapper { - DyeColor getSilver(); + boolean isWater(Block block); + boolean removeWater(Block block); - boolean isWater(Block block); - boolean removeWater(Block block); + boolean containsBlockMeta(ItemMeta meta); + boolean hasAttributeModifier(ItemStack stack); - boolean containsBlockMeta(ItemMeta meta); - boolean hasAttributeModifier(ItemStack stack); + ItemStack onBreak(Block type); - ItemStack onBreak(Block type); + boolean doRecord(BlockPhysicsEvent e); - boolean doRecord(BlockPhysicsEvent e); + void forceLoadChunk(World world, int cX, int cZ); - void forceLoadChunk(World world, int cX, int cZ); + boolean checkPistonMoving(Block block); - boolean checkPistonMoving(Block block); - - void setNamedSpawnPacketDataWatcher(Object packet); - } + void setNamedSpawnPacketDataWatcher(Object packet); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java index 6161ae0..e7bac5d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java @@ -48,7 +48,7 @@ public class ItemBuilder { meta = item.getItemMeta(); } - public ItemBuilder removeAllAttributs() { + public ItemBuilder removeAllAttributes() { meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); meta.addItemFlags(ItemFlag.HIDE_DESTROYS); meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java index 933dae9..25f22ac 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/TechHider.java @@ -161,7 +161,7 @@ public class TechHider extends StateDependent { } public static boolean bypass(Player p, int chunkX, int chunkZ){ - if(p == FightSystem.getEventLeiter()) + if(Config.isReferee(p)) return true; FightTeam ft = Fight.getPlayerTeam(p); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java index 8ca148a..3e074e5 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java @@ -28,17 +28,13 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.Player; import org.bukkit.scoreboard.Team; -public class WorldOfColorWrapper { - private WorldOfColorWrapper() {} +public interface WorldOfColorWrapper { + WorldOfColorWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final IWorldOfColorWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); + void setTeamColor(Team team, ChatColor color); + boolean isInBlock(Arrow e); - public interface IWorldOfColorWrapper { - void setTeamColor(Team team, ChatColor color); - boolean isInBlock(Arrow e); + void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch); - void playSound(Location location, Sound sound, String soundCategory, float volume, float pitch); - - void sendTitle(Player player, String title, String subtitle, int start, int hold, int stop); - } + void sendTitle(Player player, String title, String subtitle, int start, int hold, int stop); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java index 4f19e69..83c6880 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldeditWrapper.java @@ -31,17 +31,13 @@ import org.bukkit.util.Vector; import java.io.IOException; -public class WorldeditWrapper { - private WorldeditWrapper() {} +public interface WorldeditWrapper { + WorldeditWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - public static final IWorldeditWrapper impl = VersionDependent.getVersionImpl(FightSystem.getPlugin()); - - public interface IWorldeditWrapper { - void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; - int getWaterDepth(Clipboard clipboard); - void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); - Vector getDimensions(Clipboard clipboard); - Clipboard loadChar(String charName) throws IOException; - void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException; - } + void replaceTeamColor(Clipboard clipboard, DyeColor c) throws WorldEditException; + int getWaterDepth(Clipboard clipboard); + void pasteClipboard(Clipboard clipboard, Location position, Vector offset, AffineTransform aT); + Vector getDimensions(Clipboard clipboard); + Clipboard loadChar(String charName) throws IOException; + void saveSchem(SchematicNode schem, Region region, int minY) throws WorldEditException; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index e71a468..77db2ff 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -23,33 +23,19 @@ 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 de.steamwar.fightsystem.states.OneShotStateDependent; public class EventTeamOffWincondition extends Wincondition{ public EventTeamOffWincondition(){ super("TeamOffline"); - new StateDependent(ArenaMode.Event, FightState.PreRunning) { - @Override - public void enable() { - if(Fight.getBlueTeam().allPlayersOut() && Fight.getRedTeam().allPlayersOut()){ - win(null, "WIN_OFFLINE_BOTH"); - }else{ - teamOff(Fight.getBlueTeam()); - teamOff(Fight.getRedTeam()); - } + new OneShotStateDependent(ArenaMode.Event, FightState.PreRunning, () -> { + if(Fight.teams().stream().allMatch(FightTeam::allPlayersOut)){ + win(null, "WIN_OFFLINE_BOTH"); + }else{ + Fight.teams().stream().filter(FightTeam::allPlayersOut).findAny( + ).ifPresent(team -> win(Fight.getOpposite(team), "WIN_OFFLINE", team.getColoredName())); } - - @Override - public void disable() { - //Team off is a one time trigger - } - }.register(); - } - - private void teamOff(FightTeam team){ - if(team.allPlayersOut()){ - win(Fight.getOpposite(team), "WIN_OFFLINE", team.getColoredName()); - } + }); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java index c0e481c..a188528 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/PercentWincondition.java @@ -26,9 +26,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.Message; -import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -44,8 +42,6 @@ import java.util.function.ToIntFunction; public class PercentWincondition extends Wincondition implements PrintableWincondition { - private static final World world = Bukkit.getWorlds().get(0); - private final Map teamMap = new HashMap<>(); protected BooleanSupplier explosionFilter = () -> !Config.EnterStages.isEmpty() && Config.EnterStages.get(0) >= Wincondition.getTimeOverCountdown().getTimeLeft(); @@ -53,7 +49,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon protected ToIntFunction totalBlockCalc = team -> { AtomicInteger blocks = new AtomicInteger(); team.getSchemRegion().forEach((x, y, z) -> { - if (testBlock.test(world.getBlockAt(x, y, z).getType())) { + if (testBlock.test(Config.world.getBlockAt(x, y, z).getType())) { blocks.getAndIncrement(); } }); @@ -74,8 +70,7 @@ public class PercentWincondition extends Wincondition implements PrintableWincon percentWincondition = this; } - new TeamPercent(Fight.getBlueTeam(), wincondition); - new TeamPercent(Fight.getRedTeam(), wincondition); + Fight.teams().forEach(team -> new TeamPercent(team, wincondition)); } public Message getDisplay(FightTeam team) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java index 06f4138..a01d660 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -28,6 +28,8 @@ import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.List; +import java.util.function.ToDoubleFunction; +import java.util.stream.Collectors; public abstract class Wincondition { @@ -58,4 +60,17 @@ public abstract class Wincondition { public static List getPrintableWinconditions(){ return printableWinconditions; } + + public static PercentWincondition getPercentWincondition() { + return percentWincondition; + } + + protected void comparisonWin(ToDoubleFunction evaluate, String winMessage, String tieMessage) { + double max = Fight.teams().stream().mapToDouble(evaluate).max().orElseThrow(() -> new SecurityException("No teams present")); + List teams = Fight.teams().stream().filter(team -> evaluate.applyAsDouble(team) == max).collect(Collectors.toList()); + if(teams.size() > 1) + win(null, tieMessage); + else + win(teams.get(0), winMessage, teams.get(0).getColoredName()); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java similarity index 54% rename from FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java index 86bc839..b9b0c9f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionBlocks.java @@ -24,71 +24,69 @@ 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.fightsystem.utils.FlatteningWrapper; import de.steamwar.fightsystem.utils.Message; -import org.bukkit.Bukkit; -import org.bukkit.World; +import de.steamwar.inventory.SWItem; +import org.bukkit.Material; import org.bukkit.block.Block; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Predicate; -public class WinconditionWaterTechKO extends Wincondition implements PrintableWincondition { +public class WinconditionBlocks extends Wincondition implements PrintableWincondition { - private static final World WORLD = Bukkit.getWorlds().get(0); + public static final Material PUMPKIN_LANTERN = SWItem.getMaterial("JACK_O_LANTERN"); - private final Map teamMap = new HashMap<>(); + private final Map teamMap = new HashMap<>(); + private final String barMessage; + private final Predicate isOfType; - public WinconditionWaterTechKO() { - super("WaterTechKO"); - teamMap.put(Fight.getBlueTeam(), new TeamWater(Fight.getBlueTeam())); - teamMap.put(Fight.getRedTeam(), new TeamWater(Fight.getRedTeam())); + public WinconditionBlocks(Winconditions wincondition, String windescription, String barMessage, Predicate isOfType) { + super(windescription); + this.barMessage = barMessage; + this.isOfType = isOfType; + Fight.teams().forEach(team -> teamMap.put(team, new TeamBlocks(team))); - new StateDependentTask(Winconditions.WATER_TECH_KO, FightState.Ingame, this::check, 200, 200){ + new StateDependentTask(wincondition, FightState.Ingame, () -> teamMap.values().forEach(TeamBlocks::check), 200, 200){ @Override public void enable() { - teamMap.values().forEach(TeamWater::find); + teamMap.values().forEach(TeamBlocks::find); super.enable(); } }; - if(Config.ActiveWinconditions.contains(Winconditions.WATER_TECH_KO)){ - printableWinconditions.add(this); - } - } - private void check() { - teamMap.values().forEach(TeamWater::check); + if(Config.ActiveWinconditions.contains(wincondition)) + printableWinconditions.add(this); } @Override public Message getDisplay(FightTeam team) { - return new Message("BAR_WATER", team.getPrefix() + teamMap.get(team).water.size()); + return new Message(barMessage, team.getPrefix() + teamMap.get(team).blocks.size()); } - private class TeamWater { + private class TeamBlocks { private final FightTeam team; - private final List water = new ArrayList<>(); + private final List blocks = new ArrayList<>(); - private TeamWater(FightTeam team) { + private TeamBlocks(FightTeam team) { this.team = team; } private void find() { - water.clear(); + blocks.clear(); team.getExtendRegion().forEach((x, y, z) -> { - Block block = WORLD.getBlockAt(x, y, z); - if (FlatteningWrapper.impl.isWater(block)) - water.add(block); + Block block = Config.world.getBlockAt(x, y, z); + if (isOfType.test(block)) + blocks.add(block); }); } private void check() { - water.removeIf(block -> !FlatteningWrapper.impl.isWater(block)); - if(water.isEmpty()){ + blocks.removeIf(block -> !isOfType.test(block)); + if(blocks.isEmpty()) win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); - } } } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java similarity index 52% rename from FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java rename to FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.java index 35d705f..d3fa4c3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionComparisonTimeout.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 @@ -21,29 +21,18 @@ package de.steamwar.fightsystem.winconditions; import de.steamwar.fightsystem.Config; 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 Wincondition { +import java.util.function.ToDoubleFunction; - public WinconditionHeartRatioTimeout() { - super("HeartTimeout"); - if(Config.ActiveWinconditions.contains(Winconditions.HEART_RATIO_TIMEOUT)){ - timeOverCountdown = new StateDependentCountdown(Winconditions.HEART_RATIO_TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); - } - } +public class WinconditionComparisonTimeout extends Wincondition { - protected void timeOver() { - double blueHeartRatio = Fight.getBlueTeam().getHeartRatio(); - double redHeartRatio = Fight.getRedTeam().getHeartRatio(); - - if(blueHeartRatio > redHeartRatio) { - win(Fight.getBlueTeam(), "WIN_MORE_HEALTH", Fight.getBlueTeam().getPrefix()); - }else if(blueHeartRatio < redHeartRatio){ - win(Fight.getRedTeam(), "WIN_MORE_HEALTH", Fight.getRedTeam().getPrefix()); - }else{ - win(null, "WIN_TIME_OVER"); + public WinconditionComparisonTimeout(Winconditions wincondition, String windescription, String winMessage, ToDoubleFunction evaluate) { + super(windescription); + if(Config.ActiveWinconditions.contains(wincondition)) { + timeOverCountdown = new StateDependentCountdown(wincondition, FightState.Running, new TimeOverCountdown(() -> comparisonWin(evaluate, winMessage, "WIN_TIME_OVER"))); } } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java deleted file mode 100644 index 0d8b4f4..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPercentTimeout.java +++ /dev/null @@ -1,49 +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.winconditions; - -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.countdown.TimeOverCountdown; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentCountdown; - -public class WinconditionPercentTimeout extends Wincondition { - - public WinconditionPercentTimeout() { - super("PercentTimeout"); - if(Config.ActiveWinconditions.contains(Winconditions.PERCENT_TIMEOUT)) { - timeOverCountdown = new StateDependentCountdown(Winconditions.PERCENT_TIMEOUT, FightState.Running, new TimeOverCountdown(this::timeOver)); - } - } - - protected void timeOver() { - double bluePercent = Wincondition.percentWincondition.getPercent(Fight.getBlueTeam()); - double redPercent = Wincondition.percentWincondition.getPercent(Fight.getRedTeam()); - - if(bluePercent > redPercent) { - win(Fight.getRedTeam(), "WIN_LESS_DAMAGE", Fight.getRedTeam().getColoredName()); - }else if(bluePercent < redPercent){ - win(Fight.getBlueTeam(), "WIN_LESS_DAMAGE", Fight.getBlueTeam().getColoredName()); - }else{ - win(null, "WIN_TIME_OVER"); - } - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 10bf4cf..2d0396d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -46,8 +46,7 @@ public class WinconditionPoints extends PercentWincondition implements Listener checkWin = team -> {}; postEnable = this::pointInit; - teamMap.put(Fight.getBlueTeam(), new TeamPoints(Fight.getBlueTeam())); - teamMap.put(Fight.getRedTeam(), new TeamPoints(Fight.getRedTeam())); + Fight.teams().forEach(team -> teamMap.put(team, new TeamPoints(team))); new StateDependentListener(Winconditions.POINTS, FightState.Ingame, this); @@ -57,16 +56,7 @@ public class WinconditionPoints extends PercentWincondition implements Listener } private void timeOver() { - int redPoints = teamMap.get(Fight.getRedTeam()).getPoints(); - int bluePoints = teamMap.get(Fight.getBlueTeam()).getPoints(); - - if(bluePoints < redPoints) { - win(Fight.getRedTeam(), "WIN_POINTS", Fight.getRedTeam().getPrefix()); - }else if(bluePoints > redPoints){ - win(Fight.getBlueTeam(), "WIN_POINTS", Fight.getBlueTeam().getPrefix()); - }else{ - win(null, "WIN_POINTS_EQUAL"); - } + comparisonWin(team -> teamMap.get(team).getPoints(), "WIN_POINTS", "WIN_POINTS_EQUAL"); } @EventHandler diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java deleted file mode 100644 index b6cdfbb..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ /dev/null @@ -1,84 +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.winconditions; - -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.StateDependentTask; -import de.steamwar.fightsystem.utils.Message; -import de.steamwar.inventory.SWItem; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.World; - -import java.util.HashMap; -import java.util.Map; - -public class WinconditionPumpkinTechKO extends Wincondition implements PrintableWincondition { - - 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<>(); - - public WinconditionPumpkinTechKO(){ - super("PumpkinTechKO"); - 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(){ - teamMap.values().forEach(TeamPumpkin::check); - } - - @Override - public Message getDisplay(FightTeam team) { - return new Message("BAR_CANNONS", team.getPrefix() + 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; - team.getSchemRegion().forEach((x, y, z) -> { - if (world.getBlockAt(x, y, z).getType() == PUMPKIN_LANTERN) - pumpkins++; - }); - - if(pumpkins == 0) { - win(Fight.getOpposite(team), "WIN_TECHKO", team.getColoredName()); - } - } - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java index f1f6577..6e3135c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionTimeTechKO.java @@ -23,20 +23,17 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.listener.Recording; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.TNTPrimed; 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; - private final World world = Bukkit.getWorlds().get(0); private final double toggle = Config.SpecSpawn.getZ(); private final FightTeam smallerZteam; private final FightTeam biggerZteam; @@ -77,7 +74,7 @@ public class WinconditionTimeTechKO extends Wincondition { } private void run(){ - for(TNTPrimed tnt : world.getEntitiesByClass(TNTPrimed.class)){ + Recording.iterateOverEntities(Recording.primedTnt::isInstance, tnt -> { double z = tnt.getLocation().getZ(); boolean smallerZ = z < toggle; boolean wasSmallerZ = z - tnt.getVelocity().getZ() < toggle; @@ -94,7 +91,7 @@ public class WinconditionTimeTechKO extends Wincondition { biggerZcountdown = null; } } - } + }); if(smallerZtime == 0) smallerZcountdown = new TechKOCountdown(smallerZteam, TECH_KO_HALF_TIME / 20); -- 2.39.5 From c80de98733a149041a3564842a22899d5f2b3c3c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 9 Apr 2022 16:51:26 +0200 Subject: [PATCH 2/2] Wake AFK solo leaders with sound on opponent join Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 6466e21..e438033 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -32,6 +32,7 @@ import de.steamwar.fightsystem.listener.Shutdown; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.record.*; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; @@ -89,6 +90,7 @@ public class FightSystem extends JavaPlugin { new ArrowPickup(); new BlockFadeListener(); new LeaveableArena(); + new OneShotStateDependent(ArenaMode.All, FightState.PreSchemSetup, () -> Fight.playSound(SWSound.BLOCK_NOTE_PLING.getSound(), 100.0f, 2.0f)); new EnterHandler(); new TechHider(); -- 2.39.5