Skip to content

Commit

Permalink
[Savestates] Fix error handling further crashing the game
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Dec 8, 2024
1 parent f5bae49 commit d9ab780
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerList;
import net.minecraft.util.text.Style;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.WorldServer;
Expand Down Expand Up @@ -771,13 +772,11 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws

LOGGER.error(LoggerMarkers.Savestate, "Failed to create a savestate");
LOGGER.catching(e);
return;
} catch (Exception e) {
if (player != null)
player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to create a savestate: " + e.getClass().getName().toString() + ": " + e.getMessage()));

LOGGER.catching(e);
return;
} finally {
TASmod.savestateHandlerServer.state = SavestateState.NONE;
}
Expand All @@ -801,8 +800,13 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
LOGGER.error(LoggerMarkers.Savestate, "Failed to create a savestate: " + e.getMessage());
TASmod.savestateHandlerServer.state = SavestateState.NONE;
} catch (Exception e) {
if (player != null)
player.sendMessage(new TextComponentString(TextFormatting.RED + "Failed to load a savestate: " + e.getCause().toString()));
if (player != null) {
Throwable cause = e.getCause();
if (cause == null) {
cause = e;
}
player.sendMessage(new TextComponentString(String.format("Failed to load a savestate: %s", cause.getMessage())).setStyle(new Style().setColor(TextFormatting.RED)));
}

LOGGER.throwing(e);
TASmod.savestateHandlerServer.state = SavestateState.NONE;
Expand Down

0 comments on commit d9ab780

Please sign in to comment.