Class MinecraftServer

All Implemented Interfaces:
AutoCloseable, Executor, CommandOutput, SnooperListener, MessageListener<ServerTask>
Direct Known Subclasses:
IntegratedServer, MinecraftDedicatedServer

public abstract class MinecraftServer
extends ReentrantThreadExecutor<ServerTask>
implements SnooperListener, CommandOutput, AutoCloseable
  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • USER_CACHE_FILE

      public static final File USER_CACHE_FILE
    • DEMO_LEVEL_INFO

      public static final LevelInfo DEMO_LEVEL_INFO
    • session

      protected final LevelStorage.Session session
    • saveHandler

      protected final WorldSaveHandler saveHandler
    • snooper

      private final Snooper snooper
    • serverGuiTickables

      private final List<Runnable> serverGuiTickables
    • tickTimeTracker

      private final TickTimeTracker tickTimeTracker
    • profiler

      private Profiler profiler
    • networkIo

      private final ServerNetworkIo networkIo
    • worldGenerationProgressListenerFactory

      private final WorldGenerationProgressListenerFactory worldGenerationProgressListenerFactory
    • metadata

      private final ServerMetadata metadata
    • random

      private final Random random
    • dataFixer

      private final com.mojang.datafixers.DataFixer dataFixer
    • serverIp

      private String serverIp
    • serverPort

      private int serverPort
    • registryManager

      protected final DynamicRegistryManager.Impl registryManager
    • worlds

      private final Map<RegistryKey<World>,​ServerWorld> worlds
    • playerManager

      private PlayerManager playerManager
    • running

      private volatile boolean running
    • stopped

      private boolean stopped
    • ticks

      private int ticks
    • proxy

      protected final Proxy proxy
    • onlineMode

      private boolean onlineMode
    • preventProxyConnections

      private boolean preventProxyConnections
    • pvpEnabled

      private boolean pvpEnabled
    • flightEnabled

      private boolean flightEnabled
    • motd

      @Nullable private String motd
    • worldHeight

      private int worldHeight
    • playerIdleTimeout

      private int playerIdleTimeout
    • lastTickLengths

      public final long[] lastTickLengths
    • keyPair

      @Nullable private KeyPair keyPair
    • userName

      @Nullable private String userName
    • demo

      private boolean demo
    • resourcePackUrl

      private String resourcePackUrl
    • resourcePackHash

      private String resourcePackHash
    • loading

      private volatile boolean loading
    • lastTimeReference

      private long lastTimeReference
    • profilerStartQueued

      private boolean profilerStartQueued
    • forceGameMode

      private boolean forceGameMode
    • sessionService

      private final com.mojang.authlib.minecraft.MinecraftSessionService sessionService
    • gameProfileRepo

      private final com.mojang.authlib.GameProfileRepository gameProfileRepo
    • userCache

      private final UserCache userCache
    • lastPlayerSampleUpdate

      private long lastPlayerSampleUpdate
    • serverThread

      private final Thread serverThread
    • timeReference

      private long timeReference
    • field_19248

      private long field_19248
    • waitingForNextTick

      private boolean waitingForNextTick
    • iconFilePresent

      @Environment(CLIENT) private boolean iconFilePresent
    • dataPackManager

      private final ResourcePackManager dataPackManager
    • scoreboard

      private final ServerScoreboard scoreboard
    • dataCommandStorage

      @Nullable private DataCommandStorage dataCommandStorage
    • bossBarManager

      private final BossBarManager bossBarManager
    • commandFunctionManager

      private final CommandFunctionManager commandFunctionManager
    • metricsData

      private final MetricsData metricsData
    • enforceWhitelist

      private boolean enforceWhitelist
    • tickTime

      private float tickTime
    • workerExecutor

      private final Executor workerExecutor
    • serverId

      @Nullable private String serverId
    • serverResourceManager

      private ServerResourceManager serverResourceManager
    • structureManager

      private final StructureManager structureManager
    • saveProperties

      protected final SaveProperties saveProperties
  • Constructor Details

  • Method Details

    • startServer

      public static <S extends MinecraftServer> S startServer​(Function<Thread,​S> serverFactory)
    • initScoreboard

      private void initScoreboard​(PersistentStateManager persistentStateManager)
    • setupServer

      protected abstract boolean setupServer() throws IOException
      Throws:
      IOException
    • convertLevel

      public static void convertLevel​(LevelStorage.Session session)
    • loadWorld

      protected void loadWorld()
    • method_27731

      protected void method_27731()
    • createWorlds

      protected void createWorlds​(WorldGenerationProgressListener worldGenerationProgressListener)
    • setupSpawn

      private static void setupSpawn​(ServerWorld world, ServerWorldProperties serverWorldProperties, boolean bonusChest, boolean debugWorld, boolean bool)
    • setToDebugWorldProperties

      private void setToDebugWorldProperties​(SaveProperties properties)
    • prepareStartRegion

      private void prepareStartRegion​(WorldGenerationProgressListener worldGenerationProgressListener)
    • loadWorldResourcePack

      protected void loadWorldResourcePack()
    • getDefaultGameMode

      public GameMode getDefaultGameMode()
    • isHardcore

      public boolean isHardcore()
    • getOpPermissionLevel

      public abstract int getOpPermissionLevel()
    • getFunctionPermissionLevel

      public abstract int getFunctionPermissionLevel()
    • shouldBroadcastRconToOps

      public abstract boolean shouldBroadcastRconToOps()
    • save

      public boolean save​(boolean suppressLogs, boolean bool, boolean bool2)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface MessageListener<ServerTask>
    • shutdown

      protected void shutdown()
    • getServerIp

      public String getServerIp()
    • setServerIp

      public void setServerIp​(String serverIp)
    • isRunning

      public boolean isRunning()
    • stop

      public void stop​(boolean bool)
    • runServer

      protected void runServer()
    • shouldKeepTicking

      private boolean shouldKeepTicking()
    • method_16208

      protected void method_16208()
    • createTask

      protected ServerTask createTask​(Runnable runnable)
      Specified by:
      createTask in class ThreadExecutor<ServerTask>
    • canExecute

      protected boolean canExecute​(ServerTask serverTask)
      Specified by:
      canExecute in class ThreadExecutor<ServerTask>
    • runTask

      public boolean runTask()
      Overrides:
      runTask in class ThreadExecutor<ServerTask>
    • method_20415

      private boolean method_20415()
    • executeTask

      protected void executeTask​(ServerTask serverTask)
      Overrides:
      executeTask in class ReentrantThreadExecutor<ServerTask>
    • setFavicon

      private void setFavicon​(ServerMetadata metadata)
    • hasIconFile

      @Environment(CLIENT) public boolean hasIconFile()
    • getIconFile

      @Environment(CLIENT) public File getIconFile()
    • getRunDirectory

      public File getRunDirectory()
    • setCrashReport

      protected void setCrashReport​(CrashReport report)
    • exit

      protected void exit()
    • tick

      protected void tick​(BooleanSupplier shouldKeepTicking)
    • tickWorlds

      protected void tickWorlds​(BooleanSupplier shouldKeepTicking)
    • isNetherAllowed

      public boolean isNetherAllowed()
    • addServerGuiTickable

      public void addServerGuiTickable​(Runnable tickable)
    • setServerId

      protected void setServerId​(String serverId)
    • isStopping

      @Environment(CLIENT) public boolean isStopping()
    • getFile

      public File getFile​(String path)
      Parameters:
      path - relative path from the run directory
    • getOverworld

      public final ServerWorld getOverworld()
    • getWorld

      @Nullable public ServerWorld getWorld​(RegistryKey<World> key)
    • getWorldRegistryKeys

      public Set<RegistryKey<World>> getWorldRegistryKeys()
    • getWorlds

      public Iterable<ServerWorld> getWorlds()
    • getVersion

      public String getVersion()
    • getCurrentPlayerCount

      public int getCurrentPlayerCount()
    • getMaxPlayerCount

      public int getMaxPlayerCount()
    • getPlayerNames

      public String[] getPlayerNames()
    • getServerModName

      public String getServerModName()
    • populateCrashReport

      public CrashReport populateCrashReport​(CrashReport report)
    • getModdedStatusMessage

      public abstract Optional<String> getModdedStatusMessage()
    • sendSystemMessage

      public void sendSystemMessage​(Text message, UUID senderUuid)
      Specified by:
      sendSystemMessage in interface CommandOutput
    • getKeyPair

      public KeyPair getKeyPair()
    • getServerPort

      public int getServerPort()
    • setServerPort

      public void setServerPort​(int serverPort)
    • getUserName

      public String getUserName()
    • setServerName

      public void setServerName​(String serverName)
    • isSinglePlayer

      public boolean isSinglePlayer()
    • method_31400

      protected void method_31400()
    • setDifficulty

      public void setDifficulty​(Difficulty difficulty, boolean forceUpdate)
    • adjustTrackingDistance

      public int adjustTrackingDistance​(int initialDistance)
    • updateMobSpawnOptions

      private void updateMobSpawnOptions()
    • setDifficultyLocked

      public void setDifficultyLocked​(boolean locked)
    • sendDifficulty

      private void sendDifficulty​(ServerPlayerEntity player)
    • isMonsterSpawningEnabled

      protected boolean isMonsterSpawningEnabled()
    • isDemo

      public boolean isDemo()
    • setDemo

      public void setDemo​(boolean demo)
    • getResourcePackUrl

      public String getResourcePackUrl()
    • getResourcePackHash

      public String getResourcePackHash()
    • setResourcePack

      public void setResourcePack​(String url, String hash)
    • addSnooperInfo

      public void addSnooperInfo​(Snooper snooper)
      Specified by:
      addSnooperInfo in interface SnooperListener
    • isDedicated

      public abstract boolean isDedicated()
    • getRateLimit

      public abstract int getRateLimit()
    • isOnlineMode

      public boolean isOnlineMode()
    • setOnlineMode

      public void setOnlineMode​(boolean onlineMode)
    • shouldPreventProxyConnections

      public boolean shouldPreventProxyConnections()
    • setPreventProxyConnections

      public void setPreventProxyConnections​(boolean preventProxyConnections)
    • shouldSpawnAnimals

      public boolean shouldSpawnAnimals()
    • shouldSpawnNpcs

      public boolean shouldSpawnNpcs()
    • isUsingNativeTransport

      public abstract boolean isUsingNativeTransport()
    • isPvpEnabled

      public boolean isPvpEnabled()
    • setPvpEnabled

      public void setPvpEnabled​(boolean pvpEnabled)
    • isFlightEnabled

      public boolean isFlightEnabled()
    • setFlightEnabled

      public void setFlightEnabled​(boolean flightEnabled)
    • areCommandBlocksEnabled

      public abstract boolean areCommandBlocksEnabled()
      Specifies whether command blocks can execute commands on the server.
    • getServerMotd

      public String getServerMotd()
    • setMotd

      public void setMotd​(String motd)
    • getWorldHeight

      public int getWorldHeight()
    • setWorldHeight

      public void setWorldHeight​(int worldHeight)
    • isStopped

      public boolean isStopped()
    • getPlayerManager

      public PlayerManager getPlayerManager()
    • setPlayerManager

      public void setPlayerManager​(PlayerManager playerManager)
    • isRemote

      public abstract boolean isRemote()
    • setDefaultGameMode

      public void setDefaultGameMode​(GameMode gameMode)
    • getNetworkIo

      @Nullable public ServerNetworkIo getNetworkIo()
    • isLoading

      @Environment(CLIENT) public boolean isLoading()
    • hasGui

      public boolean hasGui()
    • openToLan

      public abstract boolean openToLan​(GameMode gameMode, boolean cheatsAllowed, int port)
      Opens a server for LAN connections. This is only supported on an integrated server, a dedicated server will always fail to open to LAN.
      Parameters:
      gameMode - the game mode connecting players will have set by default
      cheatsAllowed - whether players on the server have operator permissions
      port - the port to open up to LAN connections
      Returns:
      whether the server was successfully opened to LAN
    • getTicks

      public int getTicks()
      Gets the amount of ticks the server has been running for.
    • getSnooper

      @Environment(CLIENT) public Snooper getSnooper()
    • getSpawnProtectionRadius

      public int getSpawnProtectionRadius()
    • isSpawnProtected

      public boolean isSpawnProtected​(ServerWorld world, BlockPos pos, PlayerEntity player)
    • setForceGameMode

      public void setForceGameMode​(boolean forceGameMode)
      Sets whether a player's current game mode should be set to the server's current game mode when a player has connected.
    • shouldForceGameMode

      public boolean shouldForceGameMode()
      Checks whether a player's current game mode should be set to the server's current game mode when a player has connected.
    • acceptsStatusQuery

      public boolean acceptsStatusQuery()
    • getPlayerIdleTimeout

      public int getPlayerIdleTimeout()
    • setPlayerIdleTimeout

      public void setPlayerIdleTimeout​(int playerIdleTimeout)
    • getSessionService

      public com.mojang.authlib.minecraft.MinecraftSessionService getSessionService()
    • getGameProfileRepo

      public com.mojang.authlib.GameProfileRepository getGameProfileRepo()
    • getUserCache

      public UserCache getUserCache()
    • getServerMetadata

      public ServerMetadata getServerMetadata()
    • forcePlayerSampleUpdate

      public void forcePlayerSampleUpdate()
    • getMaxWorldBorderRadius

      public int getMaxWorldBorderRadius()
    • shouldExecuteAsync

      public boolean shouldExecuteAsync()
      Overrides:
      shouldExecuteAsync in class ReentrantThreadExecutor<ServerTask>
    • getThread

      public Thread getThread()
      Specified by:
      getThread in class ThreadExecutor<ServerTask>
    • getNetworkCompressionThreshold

      public int getNetworkCompressionThreshold()
    • getServerStartTime

      public long getServerStartTime()
    • getDataFixer

      public com.mojang.datafixers.DataFixer getDataFixer()
    • getSpawnRadius

      public int getSpawnRadius​(@Nullable ServerWorld world)
    • getAdvancementLoader

      public ServerAdvancementLoader getAdvancementLoader()
    • getCommandFunctionManager

      public CommandFunctionManager getCommandFunctionManager()
    • reloadResources

      public CompletableFuture<Void> reloadResources​(Collection<String> datapacks)
      Reloads this server's datapacks.
      Parameters:
      datapacks - a collection of datapacks to reload with
      Returns:
      a completable future which specifies whether the reload was successful A reload has failed when the future is exceptionally completed.
      See Also:
      CompletableFuture
    • loadDataPacks

      public static DataPackSettings loadDataPacks​(ResourcePackManager resourcePackManager, DataPackSettings dataPackSettings, boolean safeMode)
    • method_29735

      private static DataPackSettings method_29735​(ResourcePackManager resourcePackManager)
    • kickNonWhitelistedPlayers

      public void kickNonWhitelistedPlayers​(ServerCommandSource source)
    • getDataPackManager

      public ResourcePackManager getDataPackManager()
    • getCommandManager

      public CommandManager getCommandManager()
      Gets the server's command manager. The command manager is responsible for parsing and dispatching commands.
    • getCommandSource

      public ServerCommandSource getCommandSource()
      Creates a command source which represents this Minecraft server instance.
    • shouldReceiveFeedback

      public boolean shouldReceiveFeedback()
      Specified by:
      shouldReceiveFeedback in interface CommandOutput
    • shouldTrackOutput

      public boolean shouldTrackOutput()
      Specified by:
      shouldTrackOutput in interface CommandOutput
    • getRecipeManager

      public RecipeManager getRecipeManager()
    • getTagManager

      public TagManager getTagManager()
    • getScoreboard

      public ServerScoreboard getScoreboard()
    • getDataCommandStorage

      public DataCommandStorage getDataCommandStorage()
    • getLootManager

      public LootManager getLootManager()
    • getPredicateManager

      public LootConditionManager getPredicateManager()
    • getGameRules

      public GameRules getGameRules()
    • getBossBarManager

      public BossBarManager getBossBarManager()
    • isEnforceWhitelist

      public boolean isEnforceWhitelist()
    • setEnforceWhitelist

      public void setEnforceWhitelist​(boolean whitelistEnabled)
    • getTickTime

      public float getTickTime()
    • getPermissionLevel

      public int getPermissionLevel​(com.mojang.authlib.GameProfile profile)
    • getMetricsData

      @Environment(CLIENT) public MetricsData getMetricsData()
    • getProfiler

      public Profiler getProfiler()
    • isHost

      public abstract boolean isHost​(com.mojang.authlib.GameProfile profile)
    • dump

      public void dump​(Path path) throws IOException
      Throws:
      IOException
    • dumpStats

      private void dumpStats​(Path path) throws IOException
      Throws:
      IOException
    • dumpExampleCrash

      private void dumpExampleCrash​(Path path) throws IOException
      Throws:
      IOException
    • dumpGamerules

      private void dumpGamerules​(Path path) throws IOException
      Throws:
      IOException
    • dumpClasspath

      private void dumpClasspath​(Path path) throws IOException
      Throws:
      IOException
    • dumpThreads

      private void dumpThreads​(Path path) throws IOException
      Throws:
      IOException
    • startMonitor

      private void startMonitor​(@Nullable TickDurationMonitor monitor)
    • endMonitor

      private void endMonitor​(@Nullable TickDurationMonitor monitor)
    • isDebugRunning

      public boolean isDebugRunning()
    • enableProfiler

      public void enableProfiler()
    • stopDebug

      public ProfileResult stopDebug()
    • getSavePath

      public Path getSavePath​(WorldSavePath worldSavePath)
    • syncChunkWrites

      public boolean syncChunkWrites()
    • getStructureManager

      public StructureManager getStructureManager()
    • getSaveProperties

      public SaveProperties getSaveProperties()
    • getRegistryManager

      public DynamicRegistryManager getRegistryManager()
    • createFilterer

      @Nullable public TextStream createFilterer​(ServerPlayerEntity player)