From c1261a4fa25fe098a6400ba854d9e2cef759a6a8 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 7 Jul 2020 17:56:35 +0200 Subject: [PATCH 1/4] 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 2/4] 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 3/4] 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 4/4] 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);