|
1 | 1 | package com.minecrafttas.tasmod.savestates.handlers; |
2 | 2 |
|
| 3 | +import static com.minecrafttas.tasmod.TASmod.LOGGER; |
3 | 4 | import static com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate.NONE; |
4 | 5 | import static com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate.PLAYBACK; |
5 | 6 | import static com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate.RECORDING; |
|
12 | 13 | import com.minecrafttas.tasmod.events.EventPlaybackServer.EventControllerStateChange; |
13 | 14 | import com.minecrafttas.tasmod.networking.TASmodBufferBuilder; |
14 | 15 | import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate; |
| 16 | +import com.minecrafttas.tasmod.registries.TASmodPackets; |
15 | 17 | import com.minecrafttas.tasmod.savestates.SavestateHandlerServer; |
| 18 | +import com.minecrafttas.tasmod.savestates.exceptions.SavestateException; |
| 19 | +import com.minecrafttas.tasmod.util.Component; |
| 20 | + |
| 21 | +import net.minecraft.util.text.TextFormatting; |
16 | 22 |
|
17 | 23 | /** |
18 | 24 | * <p>Handles the creation of temporary savestates when recording/playing back a TAS |
@@ -48,23 +54,85 @@ public void onControllerStateChange(TASstate newstate, TASstate oldstate) { |
48 | 54 | if (newstate == RECORDING && createState) { |
49 | 55 | logger.info("Creating temporary savestate"); |
50 | 56 | createState = false; |
51 | | - handler.saveStateTemp((paths) -> { |
| 57 | + try { |
| 58 | + handler.saveStateTemp((paths) -> { |
| 59 | + try { |
| 60 | + TASmod.server.sendToAll(new TASmodBufferBuilder(SAVESTATE_CLEAR_SCREEN)); |
| 61 | + } catch (Exception e) { |
| 62 | + logger.catching(e); |
| 63 | + } |
| 64 | + }); |
| 65 | + } catch (SavestateException e) { |
| 66 | + TASmod.getServerInstance().getServer().getPlayerList().sendMessage(Component.translatable(e.getMessage()).withStyle(TextFormatting.RED).build()); |
| 67 | + |
52 | 68 | try { |
53 | | - TASmod.server.sendToAll(new TASmodBufferBuilder(SAVESTATE_CLEAR_SCREEN)); |
54 | | - } catch (Exception e) { |
| 69 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.TICKRATE_0_WARN)); |
| 70 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.CLEAR_SCREEN)); |
| 71 | + } catch (Exception e1) { |
55 | 72 | logger.catching(e); |
56 | 73 | } |
57 | | - }); |
| 74 | + |
| 75 | + LOGGER.error("Failed to create a temp savestate"); |
| 76 | + LOGGER.catching(e); |
| 77 | + } catch (Exception e) { |
| 78 | + Throwable cause = e.getCause(); |
| 79 | + if (cause == null) { |
| 80 | + cause = e; |
| 81 | + } |
| 82 | + TASmod.getServerInstance().getPlayerList().sendMessage(Component.translatable("msg.tasmod.savestate.failure", e.getMessage()).withStyle(TextFormatting.RED).build()); |
| 83 | + |
| 84 | + try { |
| 85 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.TICKRATE_0_WARN)); |
| 86 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.CLEAR_SCREEN)); |
| 87 | + } catch (Exception e1) { |
| 88 | + logger.catching(e); |
| 89 | + } |
| 90 | + |
| 91 | + LOGGER.error("Failed to create a temp savestate"); |
| 92 | + LOGGER.catching(e); |
| 93 | + } finally { |
| 94 | + handler.resetState(); |
| 95 | + } |
58 | 96 | } else if (newstate == PLAYBACK) { |
59 | 97 | logger.info("Loading temporary savestate"); |
60 | 98 | createState = false; |
61 | | - handler.loadStateTemp((paths) -> { |
| 99 | + try { |
| 100 | + handler.loadStateTemp((paths) -> { |
| 101 | + try { |
| 102 | + TASmod.server.sendToAll(new TASmodBufferBuilder(SAVESTATE_CLEAR_SCREEN)); |
| 103 | + } catch (Exception e) { |
| 104 | + logger.catching(e); |
| 105 | + } |
| 106 | + }); |
| 107 | + } catch (SavestateException e) { |
| 108 | + TASmod.getServerInstance().getServer().getPlayerList().sendMessage(Component.translatable(e.getMessage()).withStyle(TextFormatting.RED).build()); |
| 109 | + |
| 110 | + try { |
| 111 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.CLEAR_SCREEN)); |
| 112 | + } catch (Exception e1) { |
| 113 | + logger.catching(e); |
| 114 | + } |
| 115 | + |
| 116 | + LOGGER.error("Failed to load a temp savestate"); |
| 117 | + LOGGER.catching(e); |
| 118 | + } catch (Exception e) { |
| 119 | + Throwable cause = e.getCause(); |
| 120 | + if (cause == null) { |
| 121 | + cause = e; |
| 122 | + } |
| 123 | + TASmod.getServerInstance().getPlayerList().sendMessage(Component.translatable("msg.tasmod.savestate.failure", e.getMessage()).withStyle(TextFormatting.RED).build()); |
| 124 | + |
62 | 125 | try { |
63 | | - TASmod.server.sendToAll(new TASmodBufferBuilder(SAVESTATE_CLEAR_SCREEN)); |
64 | | - } catch (Exception e) { |
| 126 | + TASmod.server.sendToAll(new TASmodBufferBuilder(TASmodPackets.CLEAR_SCREEN)); |
| 127 | + } catch (Exception e1) { |
65 | 128 | logger.catching(e); |
66 | 129 | } |
67 | | - }); |
| 130 | + |
| 131 | + LOGGER.error("Failed to load a temp savestate"); |
| 132 | + LOGGER.catching(e); |
| 133 | + } finally { |
| 134 | + handler.resetState(); |
| 135 | + } |
68 | 136 | } |
69 | 137 | } |
70 | 138 |
|
|
0 commit comments