From 43fc4ecd65c8bbe2eed44adbdede9ea0cbc56861 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 15 Nov 2020 08:34:48 +0100 Subject: [PATCH] Fix replay command enabled while another replay is running. --- .../spectatesystem/FightfileConnection.java | 2 +- .../spectatesystem/commands/ReplayCommand.java | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/spectatesystem/FightfileConnection.java b/src/de/steamwar/spectatesystem/FightfileConnection.java index 6b426ea..8cff5a4 100644 --- a/src/de/steamwar/spectatesystem/FightfileConnection.java +++ b/src/de/steamwar/spectatesystem/FightfileConnection.java @@ -35,7 +35,7 @@ public class FightfileConnection extends PacketSource { } @Override - boolean isClosed() { + public boolean isClosed() { try{ return inputStream.available() == 0; }catch (IOException e){ diff --git a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java index a0b6ed0..4beea0d 100644 --- a/src/de/steamwar/spectatesystem/commands/ReplayCommand.java +++ b/src/de/steamwar/spectatesystem/commands/ReplayCommand.java @@ -29,6 +29,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.util.EnumSet; import java.util.Set; @@ -37,6 +38,7 @@ import java.util.logging.Level; public class ReplayCommand implements CommandExecutor { private static final Set allowedGroups = EnumSet.of(UserGroup.Admin, UserGroup.Developer, UserGroup.Moderator); + private static FightfileConnection fightfileConnection; @Override public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) { @@ -49,13 +51,22 @@ public class ReplayCommand implements CommandExecutor { } } + if (fightfileConnection != null && fightfileConnection.isClosed()) { + sender.sendMessage("§eSteam§8War» §cBitte warte bis kein Replay gezeigt wird."); + return false; + } + if(args.length != 1){ sender.sendMessage("§eSteam§8War» §c/replay [Dateipfad]"); return false; } try { - new FightfileConnection(new File(args[0] + ".recording")); + fightfileConnection = new FightfileConnection(new File(args[0] + (args[0].endsWith(".recording") ? "" : ".recording"))); + } catch (FileNotFoundException e) { + Bukkit.getLogger().log(Level.WARNING, "Could not start reading file", e); + sender.sendMessage("§eSteam§8War» §cReplay konnte nicht gefunden werden."); + return false; } catch (IOException e) { Bukkit.getLogger().log(Level.WARNING, "Could not start reading file", e); sender.sendMessage("§eSteam§8War» §cReplay konnte nicht gestartet werden.");