From 727c66e37004e11dca7d740a4784637fe09bb37a Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 3 Mar 2022 14:46:34 +0100 Subject: [PATCH] Better replay debugging with skipping Signed-off-by: Lixfel --- .../fightsystem/commands/SkipCommand.java | 7 +++- .../fightsystem/record/PacketProcessor.java | 39 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java b/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java index 5fb66ec..c47a2ae 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/commands/SkipCommand.java @@ -20,6 +20,7 @@ package de.steamwar.fightsystem.commands; import de.steamwar.fightsystem.ArenaMode; +import de.steamwar.fightsystem.record.PacketProcessor; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentCommand; import org.bukkit.command.Command; @@ -40,7 +41,11 @@ public class SkipCommand implements CommandExecutor { } Player player = (Player) sender; - Commands.toggleSkip(player); + if(PacketProcessor.isReplaying()) { + PacketProcessor.currentReplay().skipToSubtitle(); + } else { + Commands.toggleSkip(player); + } return false; } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java index 33d4e63..d6a2ff0 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/record/PacketProcessor.java @@ -45,22 +45,22 @@ import org.bukkit.scheduler.BukkitTask; import java.io.EOFException; import java.io.IOException; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.logging.Level; public class PacketProcessor { + private static final World world = Bukkit.getWorlds().get(0); - static boolean replaying = false; + private static PacketProcessor currentProcessor = null; - public static boolean isReplaying(){ - return replaying; + public static PacketProcessor currentReplay() { + return currentProcessor; } - private static final World world = Bukkit.getWorlds().get(0); + public static boolean isReplaying(){ + return currentProcessor != null; + } private final PacketParser[] packetDecoder = new PacketParser[256]; @@ -76,12 +76,14 @@ public class PacketProcessor { private int arenaMinY = Config.BluePasteRegion.getMinY(); private int arenaMinZ = Config.ArenaRegion.getMinZ(); + private boolean skipToSubtitle = false; + private boolean tickFinished = false; - private int lastPacket = -1; + private final List lastPackets = new LinkedList<>(); public PacketProcessor(PacketSource source){ this.source = source; - replaying = true; + currentProcessor = this; packetDecoder[0x00] = this::playerJoins; packetDecoder[0x01] = this::entityMoves; @@ -134,6 +136,10 @@ public class PacketProcessor { task = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), this::process, 1, 1); } + public void skipToSubtitle() { + skipToSubtitle = true; + } + private void winMessage() throws IOException { byte team = source.readByte(); Message message = readMessage(); @@ -455,6 +461,7 @@ public class PacketProcessor { String subtitle = source.readUTF(); FightUI.addSubtitle("OLD_STRING", subtitle); + skipToSubtitle = false; } private void printWin() throws IOException { @@ -472,7 +479,7 @@ public class PacketProcessor { freezer.disable(); FightSystem.getMessage().broadcast("REPLAY_ENDS"); FightState.setFightState(FightState.SPECTATE); - replaying = false; + currentProcessor = null; } private void bow() throws IOException { @@ -498,7 +505,7 @@ public class PacketProcessor { private void tick(){ execSync(REntity::tickFire); - if(!source.async()) + if(!source.async() && !skipToSubtitle) tickFinished = true; } @@ -511,16 +518,18 @@ public class PacketProcessor { if(parser != null){ parser.process(); }else{ - Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing. LastPacket: " + lastPacket); + Bukkit.getLogger().log(Level.SEVERE, "Unknown packet " + packetType + " recieved, closing. LastPacket: " + Arrays.toString(lastPackets.toArray())); source.close(); } - lastPacket = packetType; + lastPackets.add(packetType); + if (lastPackets.size() > 10) + lastPackets.remove(0); } } catch (EOFException e) { Bukkit.getLogger().log(Level.INFO, "The FightServer is offline"); source.close(); } catch(Exception e) { - Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet, LastPacket: " + lastPacket, e); + Bukkit.getLogger().log(Level.WARNING, "Could not recieve packet, LastPacket: " + Arrays.toString(lastPackets.toArray()), e); source.close(); } -- 2.39.2