From 775b24e6fc362afbe7951c28cbf2a109dd7b6792 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 27 Dec 2021 13:10:41 +0100 Subject: [PATCH] Lock replay functionality Signed-off-by: Lixfel --- FightSystem_Core/src/config.yml | 7 +++- .../de/steamwar/fightsystem/FightSystem.java | 2 +- .../fightsystem/FightSystem.properties | 2 +- .../fightsystem/commands/Commands.java | 4 +- ...layCommand.java => LockReplayCommand.java} | 37 ++++--------------- .../fightsystem/utils/FightStatistics.java | 9 ++++- FightSystem_Core/src/plugin.yml | 2 +- 7 files changed, 26 insertions(+), 37 deletions(-) rename FightSystem_Core/src/de/steamwar/fightsystem/commands/{ReplayCommand.java => LockReplayCommand.java} (52%) diff --git a/FightSystem_Core/src/config.yml b/FightSystem_Core/src/config.yml index 26bc9b3..65406e2 100644 --- a/FightSystem_Core/src/config.yml +++ b/FightSystem_Core/src/config.yml @@ -41,8 +41,9 @@ Arena: BorderFromSchematic: 12 # defaults to 12 if missing # If ground walkable, teams can walk below the lower arena border during setup GroundWalkable: true # defaults to true if missing - # Disable snow melt - DisableSnowMelt: false + # Disable snow and ice melting + DisableSnowMelt: false # defaults to false if missing + Schematic: # The size of the schematics Size: @@ -53,6 +54,8 @@ Schematic: Type: Normal # defaults to Normal if missing # Shortcut of the schematic type Shortcut: "" # defaults to "" if missing + # Spigot (1.8) material for GUIs + Material: STONE_BUTTON # defaults to STONE_BUTTON if missing # If the schematics should be rotated during pasting Rotate: true # defaults to true if missing # If the schematics should be pasted aligned to the borders instead of centered diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 3abc6d6..504b5ca 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -128,7 +128,7 @@ public class FightSystem extends JavaPlugin { new AkCommand(); new LeaderCommand(); new LockschemCommand(); - new ReplayCommand(); + new LockReplayCommand(); new StateCommand(); new SkipCommand(); new WinCommand(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index b165506..1bc5a62 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -53,7 +53,7 @@ LOCKSCHEM_LOCKED_BY= REMOVE_HELP=§8/§eremove §8[§eSpieler§8] -REPLAY_UNAVAILABLE=§cReplay derzeit nicht verfügbar +REPLAY_LOCKED=§7Replaywiedergabe für 1 Monat gesperrt NOT_FIGHTLEADER=§cDu bist nicht Kampfleiter WIN_HELP=§8/§7win §8[§eTeam §8or §etie§8] diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java index e4189c7..5ff08b0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/Commands.java @@ -63,7 +63,7 @@ public class Commands { return fightPlayer; } - private static FightPlayer checkGetLeader(Player p){ + public static FightPlayer checkGetLeader(Player p){ FightPlayer fightPlayer = checkGetPlayer(p); if(fightPlayer != null && !fightPlayer.isLeader()){ FightSystem.getMessage().sendPrefixless("NOT_LEADER", p, ChatMessageType.ACTION_BAR); @@ -72,7 +72,7 @@ public class Commands { return fightPlayer; } - private static FightTeam checkGetTeam(Player p){ + public static FightTeam checkGetTeam(Player p){ FightTeam fightTeam = Fight.getPlayerTeam(p); if(fightTeam == null){ errNoTeam(p); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReplayCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockReplayCommand.java similarity index 52% rename from FightSystem_Core/src/de/steamwar/fightsystem/commands/ReplayCommand.java rename to FightSystem_Core/src/de/steamwar/fightsystem/commands/LockReplayCommand.java index cc81995..72bdee6 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/ReplayCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/LockReplayCommand.java @@ -20,26 +20,19 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.FightSystem; -import de.steamwar.fightsystem.record.FileRecorder; -import de.steamwar.fightsystem.record.FileSource; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; -import de.steamwar.sql.SteamwarUser; -import net.md_5.bungee.api.ChatMessageType; +import de.steamwar.fightsystem.utils.FightStatistics; +import de.steamwar.fightsystem.utils.FightUI; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import java.io.IOException; -import java.util.logging.Level; +public class LockReplayCommand implements CommandExecutor { -public class ReplayCommand implements CommandExecutor { - - public ReplayCommand() { - new StateDependentCommand(ArenaMode.Replayable, FightState.All, "replay", this); + public LockReplayCommand() { + new StateDependentCommand(ArenaMode.AntiReplay, FightState.Schem, "lockreplay", this); } @Override @@ -49,25 +42,11 @@ public class ReplayCommand implements CommandExecutor { } Player player = (Player) sender; - if(!Config.test()){ - SteamwarUser user = SteamwarUser.get(player.getUniqueId()); - if(!user.getUserGroup().isTeamGroup()){ - FightSystem.getMessage().sendPrefixless("REPLAY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR); - return false; - } - } - - if(!FileRecorder.getFile().exists()){ - FightSystem.getMessage().sendPrefixless("REPLAY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR); + if(Commands.checkGetLeader(player) == null) return false; - } - try { - new FileSource(FileRecorder.getFile()); - } catch (IOException e) { - FightSystem.getMessage().sendPrefixless("REPLAY_UNAVAILABLE", sender, ChatMessageType.ACTION_BAR); - FightSystem.getPlugin().getLogger().log(Level.SEVERE, "Replay could not be started", e); - } + FightStatistics.lockReplay(); + FightUI.addSubtitle("REPLAY_LOCKED"); return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 25bef85..7858d6e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -38,6 +38,7 @@ import org.bukkit.Bukkit; import java.io.FileInputStream; import java.sql.Timestamp; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.logging.Level; import static de.steamwar.sql.Fight.create; @@ -46,9 +47,14 @@ import static de.steamwar.sql.Fight.setReplay; public class FightStatistics { private static final int K = 20; + private static boolean replayLock = false; private Timestamp starttime = Timestamp.from(Instant.now()); + public static void lockReplay() { + replayLock = true; + } + public FightStatistics() { new OneShotStateDependent(ArenaMode.SeriousFight, FightState.Running, this::enable); new OneShotStateDependent(ArenaMode.Event, FightState.Spectate, this::setEventResult); @@ -109,7 +115,7 @@ public class FightStatistics { try { int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, remainingTime, - blueLeader, redLeader, blueSchem, redSchem, win, windescription); + blueLeader, redLeader, blueSchem, redSchem, win, windescription, Timestamp.from(Instant.now().plus(replayLock ? 1 : 0, ChronoUnit.MONTHS))); for (FightPlayer fp : Fight.getBlueTeam().getPlayers()) savePlayerStats(fp, fightId); @@ -124,6 +130,7 @@ public class FightStatistics { }catch(Exception e){ Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } + replayLock = false; if(Config.Ranked){ int blueElo = Elo.getElo(blueLeader, gameMode); diff --git a/FightSystem_Core/src/plugin.yml b/FightSystem_Core/src/plugin.yml index 066b5aa..0013293 100644 --- a/FightSystem_Core/src/plugin.yml +++ b/FightSystem_Core/src/plugin.yml @@ -18,7 +18,7 @@ commands: remove: leader: lockschem: - replay: + lockreplay: state: skip: win: \ No newline at end of file