LifecycleEvent.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * This file is part of architectury.
  3. * Copyright (C) 2020 shedaniel
  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 when server is starting, equivalent to forge's {@code FMLServerAboutToStartEvent} and fabric's {@code ServerLifecycleEvents#SERVER_STARTING}.
  28. */
  29. Event<ServerState> SERVER_BEFORE_START = EventFactory.createLoop(ServerState.class);
  30. /**
  31. * Invoked when server is starting, equivalent to forge's {@code FMLServerStartingEvent}.
  32. */
  33. Event<ServerState> SERVER_STARTING = EventFactory.createLoop(ServerState.class);
  34. /**
  35. * Invoked when server has started, equivalent to forge's {@code FMLServerStartedEvent} and fabric's {@code ServerLifecycleEvents#SERVER_STARTED}.
  36. */
  37. Event<ServerState> SERVER_STARTED = EventFactory.createLoop(ServerState.class);
  38. /**
  39. * Invoked when server is stopping, equivalent to forge's {@code FMLServerStoppingEvent} and fabric's {@code ServerLifecycleEvents#SERVER_STOPPING}.
  40. */
  41. Event<ServerState> SERVER_STOPPING = EventFactory.createLoop(ServerState.class);
  42. /**
  43. * Invoked when server has stopped, equivalent to forge's {@code FMLServerStoppedEvent} and fabric's {@code ServerLifecycleEvents#SERVER_STOPPED}.
  44. */
  45. Event<ServerState> SERVER_STOPPED = EventFactory.createLoop(ServerState.class);
  46. /**
  47. * Invoked after a world is loaded only on server, equivalent to forge's {@code WorldEvent.Load} and fabric's {@code ServerWorldEvents#LOAD}.
  48. */
  49. Event<ServerWorldState> SERVER_WORLD_LOAD = EventFactory.createLoop(ServerWorldState.class);
  50. /**
  51. * Invoked after a world is unloaded, equivalent to forge's {@code WorldEvent.Unload} and fabric's {@code ServerWorldEvents#UNLOAD}.
  52. */
  53. Event<ServerWorldState> SERVER_WORLD_UNLOAD = EventFactory.createLoop(ServerWorldState.class);
  54. /**
  55. * Invoked during a world is saved, equivalent to forge's {@code WorldEvent.Save}.
  56. */
  57. Event<ServerWorldState> SERVER_WORLD_SAVE = EventFactory.createLoop(ServerWorldState.class);
  58. interface InstanceState<T> {
  59. void stateChanged(T instance);
  60. }
  61. interface ServerState extends InstanceState<MinecraftServer> {}
  62. interface WorldState<T extends Level> {
  63. void act(T world);
  64. }
  65. interface ServerWorldState extends WorldState<ServerLevel> {}
  66. }