From aed86fc97b9b1053cf42ab1e1d70832773134c59 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 3 Jun 2020 10:19:57 +0200 Subject: [PATCH 01/19] Some refactoring Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 9 ++-- .../de/steamwar/fightsystem/IFightSystem.java | 7 --- .../fightsystem/fight/IFightTeam.java | 1 + .../fightsystem/utils/ITechHider.java | 4 +- .../de/steamwar/fightsystem/FightSystem.java | 8 +-- .../fightsystem/countdown/Countdown.java | 2 +- .../countdown/EnternCountdown.java | 52 ++++++++++++++++--- .../fightsystem/fight/FightPlayer.java | 7 +++ .../steamwar/fightsystem/fight/FightTeam.java | 5 ++ .../src/de/steamwar/fightsystem/kit/Kit.java | 22 +++++++- .../steamwar/fightsystem/kit/KitManager.java | 5 +- .../listener/EntityExplodeListener.java | 2 +- .../listener/InFightDamageListener.java | 2 +- .../listener/InFightInventoryListener.java | 14 ++++- .../fightsystem/listener/PistonListener.java | 2 +- .../listener/PlayerMoveListener.java | 2 +- .../fightsystem/states/FightState.java | 5 +- .../fightsystem/utils/EnterHandler.java | 26 ++++++++++ .../fightsystem/utils/FightScoreboard.java | 4 +- .../winconditions/PlayerWincondition.java | 2 +- .../WinconditionHeartRatioTimeout.java | 2 +- .../WinconditionPercentSystem.java | 2 +- .../WinconditionPumpkinTechKO.java | 2 +- .../WinconditionRelativePercent.java | 3 +- .../winconditions/WinconditionTimeout.java | 2 +- 25 files changed, 144 insertions(+), 48 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 6bc2361..6ecaabe 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -24,9 +24,10 @@ public class Config { public static final int PreSchemPasteDuration; public static final int SetupDuration; public static final int PreFightDuration; - public static final int EnterPhaseBegin; public static final int SpectatorDuration; - public static final boolean Entern; + + // entern parameter + public static final List EnterStages; //arena parameter public static final int SchemsizeX; @@ -183,16 +184,16 @@ public class Config { PercentSystem = config.getBoolean("WinConditions.PercentSystem"); RelativePercent = config.getBoolean("WinConditions.RelativePercent"); Points = config.getBoolean("WinConditions.Points"); - Entern = config.getBoolean("WinConditions.Entern"); TechKO = config.getBoolean("WinConditions.TechKO"); WaterTechKO = config.getBoolean("WinConditions.WaterTechKO"); PumpkinTechKO = config.getBoolean("WinConditions.PumpkinTechKO"); TimeoutTime = config.getInt("WinConditionParams.TimeoutTime"); - EnterPhaseBegin = config.getInt("WinConditionParams.EnterPhaseBegin"); PercentWin = config.getDouble("WinConditionParams.PercentWin"); IgnoredBlocks = Collections.unmodifiableList(config.getStringList("WinConditionParams.IgnoredBlocks")); + EnterStages = Collections.unmodifiableList(config.getIntegerList("EnterStages")); + MemberDefault = config.getString("Kits.MemberDefault"); LeaderDefault = config.getString("Kits.LeaderDefault"); PersonalKits = config.getBoolean("Kits.PersonalKits"); diff --git a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java index 87856b8..6a0a0eb 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/IFightSystem.java @@ -11,7 +11,6 @@ public class IFightSystem { private static Plugin plugin; private static String prefix; private static EventFight eventFight; - private static boolean entern = false; private static Player eventLeiter; public static void init(Plugin plugin, String prefix){ @@ -21,9 +20,6 @@ public class IFightSystem { static void setEventFight(EventFight ef){ eventFight = ef; } - static void setEntern(boolean entern){ - IFightSystem.entern = entern; - } static void setEventLeiter(Player el){ eventLeiter = el; } @@ -37,9 +33,6 @@ public class IFightSystem { public static EventFight getEventFight(){ return eventFight; } - public static boolean isEntern(){ - return entern; - } public static Player getEventLeiter(){ return eventLeiter; } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java b/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java index 6491970..c18a8a7 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/fight/IFightTeam.java @@ -6,4 +6,5 @@ public interface IFightTeam { boolean isBlue(); boolean isPlayerInTeam(Player player); + boolean canPlayerEntern(Player player); } diff --git a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java index d8540b4..144075f 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/utils/ITechHider.java @@ -70,13 +70,13 @@ public class ITechHider { arenaMinZ > chunkZ || chunkZ > arenaMaxZ; }else if(ft.isBlue()){ - return IFightSystem.isEntern() || + return ft.canPlayerEntern(p) || redMinX > chunkX || chunkX > redMaxX || redMinZ > chunkZ || chunkZ > redMaxZ; }else{ - return IFightSystem.isEntern() || + return ft.canPlayerEntern(p) || blueMinX > chunkX || chunkX > blueMaxX || blueMinZ > chunkZ || diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 304b658..2571b4d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -161,8 +161,7 @@ public class FightSystem extends JavaPlugin { setFightState(FightState.RUNNING); setAllPlayersGM(GameMode.SURVIVAL); - if(Config.Entern) - mainCountdown = new EnternCountdown(); + //TODO: Entern Countdowns and Entern chunk reload FightStatistics.start(); WaterRemover.init(); @@ -170,13 +169,10 @@ public class FightSystem extends JavaPlugin { } public static void setEntern() { - if(fightState != FightState.RUNNING) - throw new SecurityException(fightState.name()); - setFightState(FightState.ENTERN); + //TODO: Remove this function final List chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer()); final List chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer()); - IFightSystem.setEntern(true); for(FightPlayer player : Fight.getBlueTeam().getPlayers()){ TechHider.reloadChunks(player.getPlayer(), chunksBlue); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java index c26acc1..d330b6c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -59,7 +59,7 @@ public abstract class Countdown { BasicListener.toActionbar(p, msg); } - private void count(){ + void count(){ switch (time) { case 900: case 600: case 300: case 180: case 120: broadcast("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 0029c7b..09258f7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -1,13 +1,19 @@ package de.steamwar.fightsystem.countdown; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.Config; -import org.bukkit.Bukkit; +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.listener.BasicListener; +import net.md_5.bungee.api.chat.TextComponent; +import org.bukkit.entity.Player; public class EnternCountdown extends Countdown { - public EnternCountdown() { - super(Config.EnterPhaseBegin, SWSound.BLOCK_NOTE_PLING, false); + private final FightPlayer fightPlayer; + + public EnternCountdown(FightPlayer fp) { + super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false); + fightPlayer = fp; } @Override @@ -17,7 +23,41 @@ public class EnternCountdown extends Countdown { @Override public void countdownFinished() { - FightSystem.setEntern(); - Bukkit.broadcastMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); + fightPlayer.getPlayer().sendMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); + //TODO + } + + @Override + void count(){ + Player player = fightPlayer.getPlayer(); + if(!fightPlayer.isLiving()){ + disable(); + return; + } + + int time = Config.EnterStages.get(fightPlayer.getKit().getEnterStage()) - FightSystem.getFightTime(); + switch (time) { + case 900: case 600: case 300: case 180: case 120: + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting())); + break; + case 60: case 30: case 20: case 15: case 10: case 5: case 4: case 3: case 2: + player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F); + + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time + " §rSekunden " + countdownCounting())); + break; + case 1: + player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F); + + BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a1 §rSekunde " + countdownCounting())); + //TODO + break; + case 0: + player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 2.0F); + + disable(); + countdownFinished(); + break; + default: + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java index 43bfbce..57f0c28 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -1,5 +1,6 @@ package de.steamwar.fightsystem.fight; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.kit.Kit; @@ -62,4 +63,10 @@ public class FightPlayer { public void addKill(){ kills++; } + + public boolean canEntern(){ + if(Config.EnterStages.size() <= kit.getEnterStage() || kit.getEnterStage() < 0) + return false; + return Config.EnterStages.get(kit.getEnterStage()) >= FightSystem.getFightTime(); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 22e7a21..0063501 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -127,6 +127,11 @@ public class FightTeam implements IFightTeam{ return false; } + @Override + public boolean canPlayerEntern(Player player) { + return getFightPlayer(player).canEntern(); + } + public boolean isPlayerLeader(Player player) { if(leader != null) return leader.getPlayer().equals(player); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java index f7a413d..fda2c5d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java @@ -21,6 +21,8 @@ public class Kit { private final ItemStack[] inventory; private final ItemStack[] armor; private final Collection effects; + private final int enterStage; + private final boolean tnt; Kit(String name, Player player) { this.name = name; @@ -29,13 +31,15 @@ public class Kit { this.inventory = player.getInventory().getContents(); this.armor = player.getInventory().getArmorContents(); this.effects = player.getActivePotionEffects(); + this.enterStage = 0; + this.tnt = true; } Kit(ConfigurationSection kit){ name = kit.getName(); - inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[1]); + inventory = Objects.requireNonNull(kit.getList("Items")).toArray(new ItemStack[0]); if(kit.isList("Armor")) - armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[1]); + armor = Objects.requireNonNull(kit.getList("Armor")).toArray(new ItemStack[0]); else armor = null; leaderAllowed = kit.getBoolean("LeaderAllowed"); @@ -44,6 +48,8 @@ public class Kit { effects = (Collection) kit.getList("Effects"); else effects = null; + enterStage = kit.getInt("EnterStage", 0); + tnt = kit.getBoolean("TNT", true); } public String getName() { @@ -58,6 +64,16 @@ public class Kit { return memberAllowed; } + /* Is this kit allowed to set/handle tnt? */ + public boolean isTnt(){ + return tnt; + } + + /* In which stage is entern allowed? */ + public int getEnterStage() { + return enterStage; + } + public boolean isStackInKit(ItemStack stack){ for(ItemStack is : inventory){ if(stack.equals(is)) @@ -88,6 +104,8 @@ public class Kit { section.set("LeaderAllowed", leaderAllowed); section.set("MemberAllowed", memberAllowed); section.set("Effects", effects); + section.set("EnterStage", enterStage); + section.set("TNT", tnt); } /** diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java index e6a05e5..88cfd3e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/KitManager.java @@ -15,8 +15,7 @@ import java.util.logging.Level; public class KitManager { private KitManager(){} - private static final String KITS_PATH = "plugins/" + FightSystem.getPlugin().getName() + "/kits.data"; - private static final File kits = new File(KITS_PATH); + private static final File kits = new File(FightSystem.getPlugin().getDataFolder(), "kits.data"); private static final FileConfiguration kitData = YamlConfiguration.loadConfiguration(kits); private static final ArrayList loadedKits = new ArrayList<>(); @@ -49,7 +48,7 @@ public class KitManager { } public static void loadAllKits() { - if(!new File(KITS_PATH).exists()) { + if(!kits.exists()) { saveAllKits(); Bukkit.getLogger().log(Level.INFO, "kits.data erstellt!"); FightSystem.shutdown(null); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java index 390ddfb..facbef6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/EntityExplodeListener.java @@ -10,7 +10,7 @@ import java.util.EnumSet; public class EntityExplodeListener extends BasicListener { public EntityExplodeListener() { - super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(EnumSet.of(FightState.RUNNING)); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java index fda06cb..9bf5239 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java @@ -15,7 +15,7 @@ import java.util.Objects; public class InFightDamageListener extends BasicListener { public InFightDamageListener() { - super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(EnumSet.of(FightState.RUNNING)); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java index 65c1bb0..821803a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java @@ -1,9 +1,13 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.states.FightState; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryDragEvent; import org.bukkit.event.inventory.InventoryPickupItemEvent; @@ -17,7 +21,7 @@ import java.util.EnumSet; public class InFightInventoryListener extends BasicListener { public InFightInventoryListener() { - super(EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(EnumSet.of(FightState.RUNNING)); } @EventHandler @@ -93,4 +97,12 @@ public class InFightInventoryListener extends BasicListener { } } + @EventHandler + public void onBlockPlace(BlockPlaceEvent e) { + FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); + if(fp != null && !fp.getKit().isTnt()){ + BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst keine Blöcke setzen!")); + e.setCancelled(true); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index 472e4b8..bbaf4d7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -15,7 +15,7 @@ public class PistonListener extends BasicListener { public PistonListener() { //Wenn Entern aktiv ist, sollen Raketen etc. entern können - super(Config.Entern + super(Config.EnterStages.isEmpty() ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) : EnumSet.allOf(FightState.class)); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java index 2584a99..5b7561c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerMoveListener.java @@ -50,7 +50,7 @@ public class PlayerMoveListener extends BasicListener { reset(event, DENY_TEAM); else if(fightTeam == Fight.getBlueTeam() && player.getGameMode() == GameMode.SPECTATOR) reset(event, DENY_ENTERN); - }else if(fightTeam != null && FightSystem.getFightState() != FightState.ENTERN && player.getGameMode() != GameMode.SPECTATOR) + }else if(fightTeam != null && player.getGameMode() != GameMode.SPECTATOR && !fightTeam.canPlayerEntern(player)) reset(event, DENY_ENTERN); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java index 36af1ae..34cc543 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/states/FightState.java @@ -6,13 +6,12 @@ public enum FightState { POST_SCHEM_SETUP(true, true, false, false), PRE_RUNNING(false, false, true, false), RUNNING(false, false, true, true), - ENTERN(false, false, true, true), //Can be skipped SPECTATE(false, true, false, false); private final boolean setup; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP private final boolean outgame; //PRE_LEADER_SETUP, PRE_SCHEM_SETUP, POST_SCHEM_SETUP, SPECTATE - private final boolean ingame; //PRE_RUNNING, RUNNING, ENTERN - private final boolean infight; //RUNNING, ENTERN + private final boolean ingame; //PRE_RUNNING, RUNNING + private final boolean infight; //RUNNING FightState(boolean setup, boolean outgame, boolean ingame, boolean infight){ this.setup = setup; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java new file mode 100644 index 0000000..e2261e9 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -0,0 +1,26 @@ +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.states.FightState; +import de.steamwar.fightsystem.states.StateDependent; + +import java.util.EnumSet; +import java.util.Set; + +public class EnterHandler implements StateDependent { + private static final Set enabled = EnumSet.of(FightState.RUNNING); + + @Override + public Set enabled() { + return enabled; + } + + @Override + public void enable() { + + } + + @Override + public void disable() { + + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java index f11db48..4e1b7a0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightScoreboard.java @@ -19,7 +19,7 @@ public class FightScoreboard { private FightScoreboard(){} - private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.ENTERN, FightState.SPECTATE); + private static final Set fullScoreboard = EnumSet.of(FightState.RUNNING, FightState.SPECTATE); private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Objective objective; private static int index = 0; @@ -70,8 +70,6 @@ public class FightScoreboard { else objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); } - if (Config.Entern) - objective.getScore("§7Entern: " + (FightSystem.getFightState() == FightState.ENTERN ? "§aja" : "§cnein")).setScore(2); if(fullScoreboard.contains(FightSystem.getFightState())){ if (Config.PercentSystem){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java index 9cac8f5..06f21af 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/PlayerWincondition.java @@ -10,7 +10,7 @@ import java.util.EnumSet; abstract class PlayerWincondition extends ListenerWincondition { PlayerWincondition(boolean condition) { - super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN)); + super(condition, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); } boolean isTarget(Player player){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index 32d8b7c..f4721a9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -13,7 +13,7 @@ public class WinconditionHeartRatioTimeout extends Wincondition { private TimeOverCountdown countdown; public WinconditionHeartRatioTimeout() { - super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(Config.HeartRatioTimeout, EnumSet.of(FightState.RUNNING)); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index b9c566a..b2146e6 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -22,7 +22,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { private static final int schematicSize = Math.abs(Config.SchemsizeX * Config.SchemsizeY * Config.SchemsizeZ); public WinconditionPercentSystem() { - super(Config.PercentSystem, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(Config.PercentSystem, EnumSet.of(FightState.RUNNING)); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index c59d1ae..313cbff 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -22,7 +22,7 @@ public class WinconditionPumpkinTechKO extends Wincondition { private BukkitTask task; public WinconditionPumpkinTechKO(){ - super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING, FightState.ENTERN)); + super(Config.PumpkinTechKO, EnumSet.of(FightState.PRE_RUNNING, FightState.RUNNING)); } public static int getTeamBluePumpkins() { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index fe4efc3..0dc010b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -89,7 +89,8 @@ public class WinconditionRelativePercent extends Wincondition{ } private int currentBlocks(){ - if(FightSystem.getFightState() == FightState.ENTERN || FightSystem.getFightState() == FightState.SPECTATE) + // Entern active + if(!Config.EnterStages.isEmpty() && Config.EnterStages.get(0) <= FightSystem.getFightTime()) return currentBlocks; int blocks = 0; diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index 6b95af1..8a9ea6d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -12,7 +12,7 @@ public class WinconditionTimeout extends Wincondition { private TimeOverCountdown countdown; public WinconditionTimeout() { - super(Config.Timeout, EnumSet.of(FightState.RUNNING, FightState.ENTERN)); + super(Config.Timeout, EnumSet.of(FightState.RUNNING)); } @Override From e4fe75693a1aae957c142a4c848820cc9e129f4b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Jun 2020 09:40:29 +0200 Subject: [PATCH 02/19] Finish enter handler Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 18 ++------------- .../countdown/EnternCountdown.java | 12 +++++++--- .../fightsystem/utils/EnterHandler.java | 22 +++++++++++++++++-- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index c1215e2..70fced4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -21,7 +21,6 @@ import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.logging.Level; @@ -77,6 +76,8 @@ public class FightSystem extends JavaPlugin { if(Core.getVersion() > 8) new ExtendedInventoryListener(); + new EnterHandler(); + new WinconditionAllDead(); new WinconditionCaptainDead(); new WinconditionPumpkinTechKO(); @@ -172,26 +173,11 @@ public class FightSystem extends JavaPlugin { setFightState(FightState.RUNNING); setAllPlayersGM(GameMode.SURVIVAL); - //TODO: Entern Countdowns and Entern chunk reload - FightStatistics.start(); WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } - public static void setEntern() { - //TODO: Remove this function - - final List chunksBlue = TechHider.prepareChunkReload(Fight.getBlueTeam().getPlayers().iterator().next().getPlayer()); - final List chunksRed = TechHider.prepareChunkReload(Fight.getRedTeam().getPlayers().iterator().next().getPlayer()); - for(FightPlayer player : Fight.getBlueTeam().getPlayers()){ - TechHider.reloadChunks(player.getPlayer(), chunksBlue); - } - for(FightPlayer player : Fight.getRedTeam().getPlayers()){ - TechHider.reloadChunks(player.getPlayer(), chunksRed); - } - } - public static void setSpectateState(FightTeam winFightTeam, String windescription) { if(!fightState.ingame()) throw new SecurityException(fightState.name()); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index 09258f7..c18b4bc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -4,12 +4,17 @@ import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.listener.BasicListener; +import de.steamwar.fightsystem.utils.ITechHider; +import de.steamwar.fightsystem.utils.TechHider; import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.entity.Player; +import java.util.List; + public class EnternCountdown extends Countdown { private final FightPlayer fightPlayer; + private List chunkPos; public EnternCountdown(FightPlayer fp) { super(fp.getKit().getEnterStage(), SWSound.BLOCK_NOTE_PLING, false); @@ -24,17 +29,17 @@ public class EnternCountdown extends Countdown { @Override public void countdownFinished() { fightPlayer.getPlayer().sendMessage(FightSystem.PREFIX + "§aEntern ist nun erlaubt!"); - //TODO + TechHider.reloadChunks(fightPlayer.getPlayer(), chunkPos); } @Override void count(){ - Player player = fightPlayer.getPlayer(); if(!fightPlayer.isLiving()){ disable(); return; } + Player player = fightPlayer.getPlayer(); int time = Config.EnterStages.get(fightPlayer.getKit().getEnterStage()) - FightSystem.getFightTime(); switch (time) { case 900: case 600: case 300: case 180: case 120: @@ -49,7 +54,8 @@ public class EnternCountdown extends Countdown { player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 1.0F); BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a1 §rSekunde " + countdownCounting())); - //TODO + + chunkPos = TechHider.prepareChunkReload(player); break; case 0: player.playSound(player.getLocation(), Countdown.getSound(SWSound.BLOCK_NOTE_PLING), 100.0F, 2.0F); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java index e2261e9..3eb6d4a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -1,26 +1,44 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.countdown.EnternCountdown; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightPlayer; +import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; import java.util.EnumSet; +import java.util.HashSet; import java.util.Set; public class EnterHandler implements StateDependent { private static final Set enabled = EnumSet.of(FightState.RUNNING); + private static final Set countdowns = new HashSet<>(); @Override public Set enabled() { return enabled; } + private void registerTeam(FightTeam team){ + for(FightPlayer fp : team.getPlayers()){ + if(Config.EnterStages.size() > fp.getKit().getEnterStage() && fp.getKit().getEnterStage() >= 0) + countdowns.add(new EnternCountdown(fp)); + } + } + @Override public void enable() { - + registerTeam(Fight.getBlueTeam()); + registerTeam(Fight.getRedTeam()); } @Override public void disable() { - + for(EnternCountdown countdown : countdowns){ + countdown.disable(); + } + countdowns.clear(); } } From 669a822bd6c7fa996384c9d5eed2970bad5da74d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 22 Jun 2020 17:14:45 +0200 Subject: [PATCH 03/19] Hotfix WaterRemover loop Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/utils/WaterRemover.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index 64ef49e..b4cb48b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -16,11 +16,19 @@ public class WaterRemover { private static final Map explodedBlocks = Collections.synchronizedMap(new HashMap<>()); private static Set waterList = new HashSet<>(); + private static boolean isRunning = false; + private static int steps = 1; public static void init() { Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { + if(isRunning){ + steps++; + return; + } + isRunning = true; wateredCheck(); removeWater(); + isRunning = false; }, 0, 20); } @@ -41,13 +49,14 @@ public class WaterRemover { it.remove(); continue; } - e.setValue(e.getValue() + 1); + e.setValue(e.getValue() + steps); if(e.getValue() > 15) it.remove(); } + steps = 1; }catch(ConcurrentModificationException e){ - wateredCheck(); + steps++; } } From 228cb9e768bbb57b3e85684a960ebb0bb7636f9e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Jul 2020 09:33:31 +0200 Subject: [PATCH 04/19] Fix non TNT-Kits only no tnt Signed-off-by: Lixfel --- .../fightsystem/listener/InFightInventoryListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java index 821803a..531b2e5 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightInventoryListener.java @@ -100,8 +100,8 @@ public class InFightInventoryListener extends BasicListener { @EventHandler public void onBlockPlace(BlockPlaceEvent e) { FightPlayer fp = Fight.getFightPlayer(e.getPlayer()); - if(fp != null && !fp.getKit().isTnt()){ - BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst keine Blöcke setzen!")); + if(fp != null && !fp.getKit().isTnt() && e.getBlockPlaced().getType() == Material.TNT){ + BasicListener.toActionbar(e.getPlayer(), TextComponent.fromLegacyText("§cDu darfst kein TNT setzen!")); e.setCancelled(true); } } From 1261459b79e85dc81b7b6738d4c46388ace6910f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Jul 2020 11:04:38 +0200 Subject: [PATCH 05/19] Fix fightstatistics Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightStatistics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 1b377eb..57c178f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -41,6 +41,6 @@ public class FightStatistics { private static void savePlayerStats(FightPlayer fp, int fightId){ SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); - de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); + de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); } } From 2aabded41edbe14504afadefd4ce373d35228d7b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 5 Jul 2020 16:29:21 +0200 Subject: [PATCH 06/19] Faster Waterremover Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/WaterRemover.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index 63119f3..c9538c9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -51,7 +51,7 @@ public class WaterRemover { } e.setValue(e.getValue() + steps); - if(e.getValue() > 15) + if(e.getValue() > 3) it.remove(); } steps = 1; From 727129fe8e80a867ad25002d7335480f72272b7c Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 6 Jul 2020 17:39:45 +0200 Subject: [PATCH 07/19] Faster Waterremover Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 1 - .../fightsystem/utils/WaterRemover.java | 111 +++++------------- 2 files changed, 31 insertions(+), 81 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index feb9395..c03ce3c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -176,7 +176,6 @@ public class FightSystem extends JavaPlugin { mainCountdown = new EnternCountdown(); FightStatistics.start(); - WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java index c9538c9..728dc91 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/WaterRemover.java @@ -1,106 +1,57 @@ package de.steamwar.fightsystem.utils; import de.steamwar.core.Core; -import de.steamwar.fightsystem.FightSystem; -import org.bukkit.Bukkit; -import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; -import java.util.*; +import java.util.List; public class WaterRemover { - private WaterRemover(){} - private static final Map explodedBlocks = Collections.synchronizedMap(new HashMap<>()); - private static Set waterList = new HashSet<>(); - private static boolean isRunning = false; - private static int steps = 1; - - public static void init() { - Bukkit.getScheduler().runTaskTimerAsynchronously(FightSystem.getPlugin(), () -> { - if(isRunning){ - steps++; - return; - } - isRunning = true; - wateredCheck(); - removeWater(); - isRunning = false; - }, 0, 20); - } - public static void add(List l) { - l.forEach((Block b) -> explodedBlocks.put(b.getLocation(), 0)); - } + for(Block b : l){ + //b cannot be water or air due to current explosion - private static void wateredCheck() { - try{ - Iterator> it = explodedBlocks.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry e = it.next(); - Block b = e.getKey().getBlock(); - if (isWater(b)) - waterList.add(b); - - if(b.getType() != Material.AIR){ - it.remove(); - continue; - } - e.setValue(e.getValue() + steps); - - if(e.getValue() > 3) - it.remove(); + int startX = b.getX(); + int startY = b.getY(); + int startZ = b.getZ(); + try{ + checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ); + }catch(IsAnOcean e){ + //ignore } - steps = 1; - }catch(ConcurrentModificationException e){ - steps++; } } - private static void removeWater() { - List blocksToRemove = new LinkedList<>(); - Iterator it = waterList.iterator(); - while(it.hasNext()){ - Block b = it.next(); - blocksToRemove.addAll(getSourceBlocksOfWater(b)); - if (!isWater(b)) - it.remove(); - } - - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> blocksToRemove.forEach((Block b) -> b.setType(Material.AIR))); - } - - private static Set getSourceBlocksOfWater(Block startBlock) { - Set water = new HashSet<>(); - collectBlocks(startBlock, water, new HashSet<>()); - return water; - } - - private static void collectBlocks(Block anchor, Set collected, Set visitedBlocks) { - if( - !isWater(anchor) || - visitedBlocks.contains(anchor) - ) + private static void checkBlock(Block b, int startX, int startY, int startZ) throws IsAnOcean { + if(!isWater(b)) return; - visitedBlocks.add(anchor); - if (isWater(anchor)) - collected.add(anchor); + // If distance to original block is greater than 20 + if(Math.abs(startX - b.getX()) + Math.abs(startY - b.getY() + Math.abs(startZ - b.getZ())) >= 20) + throw new IsAnOcean(); - if(visitedBlocks.size() > 100) { - collected.clear(); - return; + b.setType(Material.AIR); + try{ + checkBlock(b.getRelative(BlockFace.EAST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.WEST), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.NORTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.SOUTH), startX, startY, startZ); + checkBlock(b.getRelative(BlockFace.UP), startX, startY, startZ); + }catch(IsAnOcean e){ + b.setType(Material.WATER); + throw e; } - collectBlocks(anchor.getRelative(BlockFace.UP), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.NORTH), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.EAST), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.SOUTH), collected, visitedBlocks); - collectBlocks(anchor.getRelative(BlockFace.WEST), collected, visitedBlocks); } + private static class IsAnOcean extends Throwable{} + public static boolean isWater(Block block){ switch(Core.getVersion()){ case 15: From c1261a4fa25fe098a6400ba854d9e2cef759a6a8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 17:56:35 +0200 Subject: [PATCH 08/19] First ranked (ranked saving still missing) Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/Config.java | 2 ++ .../src/de/steamwar/fightsystem/FightSystem.java | 8 +++++--- .../src/de/steamwar/fightsystem/fight/Fight.java | 2 +- .../de/steamwar/fightsystem/fight/FightTeam.java | 5 ++++- .../winconditions/RankedPlayerLeftWincondition.java | 13 +++++++++++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java diff --git a/FightSystem_API/src/de/steamwar/fightsystem/Config.java b/FightSystem_API/src/de/steamwar/fightsystem/Config.java index 6bc2361..81141b4 100644 --- a/FightSystem_API/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_API/src/de/steamwar/fightsystem/Config.java @@ -81,6 +81,7 @@ public class Config { public static final String TeamChatDetection; public static final UUID BlueLeader; public static final UUID RedLeader; + public static final boolean Ranked; //Active win conditions public static final boolean Timeout; @@ -372,6 +373,7 @@ public class Config { RedLeader = null; CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); + Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); } public static boolean event(){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index c03ce3c..422081d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -101,7 +101,7 @@ public class FightSystem extends JavaPlugin { mainCountdown = new NoPlayersOnlineCountdown(); - if(Config.event()) { + if(Config.event() || Config.Ranked) { Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand()); @@ -196,8 +196,6 @@ public class FightSystem extends JavaPlugin { } public static void setSpectateState(FightTeam winFightTeam, String windescription) { - if(!fightState.ingame()) - throw new SecurityException(fightState.name()); setFightState(FightState.SPECTATE); setAllPlayersGM(GameMode.SPECTATOR); @@ -222,6 +220,10 @@ public class FightSystem extends JavaPlugin { getEventFight().setErgebnis(2); } + if(Config.Ranked){ + //TODO + } + if(!Config.test()){ new SpectateOverCountdown(); FightStatistics.saveStats(winFightTeam, windescription); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java index 9053ae2..49a14fb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/Fight.java @@ -122,7 +122,7 @@ public class Fight { return; } - if(Config.IgnorePublicOnly || Config.event()){ + if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){ schemRank = 1000; return; } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 22e7a21..5ecebdb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -8,6 +8,7 @@ import de.steamwar.fightsystem.IFightSystem; import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.utils.*; +import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition; import de.steamwar.inventory.SWItem; import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.PersonalKit; @@ -194,6 +195,8 @@ public class FightTeam implements IFightTeam{ if(!players.isEmpty()) { setLeader(players.iterator().next()); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); + }else if(Config.Ranked){ + RankedPlayerLeftWincondition.leaderQuit(this); }else if(!Config.event()){ FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); } @@ -209,7 +212,7 @@ public class FightTeam implements IFightTeam{ else inventory.setItem(1, new ItemBuilder(Material.AIR).build()); - if(!Config.event()){ + if(!Config.event() && !Config.Ranked){ inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java new file mode 100644 index 0000000..58473d8 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java @@ -0,0 +1,13 @@ +package de.steamwar.fightsystem.winconditions; + +import de.steamwar.fightsystem.FightSystem; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; + +public class RankedPlayerLeftWincondition { + private RankedPlayerLeftWincondition(){} + + public static void leaderQuit(FightTeam leaderlessTeam){ + FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit"); + } +} From 8ebf509b4e381380162b4bf1492d01d3e28f19e7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 19:07:11 +0200 Subject: [PATCH 09/19] Implementing ranked computation and setting Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 10 +++----- .../fightsystem/utils/FightStatistics.java | 24 ++++++++++++++++--- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 422081d..ca767fa 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -211,19 +211,15 @@ public class FightSystem extends JavaPlugin { Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!"); } - if(Config.event()){ - if(winFightTeam == null) + if(Config.event()) { + if (winFightTeam == null) getEventFight().setErgebnis(0); - else if(winFightTeam.isBlue()) + else if (winFightTeam.isBlue()) getEventFight().setErgebnis(1); else getEventFight().setErgebnis(2); } - if(Config.Ranked){ - //TODO - } - if(!Config.test()){ new SpectateOverCountdown(); FightStatistics.saveStats(winFightTeam, windescription); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 57c178f..bf48c30 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.sql.Elo; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; @@ -17,26 +18,43 @@ public class FightStatistics { private FightStatistics(){} private static Timestamp starttime = Timestamp.from(Instant.now()); + private static int K = 20; public static void start(){ starttime = Timestamp.from(Instant.now()); } public static void saveStats(FightTeam winner, String windescription){ + String gameMode = Config.SchematicType.toDB(); SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); int win = 0; - if(winner == Fight.getBlueTeam()) + double blueResult; + if(winner == Fight.getBlueTeam()) { win = 1; - else if(winner == Fight.getRedTeam()) + blueResult = 1; + }else if(winner == Fight.getRedTeam()) { win = 2; - int fightId = create(Config.SchematicType.toDB(), Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), + blueResult = 0; + }else{ + blueResult = 0.5; + } + int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) savePlayerStats(fp, fightId); for(FightPlayer fp : Fight.getRedTeam().getPlayers()) savePlayerStats(fp, fightId); + + if(Config.Ranked && !Config.event()){ + int blueElo = Elo.getElo(blueLeader.getId(), gameMode); + int redElo = Elo.getElo(redLeader.getId(), gameMode); + double blueWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); + double redWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); + Elo.setElo(blueLeader.getId(), gameMode, (int) Math.round(blueElo + K * (blueResult - blueWinExpectation))); + Elo.setElo(redLeader.getId(), gameMode, (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation))); + } } private static void savePlayerStats(FightPlayer fp, int fightId){ From b5bcea06b77cbed239febd06b5a02a9a96856049 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 19:35:37 +0200 Subject: [PATCH 10/19] Send ELO to players + fix potential crash issue Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 7 +++---- .../de/steamwar/fightsystem/utils/FightStatistics.java | 8 ++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java index 5ecebdb..182b4bc 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -187,10 +187,6 @@ public class FightTeam implements IFightTeam{ } public void setLeader(FightPlayer leader) { - this.leader = leader; - if(ready && leader != null) - setReady(false); - if (leader == null){ if(!players.isEmpty()) { setLeader(players.iterator().next()); @@ -202,6 +198,9 @@ public class FightTeam implements IFightTeam{ } return; } + this.leader = leader; + if(ready) + setReady(false); leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); Inventory inventory = leader.getPlayer().getInventory(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index bf48c30..85ccbd9 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -52,8 +52,12 @@ public class FightStatistics { int redElo = Elo.getElo(redLeader.getId(), gameMode); double blueWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); double redWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); - Elo.setElo(blueLeader.getId(), gameMode, (int) Math.round(blueElo + K * (blueResult - blueWinExpectation))); - Elo.setElo(redLeader.getId(), gameMode, (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation))); + int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation)); + int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); + Elo.setElo(blueLeader.getId(), gameMode, newBlueElo); + Elo.setElo(redLeader.getId(), gameMode, newRedElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + blueLeader.getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo); + Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + redLeader.getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo); } } From 7e66c9895c5d2f639d8e16f6e861058bcecdbed2 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 19:36:56 +0200 Subject: [PATCH 11/19] Only one spectate state init Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index ca767fa..ed20bc0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -196,6 +196,8 @@ public class FightSystem extends JavaPlugin { } public static void setSpectateState(FightTeam winFightTeam, String windescription) { + if(fightState == FightState.SPECTATE) + return; setFightState(FightState.SPECTATE); setAllPlayersGM(GameMode.SPECTATOR); From 72d3d0314b9a033839479d0581acde8a165a6fe1 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 07:53:04 +0200 Subject: [PATCH 12/19] Fixing fire arrow bug and kit gui bug Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java | 3 +-- .../fightsystem/listener/InFightDamageListener.java | 6 ++++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java index fda2c5d..9ab9a64 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/kit/Kit.java @@ -145,8 +145,7 @@ public class Kit { } } - inv.setCallback(-999, (click) -> GUI.kitSelection(player)); - inv.addCloseCallback((click) -> GUI.kitSelection(player)); + inv.setCallback(-999, (click) -> player.closeInventory()); inv.setItem(45, SWItem.getDye(10), (byte)10, "§aKit wählen", (click) -> { Commands.kit(player, name); player.closeInventory(); diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java index 9bf5239..f24f88b 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java @@ -44,8 +44,6 @@ public class InFightDamageListener extends BasicListener { //Shooter is not a player return; - damagerArrow.setFireTicks(0); - player.setFireTicks(0); damager = (Player) damagerArrow.getShooter(); }else{ //Damager is not a player @@ -60,6 +58,10 @@ public class InFightDamageListener extends BasicListener { if(Fight.getPlayerTeam(player) == Fight.getPlayerTeam(damager)) { event.setCancelled(true); + if(event.getDamager() instanceof Arrow){ + event.getDamager().setFireTicks(0); + player.setFireTicks(0); + } toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); } From 620677d5933473d7c5fbc3c68c3813b8bf96292f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 08:48:17 +0200 Subject: [PATCH 13/19] Fix entern countdown timer Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/countdown/EnternCountdown.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java index c18b4bc..0ebdc3c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/EnternCountdown.java @@ -40,7 +40,7 @@ public class EnternCountdown extends Countdown { } Player player = fightPlayer.getPlayer(); - int time = Config.EnterStages.get(fightPlayer.getKit().getEnterStage()) - FightSystem.getFightTime(); + int time = FightSystem.getFightTime() - Config.EnterStages.get(fightPlayer.getKit().getEnterStage()); switch (time) { case 900: case 600: case 300: case 180: case 120: BasicListener.toActionbar(player, TextComponent.fromLegacyText("§rNoch §a" + time / 60 + " §rMinuten " + countdownCounting())); From 5879ca5e18860c115d1a7c472c7ce95fa1b114ed Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 08:50:39 +0200 Subject: [PATCH 14/19] Hotfix piston listener Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/listener/PistonListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java index bbaf4d7..50ef104 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PistonListener.java @@ -16,8 +16,8 @@ public class PistonListener extends BasicListener { public PistonListener() { //Wenn Entern aktiv ist, sollen Raketen etc. entern können super(Config.EnterStages.isEmpty() - ? EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP) - : EnumSet.allOf(FightState.class)); + ? EnumSet.allOf(FightState.class) + : EnumSet.of(FightState.PRE_LEADER_SETUP, FightState.PRE_SCHEM_SETUP, FightState.POST_SCHEM_SETUP)); } @EventHandler From a95800e815fdbbe03a728b0365bd8dfb9a5fc762 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Jul 2020 10:31:18 +0200 Subject: [PATCH 15/19] Hotfix countdown Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/EnterHandler.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java index 3eb6d4a..b887aa8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/EnterHandler.java @@ -1,6 +1,7 @@ package de.steamwar.fightsystem.utils; import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.countdown.EnternCountdown; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; @@ -16,6 +17,10 @@ public class EnterHandler implements StateDependent { private static final Set enabled = EnumSet.of(FightState.RUNNING); private static final Set countdowns = new HashSet<>(); + public EnterHandler(){ + FightSystem.registerStateDependent(this); + } + @Override public Set enabled() { return enabled; From 7858a87b6037924796c78689a6e873b2f9b24d64 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jul 2020 15:53:10 +0200 Subject: [PATCH 16/19] Fix join listener Signed-off-by: Lixfel --- .../listener/NormalJoinListener.java | 2 +- .../listener/RankedJoinListener.java | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java index e2ffa52..27c01fd 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/NormalJoinListener.java @@ -14,7 +14,7 @@ import java.util.EnumSet; public class NormalJoinListener extends BasicListener { public NormalJoinListener() { - super(Config.event() || Config.test() ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP)); + super(Config.event() || Config.test() || Config.Ranked ? EnumSet.noneOf(FightState.class) : EnumSet.of(FightState.PRE_LEADER_SETUP)); } @EventHandler diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java new file mode 100644 index 0000000..d760002 --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/RankedJoinListener.java @@ -0,0 +1,32 @@ +package de.steamwar.fightsystem.listener; + +import de.steamwar.fightsystem.Config; +import de.steamwar.fightsystem.fight.Fight; +import de.steamwar.fightsystem.fight.FightTeam; +import de.steamwar.fightsystem.states.FightState; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; + +import java.util.EnumSet; + +public class RankedJoinListener extends BasicListener { + + public RankedJoinListener() { + super(!Config.event() && Config.Ranked ? EnumSet.of(FightState.PRE_SCHEM_SETUP) : EnumSet.noneOf(FightState.class)); + } + + @EventHandler + public void handlePlayerJoin(PlayerJoinEvent event) { + Player player = event.getPlayer(); + FightTeam fightTeam = Fight.getPlayerTeam(player); + + if (fightTeam == null) { + if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) { + Fight.getBlueTeam().setLeader(Fight.getBlueTeam().addMember(player)); + }else if(Fight.getRedTeam().canbeLeader(player)) { + Fight.getRedTeam().setLeader(Fight.getRedTeam().addMember(player)); + } + } + } +} From caa8b4aa6aebc44490eb93b2637dd365f2d51799 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jul 2020 15:55:16 +0200 Subject: [PATCH 17/19] Fix join listener Signed-off-by: Lixfel --- FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java | 1 + 1 file changed, 1 insertion(+) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 1172d47..98706f7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -73,6 +73,7 @@ public class FightSystem extends JavaPlugin { new CheckListener(); new TestListener(); new NormalJoinListener(); + new RankedJoinListener(); if(Core.getVersion() > 8) new ExtendedInventoryListener(); From b2a9a4ed64d52b206269658b5a518bdd927d841b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jul 2020 19:16:54 +0200 Subject: [PATCH 18/19] Fix NPE Signed-off-by: Lixfel --- .../fightsystem/utils/FightStatistics.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 85ccbd9..577224e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -39,13 +39,15 @@ public class FightStatistics { }else{ blueResult = 0.5; } - int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), - blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); + if(Fight.getBlueTeam().getSchematic() != null && Fight.getRedTeam().getSchematic() != null){ + int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), + blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); - for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) - savePlayerStats(fp, fightId); - for(FightPlayer fp : Fight.getRedTeam().getPlayers()) - savePlayerStats(fp, fightId); + for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) + savePlayerStats(fp, fightId); + for(FightPlayer fp : Fight.getRedTeam().getPlayers()) + savePlayerStats(fp, fightId); + } if(Config.Ranked && !Config.event()){ int blueElo = Elo.getElo(blueLeader.getId(), gameMode); From 2cb8c5e8b3af4a9bdb97e7953a30d80a945c0352 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 19 Jul 2020 19:37:48 +0200 Subject: [PATCH 19/19] Fix ELO Calculation Signed-off-by: Lixfel --- .../src/de/steamwar/fightsystem/utils/FightStatistics.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java index 577224e..8ccfa4f 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -52,8 +52,8 @@ public class FightStatistics { if(Config.Ranked && !Config.event()){ int blueElo = Elo.getElo(blueLeader.getId(), gameMode); int redElo = Elo.getElo(redLeader.getId(), gameMode); - double blueWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); - double redWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); + double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); + double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation)); int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); Elo.setElo(blueLeader.getId(), gameMode, newBlueElo);