Skip to content

Commit 64b6e19

Browse files
committed
[Events] Add ServerStart Event
This event is fired before ServerInit when worlds are alredy loaded
1 parent e778e0e commit 64b6e19

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/main/java/com/minecrafttas/mctcommon/events/EventServer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
*/
1414
public interface EventServer {
1515

16+
/**
17+
* Fired, just before the server initialised, for both integrated and dedicated server.
18+
*/
19+
@FunctionalInterface
20+
public static interface EventServerStart extends EventBase {
21+
22+
/**
23+
* Fired, when the server is initialised, for both integrated and dedicated server.
24+
* @param server The server
25+
*/
26+
public void onServerStart(MinecraftServer server);
27+
}
28+
1629
/**
1730
* Fired, when the server is initialised, for both integrated and dedicated server.
1831
*/

src/main/java/com/minecrafttas/mctcommon/mixin/MixinMinecraftServer.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerGameLoop;
1111
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
12+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1213
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1314
import com.minecrafttas.mctcommon.events.EventServer.EventServerTick;
1415

@@ -17,6 +18,11 @@
1718
@Mixin(MinecraftServer.class)
1819
public class MixinMinecraftServer {
1920

21+
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z"))
22+
public void inject_initStart(CallbackInfo ci) {
23+
EventListenerRegistry.fireEvent(EventServerStart.class, (MinecraftServer) (Object) this);
24+
}
25+
2026
@Inject(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;init()Z", shift = Shift.AFTER))
2127
public void inject_init(CallbackInfo ci) {
2228
EventListenerRegistry.fireEvent(EventServerInit.class, (MinecraftServer) (Object) this);

src/main/java/com/minecrafttas/tasmod/TASmod.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.minecrafttas.mctcommon.CommandRegistry;
99
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
1010
import com.minecrafttas.mctcommon.events.EventServer.EventServerInit;
11+
import com.minecrafttas.mctcommon.events.EventServer.EventServerStart;
1112
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1213
import com.minecrafttas.mctcommon.networking.PacketHandlerRegistry;
1314
import com.minecrafttas.mctcommon.networking.Server;
@@ -34,7 +35,6 @@
3435
import com.minecrafttas.tasmod.savestates.handlers.SavestateResourcePackHandler;
3536
import com.minecrafttas.tasmod.savestates.storage.builtin.ClientMotionStorage;
3637
import com.minecrafttas.tasmod.savestates.storage.builtin.KTRNGSeedStorage;
37-
import com.minecrafttas.tasmod.savestates.storage.builtin.SavestateMotionStorage;
3838
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
3939
import com.minecrafttas.tasmod.ticksync.TickSyncServer;
4040
import com.minecrafttas.tasmod.util.LoggerMarkers;
@@ -51,7 +51,7 @@
5151
*
5252
* @author Scribble
5353
*/
54-
public class TASmod implements ModInitializer, EventServerInit, EventServerStop {
54+
public class TASmod implements ModInitializer, EventServerStart, EventServerInit, EventServerStop {
5555

5656
public static final Logger LOGGER = LogManager.getLogger("TASmod");
5757

@@ -135,12 +135,17 @@ public void onInitialize() {
135135
EventListenerRegistry.register(resourcepackHandler);
136136
PacketHandlerRegistry.register(playUntil);
137137
EventListenerRegistry.register(playUntil);
138-
139138
EventListenerRegistry.register(TASmodAPIRegistry.SAVESTATE_STORAGE);
140139

141140
registerSavestateStorage();
142141
}
143142

143+
@Override
144+
public void onServerStart(MinecraftServer server) {
145+
globalRandomness = new GlobalRandomnessTimer();
146+
EventListenerRegistry.register(globalRandomness);
147+
}
148+
144149
@Override
145150
public void onServerInit(MinecraftServer server) {
146151
LOGGER.info("Initializing server");
@@ -166,9 +171,6 @@ public void onServerInit(MinecraftServer server) {
166171
PacketHandlerRegistry.register(savestateHandlerServer.getPlayerHandler());
167172
EventListenerRegistry.register(savestateHandlerServer.getSavestateTemporaryHandler());
168173

169-
globalRandomness = new GlobalRandomnessTimer();
170-
EventListenerRegistry.register(globalRandomness);
171-
172174
if (!server.isDedicatedServer()) {
173175
TASmod.tickratechanger.ticksPerSecond = 0F;
174176
TASmod.tickratechanger.tickrateSaved = 20F;

src/main/java/com/minecrafttas/tasmod/registries/TASmodAPIRegistry.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class TASmodAPIRegistry {
2020
* savestate/rerecord count and category.
2121
*
2222
* <p>Any custom class has to implement PlaybackMetadataExtension
23+
* <p><strong>Side: Client</strong></p>
2324
*/
2425
public static final PlaybackMetadataRegistry PLAYBACK_METADATA = new PlaybackMetadataRegistry();
2526

@@ -28,7 +29,7 @@ public class TASmodAPIRegistry {
2829
*
2930
* <p>File commands give the opportunity to run commands on each recorded tick and each played back tick.<br>
3031
* File commands also have access to the TASfile so that data can be stored and read in/from the TASfile.
31-
*
32+
* <p><strong>Side: Client</strong></p>
3233
*/
3334
public static final PlaybackFileCommandsRegistry PLAYBACK_FILE_COMMAND = new PlaybackFileCommandsRegistry();
3435

@@ -39,6 +40,7 @@ public class TASmodAPIRegistry {
3940
* or extend an existing flavor (like {@link Beta1Flavor}) and overwrite parts of the methods.
4041
*
4142
* <p>The resulting flavor can be registered here and can be found as a saving option with /saveTAS
43+
* <p><strong>Side: Client</strong></p>
4244
*/
4345
public static final SerialiserFlavorRegistry SERIALISER_FLAVOR = new SerialiserFlavorRegistry();
4446

@@ -47,6 +49,7 @@ public class TASmodAPIRegistry {
4749
*
4850
* <p>Create a new ClientCommand by extending {@link ClientCommandBase},<br>
4951
* then create a command like normal, as it extends from the vanilla {@link CommandBase}
52+
* <p><strong>Side: Client</strong></p>
5053
*/
5154
public static final ClientCommandRegistry CLIENT_COMMANDS = new ClientCommandRegistry();
5255

0 commit comments

Comments
 (0)