Class UpdateManager

java.lang.Object
net.minestom.server.UpdateManager

public final class UpdateManager
extends java.lang.Object
Manager responsible for the server ticks.

The ThreadProvider manages the multi-thread aspect for Instance ticks, it can be modified with setThreadProvider(ThreadProvider).

  • Constructor Details

    • UpdateManager

      protected UpdateManager()
      Should only be created in MinecraftServer.
  • Method Details

    • start

      protected void start()
      Starts the server loop in the update thread.
    • getThreadProvider

      public ThreadProvider getThreadProvider()
      Gets the current ThreadProvider.
      Returns:
      the current thread provider
    • setThreadProvider

      public void setThreadProvider​(ThreadProvider threadProvider)
      Changes the server ThreadProvider.
      Parameters:
      threadProvider - the new thread provider
      Throws:
      java.lang.NullPointerException - if threadProvider is null
    • signalInstanceCreate

      public void signalInstanceCreate​(Instance instance)
      Signals the ThreadProvider that an instance has been created.

      WARNING: should be automatically done by the InstanceManager.

      Parameters:
      instance - the instance
    • signalInstanceDelete

      public void signalInstanceDelete​(Instance instance)
      Signals the ThreadProvider that an instance has been deleted.

      WARNING: should be automatically done by the InstanceManager.

      Parameters:
      instance - the instance
    • signalChunkLoad

      public void signalChunkLoad​(Instance instance, int chunkX, int chunkZ)
      Signals the ThreadProvider that a chunk has been loaded.

      WARNING: should be automatically done by the Instance implementation.

      Parameters:
      instance - the instance of the chunk
      chunkX - the chunk X
      chunkZ - the chunk Z
    • signalChunkUnload

      public void signalChunkUnload​(Instance instance, int chunkX, int chunkZ)
      Signals the ThreadProvider that a chunk has been unloaded.

      WARNING: should be automatically done by the Instance implementation.

      Parameters:
      instance - the instance of the chunk
      chunkX - the chunk X
      chunkZ - the chunk Z
    • addTickStartCallback

      public void addTickStartCallback​(@NotNull java.util.function.LongConsumer callback)
      Adds a callback executed at the start of the next server tick.

      The long in the consumer represents the starting time (in ms) of the tick.

      Parameters:
      callback - the tick start callback
    • removeTickStartCallback

      public void removeTickStartCallback​(@NotNull java.util.function.LongConsumer callback)
      Removes a tick start callback.
      Parameters:
      callback - the callback to remove
    • addTickEndCallback

      public void addTickEndCallback​(@NotNull java.util.function.LongConsumer callback)
      Adds a callback executed at the end of the next server tick.

      The long in the consumer represents the duration (in ms) of the tick.

      Parameters:
      callback - the tick end callback
    • removeTickEndCallback

      public void removeTickEndCallback​(@NotNull java.util.function.LongConsumer callback)
      Removes a tick end callback.
      Parameters:
      callback - the callback to remove
    • stop

      public void stop()
      Stops the server loop.