From 0edbe4be94627b7b98f4e53d2fb83159a3c1aa7e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 4 Jan 2024 23:55:31 +0100 Subject: [PATCH 01/13] Fix replay IllegalStateException Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 57cfa29..ab7cb7f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -201,7 +201,7 @@ public class Hull { while(rit.hasNext()) { REntity entity = rit.next(); if(uncoveredSet.contains(new IntVector(new Location(Config.world, entity.getX(), entity.getY(), entity.getZ())))) { //TODO more precise - it.remove(); + rit.remove(); entity.hide(false); } } From 869b883b2f004f0b677d19959ea1694bd74402f7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jan 2024 16:36:24 +0100 Subject: [PATCH 02/13] Fix WaterRemover for Water based armor Signed-off-by: Lixfel --- .../fightsystem/listener/WaterRemover.java | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index a7097fb..28fd444 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -71,23 +71,25 @@ public class WaterRemover implements Listener { event.setYield(0); //No drops (additionally to world config) FightTeam spawn = tnt.remove(event.getEntity().getEntityId()); - if(spawn != null && event.blockList().isEmpty() && Fight.getOpposite(spawn).getExtendRegion().inRegion(event.getLocation())) { - checkBlock(event.getLocation().getBlock()); + if(spawn != null && event.blockList().isEmpty() && !spawn.getExtendRegion().inRegion(event.getLocation())) { + Block b = event.getLocation().getBlock(); + checkBlock(b); + checkNeighbours(b); } - for(Block b : event.blockList()){ - //b cannot be water or air due to current explosion + event.blockList().forEach(this::checkNeighbours); + } - checkBlock(b.getRelative(BlockFace.UP)); - checkBlock(b.getRelative(BlockFace.EAST)); - checkBlock(b.getRelative(BlockFace.WEST)); - checkBlock(b.getRelative(BlockFace.NORTH)); - checkBlock(b.getRelative(BlockFace.SOUTH)); - } + private void checkNeighbours(Block b) { + checkBlock(b.getRelative(BlockFace.UP)); + checkBlock(b.getRelative(BlockFace.EAST)); + checkBlock(b.getRelative(BlockFace.WEST)); + checkBlock(b.getRelative(BlockFace.NORTH)); + checkBlock(b.getRelative(BlockFace.SOUTH)); } private void checkBlock(Block b) { - //do not remove outside teamareas + //do not remove outside teamareasevent.getLocation().getBlock() if(!Config.BlueExtendRegion.inRegion(b) && !Config.RedExtendRegion.inRegion(b)) return; @@ -98,10 +100,6 @@ public class WaterRemover implements Listener { if(b.getY() < MIN_Y) return; - checkBlock(b.getRelative(BlockFace.UP)); - checkBlock(b.getRelative(BlockFace.EAST)); - checkBlock(b.getRelative(BlockFace.WEST)); - checkBlock(b.getRelative(BlockFace.NORTH)); - checkBlock(b.getRelative(BlockFace.SOUTH)); + checkNeighbours(b); } } From 5d9aa147b75d500adc8d545ad637c4bebe651a01 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jan 2024 17:21:23 +0100 Subject: [PATCH 03/13] Fix WaterRemover: Remove empty blocklist check. Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/WaterRemover.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index 28fd444..1b53196 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -71,7 +71,7 @@ public class WaterRemover implements Listener { event.setYield(0); //No drops (additionally to world config) FightTeam spawn = tnt.remove(event.getEntity().getEntityId()); - if(spawn != null && event.blockList().isEmpty() && !spawn.getExtendRegion().inRegion(event.getLocation())) { + if(spawn != null && !spawn.getExtendRegion().inRegion(event.getLocation())) { Block b = event.getLocation().getBlock(); checkBlock(b); checkNeighbours(b); From faebc3cace7c002d554c5a6183b12e9876d688d7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jan 2024 17:32:28 +0100 Subject: [PATCH 04/13] Fix WaterRemover: Iterate downwards Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/WaterRemover.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java index 1b53196..05d6d2a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/WaterRemover.java @@ -86,6 +86,7 @@ public class WaterRemover implements Listener { checkBlock(b.getRelative(BlockFace.WEST)); checkBlock(b.getRelative(BlockFace.NORTH)); checkBlock(b.getRelative(BlockFace.SOUTH)); + checkBlock(b.getRelative(BlockFace.DOWN)); } private void checkBlock(Block b) { From 6d641856fe819732fb45e517efc255c62cd78a0f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 18 Jan 2024 01:16:56 +0100 Subject: [PATCH 05/13] (Untested) Explosion, Particle and Sound Hider Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/utils/Hull.java | 4 ++ .../steamwar/fightsystem/utils/HullHider.java | 60 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index ab7cb7f..838bc2f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -90,6 +90,10 @@ public class Hull { } } + public boolean isLocationHidden(Player player, Location location) { + return players.contains(player) && !visibility.get(new IntVector(location).toId(region)); + } + @SuppressWarnings("deprecation") public void addPlayer(Player player) { if(players.add(player)) { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 1d95eef..465204f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -19,8 +19,11 @@ package de.steamwar.fightsystem.utils; +import com.comphenix.tinyprotocol.Reflection; +import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.core.Core; import de.steamwar.entity.REntity; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -29,7 +32,9 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.techhider.TechHider; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -43,28 +48,41 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.function.BiFunction; +import java.util.function.Function; public class HullHider implements Listener { private static final boolean ENABLED = TechHiderWrapper.ENABLED && Core.getVersion() >= 18; private final Map hulls = new HashMap<>(); + private final Map, BiFunction> packetHiders = new HashMap<>(); public HullHider() { if(ENABLED) Fight.teams().forEach(team -> hulls.put(team, new Hull(team))); + packetHiders.put(packetPlayOutWorldEvent, this::worldEventHider); + packetHiders.put(packetPlayOutExplosion, this::explosionHider); + posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutWorldParticles", Core.getVersion() >= 18 ? double.class : float.class, 1.0); + posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutNamedSoundEffect", int.class, 8.0); + if(Core.getVersion() >= 9 && Core.getVersion() < 18) + posHiderGenerator("{nms.network.protocol.game}.PacketPlayOutCustomSoundEffect", int.class, 8.0); + new StateDependentListener(ENABLED, FightState.Schem, this); new StateDependent(ENABLED, FightState.Schem) { @Override public void enable() { + packetHiders.forEach(TinyProtocol.instance::addFilter); Bukkit.getOnlinePlayers().forEach(HullHider.this::updatePlayer); } @Override public void disable() { Bukkit.getOnlinePlayers().forEach(player -> removePlayer(player, true)); + packetHiders.forEach(TinyProtocol.instance::removeFilter); } }.register(); new StateDependentTask(ENABLED, FightState.Schem, this::onTick, 0, 1); @@ -144,4 +162,46 @@ public class HullHider implements Listener { public void despawnREntity(REntity e) { hulls.values().forEach(hull -> hull.removeREntity(e)); } + + + private static final Class packetPlayOutWorldEvent = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutWorldEvent"); + private static final Reflection.FieldAccessor worldEventPosition = Reflection.getField(packetPlayOutWorldEvent, TechHider.blockPosition, 0); + public static final Reflection.FieldAccessor blockPositionY = Reflection.getField("{nms.core}.BaseBlockPosition", int.class, 1); + private Object worldEventHider(Player player, Object packet) { + Object baseBlock = worldEventPosition.get(packet); + return packetHider(player, packet, new Location(Config.world, TechHider.blockPositionX.get(baseBlock), blockPositionY.get(baseBlock), TechHider.blockPositionZ.get(baseBlock))); + } + + private static final Class packetPlayOutExplosion = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion"); + private static final Reflection.FieldAccessor explosionBlocks = Reflection.getField(packetPlayOutExplosion, List.class, 0); + private static final Function explosionLocation = posPacketToLocation(packetPlayOutExplosion, double.class, 1.0); + private Object explosionHider(Player player, Object packet) { + if(explosionBlocks.get(packet).isEmpty()) + return packetHider(player, packet, explosionLocation.apply(packet)); + + return packet; + } + + private void posHiderGenerator(String typeName, Class posType, double factor) { + Class type = Reflection.getClass(typeName); + Function location = posPacketToLocation(type, posType, factor); + packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet))); + } + + private static Function posPacketToLocation(Class type, Class posType, double factor) { + Reflection.FieldAccessor x = Reflection.getField(type, posType, 0); + Reflection.FieldAccessor y = Reflection.getField(type, posType, 1); + Reflection.FieldAccessor z = Reflection.getField(type, posType, 2); + + return packet -> new Location(Config.world, (double)x.get(packet)/factor, (double)y.get(packet)/factor, (double)z.get(packet)/factor); + } + + private Object packetHider(Player player, Object packet, Location location) { + for(Hull hull : hulls.values()) { + if(hull.isLocationHidden(player, location)) + return null; + } + + return packet; + } } From 965bba1ea5ce587f058c9a8986a0510cf38e1c7b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 18 Jan 2024 23:45:28 +0100 Subject: [PATCH 06/13] Better sound location Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/Fight.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index e8966ab..9d59a0b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -21,6 +21,7 @@ package de.steamwar.fightsystem.fight; import com.comphenix.tinyprotocol.TinyProtocol; import com.mojang.authlib.GameProfile; +import de.steamwar.core.Core; import de.steamwar.core.ProtocolWrapper; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; @@ -94,7 +95,10 @@ public class Fight { public static void playSound(Sound sound, float volume, float pitch) { GlobalRecorder.getInstance().soundAtPlayer(sound.name(), volume, pitch); //volume: max. 100, pitch: max. 2 - Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); + if(Core.getVersion() >= 18) + Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player, sound, volume, pitch)); + else + Bukkit.getServer().getOnlinePlayers().forEach(player -> player.playSound(player.getLocation(), sound, volume, pitch)); } public static FightTeam getTeamByName(String name) { From 918f3096253acb2a14ed436b0954e6a0cf5cb2f9 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 18 Jan 2024 23:48:46 +0100 Subject: [PATCH 07/13] Join request with leader names instead of team names Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index 438bd1a..b2933bd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -50,7 +50,7 @@ public class GUI { @SuppressWarnings("deprecation") private static void addTeamRequest(Player p, SWInventory inv, int pos, FightTeam team) { byte colorCode = ColorConverter.chat2dye(team.getColor()).getDyeData(); - inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColoredName()), click -> { + inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + team.getLeader().getEntity().getName()), click -> { p.closeInventory(); new JoinRequest(p, team); }); From f5419a1a770e36a923bd6aeceafbed1fc0eef6cc Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Jan 2024 16:45:03 +0100 Subject: [PATCH 08/13] Fix Sound and Particle HullHider Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/Hull.java | 2 +- .../src/de/steamwar/fightsystem/utils/HullHider.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java index 838bc2f..118e564 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Hull.java @@ -91,7 +91,7 @@ public class Hull { } public boolean isLocationHidden(Player player, Location location) { - return players.contains(player) && !visibility.get(new IntVector(location).toId(region)); + return players.contains(player) && region.inRegion(location) && !visibility.get(new IntVector(location).toId(region)); } @SuppressWarnings("deprecation") diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java index 465204f..06363e3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/HullHider.java @@ -182,18 +182,18 @@ public class HullHider implements Listener { return packet; } - private void posHiderGenerator(String typeName, Class posType, double factor) { + private void posHiderGenerator(String typeName, Class posType, double factor) { Class type = Reflection.getClass(typeName); Function location = posPacketToLocation(type, posType, factor); packetHiders.put(type, (player, packet) -> packetHider(player, packet, location.apply(packet))); } - private static Function posPacketToLocation(Class type, Class posType, double factor) { - Reflection.FieldAccessor x = Reflection.getField(type, posType, 0); - Reflection.FieldAccessor y = Reflection.getField(type, posType, 1); - Reflection.FieldAccessor z = Reflection.getField(type, posType, 2); + private static Function posPacketToLocation(Class type, Class posType, double factor) { + Reflection.FieldAccessor x = Reflection.getField(type, posType, 0); + Reflection.FieldAccessor y = Reflection.getField(type, posType, 1); + Reflection.FieldAccessor z = Reflection.getField(type, posType, 2); - return packet -> new Location(Config.world, (double)x.get(packet)/factor, (double)y.get(packet)/factor, (double)z.get(packet)/factor); + return packet -> new Location(Config.world, x.get(packet).doubleValue()/factor, y.get(packet).doubleValue()/factor, z.get(packet).doubleValue()/factor); } private Object packetHider(Player player, Object packet, Location location) { From edc77ca2d4b23845dfa879f673598749dfab4259 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Jan 2024 17:51:44 +0100 Subject: [PATCH 09/13] Fix Name if leader null Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java index b2933bd..0fba538 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GUI.java @@ -50,7 +50,8 @@ public class GUI { @SuppressWarnings("deprecation") private static void addTeamRequest(Player p, SWInventory inv, int pos, FightTeam team) { byte colorCode = ColorConverter.chat2dye(team.getColor()).getDyeData(); - inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + team.getLeader().getEntity().getName()), click -> { + String name = team.getLeader() != null ? team.getLeader().getEntity().getName() : team.getName(); + inv.setItem(pos, SWItem.getDye(colorCode), colorCode, msg.parse("JOIN_REQUEST_TEAM", p, team.getColor() + name), click -> { p.closeInventory(); new JoinRequest(p, team); }); From 9d3516152d1c5f62b3938c2dbb1887e3ad25ead7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Jan 2024 18:42:22 +0100 Subject: [PATCH 10/13] (Untested) Team Event API, Fancy Borders Signed-off-by: Lixfel --- .../utils/FlatteningWrapper14.java | 5 + .../fightsystem/utils/FlatteningWrapper8.java | 6 + FightSystem_Core/build.gradle | 3 + .../src/de/steamwar/fightsystem/Config.java | 12 +- .../de/steamwar/fightsystem/FightSystem.java | 3 +- .../countdown/EnternCountdown.java | 3 + .../fightsystem/events/BoardingEvent.java | 40 +++++ .../fightsystem/events/TeamDeathEvent.java | 40 +++++ .../fightsystem/events/TeamLeaveEvent.java | 40 +++++ .../fightsystem/events/TeamSpawnEvent.java | 40 +++++ .../fightsystem/fight/FightPlayer.java | 2 + .../steamwar/fightsystem/fight/FightTeam.java | 66 +++----- .../fightsystem/listener/ArenaBorder.java | 73 ++++++--- .../steamwar/fightsystem/listener/Border.java | 131 ++++++++++++++++ .../fightsystem/listener/Permanent.java | 23 +++ .../fightsystem/listener/Recording.java | 22 +-- .../fightsystem/listener/TeamArea.java | 145 ++++++++---------- .../fightsystem/utils/FlatteningWrapper.java | 2 + .../de/steamwar/fightsystem/utils/Region.java | 63 +++----- .../winconditions/WinconditionAllDead.java | 24 +-- .../WinconditionCaptainDead.java | 26 +--- build.gradle | 5 - 22 files changed, 527 insertions(+), 247 deletions(-) create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/events/BoardingEvent.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/events/TeamDeathEvent.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/events/TeamLeaveEvent.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/events/TeamSpawnEvent.java create mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java index cda664d..2cce880 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/FlatteningWrapper14.java @@ -108,4 +108,9 @@ public class FlatteningWrapper14 implements FlatteningWrapper { public boolean isCrouching(Player player) { return player.getPose() == Pose.SWIMMING; } + + @Override + public void sendBlockChange(Player player, Block block, Material type) { + player.sendBlockChange(block.getLocation(), type.createBlockData()); + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java index 6a0e132..c788f06 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/FlatteningWrapper8.java @@ -83,4 +83,10 @@ public class FlatteningWrapper8 implements FlatteningWrapper { public boolean isCrouching(Player player) { return false; } + + @Override + @SuppressWarnings("deprecation") + public void sendBlockChange(Player player, Block block, Material type) { + player.sendBlockChange(block.getLocation(), type, (byte)0); + } } diff --git a/FightSystem_Core/build.gradle b/FightSystem_Core/build.gradle index b9d32c2..25c8d64 100644 --- a/FightSystem_Core/build.gradle +++ b/FightSystem_Core/build.gradle @@ -47,6 +47,9 @@ dependencies { compileOnly 'io.netty:netty-all:4.1.68.Final' compileOnly 'com.mojang:authlib:1.5.25' + compileOnly 'org.projectlombok:lombok:1.18.30' + annotationProcessor 'org.projectlombok:lombok:1.18.30' + compileOnly swdep("WorldEdit-1.15") compileOnly swdep("SpigotCore") } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index b1030f7..dba60ee 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -309,13 +309,13 @@ public class Config { RedRotate = teamRedRotate; BlueRotate = teamBlueRotate; - RedPasteRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); - BluePasteRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); + RedPasteRegion = Region.fromSize(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ); + BluePasteRegion = Region.fromSize(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ); - RedExtendRegion = new Region(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - BlueExtendRegion = new Region(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); - ArenaRegion = new Region(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); - PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX - arenaMinX, world.getMaxHeight() - underBorder, arenaMaxZ - arenaMinZ); + RedExtendRegion = Region.withExtension(teamRedCornerX, teamRedCornerY, teamRedCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); + BlueExtendRegion = Region.withExtension(blueCornerX, blueCornerY, blueCornerZ, schemsizeX, schemsizeY, schemsizeZ, PreperationArea, PreperationArea, PreperationArea); + ArenaRegion = Region.withExtension(arenaMinX, blueCornerY, arenaMinZ, arenaMaxX - arenaMinX, schemsizeY, arenaMaxZ - arenaMinZ, 0, PreperationArea, 0); + PlayerRegion = new Region(arenaMinX, underBorder, arenaMinZ, arenaMaxX, world.getMaxHeight(), arenaMaxZ); EventKampfID = Integer.parseInt(System.getProperty("fightID", "0")); if(EventKampfID >= 1){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 48fe546..597748d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -81,7 +81,6 @@ public class FightSystem extends JavaPlugin { }); new Chat(); new ArenaBorder(); - new TeamArea(); new IngameDeath(); new InFightDamage(); new InFightInventory(); @@ -94,7 +93,7 @@ public class FightSystem extends JavaPlugin { new SetupQuit(); new PrepareSchem(); new TestJoin(); - new NormalJoin(); + //new NormalJoin(); new RunningWorldInteraction(); new PersonalKitCreator(); new ArrowStopper(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 157c296..5581fe8 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -21,11 +21,13 @@ package de.steamwar.fightsystem.countdown; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.events.BoardingEvent; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.utils.Message; import de.steamwar.fightsystem.utils.SWSound; import de.steamwar.techhider.ProtocolUtils; import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Bukkit; import java.util.List; @@ -55,6 +57,7 @@ public class EnternCountdown extends Countdown { @Override public void countdownFinished() { + Bukkit.getPluginManager().callEvent(new BoardingEvent(fightPlayer)); FightSystem.getMessage().sendPrefixless("ENTERN_ALLOWED", fightPlayer.getEntity(), ChatMessageType.ACTION_BAR); fightPlayer.ifPlayer(player -> { FightSystem.getHullHider().updatePlayer(player); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/events/BoardingEvent.java b/FightSystem_Core/src/de/steamwar/fightsystem/events/BoardingEvent.java new file mode 100644 index 0000000..373d91b --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/events/BoardingEvent.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.events; + +import de.steamwar.fightsystem.fight.FightPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@AllArgsConstructor +public class BoardingEvent extends Event { + @Getter + private static final HandlerList handlerList = new HandlerList(); + + private final FightPlayer fightPlayer; + + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamDeathEvent.java b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamDeathEvent.java new file mode 100644 index 0000000..6cbdd05 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamDeathEvent.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.events; + +import de.steamwar.fightsystem.fight.FightPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@AllArgsConstructor +public class TeamDeathEvent extends Event { + @Getter + private static final HandlerList handlerList = new HandlerList(); + + private final FightPlayer fightPlayer; + + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamLeaveEvent.java b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamLeaveEvent.java new file mode 100644 index 0000000..36d96b0 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamLeaveEvent.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.events; + +import de.steamwar.fightsystem.fight.FightPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@AllArgsConstructor +public class TeamLeaveEvent extends Event { + @Getter + private static final HandlerList handlerList = new HandlerList(); + + private final FightPlayer fightPlayer; + + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamSpawnEvent.java b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamSpawnEvent.java new file mode 100644 index 0000000..7ca62be --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/events/TeamSpawnEvent.java @@ -0,0 +1,40 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 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.events; + +import de.steamwar.fightsystem.fight.FightPlayer; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +@Getter +@AllArgsConstructor +public class TeamSpawnEvent extends Event { + @Getter + private static final HandlerList handlerList = new HandlerList(); + + private final FightPlayer fightPlayer; + + @Override + public HandlerList getHandlers() { + return handlerList; + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index e6740a8..f28c039 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -23,6 +23,7 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.ai.AI; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.countdown.EnternCountdown; +import de.steamwar.fightsystem.events.TeamDeathEvent; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -62,6 +63,7 @@ public class FightPlayer { public void setOut() { isOut = true; + Bukkit.getPluginManager().callEvent(new TeamDeathEvent(this)); stopEnternCountdown(); ifAI(AI::stop); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 7aad62d..a8dfbca 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -25,10 +25,12 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.commands.GUI; import de.steamwar.fightsystem.countdown.Countdown; +import de.steamwar.fightsystem.events.TeamLeaveEvent; +import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.Permanent; import de.steamwar.fightsystem.listener.PersonalKitCreator; -import de.steamwar.fightsystem.record.GlobalRecorder; +import de.steamwar.fightsystem.listener.TeamArea; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependent; @@ -39,6 +41,7 @@ import de.steamwar.inventory.SWItem; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import de.steamwar.techhider.ProtocolUtils; +import lombok.Getter; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; import org.bukkit.enchantments.Enchantment; @@ -89,24 +92,35 @@ public class FightTeam { readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false)); } + @Getter private UUID designatedLeader; + @Getter private FightPlayer leader; + @Getter private boolean publicsOnly; private final Map players = new HashMap<>(); + @Getter private String name; + @Getter private String prefix; + @Getter private ChatColor color; private final FightSchematic schematic; private final Team team; + @Getter private final boolean blue; + @Getter private boolean ready; private boolean skip; + @Getter private final Location spawn; + @Getter private final Region schemRegion; + @Getter private final Region extendRegion; @SuppressWarnings("deprecation") @@ -123,6 +137,7 @@ public class FightTeam { this.schematic = new FightSchematic(this, rotate); new KitLoader(); new SpectateHandler(); + new TeamArea(this); team = FightScoreboard.getBukkitTeam(name); WorldOfColorWrapper.impl.setTeamColor(team, color); @@ -146,26 +161,10 @@ public class FightTeam { this.color = ChatColor.getByChar(ChatColor.getLastColors(prefix).replace("ยง", "")); } - public UUID getDesignatedLeader(){ - return designatedLeader; - } - - public Region getSchemRegion() { - return schemRegion; - } - - public Region getExtendRegion() { - return extendRegion; - } - public boolean canbeLeader(Player p){ return isLeaderless() && (designatedLeader == null || designatedLeader.equals(p.getUniqueId())); } - public boolean isPublicsOnly() { - return publicsOnly; - } - public void teleportToSpawn(){ players.forEach((player, fp) -> fp.getEntity().teleport(spawn)); } @@ -265,6 +264,8 @@ public class FightTeam { FightPlayer fightPlayer = getFightPlayer(entity) != null ? getFightPlayer(entity) : new FightPlayer(entity, user, this); fightPlayer.revive(); players.put(entity.getUniqueId(), fightPlayer); + Bukkit.getPluginManager().callEvent(new TeamSpawnEvent(fightPlayer)); + Permanent.getSpectatorTeam().removeEntry(entity.getName()); team.addEntry(entity.getName()); @@ -288,7 +289,6 @@ public class FightTeam { if(FightState.Running.contains(FightState.getFightState())) fightPlayer.startEnternCountdown(Wincondition.getTimeOverCountdown()); - GlobalRecorder.getInstance().playerJoins(entity, user); fightPlayer.ifPlayer(player -> FightSystem.getTechHider().reloadChunks(player, chunksToReload, false)); if(isLeaderless()) @@ -299,6 +299,7 @@ public class FightTeam { public void removePlayer(LivingEntity entity) { FightPlayer fightPlayer = getFightPlayer(entity); + Bukkit.getPluginManager().callEvent(new TeamLeaveEvent(fightPlayer)); fightPlayer.ifPlayer(PersonalKitCreator::closeIfInKitCreator); List chunksToReload = FightSystem.getTechHider().prepareChunkReload(entity, true); @@ -311,7 +312,6 @@ public class FightTeam { if(fightPlayer.equals(leader)) removeLeader(); - GlobalRecorder.getInstance().entityDespawns(entity); entity.teleport(Config.SpecSpawn); fightPlayer.ifPlayer(player -> { @@ -332,14 +332,6 @@ public class FightTeam { return leader == null; } - public boolean isBlue(){ - return blue; - } - - public FightPlayer getLeader() { - return leader; - } - private void removeLeader() { this.leader = null; if(!players.isEmpty()) { @@ -383,10 +375,6 @@ public class FightTeam { return players.values(); } - public boolean isReady() { - return ready; - } - public void pasteSchem() { testPasteAction(); } @@ -457,26 +445,14 @@ public class FightTeam { } } - public String getName() { - return name; - } - public String getColoredName() { return prefix + name; } - public String getPrefix() { - return prefix; - } - public int getSchematic() { return schematic.getId(); } - public Location getSpawn() { - return spawn; - } - public double getCurrentHearts() { return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getEntity().getHealth()).sum(); } @@ -494,10 +470,6 @@ public class FightTeam { return (int) players.values().stream().filter(FightPlayer::isLiving).count(); } - public ChatColor getColor() { - return color; - } - @Override public String toString() { return name; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java index d0a428e..8f9c287 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArenaBorder.java @@ -21,52 +21,72 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.events.TeamDeathEvent; +import de.steamwar.fightsystem.events.TeamLeaveEvent; +import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.GameMode; -import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; public class ArenaBorder implements Listener { + private final Border spectatorBorder = new Border(Config.PlayerRegion, true, 5, "NO_ARENA_LEAVING"); + private final Border playerBorder = new Border(Config.PlayerRegion.to2d(), true, 5, "NO_ARENA_LEAVING"); + public ArenaBorder() { new StateDependentListener(ArenaMode.All, FightState.All, this); new StateDependentTask(ArenaMode.All, FightState.Running, this::damage, 2, 2); + new StateDependentListener(!Config.GroundWalkable, FightState.AntiIngame, new Listener() { + @EventHandler + public void onMove(PlayerMoveEvent e) { + Player player = e.getPlayer(); + if(e.getTo().getY() <= Config.PlayerRegion.getMinY() && playerBorder.contains(player)) + player.teleport(Fight.getPlayerTeam(player).getSpawn()); + } + }); } @EventHandler - public void arenaBorder(PlayerMoveEvent event){ - Player player = event.getPlayer(); - FightTeam team = Fight.getPlayerTeam(player); + public void onPlayerJoin(PlayerJoinEvent e) { + addToSpectator(e.getPlayer()); + } - if(Config.ArenaLeaveable && team == null) - return; + @EventHandler + public void onTeamJoin(TeamSpawnEvent e) { + e.getFightPlayer().ifPlayer(player -> { + spectatorBorder.removePlayer(player); + playerBorder.addPlayer(player); + }); + } - Location to = event.getTo(); - assert to != null; + @EventHandler + public void onTeamDeath(TeamDeathEvent e) { + e.getFightPlayer().ifPlayer(player -> { + playerBorder.removePlayer(player); + addToSpectator(player); + }); + } - if(Config.PlayerRegion.inRegion(to)) - return; + @EventHandler + public void onTeamLeave(TeamLeaveEvent e) { + e.getFightPlayer().ifPlayer(player -> { + playerBorder.removePlayer(player); + addToSpectator(player); + }); + } - if(to.getY() <= Config.PlayerRegion.getMinY() && player.getGameMode() != GameMode.SPECTATOR && team != null) { - if(!Config.GroundWalkable && !FightState.infight()) - player.teleport(team.getSpawn()); - - return; - } - - player.teleport(event.getFrom()); - FightSystem.getMessage().sendPrefixless("NO_ARENA_LEAVING", player, ChatMessageType.ACTION_BAR); + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) { + spectatorBorder.removePlayer(e.getPlayer()); } private void damage() { @@ -78,4 +98,11 @@ public class ArenaBorder implements Listener { } }); } + + private void addToSpectator(Player player) { + if(Config.ArenaLeaveable || !player.isOnline() || playerBorder.contains(player)) + return; + + spectatorBorder.addPlayer(player); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java new file mode 100644 index 0000000..6ae3384 --- /dev/null +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Border.java @@ -0,0 +1,131 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2024 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.utils.FlatteningWrapper; +import de.steamwar.fightsystem.utils.Region; +import net.md_5.bungee.api.ChatMessageType; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class Border { + + private final Map> ghostBarriers = new HashMap<>(); + private final Map lastLocation = new HashMap<>(); + private final boolean contain; + private final String resetMessage; + private final Region region; + private final int ghostRange; + private final int ghostSize; + + public Border(Region region, boolean contain, int ghostRange, String resetMessage) { + this.contain = contain; + this.resetMessage = resetMessage; + this.region = region; + this.ghostRange = ghostRange; + this.ghostSize = 2*ghostRange + 1; + + new StateDependentTask(ArenaMode.All, FightState.All, this::run, 1, 1); + } + + public void addPlayer(Player player) { + ghostBarriers.computeIfAbsent(player, uuid -> new HashSet<>()); + lastLocation.put(player, player.getLocation()); + } + + public boolean contains(Player player) { + return ghostBarriers.containsKey(player); + } + + public void removePlayer(Player player) { + lastLocation.remove(player); + Set blocks = ghostBarriers.remove(player); + if(blocks == null || !player.isOnline()) + return; + + for(Block block : blocks) + sendChange(player, block, Material.AIR); + } + + private void run() { + for(Map.Entry> entry : ghostBarriers.entrySet()) { + Player player = entry.getKey(); + Location location = player.getLocation(); + if(region.playerInRegion(location) != contain) { + player.teleport(lastLocation.get(player)); + FightSystem.getMessage().sendPrefixless(resetMessage, player, ChatMessageType.ACTION_BAR); + return; + } + + Set ghostBlocks = entry.getValue(); + Region ghostRegion = Region.fromSize(location.getBlockX() - ghostRange, location.getBlockY() - ghostRange, location.getBlockZ() - ghostRange, ghostSize, ghostSize, ghostSize); + ghostBlocks.removeIf(block -> { + if(!ghostRegion.inRegion(block)) { + sendChange(player, block, Material.AIR); + return true; + } + return false; + }); + + if(contain) { + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion)); + } else { + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMinZ(), region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMaxX()-1, region.getMinY(), region.getMinZ(), 1, region.getSizeY(), region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMaxY()-1, region.getMinZ(), region.getSizeX(), 1, region.getSizeZ()).intersection(ghostRegion)); + borderIteration(player, ghostBlocks, Region.fromSize(region.getMinX(), region.getMinY(), region.getMaxZ()-1, region.getSizeX(), region.getSizeY(), 1).intersection(ghostRegion)); + } + + lastLocation.put(entry.getKey(), location); + } + } + + private void borderIteration(Player player, Set ghostBlocks, Region border) { + border.forEach((x, y, z) -> { + Block block = Config.world.getBlockAt(x, y, z); + if(ghostBlocks.add(block)) + sendChange(player, block, Material.BARRIER); + }); + } + + private void sendChange(Player player, Block block, Material type) { + if(block.getType() == Material.AIR) + FlatteningWrapper.impl.sendBlockChange(player, block, type); + } +} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index a0eabba..90342de 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -37,8 +37,10 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDispenseEvent; import org.bukkit.event.block.BlockFromToEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.entity.EntityExplodeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.PlayerDeathEvent; @@ -217,4 +219,25 @@ public class Permanent implements Listener { if(e.getItem().getType() == Material.TNT || FlatteningWrapper.impl.isFacingWater(block)) e.setCancelled(true); } + + @EventHandler + public void blockPlace(BlockPlaceEvent event) { + Player player = event.getPlayer(); + Block block = event.getBlock(); + if(Fight.teams().stream().anyMatch(team -> team.getExtendRegion().inRegion(block))) + return; + + event.setCancelled(true); + FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR); + } + + @EventHandler + public void blockBreak(BlockBreakEvent event) { + Block block = event.getBlock(); + if(Config.BlueExtendRegion.getMinY() <= block.getY()) + return; + + event.setCancelled(true); + FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR); + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index b51964b..f77c190 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -23,6 +23,9 @@ import com.comphenix.tinyprotocol.Reflection; import com.comphenix.tinyprotocol.TinyProtocol; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.events.TeamDeathEvent; +import de.steamwar.fightsystem.events.TeamLeaveEvent; +import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; @@ -142,6 +145,11 @@ public class Recording implements Listener { return packet; } + @EventHandler + public void onPlayerSpawn(TeamSpawnEvent e) { + GlobalRecorder.getInstance().playerJoins(e.getFightPlayer().getEntity(), e.getFightPlayer().getUser()); + } + @EventHandler(priority = EventPriority.HIGH) public void onPlayerMove(PlayerMoveEvent e){ if(isNotSent(e.getPlayer())) @@ -151,19 +159,13 @@ public class Recording implements Listener { } @EventHandler - public void onPlayerDeath(PlayerDeathEvent e) { - if(isNotSent(e.getEntity())) - return; - - GlobalRecorder.getInstance().entityDespawns(e.getEntity()); + public void onPlayerDeath(TeamDeathEvent e) { + GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity()); } @EventHandler - public void onPlayerQuit(PlayerQuitEvent e){ - if(isNotSent(e.getPlayer())) - return; - - GlobalRecorder.getInstance().entityDespawns(e.getPlayer()); + public void onPlayerLeave(TeamLeaveEvent e) { + GlobalRecorder.getInstance().entityDespawns(e.getFightPlayer().getEntity()); } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java index e091c92..be2be56 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -21,110 +21,101 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.events.BoardingEvent; +import de.steamwar.fightsystem.events.TeamDeathEvent; +import de.steamwar.fightsystem.events.TeamSpawnEvent; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.fightsystem.utils.Region; -import net.md_5.bungee.api.ChatMessageType; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.block.Block; +import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockBreakEvent; -import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import java.util.HashSet; import java.util.Set; -import java.util.logging.Level; public class TeamArea implements Listener { - private static final Set realSpectator = new HashSet<>(); + private final FightTeam team; + private final Border spectatorBorder; + private final Border bordingBorder; + private final Set realSpectator = new HashSet<>(); + + public TeamArea(FightTeam team) { + this.team = team; + this.spectatorBorder = new Border(team.getExtendRegion(), false, 5, "NO_TEAMAREA"); + this.bordingBorder = new Border(team.getExtendRegion().to2d(), true, 1, "NO_ENTERN"); - public TeamArea() { new StateDependentListener(ArenaMode.AntiTest, FightState.All, this); + new StateDependentTask(ArenaMode.AntiTest, FightState.TeamFix, this::realSpectatorCheck, 1, 1); } @EventHandler - public void teamAreas(PlayerMoveEvent event) { - Player player = event.getPlayer(); - if(Config.isReferee(player)) - return; + public void playerJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + if(Fight.getPlayerTeam(player) != team && !Config.isReferee(player)) + spectatorBorder.addPlayer(player); + } - FightTeam team = Fight.getPlayerTeam(player); - Fight.teams().forEach(t -> checkInTeamRegion(event, t, player, team)); + @EventHandler + public void teamJoin(TeamSpawnEvent e) { + FightPlayer fightPlayer = e.getFightPlayer(); + if(fightPlayer.getTeam() == team) { + fightPlayer.ifPlayer(player -> { + spectatorBorder.removePlayer(player); + bordingBorder.addPlayer(player); + }); + } + } + + @EventHandler + public void boarding(BoardingEvent e) { + FightPlayer fightPlayer = e.getFightPlayer(); + if(fightPlayer.getTeam() == team) { + fightPlayer.ifPlayer(bordingBorder::removePlayer); + } else { + fightPlayer.ifPlayer(spectatorBorder::removePlayer); + } + } + + @EventHandler + public void teamDeath(TeamDeathEvent e) { + FightPlayer fightPlayer = e.getFightPlayer(); + if(fightPlayer.getTeam() == team) { + fightPlayer.ifPlayer(bordingBorder::removePlayer); + } else { + fightPlayer.ifPlayer(spectatorBorder::addPlayer); + } } @EventHandler public void playerQuit(PlayerQuitEvent e) { - realSpectator.remove(e.getPlayer()); + Player player = e.getPlayer(); + spectatorBorder.removePlayer(player); + bordingBorder.removePlayer(player); + realSpectator.remove(player); } - @EventHandler - public void blockPlace(BlockPlaceEvent event) { - Player player = event.getPlayer(); - Block block = event.getBlock(); - if(Config.BlueExtendRegion.inRegion(block) || Config.RedExtendRegion.inRegion(block)) - return; + private void realSpectatorCheck() { + for(FightPlayer fightPlayer : team.getPlayers()) { + if(fightPlayer.isLiving()) + continue; - event.setCancelled(true); - FightSystem.getMessage().sendPrefixless("NO_BLOCK_PLACE", player, ChatMessageType.ACTION_BAR); - } - - @EventHandler - public void blockBreak(BlockBreakEvent event) { - Block block = event.getBlock(); - if(Config.BlueExtendRegion.getMinY() <= block.getY()) - return; - - event.setCancelled(true); - FightSystem.getMessage().sendPrefixless("NO_BLOCK_BREAK", event.getPlayer(), ChatMessageType.ACTION_BAR); - } - - private void checkInTeamRegion(PlayerMoveEvent event, FightTeam team, Player player, FightTeam playerTeam) { - boolean spectator = player.getGameMode() == GameMode.SPECTATOR; - if(!spectator && playerTeam != null && playerTeam.canPlayerEntern(player)) - return; // Player can entern - - Region region = team.getExtendRegion(); - boolean inRegion = region.in2dRegion(event.getTo()); - if(team == playerTeam) { - if(spectator) { - realSpectator(inRegion, player); - } else if (!playerTeam.canPlayerEntern(player) && !inRegion) { - reset(event, "NO_ENTERN"); // Leaving prior to entern - } - return; // Always allowed in own region + fightPlayer.ifPlayer(player -> { + boolean inRegion = team.getExtendRegion().playerInRegion(player.getLocation()); + if(inRegion && !realSpectator.contains(player)) { + Fight.pseudoSpectator(player, false); + realSpectator.add(player); + }else if(!inRegion && realSpectator.contains(player)) { + Fight.pseudoSpectator(player, true); + realSpectator.remove(player); + } + }); } - - if(region.playerInRegion(event.getTo())) { - reset(event, "NO_TEAMAREA"); // Not allowed in region - if(team.getSchemRegion().playerInRegion(event.getTo()) && Config.PreperationArea >= 5){ // Preventing false positives due to small extension - player.kickPlayer(null); - Bukkit.getLogger().log(Level.INFO, player.getName() + " has entered a team area"); - } - } - } - - private void realSpectator(boolean inRegion, Player player) { - if(inRegion && !realSpectator.contains(player)) { - Fight.pseudoSpectator(player, false); - realSpectator.add(player); - }else if(!inRegion && realSpectator.contains(player)) { - Fight.pseudoSpectator(player, true); - realSpectator.remove(player); - } - } - - private void reset(PlayerMoveEvent event, String message){ - Player player = event.getPlayer(); - player.teleport(event.getFrom()); - FightSystem.getMessage().sendPrefixless(message, player, ChatMessageType.ACTION_BAR); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java index 4f76656..aa2f10e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FlatteningWrapper.java @@ -22,6 +22,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.VersionDependent; import de.steamwar.fightsystem.FightSystem; import org.bukkit.DyeColor; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Player; @@ -49,4 +50,5 @@ public interface FlatteningWrapper { boolean isFacingWater(Block dispenser); boolean isCrouching(Player player); + void sendBlockChange(Player player, Block block, Material type); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 1308f40..0f9b91b 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -20,13 +20,26 @@ package de.steamwar.fightsystem.utils; import de.steamwar.techhider.ProtocolUtils; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.bukkit.Location; import org.bukkit.block.Block; import java.util.function.ObjIntConsumer; +@Getter +@AllArgsConstructor public class Region { + public static Region withExtension(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) { + return Region.fromSize(minX - extendX, minY - extendY, minZ - extendZ, + sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2); + } + + public static Region fromSize(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { + return new Region(minX, minY, minZ, minX+sizeX, minY+sizeY, minZ+sizeZ); + } + private final int minX; private final int minY; private final int minZ; @@ -34,44 +47,6 @@ public class Region { private final int maxY; private final int maxZ; - public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ, int extendX, int extendY, int extendZ) { - this(minX - extendX, minY - extendY, minZ - extendZ, - sizeX + extendX * 2, sizeY + extendY * 2, sizeZ + extendZ * 2); - } - - public Region(int minX, int minY, int minZ, int sizeX, int sizeY, int sizeZ) { - this.minX = minX; - this.minY = minY; - this.minZ = minZ; - this.maxX = minX + sizeX; - this.maxY = minY + sizeY; - this.maxZ = minZ + sizeZ; - } - - public int getMinX() { - return minX; - } - - public int getMinY() { - return minY; - } - - public int getMinZ() { - return minZ; - } - - public int getMaxX() { - return maxX; - } - - public int getMaxY() { - return maxY; - } - - public int getMaxZ() { - return maxZ; - } - public int getSizeX() { return maxX - minX; } @@ -161,6 +136,18 @@ public class Region { return in2dRegion(x, z) && minY <= y && y < maxY; } + public Region intersection(Region other) { + int x = Math.max(minX, other.minX); + int y = Math.max(minY, other.minY); + int z = Math.max(minZ, other.minZ); + + return new Region(x, y, z, Math.min(maxX, other.maxX), Math.min(maxY, other.maxY), Math.min(maxZ, other.maxZ)); + } + + public Region to2d() { + return new Region(minX, Integer.MIN_VALUE/2, minZ, maxX, Integer.MAX_VALUE/2, maxY); + } + public interface TriConsumer{ void accept(T x, V y, U z); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 041a752..8f2d73a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -19,16 +19,13 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.events.TeamDeathEvent; import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.player.PlayerQuitEvent; public class WinconditionAllDead extends Wincondition implements Listener { @@ -38,25 +35,12 @@ public class WinconditionAllDead extends Wincondition implements Listener { } @EventHandler - public void handlePlayerDeath(EntityDeathEvent event) { - handleDeath(event.getEntity()); - } + public void handlePlayerDeath(TeamDeathEvent event) { + FightTeam team = event.getFightPlayer().getTeam(); - @EventHandler - public void handlePlayerQuit(PlayerQuitEvent event) { - handleDeath(event.getPlayer()); - } - - private void handleDeath(Entity player){ - FightTeam team = isTarget(player); - if(team == null) + if(team.getAlivePlayers() > 0) return; - for(FightPlayer fp : team.getPlayers()) { - if(fp.isLiving() && fp.getEntity() != player) - return; - } - win(Fight.getOpposite(team), "WIN_ALL_DEAD", team.getPrefix()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index 53759a9..de0205a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -19,16 +19,14 @@ package de.steamwar.fightsystem.winconditions; +import de.steamwar.fightsystem.events.TeamDeathEvent; import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.player.PlayerQuitEvent; public class WinconditionCaptainDead extends Wincondition implements Listener { @@ -38,22 +36,12 @@ public class WinconditionCaptainDead extends Wincondition implements Listener { } @EventHandler - public void handlePlayerDeath(EntityDeathEvent event) { - handleDeath(event.getEntity()); - } - - @EventHandler - public void handlePlayerQuit(PlayerQuitEvent event) { - handleDeath(event.getPlayer()); - } - - private void handleDeath(Entity player){ - FightTeam team = isTarget(player); - if(team == null) + public void handlePlayerDeath(TeamDeathEvent event) { + FightPlayer leader = event.getFightPlayer(); + if(!leader.isLeader()) return; - if(team.isPlayerLeader((LivingEntity) player)) { - win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + team.getLeader().getEntity().getName()); - } + FightTeam team = leader.getTeam(); + win(Fight.getOpposite(team), "WIN_LEADER_DEAD", team.getPrefix() + leader.getEntity().getName()); } } diff --git a/build.gradle b/build.gradle index 3cacf6e..2c1673c 100644 --- a/build.gradle +++ b/build.gradle @@ -46,11 +46,6 @@ mainClassName = '' allprojects { repositories { mavenCentral() - jcenter() - - maven { - url = uri("https://repo.codemc.io/repository/maven-snapshots/") - } maven { url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/') From ba475457db3b870be55e663f266ec86f41eddd52 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Jan 2024 19:18:09 +0100 Subject: [PATCH 11/13] Fix Z and NormalJoin bug Signed-off-by: Lixfel --- FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java | 2 +- FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 597748d..0b17349 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -93,7 +93,7 @@ public class FightSystem extends JavaPlugin { new SetupQuit(); new PrepareSchem(); new TestJoin(); - //new NormalJoin(); + new NormalJoin(); new RunningWorldInteraction(); new PersonalKitCreator(); new ArrowStopper(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java index 0f9b91b..807822a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Region.java @@ -145,7 +145,7 @@ public class Region { } public Region to2d() { - return new Region(minX, Integer.MIN_VALUE/2, minZ, maxX, Integer.MAX_VALUE/2, maxY); + return new Region(minX, Integer.MIN_VALUE/2, minZ, maxX, Integer.MAX_VALUE/2, maxZ); } public interface TriConsumer{ From c8b9263b70e1d73d2756f813d1f743d4d85fa8e7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 20 Jan 2024 21:16:48 +0100 Subject: [PATCH 12/13] Fix behaviour during spectator phase Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/TeamArea.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java index be2be56..154919c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/TeamArea.java @@ -28,6 +28,7 @@ import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.states.StateDependentTask; import org.bukkit.entity.Player; @@ -53,6 +54,7 @@ public class TeamArea implements Listener { new StateDependentListener(ArenaMode.AntiTest, FightState.All, this); new StateDependentTask(ArenaMode.AntiTest, FightState.TeamFix, this::realSpectatorCheck, 1, 1); + new OneShotStateDependent(ArenaMode.AntiTest, FightState.Spectate, () -> Fight.teams().forEach(t -> t.getPlayers().forEach(this::teamSpectator))); } @EventHandler @@ -85,7 +87,10 @@ public class TeamArea implements Listener { @EventHandler public void teamDeath(TeamDeathEvent e) { - FightPlayer fightPlayer = e.getFightPlayer(); + teamSpectator(e.getFightPlayer()); + } + + private void teamSpectator(FightPlayer fightPlayer) { if(fightPlayer.getTeam() == team) { fightPlayer.ifPlayer(bordingBorder::removePlayer); } else { From 5dfdb8e72224e2e1fd61f70fd6e82a09a3183d9a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 24 Jan 2024 12:07:38 +0100 Subject: [PATCH 13/13] Code cleanup, Utilize Lombok Signed-off-by: Lixfel --- .../utils/CraftbukkitWrapper10.java | 2 +- .../utils/CraftbukkitWrapper12.java | 2 +- .../utils/CraftbukkitWrapper14.java | 2 +- .../utils/CraftbukkitWrapper15.java | 2 +- .../utils/CraftbukkitWrapper9.java | 2 +- .../de/steamwar/fightsystem/FightSystem.java | 14 ++---- .../fightsystem/commands/CommandInjector.java | 42 ------------------ .../fightsystem/commands/Commands.java | 11 ++++- .../fightsystem/commands/GamemodeCommand.java | 2 +- .../de/steamwar/fightsystem/fight/Fight.java | 11 ++--- .../fightsystem/fight/FightPlayer.java | 22 +++------- .../steamwar/fightsystem/fight/FightTeam.java | 17 ++++--- .../fightsystem/fight/FightWorld.java | 8 ++-- .../steamwar/fightsystem/fight/HotbarKit.java | 2 +- .../de/steamwar/fightsystem/fight/Kit.java | 35 ++++----------- .../fightsystem/listener/ArrowPickup.java | 32 -------------- .../fightsystem/record/FileRecorder.java | 6 +-- .../fightsystem/states/FightState.java | 7 ++- .../fightsystem/utils/FightStatistics.java | 6 +-- .../steamwar/fightsystem/utils/FightUI.java | 5 +-- .../fightsystem/utils/ItemBuilder.java | 44 ++++--------------- .../steamwar/fightsystem/utils/Message.java | 12 ++--- .../winconditions/Wincondition.java | 11 ++--- 23 files changed, 75 insertions(+), 222 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java diff --git a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java index e6b9dc8..78dd79a 100644 --- a/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java +++ b/FightSystem_10/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper10.java @@ -39,7 +39,7 @@ public class CraftbukkitWrapper10 implements CraftbukkitWrapper { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { + if (!FightWorld.isPAPER()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); diff --git a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java index 36fd0ab..f8e843b 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper12.java @@ -39,7 +39,7 @@ public class CraftbukkitWrapper12 implements CraftbukkitWrapper { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { + if (!FightWorld.isPAPER()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); diff --git a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java index 7528fcf..07c525d 100644 --- a/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java +++ b/FightSystem_14/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper14.java @@ -38,7 +38,7 @@ public class CraftbukkitWrapper14 implements CraftbukkitWrapper { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { + if (!FightWorld.isPAPER()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); diff --git a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java index f06902b..70d9e8c 100644 --- a/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java +++ b/FightSystem_15/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper15.java @@ -38,7 +38,7 @@ public class CraftbukkitWrapper15 implements CraftbukkitWrapper { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { + if (!FightWorld.isPAPER()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java index a0ddcd9..54281ed 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/CraftbukkitWrapper9.java @@ -39,7 +39,7 @@ public class CraftbukkitWrapper9 implements CraftbukkitWrapper { System.arraycopy(backupChunk.getSections(), 0, chunk.getSections(), 0, chunk.getSections().length); System.arraycopy(backupChunk.heightMap, 0, chunk.heightMap, 0, chunk.heightMap.length); w.tileEntityListTick.removeAll(chunk.tileEntities.values()); - if (!FightWorld.isPaper()) { + if (!FightWorld.isPAPER()) { w.tileEntityList.removeAll(chunk.tileEntities.values()); } chunk.tileEntities.clear(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 0b17349..6e6b1c4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -39,15 +39,18 @@ import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.record.LiveRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; +import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.message.Message; import de.steamwar.sql.SchematicNode; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; public class FightSystem extends JavaPlugin { + @Getter private static FightSystem plugin; private Message message; @@ -97,7 +100,7 @@ public class FightSystem extends JavaPlugin { new RunningWorldInteraction(); new PersonalKitCreator(); new ArrowStopper(); - new ArrowPickup(); + new StateDependentListener(ArenaMode.All, FightState.All, BountifulWrapper.impl.newDenyArrowPickupListener()); new BlockFadeListener(); new LeaveableArena(); new ClickAnalyzer(); @@ -194,15 +197,6 @@ public class FightSystem extends JavaPlugin { FightState.setFightState(FightState.SPECTATE); } - public static FightSystem getPlugin() { - return plugin; - } - - public static void broadcast(String msg, Object... params) { - getMessage().broadcast(msg, params); - GlobalRecorder.getInstance().system(msg, params); - } - public static Message getMessage() { return plugin.message; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java deleted file mode 100644 index 2c69fde..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/CommandInjector.java +++ /dev/null @@ -1,42 +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.commands; - -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.SimpleCommandMap; - -import java.lang.reflect.Field; - -public class CommandInjector { - - private CommandInjector(){} - - private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName(); - private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf('.') + 1); - - public static void injectCommand(Command cmd) throws Exception { - Class serverClass = Class.forName("org.bukkit.craftbukkit." + VERSION + ".CraftServer"); - Field f1 = serverClass.getDeclaredField("commandMap"); - f1.setAccessible(true); - SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer()); - commandMap.register("BauSystem", cmd); - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index 6102728..b880fa6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.commands; +import com.comphenix.tinyprotocol.Reflection; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; @@ -28,12 +29,20 @@ import de.steamwar.fightsystem.fight.Kit; import de.steamwar.fightsystem.states.FightState; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; +import lombok.experimental.UtilityClass; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.SimpleCommandMap; import org.bukkit.entity.Player; +@UtilityClass public class Commands { - private Commands(){} + + private static final Reflection.FieldAccessor commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + public static void injectCommand(Command cmd) { + commandMap.get(Bukkit.getServer()).register("FightSystem", cmd); + } private static void errNoTeam(Player p){ FightSystem.getMessage().sendPrefixless("NO_TEAM", p, ChatMessageType.ACTION_BAR); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java index 0cde5ac..5c56626 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/GamemodeCommand.java @@ -47,10 +47,10 @@ public class GamemodeCommand extends BukkitCommand { try { CommandRemover.removeAll("gamemode"); - CommandInjector.injectCommand(this); } catch (Exception e) { FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Failed to replace commands", e); } + Commands.injectCommand(this); } @Override diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java index 9d59a0b..cd7a232 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Fight.java @@ -27,6 +27,7 @@ import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.record.GlobalRecorder; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Sound; @@ -39,7 +40,9 @@ import java.util.HashSet; public class Fight { private Fight(){} + @Getter private static final FightTeam redTeam = new FightTeam(Config.TeamRedName, Config.TeamRedColor, Config.TeamRedSpawn, Config.RedPasteRegion, Config.RedExtendRegion, Config.RedRotate, false, Config.RedLeader); + @Getter 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 { @@ -76,14 +79,6 @@ public class Fight { return getPlayerTeam(player) != null; } - public static FightTeam getRedTeam() { - return redTeam; - } - - public static FightTeam getBlueTeam() { - return blueTeam; - } - public static Collection teams() { return teams; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java index f28c039..763bd6f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -26,6 +26,8 @@ import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.fightsystem.events.TeamDeathEvent; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; +import lombok.Getter; +import lombok.Setter; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -36,9 +38,13 @@ public class FightPlayer { private final int id; private LivingEntity entity; + @Getter private final FightTeam team; private boolean isOut; + @Setter + @Getter private Kit kit; + @Getter private int kills; private EnternCountdown enternCountdown = null; @@ -113,22 +119,6 @@ public class FightPlayer { return leader != null && leader.getEntity() == entity; } - public Kit getKit() { - return kit; - } - - public void setKit(Kit kit) { - this.kit = kit; - } - - public FightTeam getTeam(){ - return team; - } - - public int getKills(){ - return kills; - } - public void addKill(){ kills++; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index a8dfbca..544be31 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -44,7 +44,6 @@ import de.steamwar.techhider.ProtocolUtils; import lombok.Getter; import net.md_5.bungee.api.ChatMessageType; import org.bukkit.*; -import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.scoreboard.NameTagVisibility; @@ -58,7 +57,7 @@ public class FightTeam { private static void setKitButton(HotbarKit kit, boolean leader) { if (Kit.getAvailableKits(leader).size() > 1 || Config.PersonalKits) - kit.setItem(1, "CHOOSE_KIT", new ItemBuilder(Material.LEATHER_CHESTPLATE).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), player -> GUI.kitSelection(player, "")); + kit.setItem(1, "CHOOSE_KIT", new ItemBuilder(Material.LEATHER_CHESTPLATE).enchant().build(), player -> GUI.kitSelection(player, "")); else kit.setItem(1, null, null, null); } @@ -66,30 +65,30 @@ public class FightTeam { private static final HotbarKit memberKit = new HotbarKit(); static { setKitButton(memberKit, false); - memberKit.setItem(7, "RESPAWN", new ItemBuilder(Material.BEACON).removeAllAttributes().build(), player -> player.teleport(Objects.requireNonNull(Fight.getPlayerTeam(player)).getSpawn())); + memberKit.setItem(7, "RESPAWN", new ItemBuilder(Material.BEACON).build(), player -> player.teleport(Objects.requireNonNull(Fight.getPlayerTeam(player)).getSpawn())); } private static final HotbarKit notReadyKit = new HotbarKit(memberKit); static { setKitButton(notReadyKit, true); if(!ArenaMode.RankedEvent.contains(Config.mode)){ - notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::chooseJoinRequests); - notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributes().build(), GUI::chooseRemove); + notReadyKit.setItem(2, "REQUESTS", new ItemBuilder(Material.PAPER).build(), GUI::chooseJoinRequests); + notReadyKit.setItem(3, "REMOVE_PLAYERS", new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).build(), GUI::chooseRemove); } if(Config.test()) - notReadyKit.setItem(5, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), GUI::preSchemDialog); + notReadyKit.setItem(5, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).enchant().build(), GUI::preSchemDialog); - notReadyKit.setItem(4, "TEAM_NOT_READY", new ItemBuilder(SWItem.getDye(10), (short) 10).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(true)); + notReadyKit.setItem(4, "TEAM_NOT_READY", new ItemBuilder(SWItem.getDye(10), (short) 10).enchant().build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(true)); } private static final HotbarKit chooseSchemKit = new HotbarKit(notReadyKit); static { - chooseSchemKit.setItem(4, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).removeAllAttributes().addEnchantment(Enchantment.DURABILITY, 1).build(), GUI::preSchemDialog); + chooseSchemKit.setItem(4, "CHOOSE_SCHEMATIC", new ItemBuilder(SWItem.getMaterial("CAULDRON_ITEM")).enchant().build(), GUI::preSchemDialog); } private static final HotbarKit readyKit = new HotbarKit(memberKit); static { readyKit.setItem(1, null, null, null); - readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).removeAllAttributes().addEnchantment(Enchantment.DURABILITY,1 ).build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false)); + readyKit.setItem(4, "TEAM_READY", new ItemBuilder(SWItem.getDye(8), (short) 8).enchant().build(), player -> Objects.requireNonNull(Fight.getPlayerTeam(player)).setReady(false)); } @Getter diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java index 9e246da..6527e51 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightWorld.java @@ -26,6 +26,7 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import de.steamwar.fightsystem.utils.CraftbukkitWrapper; import de.steamwar.fightsystem.utils.FlatteningWrapper; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.WorldCreator; @@ -39,11 +40,8 @@ import java.util.Objects; public class FightWorld extends StateDependent { - private static final boolean paper = Bukkit.getVersion().contains("git-Paper"); - - public static boolean isPaper(){ - return paper; - } + @Getter + private static final boolean PAPER = Bukkit.getVersion().contains("git-Paper"); public FightWorld() { super(ArenaMode.Restartable.contains(Config.mode) || Config.replayserver(), FightState.Schem); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java index 8310d2c..5bc1d84 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/HotbarKit.java @@ -51,7 +51,7 @@ public class HotbarKit extends Kit { public static final HotbarKit SPECTATOR_KIT = new HotbarKit(); static { for(int i = 0; i < 9; i++) - SPECTATOR_KIT.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).removeAllAttributes().build(), GUI::joinRequest); + SPECTATOR_KIT.setItem(i, "JOIN_REQUEST", new ItemBuilder(Material.PAPER).build(), GUI::joinRequest); } private static final int HOTBAR_SIZE = 9; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java index 0ba4628..e382909 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/Kit.java @@ -30,6 +30,7 @@ import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.sql.PersonalKit; import de.steamwar.sql.SteamwarUser; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -69,11 +70,19 @@ public class Kit { } } + @Getter private final String name; + @Getter private final ItemStack[] inventory; + @Getter private final ItemStack[] armor; + @Getter private final Collection effects; + /* In which stage is entern allowed? */ + @Getter private final int enterStage; + /* Is this kit allowed to set/handle tnt? */ + @Getter private final boolean tnt; private final boolean leaderAllowed; private final boolean memberAllowed; @@ -140,10 +149,6 @@ public class Kit { return kits; } - public String getName() { - return name; - } - public boolean canUseKit(boolean leader){ if (leader) { return leaderAllowed; @@ -156,10 +161,6 @@ public class Kit { return !memberAllowed; } - public ItemStack[] getInventory() { - return inventory; - } - public boolean contains(ItemStack stack) { for(ItemStack i : inventory) { if(similar(i, stack)) @@ -172,24 +173,6 @@ public class Kit { return false; } - public ItemStack[] getArmor() { - return armor; - } - - public Collection getEffects() { - return effects; - } - - /* Is this kit allowed to set/handle tnt? */ - public boolean isTnt(){ - return tnt; - } - - /* In which stage is entern allowed? */ - public int getEnterStage() { - return enterStage; - } - public void toPersonalKit(PersonalKit kit) { kit.setContainer(inventory, armor); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java deleted file mode 100644 index 6839a3f..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; -import de.steamwar.fightsystem.utils.BountifulWrapper; - -public class ArrowPickup { - - public ArrowPickup() { - new StateDependentListener(ArenaMode.All, FightState.All, BountifulWrapper.impl.newDenyArrowPickupListener()); - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java index 67d39bc..98933dd 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/FileRecorder.java @@ -22,19 +22,17 @@ package de.steamwar.fightsystem.record; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; +import lombok.Getter; import java.io.*; import java.util.zip.GZIPOutputStream; public class FileRecorder extends StateDependent implements Recorder { + @Getter private static final File file = new File(Config.world.getWorldFolder(), "recording.recording"); private DataOutputStream outputStream; - public static File getFile() { - return file; - } - public FileRecorder(){ super(Config.ReplayID == 0, FightState.Recording); register(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java index 1a75d1a..1d5acf3 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/states/FightState.java @@ -19,6 +19,8 @@ package de.steamwar.fightsystem.states; +import lombok.Getter; + import java.util.*; public enum FightState { @@ -48,12 +50,9 @@ public enum FightState { public static final Set AntiSpectate = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(SPECTATE))); private static final Map stateDependentFeatures = new HashMap<>(); + @Getter private static FightState fightState = PRE_LEADER_SETUP; - public static FightState getFightState() { - return fightState; - } - public static void registerStateDependent(IStateDependent stateDependent){ if(stateDependent.enabled().isEmpty()) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index df12a82..1f46a3a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -35,6 +35,7 @@ import de.steamwar.network.packets.common.FightEndsPacket; import de.steamwar.sql.Replay; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; +import lombok.Getter; import org.bukkit.Bukkit; import java.sql.Timestamp; @@ -46,6 +47,7 @@ import static de.steamwar.sql.Fight.create; public class FightStatistics { + @Getter private static boolean unranked = false; public static void unrank() { @@ -53,10 +55,6 @@ public class FightStatistics { FightUI.addSubtitle("UI_UNRANKED"); } - public static boolean isUnranked() { - return unranked; - } - private Timestamp starttime = Timestamp.from(Instant.now()); public FightStatistics() { diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java index da6df9c..122b690 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java @@ -31,6 +31,7 @@ import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.winconditions.Wincondition; +import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -43,10 +44,8 @@ import java.util.stream.Collectors; public class FightUI { + @Getter private static FightUI instance; - public static FightUI getInstance() { - return instance; - } public FightUI() { new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java index e7bac5d..728fb92 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/ItemBuilder.java @@ -25,51 +25,26 @@ import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; -import java.util.List; - public class ItemBuilder { private final ItemStack item; private final ItemMeta meta; - public ItemBuilder(Material matrial) { - item = new ItemStack(matrial); - meta = item.getItemMeta(); - } - - public ItemBuilder(Material matrial, int amount) { - item = new ItemStack(matrial, amount); + public ItemBuilder(Material material) { + item = new ItemStack(material); meta = item.getItemMeta(); + meta.addItemFlags(ItemFlag.values()); } @SuppressWarnings("deprecation") - public ItemBuilder(Material matrial, short subid) { - item = new ItemStack(matrial, 1, subid); + public ItemBuilder(Material material, short subid) { + item = new ItemStack(material, 1, subid); meta = item.getItemMeta(); + meta.addItemFlags(ItemFlag.values()); } - - public ItemBuilder removeAllAttributes() { - meta.addItemFlags(ItemFlag.HIDE_ATTRIBUTES); - meta.addItemFlags(ItemFlag.HIDE_DESTROYS); - meta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - meta.addItemFlags(ItemFlag.HIDE_PLACED_ON); - meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS); - return this; - } - - public ItemBuilder setDisplayName(String name) { - meta.setDisplayName(name); - return this; - } - - public ItemBuilder addLore(List lore) { - meta.setLore(lore); - return this; - } - - public ItemBuilder addEnchantment(Enchantment enchantment, int level) { - meta.addEnchant(enchantment, level, true); + + public ItemBuilder enchant() { + meta.addEnchant(Enchantment.DURABILITY, 1, true); return this; } @@ -77,5 +52,4 @@ public class ItemBuilder { item.setItemMeta(meta); return item; } - } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Message.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Message.java index a142a7e..9484b64 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/Message.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/Message.java @@ -19,7 +19,11 @@ package de.steamwar.fightsystem.utils; +import lombok.Getter; + +@Getter public class Message { + private final String msg; private final Object[] params; @@ -27,12 +31,4 @@ public class Message { this.msg = msg; this.params = params; } - - public String getMsg() { - return msg; - } - - public Object[] getParams() { - return params; - } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java index 3f0f58e..3b62aff 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/Wincondition.java @@ -24,6 +24,7 @@ import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.StateDependentCountdown; +import lombok.Getter; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -34,8 +35,10 @@ import java.util.stream.Collectors; public abstract class Wincondition { + @Getter protected static WinconditionPercent percentWincondition = null; protected static StateDependentCountdown timeOverCountdown = null; + @Getter protected static final List printableWinconditions = new ArrayList<>(); private final String windescription; @@ -61,14 +64,6 @@ public abstract class Wincondition { return Fight.getPlayerTeam((LivingEntity) player); } - public static List getPrintableWinconditions(){ - return printableWinconditions; - } - - public static WinconditionPercent 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());