From e053ecf286855292f2475c28177a0c18bdcc6569 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 23 Jan 2020 17:33:29 +0100 Subject: [PATCH] Adding fight statistics Signed-off-by: Lixfel --- .../de/steamwar/fightsystem/FightSystem.java | 12 ++--- .../countdown/TechKOCountdown.java | 2 +- .../fightsystem/fight/FightPlayer.java | 10 ++++ .../listener/InFightDamageListener.java | 5 ++ .../fightsystem/utils/FightStatistics.java | 46 +++++++++++++++++++ .../EventTeamOffWincondition.java | 2 +- .../winconditions/WinconditionAllDead.java | 2 +- .../WinconditionCaptainDead.java | 2 +- .../WinconditionHeartRatioTimeout.java | 6 +-- .../WinconditionPercentSystem.java | 4 +- .../winconditions/WinconditionPoints.java | 6 +-- .../WinconditionPumpkinTechKO.java | 2 +- .../WinconditionRelativePercent.java | 2 +- .../winconditions/WinconditionTimeout.java | 2 +- .../WinconditionWaterTechKO.java | 2 +- 15 files changed, 83 insertions(+), 22 deletions(-) create mode 100644 FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java index 6fd1d5d..d188516 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/FightSystem.java @@ -9,10 +9,7 @@ import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.listener.*; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependent; -import de.steamwar.fightsystem.utils.FightScoreboard; -import de.steamwar.fightsystem.utils.ITechHider; -import de.steamwar.fightsystem.utils.TechHider; -import de.steamwar.fightsystem.utils.WaterRemover; +import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.winconditions.*; import de.steamwar.sql.EventFight; import org.bukkit.Bukkit; @@ -158,6 +155,7 @@ public class FightSystem extends JavaPlugin { if(Config.Entern) mainCountdown = new EnternCountdown(); + FightStatistics.start(); WaterRemover.init(); Bukkit.broadcastMessage(PREFIX + "§aArena freigegeben!"); } @@ -178,7 +176,7 @@ public class FightSystem extends JavaPlugin { } } - public static void setSpectateState(FightTeam winFightTeam) { + public static void setSpectateState(FightTeam winFightTeam, String windescription) { if(!fightState.ingame()) throw new SecurityException(fightState.name()); setFightState(FightState.SPECTATE); @@ -205,8 +203,10 @@ public class FightSystem extends JavaPlugin { getEventFight().setErgebnis(2); } - if(!Config.test()) + if(!Config.test()){ new SpectateOverCountdown(); + FightStatistics.saveStats(winFightTeam, windescription); + } } public static void setFightTime(int fightTime) { diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java index dc88975..33dd17d 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/countdown/TechKOCountdown.java @@ -23,6 +23,6 @@ public class TechKOCountdown extends Countdown { @Override void countdownFinished() { Bukkit.broadcastMessage(FightSystem.PREFIX + team.getColoredName() + "§7 ist §eTech K§8.§eO§8.!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "TechKO"); } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java index 040dc17..43bfbce 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/fight/FightPlayer.java @@ -11,6 +11,7 @@ public class FightPlayer { private final FightTeam team; private boolean isOut; private Kit kit; + private int kills; public void sendMessage(String message) { if (this.player != null && this.player.isOnline()) @@ -22,6 +23,7 @@ public class FightPlayer { this.team = team; this.isOut = false; kit = KitManager.getKitByName(Config.MemberDefault); + kills = 0; } public void setOut() { @@ -52,4 +54,12 @@ public class FightPlayer { public FightTeam getTeam(){ return team; } + + public int getKills(){ + return kills; + } + + public void addKill(){ + kills++; + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java index cbf4d50..fda06cb 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/InFightDamageListener.java @@ -10,6 +10,7 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import java.util.EnumSet; +import java.util.Objects; public class InFightDamageListener extends BasicListener { @@ -61,5 +62,9 @@ public class InFightDamageListener extends BasicListener { event.setCancelled(true); toActionbar(damager, TextComponent.fromLegacyText("§cDu darfst deinen Teamkollegen keinen Schaden zufügen!")); } + + if(player.getHealth() - event.getFinalDamage() <= 0){ + Objects.requireNonNull(Fight.getFightPlayer(damager)).addKill(); + } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java new file mode 100644 index 0000000..1b377eb --- /dev/null +++ b/FightSystem_Main/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -0,0 +1,46 @@ +package de.steamwar.fightsystem.utils; + +import de.steamwar.fightsystem.Config; +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.SteamwarUser; +import org.bukkit.Bukkit; + +import java.sql.Timestamp; +import java.time.Instant; + +import static de.steamwar.sql.Fight.create; + +public class FightStatistics { + private FightStatistics(){} + + private static Timestamp starttime = Timestamp.from(Instant.now()); + + public static void start(){ + starttime = Timestamp.from(Instant.now()); + } + + public static void saveStats(FightTeam winner, String windescription){ + 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()) + win = 1; + else if(winner == Fight.getRedTeam()) + win = 2; + int fightId = create(Config.SchematicType.toDB(), 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); + } + + 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()); + } +} diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java index 2a7edbd..3fcb29e 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/EventTeamOffWincondition.java @@ -29,7 +29,7 @@ public class EventTeamOffWincondition extends Wincondition { private void teamOff(FightTeam team){ if(team.allPlayersOut()){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§6Das Team " + team.getColoredName() + " §6ist Offline!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "TeamOffline"); } } } \ No newline at end of file diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java index 862fcfe..b8be083 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionAllDead.java @@ -34,7 +34,7 @@ public class WinconditionAllDead extends PlayerWincondition { assert fightTeam != null; // Checked with isTarget if(fightTeam.allPlayersOut()) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer letzte Spieler aus " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); + FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "AllDead"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java index c716d0c..e4b460a 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionCaptainDead.java @@ -34,7 +34,7 @@ public class WinconditionCaptainDead extends PlayerWincondition { assert fightTeam != null; // Checked with isTarget if(fightTeam.isPlayerLeader(player)) { Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Leader von " + fightTeam.getColoredName() + message); - FightSystem.setSpectateState(Fight.getOpposite(fightTeam)); + FightSystem.setSpectateState(Fight.getOpposite(fightTeam), "LeaderDead"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java index 18974be..32d8b7c 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionHeartRatioTimeout.java @@ -23,11 +23,11 @@ public class WinconditionHeartRatioTimeout extends Wincondition { double redHeartRatio = Fight.getRedTeam().getHeartRatio(); if(blueHeartRatio > redHeartRatio) - FightSystem.setSpectateState(Fight.getBlueTeam()); + FightSystem.setSpectateState(Fight.getBlueTeam(), "HeartTimeout"); else if(blueHeartRatio < redHeartRatio) - FightSystem.setSpectateState(Fight.getRedTeam()); + FightSystem.setSpectateState(Fight.getRedTeam(), "HeartTimeout"); else - FightSystem.setSpectateState(null); + FightSystem.setSpectateState(null, "HeartTimeout"); }); } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java index 664c522..441f926 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPercentSystem.java @@ -37,7 +37,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleBlueDestroyedBlocks * 100 / schematicSize; bluePercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.redTeam); + FightSystem.setSpectateState(Fight.redTeam, "Percent"); } //Team Red }else if(Region.isInRange(entity.getLocation(), Config.TeamRedCornerX, Config.TeamRedCornerY, Config.TeamRedCornerZ, Config.SchemsizeX, Config.SchemsizeY, Config.SchemsizeZ, Config.BorderFromSchematic)) { @@ -46,7 +46,7 @@ public class WinconditionPercentSystem extends ListenerWincondition { double destroyPercent = doubleRedDestroyedBlocks * 100 / schematicSize; redPercent = destroyPercent; if(destroyPercent >= Config.PercentWin) { - FightSystem.setSpectateState(Fight.blueTeam); + FightSystem.setSpectateState(Fight.blueTeam, "Percent"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java index 6bbfea8..e0161a8 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPoints.java @@ -80,11 +80,11 @@ public class WinconditionPoints extends PlayerWincondition { private void fightEnds(){ if(red.getPoints() > blue.getPoints()) - FightSystem.setSpectateState(blue.enemy); + FightSystem.setSpectateState(blue.enemy, "Points"); else if(red.getPoints() < blue.getPoints()) - FightSystem.setSpectateState(red.enemy); + FightSystem.setSpectateState(red.enemy, "Points"); else - FightSystem.setSpectateState(null); + FightSystem.setSpectateState(null, "Points"); } private TeamPoints getEnemyByTeam(FightTeam team){ diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java index 6dc6d23..c59d1ae 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionPumpkinTechKO.java @@ -76,7 +76,7 @@ public class WinconditionPumpkinTechKO extends Wincondition { private static void checkKO(FightTeam team, int pumpkins){ if(pumpkins == 0){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "PumpkinTechKO")); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java index 413047b..c5a1ac7 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionRelativePercent.java @@ -105,7 +105,7 @@ public class WinconditionRelativePercent extends Wincondition{ return; if(getPercent() * 100 >= Config.PercentWin){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§cDer Schiff von " + team.getColoredName() + " §cwurde zu stark beschädigt!"); - FightSystem.setSpectateState(Fight.getOpposite(team)); + FightSystem.setSpectateState(Fight.getOpposite(team), "RelativePercent"); } } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java index a2c46ad..6b95af1 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionTimeout.java @@ -17,7 +17,7 @@ public class WinconditionTimeout extends Wincondition { @Override public void enable() { - countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null)); + countdown = new TimeOverCountdown(() -> FightSystem.setSpectateState(null, "Timeout")); } @Override diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java index 84c66ae..f845bca 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/winconditions/WinconditionWaterTechKO.java @@ -63,7 +63,7 @@ public class WinconditionWaterTechKO extends Wincondition { private void checkEmpty(FightTeam team, Set teamWater){ if(teamWater.isEmpty()){ Bukkit.broadcastMessage(FightSystem.PREFIX + "§eDas Team " + team.getColoredName() + " §eist Tech K.O.!"); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team))); + Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> FightSystem.setSpectateState(Fight.getOpposite(team), "WaterTechKO")); } } -- 2.39.5