Class MinecraftServer

All Implemented Interfaces:
AutoCloseable, Executor, CommandSource, ProfilerMeasured, ProcessorHandle<TickTask>, SnooperPopulator
Direct Known Subclasses:
DedicatedServer, GameTestServer, IntegratedServer

public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements SnooperPopulator, CommandSource, AutoCloseable
  • Field Details

    • LOGGER

      static final org.apache.logging.log4j.Logger LOGGER
    • AVERAGE_TICK_TIME_SMOOTHING

      private static final float AVERAGE_TICK_TIME_SMOOTHING
      See Also:
      Constant Field Values
    • TICK_STATS_SPAN

      private static final int TICK_STATS_SPAN
      See Also:
      Constant Field Values
    • MS_PER_TICK

      public static final int MS_PER_TICK
      See Also:
      Constant Field Values
    • SNOOPER_UPDATE_INTERVAL

      private static final int SNOOPER_UPDATE_INTERVAL
      See Also:
      Constant Field Values
    • OVERLOADED_THRESHOLD

      private static final int OVERLOADED_THRESHOLD
      See Also:
      Constant Field Values
    • OVERLOADED_WARNING_INTERVAL

      private static final int OVERLOADED_WARNING_INTERVAL
      See Also:
      Constant Field Values
    • LEVEL_STORAGE_PROTOCOL

      public static final String LEVEL_STORAGE_PROTOCOL
      See Also:
      Constant Field Values
    • LEVEL_STORAGE_SCHEMA

      public static final String LEVEL_STORAGE_SCHEMA
      See Also:
      Constant Field Values
    • STATUS_EXPIRE_TIME_NS

      private static final long STATUS_EXPIRE_TIME_NS
      See Also:
      Constant Field Values
    • MAX_STATUS_PLAYER_SAMPLE

      private static final int MAX_STATUS_PLAYER_SAMPLE
      See Also:
      Constant Field Values
    • MAP_RESOURCE_FILE

      public static final String MAP_RESOURCE_FILE
      See Also:
      Constant Field Values
    • USERID_CACHE_FILE

      public static final File USERID_CACHE_FILE
    • START_CHUNK_RADIUS

      public static final int START_CHUNK_RADIUS
      See Also:
      Constant Field Values
    • START_TICKING_CHUNK_COUNT

      private static final int START_TICKING_CHUNK_COUNT
      See Also:
      Constant Field Values
    • AUTOSAVE_INTERVAL

      private static final int AUTOSAVE_INTERVAL
      See Also:
      Constant Field Values
    • MAX_TICK_LATENCY

      private static final int MAX_TICK_LATENCY
      See Also:
      Constant Field Values
    • ABSOLUTE_MAX_WORLD_SIZE

      public static final int ABSOLUTE_MAX_WORLD_SIZE
      See Also:
      Constant Field Values
    • DEMO_SETTINGS

      public static final LevelSettings DEMO_SETTINGS
    • DELAYED_TASKS_TICK_EXTENSION

      private static final long DELAYED_TASKS_TICK_EXTENSION
      See Also:
      Constant Field Values
    • storageSource

      protected final LevelStorageSource.LevelStorageAccess storageSource
    • playerDataStorage

      protected final PlayerDataStorage playerDataStorage
    • snooper

      private final Snooper snooper
    • tickables

      private final List<Runnable> tickables
    • metricsRecorder

      private MetricsRecorder metricsRecorder
    • profiler

      private ProfilerFiller profiler
    • onMetricsRecordingStopped

      private Consumer<ProfileResults> onMetricsRecordingStopped
    • onMetricsRecordingFinished

      private Consumer<Path> onMetricsRecordingFinished
    • willStartRecordingMetrics

      private boolean willStartRecordingMetrics
    • debugCommandProfiler

      @Nullable private MinecraftServer.TimeProfiler debugCommandProfiler
    • debugCommandProfilerDelayStart

      private boolean debugCommandProfilerDelayStart
    • connection

      private final ServerConnectionListener connection
    • progressListenerFactory

      private final ChunkProgressListenerFactory progressListenerFactory
    • status

      private final ServerStatus status
    • random

      private final Random random
    • fixerUpper

      private final com.mojang.datafixers.DataFixer fixerUpper
    • localIp

      private String localIp
    • port

      private int port
    • registryHolder

      protected final RegistryAccess.RegistryHolder registryHolder
    • levels

      private final Map<ResourceKey<Level>,​ServerLevel> levels
    • playerList

      private PlayerList playerList
    • running

      private volatile boolean running
    • stopped

      private boolean stopped
    • tickCount

      private int tickCount
    • proxy

      protected final Proxy proxy
    • onlineMode

      private boolean onlineMode
    • preventProxyConnections

      private boolean preventProxyConnections
    • pvp

      private boolean pvp
    • allowFlight

      private boolean allowFlight
    • motd

      @Nullable private String motd
    • playerIdleTimeout

      private int playerIdleTimeout
    • tickTimes

      public final long[] tickTimes
    • keyPair

      @Nullable private KeyPair keyPair
    • singleplayerName

      @Nullable private String singleplayerName
    • isDemo

      private boolean isDemo
    • resourcePack

      private String resourcePack
    • resourcePackHash

      private String resourcePackHash
    • isReady

      private volatile boolean isReady
    • lastOverloadWarning

      private long lastOverloadWarning
    • sessionService

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

      @Nullable private final com.mojang.authlib.GameProfileRepository profileRepository
    • profileCache

      @Nullable private final GameProfileCache profileCache
    • lastServerStatus

      private long lastServerStatus
    • serverThread

      private final Thread serverThread
    • nextTickTime

      protected long nextTickTime
    • delayedTasksMaxNextTickTime

      private long delayedTasksMaxNextTickTime
    • mayHaveDelayedTasks

      private boolean mayHaveDelayedTasks
    • packRepository

      private final PackRepository packRepository
    • scoreboard

      private final ServerScoreboard scoreboard
    • commandStorage

      @Nullable private CommandStorage commandStorage
    • customBossEvents

      private final CustomBossEvents customBossEvents
    • functionManager

      private final ServerFunctionManager functionManager
    • frameTimer

      private final FrameTimer frameTimer
    • enforceWhitelist

      private boolean enforceWhitelist
    • averageTickTime

      private float averageTickTime
    • executor

      private final Executor executor
    • serverId

      @Nullable private String serverId
    • resources

      private ServerResources resources
    • structureManager

      private final StructureManager structureManager
    • worldData

      protected final WorldData worldData
    • perWorldTickTimes

      private Map<ResourceKey<Level>,​long[]> perWorldTickTimes
    • worldArrayMarker

      private int worldArrayMarker
    • worldArrayLast

      private int worldArrayLast
    • worldArray

      private ServerLevel[] worldArray
  • Constructor Details

  • Method Details

    • spin

      public static <S extends MinecraftServer> S spin(Function<Thread,​S> p_129873_)
    • readScoreboard

      private void readScoreboard(DimensionDataStorage p_129842_)
    • initServer

      protected abstract boolean initServer() throws IOException
      Throws:
      IOException
    • convertFromRegionFormatIfNeeded

      public static void convertFromRegionFormatIfNeeded(LevelStorageSource.LevelStorageAccess p_129846_)
    • loadLevel

      protected void loadLevel()
    • forceDifficulty

      protected void forceDifficulty()
    • createLevels

      protected void createLevels(ChunkProgressListener p_129816_)
    • setInitialSpawn

      private static void setInitialSpawn(ServerLevel p_177897_, ServerLevelData p_177898_, boolean p_177899_, boolean p_177900_)
    • setupDebugLevel

      private void setupDebugLevel(WorldData p_129848_)
    • prepareLevels

      private void prepareLevels(ChunkProgressListener p_129941_)
    • detectBundledResources

      protected void detectBundledResources()
    • getDefaultGameType

      public GameType getDefaultGameType()
    • isHardcore

      public boolean isHardcore()
    • getOperatorUserPermissionLevel

      public abstract int getOperatorUserPermissionLevel()
    • getFunctionCompilationLevel

      public abstract int getFunctionCompilationLevel()
    • shouldRconBroadcast

      public abstract boolean shouldRconBroadcast()
    • saveAllChunks

      public boolean saveAllChunks(boolean p_129886_, boolean p_129887_, boolean p_129888_)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ProcessorHandle<TickTask>
    • stopServer

      public void stopServer()
    • getLocalIp

      public String getLocalIp()
    • setLocalIp

      public void setLocalIp(String p_129914_)
    • isRunning

      public boolean isRunning()
    • halt

      public void halt(boolean p_129884_)
    • runServer

      protected void runServer()
    • haveTime

      private boolean haveTime()
    • waitUntilNextTick

      protected void waitUntilNextTick()
    • wrapRunnable

      protected TickTask wrapRunnable(Runnable p_129852_)
      Specified by:
      wrapRunnable in class BlockableEventLoop<TickTask>
    • shouldRun

      protected boolean shouldRun(TickTask p_129883_)
      Specified by:
      shouldRun in class BlockableEventLoop<TickTask>
    • pollTask

      public boolean pollTask()
      Overrides:
      pollTask in class BlockableEventLoop<TickTask>
    • pollTaskInternal

      private boolean pollTaskInternal()
    • doRunTask

      public void doRunTask(TickTask p_129957_)
      Overrides:
      doRunTask in class ReentrantBlockableEventLoop<TickTask>
    • updateStatusIcon

      private void updateStatusIcon(ServerStatus p_129879_)
    • getWorldScreenshotFile

      public Optional<Path> getWorldScreenshotFile()
    • getServerDirectory

      public File getServerDirectory()
    • onServerCrash

      protected void onServerCrash(CrashReport p_129874_)
    • onServerExit

      public void onServerExit()
    • tickServer

      public void tickServer(BooleanSupplier p_129871_)
    • tickChildren

      public void tickChildren(BooleanSupplier p_129954_)
    • isNetherEnabled

      public boolean isNetherEnabled()
    • addTickable

      public void addTickable(Runnable p_129947_)
    • setId

      protected void setId(String p_129949_)
    • isShutdown

      public boolean isShutdown()
    • getFile

      public File getFile(String p_129972_)
    • overworld

      public final ServerLevel overworld()
    • getLevel

      @Nullable public ServerLevel getLevel(ResourceKey<Level> p_129881_)
    • levelKeys

      public Set<ResourceKey<Level>> levelKeys()
    • getAllLevels

      public Iterable<ServerLevel> getAllLevels()
    • getServerVersion

      public String getServerVersion()
    • getPlayerCount

      public int getPlayerCount()
    • getMaxPlayers

      public int getMaxPlayers()
    • getPlayerNames

      public String[] getPlayerNames()
    • getServerModName

      public String getServerModName()
    • fillSystemReport

      public SystemReport fillSystemReport(SystemReport p_177936_)
    • fillServerSystemReport

      public abstract SystemReport fillServerSystemReport(SystemReport p_177901_)
    • getModdedStatus

      public abstract Optional<String> getModdedStatus()
    • sendMessage

      public void sendMessage(Component p_129876_, UUID p_129877_)
      Specified by:
      sendMessage in interface CommandSource
    • getKeyPair

      public KeyPair getKeyPair()
    • getPort

      public int getPort()
    • setPort

      public void setPort(int p_129802_)
    • getSingleplayerName

      public String getSingleplayerName()
    • setSingleplayerName

      public void setSingleplayerName(String p_129982_)
    • isSingleplayer

      public boolean isSingleplayer()
    • initializeKeyPair

      protected void initializeKeyPair()
    • setDifficulty

      public void setDifficulty(Difficulty p_129828_, boolean p_129829_)
    • getScaledTrackingDistance

      public int getScaledTrackingDistance(int p_129935_)
    • updateMobSpawningFlags

      private void updateMobSpawningFlags()
    • setDifficultyLocked

      public void setDifficultyLocked(boolean p_129959_)
    • sendDifficultyUpdate

      private void sendDifficultyUpdate(ServerPlayer p_129939_)
    • isSpawningMonsters

      public boolean isSpawningMonsters()
    • isDemo

      public boolean isDemo()
    • setDemo

      public void setDemo(boolean p_129976_)
    • getResourcePack

      public String getResourcePack()
    • getResourcePackHash

      public String getResourcePackHash()
    • setResourcePack

      public void setResourcePack(String p_129854_, String p_129855_)
    • populateSnooper

      public void populateSnooper(Snooper p_129831_)
      Specified by:
      populateSnooper in interface SnooperPopulator
    • populateSnooperInitial

      public void populateSnooperInitial(Snooper p_177938_)
      Specified by:
      populateSnooperInitial in interface SnooperPopulator
    • isSnooperEnabled

      public boolean isSnooperEnabled()
      Specified by:
      isSnooperEnabled in interface SnooperPopulator
    • isDedicatedServer

      public abstract boolean isDedicatedServer()
    • getRateLimitPacketsPerSecond

      public abstract int getRateLimitPacketsPerSecond()
    • usesAuthentication

      public boolean usesAuthentication()
    • setUsesAuthentication

      public void setUsesAuthentication(boolean p_129986_)
    • getPreventProxyConnections

      public boolean getPreventProxyConnections()
    • setPreventProxyConnections

      public void setPreventProxyConnections(boolean p_129994_)
    • isSpawningAnimals

      public boolean isSpawningAnimals()
    • areNpcsEnabled

      public boolean areNpcsEnabled()
    • isEpollEnabled

      public abstract boolean isEpollEnabled()
    • isPvpAllowed

      public boolean isPvpAllowed()
    • setPvpAllowed

      public void setPvpAllowed(boolean p_129998_)
    • isFlightAllowed

      public boolean isFlightAllowed()
    • setFlightAllowed

      public void setFlightAllowed(boolean p_130000_)
    • isCommandBlockEnabled

      public abstract boolean isCommandBlockEnabled()
    • getMotd

      public String getMotd()
    • setMotd

      public void setMotd(String p_129990_)
    • isStopped

      public boolean isStopped()
    • getPlayerList

      public PlayerList getPlayerList()
    • setPlayerList

      public void setPlayerList(PlayerList p_129824_)
    • isPublished

      public abstract boolean isPublished()
    • setDefaultGameType

      public void setDefaultGameType(GameType p_129832_)
    • getConnection

      @Nullable public ServerConnectionListener getConnection()
    • isReady

      public boolean isReady()
    • hasGui

      public boolean hasGui()
    • publishServer

      public boolean publishServer(@Nullable GameType p_129833_, boolean p_129834_, int p_129835_)
    • getTickCount

      public int getTickCount()
    • getSnooper

      public Snooper getSnooper()
    • getSpawnProtectionRadius

      public int getSpawnProtectionRadius()
    • isUnderSpawnProtection

      public boolean isUnderSpawnProtection(ServerLevel p_129811_, BlockPos p_129812_, Player p_129813_)
    • repliesToStatus

      public boolean repliesToStatus()
    • getProxy

      public Proxy getProxy()
    • getPlayerIdleTimeout

      public int getPlayerIdleTimeout()
    • setPlayerIdleTimeout

      public void setPlayerIdleTimeout(int p_129978_)
    • getSessionService

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

      public com.mojang.authlib.GameProfileRepository getProfileRepository()
    • getProfileCache

      public GameProfileCache getProfileCache()
    • getStatus

      public ServerStatus getStatus()
    • invalidateStatus

      public void invalidateStatus()
    • getAbsoluteMaxWorldSize

      public int getAbsoluteMaxWorldSize()
    • scheduleExecutables

      public boolean scheduleExecutables()
      Overrides:
      scheduleExecutables in class ReentrantBlockableEventLoop<TickTask>
    • getRunningThread

      public Thread getRunningThread()
      Specified by:
      getRunningThread in class BlockableEventLoop<TickTask>
    • getCompressionThreshold

      public int getCompressionThreshold()
    • getNextTickTime

      public long getNextTickTime()
    • getFixerUpper

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

      public int getSpawnRadius(@Nullable ServerLevel p_129804_)
    • getAdvancements

      public ServerAdvancementManager getAdvancements()
    • getFunctions

      public ServerFunctionManager getFunctions()
    • reloadResources

      public CompletableFuture<Void> reloadResources(Collection<String> p_129862_)
    • configurePackRepository

      public static DataPackConfig configurePackRepository(PackRepository p_129820_, DataPackConfig p_129821_, boolean p_129822_)
    • getSelectedPacks

      private static DataPackConfig getSelectedPacks(PackRepository p_129818_)
    • kickUnlistedPlayers

      public void kickUnlistedPlayers(CommandSourceStack p_129850_)
    • getPackRepository

      public PackRepository getPackRepository()
    • getCommands

      public Commands getCommands()
    • createCommandSourceStack

      public CommandSourceStack createCommandSourceStack()
    • acceptsSuccess

      public boolean acceptsSuccess()
      Specified by:
      acceptsSuccess in interface CommandSource
    • acceptsFailure

      public boolean acceptsFailure()
      Specified by:
      acceptsFailure in interface CommandSource
    • shouldInformAdmins

      public abstract boolean shouldInformAdmins()
      Specified by:
      shouldInformAdmins in interface CommandSource
    • getRecipeManager

      public RecipeManager getRecipeManager()
    • getTags

      public TagContainer getTags()
    • getScoreboard

      public ServerScoreboard getScoreboard()
    • getCommandStorage

      public CommandStorage getCommandStorage()
    • getLootTables

      public LootTables getLootTables()
    • getPredicateManager

      public PredicateManager getPredicateManager()
    • getItemModifierManager

      public ItemModifierManager getItemModifierManager()
    • getGameRules

      public GameRules getGameRules()
    • getCustomBossEvents

      public CustomBossEvents getCustomBossEvents()
    • isEnforceWhitelist

      public boolean isEnforceWhitelist()
    • setEnforceWhitelist

      public void setEnforceWhitelist(boolean p_130005_)
    • getAverageTickTime

      public float getAverageTickTime()
    • getProfilePermissions

      public int getProfilePermissions(com.mojang.authlib.GameProfile p_129945_)
    • getFrameTimer

      public FrameTimer getFrameTimer()
    • getProfiler

      public ProfilerFiller getProfiler()
    • isSingleplayerOwner

      public abstract boolean isSingleplayerOwner(com.mojang.authlib.GameProfile p_129840_)
    • getTickTime

      @Nullable public long[] getTickTime(ResourceKey<Level> dim)
    • forgeGetWorldMap

      @Deprecated public Map<ResourceKey<Level>,​ServerLevel> forgeGetWorldMap()
      Deprecated.
    • markWorldsDirty

      @Deprecated public void markWorldsDirty()
      Deprecated.
    • getWorldArray

      private ServerLevel[] getWorldArray()
    • dumpServerProperties

      public void dumpServerProperties(Path p_177911_) throws IOException
      Throws:
      IOException
    • saveDebugReport

      private void saveDebugReport(Path p_129860_)
    • dumpMiscStats

      private void dumpMiscStats(Path p_129951_) throws IOException
      Throws:
      IOException
    • dumpGameRules

      private void dumpGameRules(Path p_129984_) throws IOException
      Throws:
      IOException
    • dumpClasspath

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

      private void dumpThreads(Path p_129996_) throws IOException
      Throws:
      IOException
    • startMetricsRecordingTick

      private void startMetricsRecordingTick()
    • endMetricsRecordingTick

      private void endMetricsRecordingTick()
    • isRecordingMetrics

      public boolean isRecordingMetrics()
    • startRecordingMetrics

      public void startRecordingMetrics(Consumer<ProfileResults> p_177924_, Consumer<Path> p_177925_)
    • stopRecordingMetrics

      public void stopRecordingMetrics()
    • finishRecordingMetrics

      public void finishRecordingMetrics()
    • getWorldPath

      public Path getWorldPath(LevelResource p_129844_)
    • forceSynchronousWrites

      public boolean forceSynchronousWrites()
    • getStructureManager

      public StructureManager getStructureManager()
    • getWorldData

      public WorldData getWorldData()
    • getServerResources

      public ServerResources getServerResources()
    • registryAccess

      public RegistryAccess registryAccess()
    • createTextFilterForPlayer

      public TextFilter createTextFilterForPlayer(ServerPlayer p_129814_)
    • isResourcePackRequired

      public boolean isResourcePackRequired()
    • createGameModeForPlayer

      public ServerPlayerGameMode createGameModeForPlayer(ServerPlayer p_177934_)
    • getForcedGameType

      @Nullable public GameType getForcedGameType()
    • getResourceManager

      public ResourceManager getResourceManager()
    • getResourcePackPrompt

      @Nullable public Component getResourcePackPrompt()
    • isTimeProfilerRunning

      public boolean isTimeProfilerRunning()
    • startTimeProfiler

      public void startTimeProfiler()
    • stopTimeProfiler

      public ProfileResults stopTimeProfiler()