SteamWar/FightSystem
Archiviert
13
1

Better replay debugging with skipping #331

Zusammengeführt
Lixfel hat 1 Commits von betterReplayDebug nach master 2022-03-03 18:03:29 +01:00 zusammengeführt
2 geänderte Dateien mit 30 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -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;
if(PacketProcessor.isReplaying()) {
PacketProcessor.currentReplay().skipToSubtitle();
} else {
Commands.toggleSkip(player);
}
return false;
}
}

Datei anzeigen

@ -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<Integer> 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();
}