LifecycleEvent.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * This file is part of architectury.
  3. * Copyright (C) 2020, 2021, 2022 architectury
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 3 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. package me.shedaniel.architectury.event.events;
  20. import me.shedaniel.architectury.event.Event;
  21. import me.shedaniel.architectury.event.EventFactory;
  22. import net.minecraft.server.MinecraftServer;
  23. import net.minecraft.server.level.ServerLevel;
  24. import net.minecraft.world.level.Level;
  25. public interface LifecycleEvent {
  26. /**
  27. * Invoked before initial server startup. This is the earliest point at which the server will be available.
  28. * Equivalent to Forge's {@code FMLServerAboutToStartEvent} event and
  29. * Fabric's {@code ServerLifecycleEvents#SERVER_STARTING}.
  30. *
  31. * @see ServerState#stateChanged(Object)
  32. */
  33. Event<ServerState> SERVER_BEFORE_START = EventFactory.createLoop();
  34. /**
  35. * Invoked during server startup.
  36. * Equivalent to Forge's {@code FMLServerStartingEvent} event.
  37. *
  38. * @see ServerState#stateChanged(Object)
  39. */
  40. Event<ServerState> SERVER_STARTING = EventFactory.createLoop();
  41. /**
  42. * Invoked when the server has started and is ready to accept players.
  43. * Equivalent to Forge's {@code FMLServerStartedEvent} event
  44. * and Fabric's {@code ServerLifecycleEvents#SERVER_STARTED}.
  45. *
  46. * @see ServerState#stateChanged(Object)
  47. */
  48. Event<ServerState> SERVER_STARTED = EventFactory.createLoop();
  49. /**
  50. * Invoked when the server begins shutting down.
  51. * Equivalent to Forge's {@code FMLServerStoppingEvent} event and
  52. * Fabric's {@code ServerLifecycleEvents#SERVER_STOPPING}.
  53. *
  54. * @see ServerState#stateChanged(Object)
  55. */
  56. Event<ServerState> SERVER_STOPPING = EventFactory.createLoop();
  57. /**
  58. * Invoked when the server has finished stopping, and is about to fully shut down.
  59. * Equivalent to Forge's {@code FMLServerStoppedEvent} event and
  60. * Fabric's {@code ServerLifecycleEvents#SERVER_STOPPED}.
  61. *
  62. * @see ServerState#stateChanged(Object)
  63. */
  64. Event<ServerState> SERVER_STOPPED = EventFactory.createLoop();
  65. /**
  66. * Invoked when a world is loaded on the server-side.
  67. * Equivalent to Forge's {@code WorldEvent.Load} event (on server)
  68. * and Fabric's {@code ServerWorldEvents#LOAD}.
  69. *
  70. * @see ServerWorldState#act(Level)
  71. */
  72. Event<ServerWorldState> SERVER_WORLD_LOAD = EventFactory.createLoop();
  73. /**
  74. * Invoked when a world is unloaded on the server-side.
  75. * Equivalent to Forge's {@code WorldEvent.Unload} event (on server)
  76. * and Fabric's {@code ServerWorldEvents#UNLOAD}.
  77. *
  78. * @see ServerWorldState#act(Level)
  79. */
  80. Event<ServerWorldState> SERVER_WORLD_UNLOAD = EventFactory.createLoop();
  81. /**
  82. * Invoked when the world is being saved.
  83. * Equivalent to Forge's {@code WorldEvent.Save} event.
  84. *
  85. * @see ServerWorldState#act(Level)
  86. */
  87. Event<ServerWorldState> SERVER_WORLD_SAVE = EventFactory.createLoop();
  88. /**
  89. * Invoked once common setup has begun.
  90. * <p> This happens during {@code FMLCommonSetupEvent} on Forge,
  91. * or when Architectury API's client/server entrypoint initialises on Fabric.
  92. * <p>
  93. * Registries should have been initialised by this point, but there
  94. * are no such guarantees, as you can modify the registry beyond this point
  95. * on non-Forge environments.
  96. */
  97. Event<Runnable> SETUP = EventFactory.createLoop();
  98. interface InstanceState<T> {
  99. /**
  100. * Parent event type for any events that are invoked on instance state change.
  101. *
  102. * @param instance The changed state.
  103. */
  104. void stateChanged(T instance);
  105. }
  106. interface ServerState extends InstanceState<MinecraftServer> {
  107. }
  108. interface WorldState<T extends Level> {
  109. /**
  110. * Parent event type for any events that are invoked on world state change.
  111. *
  112. * @param world The world that has changed.
  113. */
  114. void act(T world);
  115. }
  116. interface ServerWorldState extends WorldState<ServerLevel> {
  117. }
  118. }