Class SharedInstance

java.lang.Object
net.minestom.server.instance.Instance
net.minestom.server.instance.SharedInstance
All Implemented Interfaces:
Audience, ForwardingAudience, Pointered, PacketGroupingAudience, EventHandler<InstanceEvent>, Block.Getter, Block.Setter, Snapshotable, Taggable, TagReadable, TagWritable, Tickable, Schedulable

public class SharedInstance extends Instance
The SharedInstance is an instance that shares the same chunks as its linked InstanceContainer, entities are separated.
  • Constructor Details

    • SharedInstance

      public SharedInstance(@NotNull @NotNull UUID uniqueId, @NotNull @NotNull InstanceContainer instanceContainer)
  • Method Details

    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull Block block, boolean doBlockUpdates)
      Specified by:
      setBlock in class Instance
    • placeBlock

      public boolean placeBlock(@NotNull BlockHandler.Placement placement, boolean doBlockUpdates)
      Specified by:
      placeBlock in class Instance
    • breakBlock

      public boolean breakBlock(@NotNull @NotNull Player player, @NotNull @NotNull Point blockPosition, @NotNull @NotNull BlockFace blockFace, boolean doBlockUpdates)
      Description copied from class: Instance
      Does call PlayerBlockBreakEvent and send particle packets
      Specified by:
      breakBlock in class Instance
      Parameters:
      player - the Player who break the block
      blockPosition - the position of the broken block
      doBlockUpdates - true to do block updates, false otherwise
      Returns:
      true if the block has been broken, false if it has been cancelled
    • loadChunk

      @NotNull public @NotNull CompletableFuture<Chunk> loadChunk(int chunkX, int chunkZ)
      Description copied from class: Instance
      Forces the generation of a Chunk, even if no file and Generator are defined.
      Specified by:
      loadChunk in class Instance
      Parameters:
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      a CompletableFuture completed once the chunk has been loaded
    • loadOptionalChunk

      @NotNull public @NotNull CompletableFuture<Chunk> loadOptionalChunk(int chunkX, int chunkZ)
      Description copied from class: Instance
      Loads the chunk if the chunk is already loaded or if Instance.hasEnabledAutoChunkLoad() returns true.
      Specified by:
      loadOptionalChunk in class Instance
      Parameters:
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      a CompletableFuture completed once the chunk has been processed, can be null if not loaded
    • unloadChunk

      public void unloadChunk(@NotNull @NotNull Chunk chunk)
      Description copied from class: Instance
      Schedules the removal of a Chunk, this method does not promise when it will be done.

      WARNING: during unloading, all entities other than Player will be removed.

      Specified by:
      unloadChunk in class Instance
      Parameters:
      chunk - the chunk to unload
    • getChunk

      public Chunk getChunk(int chunkX, int chunkZ)
      Description copied from class: Instance
      Gets the loaded Chunk at a position.

      WARNING: this should only return already-loaded chunk, use Instance.loadChunk(int, int) or similar to load one instead.

      Specified by:
      getChunk in class Instance
      Parameters:
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      the chunk at the specified position, null if not loaded
    • saveInstance

      @NotNull public @NotNull CompletableFuture<Void> saveInstance()
      Description copied from class: Instance
      Saves the current instance tags.

      Warning: only the global instance data will be saved, not chunks. You would need to call Instance.saveChunksToStorage() too.

      Specified by:
      saveInstance in class Instance
      Returns:
      the future called once the instance data has been saved
    • saveChunkToStorage

      @NotNull public @NotNull CompletableFuture<Void> saveChunkToStorage(@NotNull @NotNull Chunk chunk)
      Description copied from class: Instance
      Saves a Chunk to permanent storage.
      Specified by:
      saveChunkToStorage in class Instance
      Parameters:
      chunk - the Chunk to save
      Returns:
      future called when the chunk is done saving
    • saveChunksToStorage

      @NotNull public @NotNull CompletableFuture<Void> saveChunksToStorage()
      Description copied from class: Instance
      Saves multiple chunks to permanent storage.
      Specified by:
      saveChunksToStorage in class Instance
      Returns:
      future called when the chunks are done saving
    • setChunkSupplier

      public void setChunkSupplier(@NotNull @NotNull ChunkSupplier chunkSupplier)
      Specified by:
      setChunkSupplier in class Instance
    • getChunkSupplier

      public ChunkSupplier getChunkSupplier()
      Description copied from class: Instance
      Gets the chunk supplier of the instance.
      Specified by:
      getChunkSupplier in class Instance
      Returns:
      the chunk supplier of the instance
    • generator

      @Nullable public @Nullable Generator generator()
      Description copied from class: Instance
      Gets the generator associated with the instance
      Specified by:
      generator in class Instance
      Returns:
      the generator if any
    • setGenerator

      public void setGenerator(@Nullable @Nullable Generator generator)
      Description copied from class: Instance
      Changes the generator of the instance
      Specified by:
      setGenerator in class Instance
      Parameters:
      generator - the new generator, or null to disable generation
    • getChunks

      @NotNull public @NotNull Collection<Chunk> getChunks()
      Description copied from class: Instance
      Gets all the instance's loaded chunks.
      Specified by:
      getChunks in class Instance
      Returns:
      an unmodifiable containing all the instance chunks
    • enableAutoChunkLoad

      public void enableAutoChunkLoad(boolean enable)
      Description copied from class: Instance
      When set to true, chunks will load automatically when requested. Otherwise using Instance.loadChunk(int, int) will be required to even spawn a player
      Specified by:
      enableAutoChunkLoad in class Instance
      Parameters:
      enable - enable the auto chunk load
    • hasEnabledAutoChunkLoad

      public boolean hasEnabledAutoChunkLoad()
      Description copied from class: Instance
      Gets if the instance should auto load chunks.
      Specified by:
      hasEnabledAutoChunkLoad in class Instance
      Returns:
      true if auto chunk load is enabled, false otherwise
    • isInVoid

      public boolean isInVoid(@NotNull @NotNull Point point)
      Description copied from class: Instance
      Determines whether a position in the void.
      Specified by:
      isInVoid in class Instance
      Parameters:
      point - the point in the world
      Returns:
      true if the point is inside the void
    • getInstanceContainer

      @NotNull public @NotNull InstanceContainer getInstanceContainer()
      Gets the InstanceContainer from where this instance takes its chunks from.
      Returns:
      the associated InstanceContainer
    • areLinked

      public static boolean areLinked(Instance instance1, Instance instance2)
      Gets if two instances share the same chunks.
      Parameters:
      instance1 - the first instance
      instance2 - the second instance
      Returns:
      true if the two instances share the same chunks