Commit 7bd1f7fcb9c104020a50606cd30964e2bca49fca
1 parent
3810e896
add ShutdownListener
Showing
4 changed files
with
50 additions
and
3 deletions
java/client/com/mumfrey/liteloader/client/api/LiteLoaderCoreAPIClient.java
| ... | ... | @@ -125,10 +125,13 @@ public class LiteLoaderCoreAPIClient extends LiteLoaderCoreAPI |
| 125 | 125 | @Override |
| 126 | 126 | public List<Observer> getObservers() |
| 127 | 127 | { |
| 128 | + ObjectFactory<?, ?> objectFactory = this.getObjectFactory(); | |
| 129 | + | |
| 128 | 130 | return ImmutableList.<Observer>of |
| 129 | 131 | ( |
| 130 | 132 | new ResourceObserver(), |
| 131 | - this.getObjectFactory().getPanelManager() | |
| 133 | + objectFactory.getPanelManager(), | |
| 134 | + objectFactory.getEventBroker() | |
| 132 | 135 | ); |
| 133 | 136 | } |
| 134 | 137 | ... | ... |
java/common/com/mumfrey/liteloader/ShutdownListener.java
0 → 100644
| 1 | +package com.mumfrey.liteloader; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * Interface for mods that want to receive an event when the game is shutting down due to a user request. They do | |
| 5 | + * not receive the callback when the VM is terminating for other reasons, use a regular VM shutdownhook for that. | |
| 6 | + * | |
| 7 | + * @author Adam Mummery-Smith | |
| 8 | + */ | |
| 9 | +public interface ShutdownListener extends LiteMod | |
| 10 | +{ | |
| 11 | + public abstract void onShutDown(); | |
| 12 | +} | ... | ... |
java/common/com/mumfrey/liteloader/core/LiteLoaderEventBroker.java
| ... | ... | @@ -35,8 +35,10 @@ import com.mumfrey.liteloader.ServerCommandProvider; |
| 35 | 35 | import com.mumfrey.liteloader.ServerPlayerListener; |
| 36 | 36 | import com.mumfrey.liteloader.ServerPluginChannelListener; |
| 37 | 37 | import com.mumfrey.liteloader.ServerTickable; |
| 38 | +import com.mumfrey.liteloader.ShutdownListener; | |
| 38 | 39 | import com.mumfrey.liteloader.api.InterfaceProvider; |
| 39 | 40 | import com.mumfrey.liteloader.api.Listener; |
| 41 | +import com.mumfrey.liteloader.api.ShutdownObserver; | |
| 40 | 42 | import com.mumfrey.liteloader.common.GameEngine; |
| 41 | 43 | import com.mumfrey.liteloader.common.LoadingProgress; |
| 42 | 44 | import com.mumfrey.liteloader.core.event.HandlerList; |
| ... | ... | @@ -54,7 +56,7 @@ import com.mumfrey.liteloader.util.log.LiteLoaderLogger; |
| 54 | 56 | * @param <TClient> Type of the client runtime, "Minecraft" on client and null on the server |
| 55 | 57 | * @param <TServer> Type of the server runtime, "IntegratedServer" on the client, "MinecraftServer" on the server |
| 56 | 58 | */ |
| 57 | -public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftServer> implements InterfaceProvider | |
| 59 | +public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftServer> implements InterfaceProvider, ShutdownObserver | |
| 58 | 60 | { |
| 59 | 61 | /** |
| 60 | 62 | * @author Adam Mummery-Smith |
| ... | ... | @@ -152,6 +154,11 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 152 | 154 | private FastIterable<ServerTickable> serverTickListeners = new HandlerList<ServerTickable>(ServerTickable.class); |
| 153 | 155 | |
| 154 | 156 | /** |
| 157 | + * List of mods which want to be notified when the game is shutting down | |
| 158 | + */ | |
| 159 | + private FastIterable<ShutdownListener> shutdownListeners = new HandlerList<ShutdownListener>(ShutdownListener.class); | |
| 160 | + | |
| 161 | + /** | |
| 155 | 162 | * ctor |
| 156 | 163 | * |
| 157 | 164 | * @param loader |
| ... | ... | @@ -210,6 +217,7 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 210 | 217 | delegate.registerInterface(PlayerMoveListener.class); |
| 211 | 218 | delegate.registerInterface(CommonPluginChannelListener.class); |
| 212 | 219 | delegate.registerInterface(ServerTickable.class); |
| 220 | + delegate.registerInterface(ShutdownListener.class); | |
| 213 | 221 | } |
| 214 | 222 | |
| 215 | 223 | /** |
| ... | ... | @@ -264,6 +272,14 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 264 | 272 | { |
| 265 | 273 | this.serverTickListeners.add(serverTickable); |
| 266 | 274 | } |
| 275 | + | |
| 276 | + /** | |
| 277 | + * @param shutdownListener | |
| 278 | + */ | |
| 279 | + public void addShutdownListener(ShutdownListener shutdownListener) | |
| 280 | + { | |
| 281 | + this.shutdownListeners.add(shutdownListener); | |
| 282 | + } | |
| 267 | 283 | |
| 268 | 284 | /** |
| 269 | 285 | * @param instance |
| ... | ... | @@ -510,4 +526,20 @@ public abstract class LiteLoaderEventBroker<TClient, TServer extends MinecraftSe |
| 510 | 526 | this.playerStateList.remove(playerState); |
| 511 | 527 | } |
| 512 | 528 | } |
| 529 | + | |
| 530 | + @Override | |
| 531 | + public void onShutDown() | |
| 532 | + { | |
| 533 | + for (ShutdownListener listener : this.shutdownListeners) | |
| 534 | + { | |
| 535 | + try | |
| 536 | + { | |
| 537 | + listener.onShutDown(); | |
| 538 | + } | |
| 539 | + catch (Throwable th) | |
| 540 | + { | |
| 541 | + th.printStackTrace(); | |
| 542 | + } | |
| 543 | + } | |
| 544 | + } | |
| 513 | 545 | } | ... | ... |
java/common/com/mumfrey/liteloader/interfaces/FastIterable.java