Class MinecraftServer

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

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

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • VANILLA_BRAND

      public static final String VANILLA_BRAND
      See Also:
    • AVERAGE_TICK_TIME_SMOOTHING

      private static final float AVERAGE_TICK_TIME_SMOOTHING
      See Also:
    • TICK_STATS_SPAN

      private static final int TICK_STATS_SPAN
      See Also:
    • MS_PER_TICK

      public static final int MS_PER_TICK
      See Also:
    • OVERLOADED_THRESHOLD

      private static final int OVERLOADED_THRESHOLD
      See Also:
    • OVERLOADED_WARNING_INTERVAL

      private static final int OVERLOADED_WARNING_INTERVAL
      See Also:
    • STATUS_EXPIRE_TIME_NS

      private static final long STATUS_EXPIRE_TIME_NS
      See Also:
    • MAX_STATUS_PLAYER_SAMPLE

      private static final int MAX_STATUS_PLAYER_SAMPLE
      See Also:
    • START_CHUNK_RADIUS

      public static final int START_CHUNK_RADIUS
      See Also:
    • START_TICKING_CHUNK_COUNT

      private static final int START_TICKING_CHUNK_COUNT
      See Also:
    • AUTOSAVE_INTERVAL

      private static final int AUTOSAVE_INTERVAL
      See Also:
    • MAX_TICK_LATENCY

      private static final int MAX_TICK_LATENCY
      See Also:
    • ABSOLUTE_MAX_WORLD_SIZE

      public static final int ABSOLUTE_MAX_WORLD_SIZE
      See Also:
    • DEMO_SETTINGS

      public static final LevelSettings DEMO_SETTINGS
    • DELAYED_TASKS_TICK_EXTENSION

      private static final long DELAYED_TASKS_TICK_EXTENSION
      See Also:
    • ANONYMOUS_PLAYER_PROFILE

      public static final com.mojang.authlib.GameProfile ANONYMOUS_PLAYER_PROFILE
    • storageSource

      protected final LevelStorageSource.LevelStorageAccess storageSource
    • playerDataStorage

      protected final PlayerDataStorage playerDataStorage
    • 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 RandomSource random
    • fixerUpper

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

      private String localIp
    • port

      private int port
    • registryHolder

      private final RegistryAccess.Frozen 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
    • singleplayerProfile

      @Nullable private com.mojang.authlib.GameProfile singleplayerProfile
    • isDemo

      private boolean isDemo
    • isReady

      private volatile boolean isReady
    • lastOverloadWarning

      private long lastOverloadWarning
    • services

      protected final Services services
    • 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

    • structureTemplateManager

      private final StructureTemplateManager structureTemplateManager
    • worldData

      protected final WorldData worldData
    • isSaving

      private volatile boolean isSaving
    • 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
    • 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_)
    • 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_)
    • saveEverything

      public boolean saveEverything(boolean p_195515_, boolean p_195516_, boolean p_195517_)
    • 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()
    • constructOrExtractCrashReport

      private static CrashReport constructOrExtractCrashReport(Throwable p_206569_)
    • 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

      public 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 ModCheck getModdedStatus()
    • sendSystemMessage

      public void sendSystemMessage(Component p_236736_)
      Specified by:
      sendSystemMessage in interface CommandSource
    • getKeyPair

      public KeyPair getKeyPair()
    • getPort

      public int getPort()
    • setPort

      public void setPort(int p_129802_)
    • getSingleplayerProfile

      @Nullable public com.mojang.authlib.GameProfile getSingleplayerProfile()
    • setSingleplayerProfile

      public void setSingleplayerProfile(@Nullable com.mojang.authlib.GameProfile p_236741_)
    • 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_)
    • getServerResourcePack

      public Optional<MinecraftServer.ServerResourcePackInfo> getServerResourcePack()
    • isResourcePackRequired

      public boolean isResourcePackRequired()
    • 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_)
    • previewsChat

      public boolean previewsChat()
    • 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()
    • getSpawnProtectionRadius

      public int getSpawnProtectionRadius()
    • isUnderSpawnProtection

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

      public boolean repliesToStatus()
    • hidesOnlinePlayers

      public boolean hidesOnlinePlayers()
    • getProxy

      public Proxy getProxy()
    • getPlayerIdleTimeout

      public int getPlayerIdleTimeout()
    • setPlayerIdleTimeout

      public void setPlayerIdleTimeout(int p_129978_)
    • getSessionService

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

      public SignatureValidator getServiceSignatureValidator()
    • 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>
    • executeIfPossible

      public void executeIfPossible(Runnable p_202482_)
      Overrides:
      executeIfPossible in class BlockableEventLoop<TickTask>
    • getRunningThread

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

      public int getCompressionThreshold()
    • enforceSecureProfile

      public boolean enforceSecureProfile()
    • 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()
    • 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
    • dumpNativeModules

      private void dumpNativeModules(Path p_195522_) 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()
    • cancelRecordingMetrics

      public void cancelRecordingMetrics()
    • getWorldPath

      public Path getWorldPath(LevelResource p_129844_)
    • forceSynchronousWrites

      public boolean forceSynchronousWrites()
    • getStructureManager

      public StructureTemplateManager getStructureManager()
    • getWorldData

      public WorldData getWorldData()
    • getServerResources

      public MinecraftServer.ReloadableResources getServerResources()
    • registryAccess

      public RegistryAccess.Frozen registryAccess()
    • createTextFilterForPlayer

      public TextFilter createTextFilterForPlayer(ServerPlayer p_129814_)
    • createGameModeForPlayer

      public ServerPlayerGameMode createGameModeForPlayer(ServerPlayer p_177934_)
    • getForcedGameType

      @Nullable public GameType getForcedGameType()
    • getResourceManager

      public ResourceManager getResourceManager()
    • isCurrentlySaving

      public boolean isCurrentlySaving()
    • isTimeProfilerRunning

      public boolean isTimeProfilerRunning()
    • startTimeProfiler

      public void startTimeProfiler()
    • stopTimeProfiler

      public ProfileResults stopTimeProfiler()
    • getMaxChainedNeighborUpdates

      public int getMaxChainedNeighborUpdates()
    • logChatMessage

      public void logChatMessage(Component p_241503_, ChatType.Bound p_241402_, @Nullable String p_241481_)
    • getChatDecorator

      public ChatDecorator getChatDecorator()