From 65e1315cca769ecacd2fe70ce60529ec50b8318e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 1 Oct 2021 14:51:00 +0200 Subject: [PATCH] Add TPS watcher, fix tie Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/commands/WinCommand.java | 6 +++--- .../src/de/steamwar/fightsystem/fight/FightTeam.java | 2 +- .../src/de/steamwar/fightsystem/utils/FightUI.java | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java index db0c996..776c4a0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/WinCommand.java @@ -33,12 +33,12 @@ public class WinCommand implements CommandExecutor { return false; } - if(args[0].equalsIgnoreCase(Fight.getBlueTeam().getName())){ + if(args[0].equalsIgnoreCase("tie")){ + FightSystem.setSpectateState(null, "Referee", "§7Kampfleiterentscheidung"); + }else if(args[0].equalsIgnoreCase(Fight.getBlueTeam().getName())){ FightSystem.setSpectateState(Fight.getBlueTeam(), "Referee", "§7Kampfleiterentscheidung"); }else if(args[0].equalsIgnoreCase(Fight.getRedTeam().getName())){ FightSystem.setSpectateState(Fight.getRedTeam(), "Referee", "§7Kampfleiterentscheidung"); - }else if(args[0].equalsIgnoreCase("tie")){ - FightSystem.setSpectateState(null, "Referee", "§7Kampfleiterentscheidung"); } return false; } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java index 092a399..7696963 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/fight/FightTeam.java @@ -406,7 +406,7 @@ public class FightTeam { } public double getCurrentHearts() { - return players.values().stream().filter(FightPlayer::isLiving).map(fp -> fp.getPlayer().getHealth()).reduce(Double::sum).orElse(0.0); + return players.values().stream().filter(FightPlayer::isLiving).mapToDouble(fp -> fp.getPlayer().getHealth()).sum(); } public double getHeartRatio(){ diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java index 9442349..09c6f7a 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightUI.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.core.TPSWatcher; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -29,6 +30,8 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCountdown; import de.steamwar.fightsystem.states.StateDependentTask; import de.steamwar.fightsystem.winconditions.Wincondition; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -51,6 +54,7 @@ public class FightUI { public FightUI() { new StateDependentTask(ArenaMode.AntiReplay, FightState.All, this::update, 20, 20); new StateDependentTask(ArenaMode.All, FightState.All, this::sendToPlayers, 5, 5); + new StateDependentTask(ArenaMode.All, FightState.All, this::tpsWatcher, 20, 20); instance = this; } @@ -132,6 +136,14 @@ public class FightUI { BountifulWrapper.impl.broadcastBossbar(); } + private void tpsWatcher() { + double tps = TPSWatcher.getTPS(); + if(tps < 15.0) { + BaseComponent[] message = TextComponent.fromLegacyText("§c" + tps + " §7TPS"); + Bukkit.getOnlinePlayers().forEach(player -> BountifulWrapper.impl.toActionbar(player, message)); + } + } + public enum BossBarType { BLUE_LEFT(345, 165), RED_LEFT(165, 345);