From 765a9e4f6ca3b15d6fc8edba088ebb9197a75ec1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 31 Aug 2021 11:19:56 +0200 Subject: [PATCH] Reduce overhead and add a World of Colors! Signed-off-by: Lixfel --- .../fightsystem/fight/FightTeam12.java | 31 ------------------ .../WorldOfColorWrapper12.java} | 10 ++++-- .../fightsystem/listener/ArrowPickup8.java | 25 --------------- .../listener/DenyWorldInteraction8.java | 25 --------------- .../fightsystem/utils/BountifulWrapper8.java | 11 +++++++ .../WorldOfColorWrapper8.java} | 11 +++++-- .../fightsystem/listener/ArrowPickup9.java | 32 ------------------- .../listener/DenyWorldInteraction9.java | 32 ------------------- .../fightsystem/utils/BountifulWrapper9.java | 24 ++++++++++++++ .../steamwar/fightsystem/fight/FightTeam.java | 14 ++------ .../fightsystem/listener/ArrowPickup.java | 4 +-- .../fightsystem/listener/ArrowStopper.java | 6 ++-- .../listener/DenyWorldInteraction.java | 4 +-- .../fightsystem/utils/BountifulWrapper.java | 4 +++ .../utils/WorldOfColorWrapper.java | 24 ++++++++------ 15 files changed, 78 insertions(+), 179 deletions(-) delete mode 100644 FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java rename FightSystem_12/src/de/steamwar/fightsystem/{listener/ArrowStopper12.java => utils/WorldOfColorWrapper12.java} (75%) delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java delete mode 100644 FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java rename FightSystem_8/src/de/steamwar/fightsystem/{listener/ArrowStopper8.java => utils/WorldOfColorWrapper8.java} (73%) delete mode 100644 FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java delete mode 100644 FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java rename FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java => FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java (61%) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java b/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java deleted file mode 100644 index 7f24260..0000000 --- a/FightSystem_12/src/de/steamwar/fightsystem/fight/FightTeam12.java +++ /dev/null @@ -1,31 +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.fight; - -import org.bukkit.ChatColor; -import org.bukkit.scoreboard.Team; - -public class FightTeam12 implements FightTeam.IFightTeam { - - @Override - public void setTeamColor(Team team, ChatColor color){ - team.setColor(color); - } -} diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java similarity index 75% rename from FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java rename to FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java index 08b42cc..1c3e416 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/listener/ArrowStopper12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper12.java @@ -17,11 +17,17 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; +import org.bukkit.ChatColor; import org.bukkit.entity.Arrow; +import org.bukkit.scoreboard.Team; -public class ArrowStopper12 implements ArrowStopper.IArrowStopper { +public class WorldOfColorWrapper12 implements WorldOfColorWrapper.IWorldOfColorWrapper { + @Override + public void setTeamColor(Team team, ChatColor color) { + team.setColor(color); + } @Override public boolean isInBlock(Arrow e) { diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java deleted file mode 100644 index f5a9c7e..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowPickup8.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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 org.bukkit.event.Listener; - -public class ArrowPickup8 implements Listener { -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java deleted file mode 100644 index db0b29c..0000000 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/DenyWorldInteraction8.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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 org.bukkit.event.Listener; - -public class DenyWorldInteraction8 implements Listener { -} diff --git a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java index 6d9c805..b09a3df 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/BountifulWrapper8.java @@ -26,6 +26,7 @@ import net.minecraft.server.v1_8_R3.PacketPlayOutChat; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @@ -55,4 +56,14 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { public void setNametagVisibility(Team team) { //nothing to do } + + @Override + public Listener newDenyArrowPickupListener() { + return new Listener() {}; + } + + @Override + public Listener newDenyHandSwapListener() { + return new Listener() {}; + } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java similarity index 73% rename from FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java rename to FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java index 1c1c96c..79be18a 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/ArrowStopper8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper8.java @@ -17,11 +17,18 @@ along with this program. If not, see . */ -package de.steamwar.fightsystem.listener; +package de.steamwar.fightsystem.utils; +import org.bukkit.ChatColor; import org.bukkit.entity.Arrow; +import org.bukkit.scoreboard.Team; + +public class WorldOfColorWrapper8 implements WorldOfColorWrapper.IWorldOfColorWrapper { + @Override + public void setTeamColor(Team team, ChatColor color) { + team.setPrefix("§" + color.getChar()); + } -public class ArrowStopper8 implements ArrowStopper.IArrowStopper { @Override public boolean isInBlock(Arrow e) { return false; diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.java deleted file mode 100644 index 28ce13b..0000000 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/ArrowPickup9.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 org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerPickupArrowEvent; - -public class ArrowPickup9 implements Listener { - - @EventHandler - public void onArrowPickup(PlayerPickupArrowEvent e){ - e.setCancelled(true); - } -} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java b/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java deleted file mode 100644 index c5c6733..0000000 --- a/FightSystem_9/src/de/steamwar/fightsystem/listener/DenyWorldInteraction9.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2021 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 org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerSwapHandItemsEvent; - -public class DenyWorldInteraction9 implements Listener { - - @EventHandler - public void onSwapItems(PlayerSwapHandItemsEvent event) { - event.setCancelled(true); - } -} diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index ba721de..5bc1d10 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -26,6 +26,10 @@ import org.bukkit.Material; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupArrowEvent; +import org.bukkit.event.player.PlayerSwapHandItemsEvent; import org.bukkit.scoreboard.Team; public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @@ -55,4 +59,24 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { public void setNametagVisibility(Team team) { team.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM); } + + @Override + public Listener newDenyArrowPickupListener() { + return new Listener() { + @EventHandler + public void onArrowPickup(PlayerPickupArrowEvent e){ + e.setCancelled(true); + } + }; + } + + @Override + public Listener newDenyHandSwapListener() { + return new Listener() { + @EventHandler + public void onSwapItems(PlayerSwapHandItemsEvent event) { + event.setCancelled(true); + } + }; + } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index fab2aea..37a705c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -24,17 +24,13 @@ import de.steamwar.comms.packets.TablistNamePacket; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.countdown.Countdown; import de.steamwar.fightsystem.listener.FightScoreboard; import de.steamwar.fightsystem.listener.PersonalKitCreator; import de.steamwar.fightsystem.record.GlobalRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.BountifulWrapper; -import de.steamwar.fightsystem.utils.ItemBuilder; -import de.steamwar.fightsystem.utils.Region; -import de.steamwar.fightsystem.utils.TechHider; +import de.steamwar.fightsystem.utils.*; import de.steamwar.inventory.SWItem; import de.steamwar.sql.Schematic; import de.steamwar.sql.SteamwarUser; @@ -50,8 +46,6 @@ import java.util.*; public class FightTeam { - private static final IFightTeam impl = VersionDependent.getVersionImpl(FightTeam.class.getName()); - private UUID designatedLeader; private FightPlayer leader; private final Map players = new HashMap<>(); @@ -89,7 +83,7 @@ public class FightTeam { else team = FightScoreboard.getBukkit().getTeam(name); assert team != null; - impl.setTeamColor(team, color); + WorldOfColorWrapper.impl.setTeamColor(team, color); BountifulWrapper.impl.setNametagVisibility(team); //noinspection deprecation team.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS); @@ -406,10 +400,6 @@ public class FightTeam { return color; } - public interface IFightTeam { - void setTeamColor(Team team, ChatColor color); - } - private class KitLoader extends StateDependent { private KitLoader() { super(ArenaMode.AntiReplay, FightState.Ingame); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java index ccf9acd..6839a3f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowPickup.java @@ -20,13 +20,13 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.VersionDependent; 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, VersionDependent.getVersionImpl(ArrowPickup.class.getName())); + new StateDependentListener(ArenaMode.All, FightState.All, BountifulWrapper.impl.newDenyArrowPickupListener()); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java index 47fcecf..1e286e9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/ArrowStopper.java @@ -20,9 +20,9 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentTask; +import de.steamwar.fightsystem.utils.WorldOfColorWrapper; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -37,8 +37,6 @@ public class ArrowStopper { private static final Vector NULL_VECTOR = new Vector(0, 0, 0); private static final BlockFace[] BLOCK_FACES = {BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.WEST, BlockFace.NORTH, BlockFace.SOUTH}; - private static final IArrowStopper impl = VersionDependent.getVersionImpl(ArrowStopper.class.getName()); - public ArrowStopper() { new StateDependentTask(Config.TechhiderActive, FightState.Running, this::run, 1, 1); } @@ -93,7 +91,7 @@ public class ArrowStopper { boolean overMid = entity.getLocation().getZ() > Config.SpecSpawn.getZ(); boolean otherSide = teamFrom == overMid; return otherSide || - impl.isInBlock(entity) || + WorldOfColorWrapper.impl.isInBlock(entity) || entity.getVelocity().equals(NULL_VECTOR); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java index 998f8cb..579d303 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/DenyWorldInteraction.java @@ -20,9 +20,9 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.VersionDependent; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; +import de.steamwar.fightsystem.utils.BountifulWrapper; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -41,7 +41,7 @@ public class DenyWorldInteraction implements Listener { new StateDependentListener(ArenaMode.Test, FightState.PreRunning, this); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, this); - Listener listener = VersionDependent.getVersionImpl(DenyWorldInteraction.class.getName()); + Listener listener = BountifulWrapper.impl.newDenyHandSwapListener(); new StateDependentListener(ArenaMode.Test, FightState.PreRunning, listener); new StateDependentListener(ArenaMode.AntiTest, FightState.AntiRunning, listener); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java index e6705b8..f205977 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/BountifulWrapper.java @@ -23,6 +23,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers; import de.steamwar.fightsystem.VersionDependent; import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.entity.Player; +import org.bukkit.event.Listener; import org.bukkit.scoreboard.Team; public class BountifulWrapper { @@ -39,5 +40,8 @@ public class BountifulWrapper { void setAttackSpeed(Player player); void setNametagVisibility(Team team); + + Listener newDenyArrowPickupListener(); + Listener newDenyHandSwapListener(); } } diff --git a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java similarity index 61% rename from FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java rename to FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java index de213b8..f1a3bce 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/fight/FightTeam8.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/WorldOfColorWrapper.java @@ -1,7 +1,7 @@ -/* +/* This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam + + Copyright (C) 2021 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 @@ -15,18 +15,22 @@ You should have received a copy of the GNU Affero General Public License along with this program. If not, see . -*/ + */ -package de.steamwar.fightsystem.fight; +package de.steamwar.fightsystem.utils; +import de.steamwar.fightsystem.VersionDependent; import org.bukkit.ChatColor; +import org.bukkit.entity.Arrow; import org.bukkit.scoreboard.Team; -public class FightTeam8 implements FightTeam.IFightTeam { +public class WorldOfColorWrapper { + private WorldOfColorWrapper() {} - @Override - public void setTeamColor(Team team, ChatColor color){ - team.setPrefix("§" + color.getChar()); + public static final IWorldOfColorWrapper impl = VersionDependent.getVersionImpl(WorldOfColorWrapper.class.getName()); + + public interface IWorldOfColorWrapper { + void setTeamColor(Team team, ChatColor color); + boolean isInBlock(Arrow e); } - }