Package org.bukkit

Class Bukkit

java.lang.Object
org.bukkit.Bukkit

public final class Bukkit
extends java.lang.Object
Represents the Bukkit core, for version and Server singleton handling
  • Method Details

    • getServer

      public static Server getServer()
      Gets the current Server singleton
      Returns:
      Server instance being ran
    • setServer

      public static void setServer​(Server server)
      Attempts to set the Server singleton.

      This cannot be done if the Server is already set.

      Parameters:
      server - Server instance
    • getName

      public static java.lang.String getName()
      Gets the name of this server implementation.
      Returns:
      name of this server implementation
    • getVersion

      public static java.lang.String getVersion()
      Gets the version string of this server implementation.
      Returns:
      version of this server implementation
    • getBukkitVersion

      public static java.lang.String getBukkitVersion()
      Gets the Bukkit version that this server is running.
      Returns:
      version of Bukkit
    • _INVALID_getOnlinePlayers

      @Deprecated public static Player[] _INVALID_getOnlinePlayers()
      Deprecated.
      superseded by getOnlinePlayers()
      Gets an array copy of all currently logged in players.

      This method exists for legacy reasons to provide backwards compatibility. It will not exist at runtime and should not be used under any circumstances.

      Returns:
      an array of Players that are currently online
    • getOnlinePlayers

      public static java.util.Collection<? extends Player> getOnlinePlayers()
      Gets a view of all currently logged in players. This view is a reused object, making some operations like Collection.size() zero-allocation.

      The collection is a view backed by the internal representation, such that, changes to the internal state of the server will be reflected immediately. However, the reuse of the returned collection (identity) is not strictly guaranteed for future or all implementations. Casting the collection, or relying on interface implementations (like Serializable or List), is deprecated.

      Iteration behavior is undefined outside of self-contained main-thread uses. Normal and immediate iterator use without consequences that affect the collection are fully supported. The effects following (non-exhaustive) teleportation, death, and kicking are undefined. Any use of this collection from asynchronous threads is unsafe.

      For safe consequential iteration or mimicking the old array behavior, using Collection.toArray(Object[]) is recommended. For making snapshots, ImmutableList.copyOf(Collection) is recommended.

      Returns:
      a view of currently online players.
    • getMaxPlayers

      public static int getMaxPlayers()
      Get the maximum amount of players which can login to this server.
      Returns:
      the amount of players this server allows
    • getPort

      public static int getPort()
      Get the game port that the server runs on.
      Returns:
      the port number of this server
    • getViewDistance

      public static int getViewDistance()
      Get the view distance from this server.
      Returns:
      the view distance from this server.
    • getIp

      public static java.lang.String getIp()
      Get the IP that this server is bound to, or empty string if not specified.
      Returns:
      the IP string that this server is bound to, otherwise empty string
    • getServerName

      public static java.lang.String getServerName()
      Get the name of this server.
      Returns:
      the name of this server
    • getServerId

      public static java.lang.String getServerId()
      Get an ID of this server. The ID is a simple generally alphanumeric ID that can be used for uniquely identifying this server.
      Returns:
      the ID of this server
    • getWorldType

      public static java.lang.String getWorldType()
      Get world type (level-type setting) for default world.
      Returns:
      the value of level-type (e.g. DEFAULT, FLAT, DEFAULT_1_1)
    • getGenerateStructures

      public static boolean getGenerateStructures()
      Get generate-structures setting.
      Returns:
      true if structure generation is enabled, false otherwise
    • getAllowEnd

      public static boolean getAllowEnd()
      Gets whether this server allows the End or not.
      Returns:
      whether this server allows the End or not
    • getAllowNether

      public static boolean getAllowNether()
      Gets whether this server allows the Nether or not.
      Returns:
      whether this server allows the Nether or not
    • hasWhitelist

      public static boolean hasWhitelist()
      Gets whether this server has a whitelist or not.
      Returns:
      whether this server has a whitelist or not
    • setWhitelist

      public static void setWhitelist​(boolean value)
      Sets if the server is whitelisted.
      Parameters:
      value - true for whitelist on, false for off
    • getWhitelistedPlayers

      public static java.util.Set<OfflinePlayer> getWhitelistedPlayers()
      Gets a list of whitelisted players.
      Returns:
      a set containing all whitelisted players
    • reloadWhitelist

      public static void reloadWhitelist()
      Reloads the whitelist from disk.
    • broadcastMessage

      public static int broadcastMessage​(java.lang.String message)
      Broadcast a message to all players.

      This is the same as calling broadcast(java.lang.String, java.lang.String) to Server.BROADCAST_CHANNEL_USERS

      Parameters:
      message - the message
      Returns:
      the number of players
    • getUpdateFolder

      public static java.lang.String getUpdateFolder()
      Gets the name of the update folder. The update folder is used to safely update plugins at the right moment on a plugin load.

      The update folder name is relative to the plugins folder.

      Returns:
      the name of the update folder
    • getUpdateFolderFile

      public static java.io.File getUpdateFolderFile()
      Gets the update folder. The update folder is used to safely update plugins at the right moment on a plugin load.
      Returns:
      the update folder
    • getConnectionThrottle

      public static long getConnectionThrottle()
      Gets the value of the connection throttle setting.
      Returns:
      the value of the connection throttle setting
    • getTicksPerAnimalSpawns

      public static int getTicksPerAnimalSpawns()
      Gets default ticks per animal spawns value.

      Example Usage:

      • A value of 1 will mean the server will attempt to spawn monsters every tick.
      • A value of 400 will mean the server will attempt to spawn monsters every 400th tick.
      • A value below 0 will be reset back to Minecraft's default.

      Note: If set to 0, animal spawning will be disabled. We recommend using spawn-animals to control this instead.

      Minecraft default: 400.

      Returns:
      the default ticks per animal spawns value
    • getTicksPerMonsterSpawns

      public static int getTicksPerMonsterSpawns()
      Gets the default ticks per monster spawns value.

      Example Usage:

      • A value of 1 will mean the server will attempt to spawn monsters every tick.
      • A value of 400 will mean the server will attempt to spawn monsters every 400th tick.
      • A value below 0 will be reset back to Minecraft's default.

      Note: If set to 0, monsters spawning will be disabled. We recommend using spawn-monsters to control this instead.

      Minecraft default: 1.

      Returns:
      the default ticks per monsters spawn value
    • getPlayer

      public static Player getPlayer​(java.lang.String name)
      Gets a player object by the given username.

      This method may not return objects for offline players.

      Parameters:
      name - the name to look up
      Returns:
      a player if one was found, null otherwise
    • getPlayerExact

      public static Player getPlayerExact​(java.lang.String name)
      Gets the player with the exact given name, case insensitive.
      Parameters:
      name - Exact name of the player to retrieve
      Returns:
      a player object if one was found, null otherwise
    • matchPlayer

      public static java.util.List<Player> matchPlayer​(java.lang.String name)
      Attempts to match any players with the given name, and returns a list of all possibly matches.

      This list is not sorted in any particular order. If an exact match is found, the returned list will only contain a single result.

      Parameters:
      name - the (partial) name to match
      Returns:
      list of all possible players
    • getPlayer

      public static Player getPlayer​(java.util.UUID id)
      Gets the player with the given UUID.
      Parameters:
      id - UUID of the player to retrieve
      Returns:
      a player object if one was found, null otherwise
    • getPluginManager

      public static PluginManager getPluginManager()
      Gets the plugin manager for interfacing with plugins.
      Returns:
      a plugin manager for this Server instance
    • getScheduler

      public static BukkitScheduler getScheduler()
      Gets the scheduler for managing scheduled events.
      Returns:
      a scheduling service for this server
    • getServicesManager

      public static ServicesManager getServicesManager()
      Gets a services manager.
      Returns:
      s services manager
    • getWorlds

      public static java.util.List<World> getWorlds()
      Gets a list of all worlds on this server.
      Returns:
      a list of worlds
    • createWorld

      public static World createWorld​(WorldCreator creator)
      Creates or loads a world with the given name using the specified options.

      If the world is already loaded, it will just return the equivalent of getWorld(creator.name()).

      Parameters:
      creator - the options to use when creating the world
      Returns:
      newly created or loaded world
    • unloadWorld

      public static boolean unloadWorld​(java.lang.String name, boolean save)
      Unloads a world with the given name.
      Parameters:
      name - Name of the world to unload
      save - whether to save the chunks before unloading
      Returns:
      true if successful, false otherwise
    • unloadWorld

      public static boolean unloadWorld​(World world, boolean save)
      Unloads the given world.
      Parameters:
      world - the world to unload
      save - whether to save the chunks before unloading
      Returns:
      true if successful, false otherwise
    • getWorld

      public static World getWorld​(java.lang.String name)
      Gets the world with the given name.
      Parameters:
      name - the name of the world to retrieve
      Returns:
      a world with the given name, or null if none exists
    • getWorld

      public static World getWorld​(java.util.UUID uid)
      Gets the world from the given Unique ID.
      Parameters:
      uid - a unique-id of the world to retrieve
      Returns:
      a world with the given Unique ID, or null if none exists
    • getMap

      @Deprecated public static MapView getMap​(short id)
      Deprecated.
      Magic value
      Gets the map from the given item ID.
      Parameters:
      id - the id of the map to get
      Returns:
      a map view if it exists, or null otherwise
    • createMap

      public static MapView createMap​(World world)
      Create a new map with an automatically assigned ID.
      Parameters:
      world - the world the map will belong to
      Returns:
      a newly created map view
    • reload

      public static void reload()
      Reloads the server, refreshing settings and plugin information.
    • getLogger

      public static java.util.logging.Logger getLogger()
      Returns the primary logger associated with this server instance.
      Returns:
      Logger associated with this server
    • getPluginCommand

      public static PluginCommand getPluginCommand​(java.lang.String name)
      Gets a PluginCommand with the given name or alias.
      Parameters:
      name - the name of the command to retrieve
      Returns:
      a plugin command if found, null otherwise
    • savePlayers

      public static void savePlayers()
      Writes loaded players to disk.
    • dispatchCommand

      public static boolean dispatchCommand​(CommandSender sender, java.lang.String commandLine) throws CommandException
      Dispatches a command on this server, and executes it if found.
      Parameters:
      sender - the apparent sender of the command
      commandLine - the command + arguments. Example: test abc 123
      Returns:
      returns false if no target is found
      Throws:
      CommandException - thrown when the executor for the given command fails with an unhandled exception
    • configureDbConfig

      public static void configureDbConfig​(com.avaje.ebean.config.ServerConfig config)
      Populates a given ServerConfig with values attributes to this server.
      Parameters:
      config - the server config to populate
    • addRecipe

      public static boolean addRecipe​(Recipe recipe)
      Adds a recipe to the crafting manager.
      Parameters:
      recipe - the recipe to add
      Returns:
      true if the recipe was added, false if it wasn't for some reason
    • getRecipesFor

      public static java.util.List<Recipe> getRecipesFor​(ItemStack result)
      Get a list of all recipes for a given item. The stack size is ignored in comparisons. If the durability is -1, it will match any data value.
      Parameters:
      result - the item to match against recipe results
      Returns:
      a list of recipes with the given result
    • recipeIterator

      public static java.util.Iterator<Recipe> recipeIterator()
      Get an iterator through the list of crafting recipes.
      Returns:
      an iterator
    • clearRecipes

      public static void clearRecipes()
      Clears the list of crafting recipes.
    • resetRecipes

      public static void resetRecipes()
      Resets the list of crafting recipes to the default.
    • getCommandAliases

      public static java.util.Map<java.lang.String,​java.lang.String[]> getCommandAliases()
      Gets a list of command aliases defined in the server properties.
      Returns:
      a map of aliases to command names
    • getSpawnRadius

      public static int getSpawnRadius()
      Gets the radius, in blocks, around each worlds spawn point to protect.
      Returns:
      spawn radius, or 0 if none
    • setSpawnRadius

      public static void setSpawnRadius​(int value)
      Sets the radius, in blocks, around each worlds spawn point to protect.
      Parameters:
      value - new spawn radius, or 0 if none
    • getOnlineMode

      public static boolean getOnlineMode()
      Gets whether the Server is in online mode or not.
      Returns:
      true if the server authenticates clients, false otherwise
    • getAllowFlight

      public static boolean getAllowFlight()
      Gets whether this server allows flying or not.
      Returns:
      true if the server allows flight, false otherwise
    • isHardcore

      public static boolean isHardcore()
      Gets whether the server is in hardcore mode or not.
      Returns:
      true if the server mode is hardcore, false otherwise
    • useExactLoginLocation

      @Deprecated public static boolean useExactLoginLocation()
      Deprecated.
      non standard and unused feature.
      Gets whether to use vanilla (false) or exact behaviour (true).
      • Vanilla behaviour: check for collisions and move the player if needed.
      • Exact behaviour: spawn players exactly where they should be.
      Returns:
      true if exact location locations are used for spawning, false for vanilla collision detection or otherwise
    • shutdown

      public static void shutdown()
      Shutdowns the server, stopping everything.
    • broadcast

      public static int broadcast​(java.lang.String message, java.lang.String permission)
      Broadcasts the specified message to every user with the given permission name.
      Parameters:
      message - message to broadcast
      permission - the required permission permissibles must have to receive the broadcast
      Returns:
      number of message recipients
    • getOfflinePlayer

      @Deprecated public static OfflinePlayer getOfflinePlayer​(java.lang.String name)
      Deprecated.
      Persistent storage of users should be by UUID as names are no longer unique past a single session.
      Gets the player by the given name, regardless if they are offline or online.

      This method may involve a blocking web request to get the UUID for the given name.

      This will return an object even if the player does not exist. To this method, all players will exist.

      Parameters:
      name - the name the player to retrieve
      Returns:
      an offline player
      See Also:
      getOfflinePlayer(java.util.UUID)
    • getOfflinePlayer

      public static OfflinePlayer getOfflinePlayer​(java.util.UUID id)
      Gets the player by the given UUID, regardless if they are offline or online.

      This will return an object even if the player does not exist. To this method, all players will exist.

      Parameters:
      id - the UUID of the player to retrieve
      Returns:
      an offline player
    • getIPBans

      public static java.util.Set<java.lang.String> getIPBans()
      Gets a set containing all current IPs that are banned.
      Returns:
      a set containing banned IP addresses
    • banIP

      public static void banIP​(java.lang.String address)
      Bans the specified address from the server.
      Parameters:
      address - the IP address to ban
    • unbanIP

      public static void unbanIP​(java.lang.String address)
      Unbans the specified address from the server.
      Parameters:
      address - the IP address to unban
    • getBannedPlayers

      public static java.util.Set<OfflinePlayer> getBannedPlayers()
      Gets a set containing all banned players.
      Returns:
      a set containing banned players
    • getBanList

      public static BanList getBanList​(BanList.Type type)
      Gets a ban list for the supplied type.

      Bans by name are no longer supported and this method will return null when trying to request them. The replacement is bans by UUID.

      Parameters:
      type - the type of list to fetch, cannot be null
      Returns:
      a ban list of the specified type
    • getOperators

      public static java.util.Set<OfflinePlayer> getOperators()
      Gets a set containing all player operators.
      Returns:
      a set containing player operators
    • getDefaultGameMode

      public static GameMode getDefaultGameMode()
      Gets the default GameMode for new players.
      Returns:
      the default game mode
    • setDefaultGameMode

      public static void setDefaultGameMode​(GameMode mode)
      Sets the default GameMode for new players.
      Parameters:
      mode - the new game mode
    • getConsoleSender

      public static ConsoleCommandSender getConsoleSender()
      Gets a ConsoleCommandSender that may be used as an input source for this server.
      Returns:
      a console command sender
    • getWorldContainer

      public static java.io.File getWorldContainer()
      Gets the folder that contains all of the various Worlds.
      Returns:
      folder that contains all worlds
    • getOfflinePlayers

      public static OfflinePlayer[] getOfflinePlayers()
      Gets every player that has ever played on this server.
      Returns:
      an array containing all previous players
    • getMessenger

      public static Messenger getMessenger()
      Gets the Messenger responsible for this server.
      Returns:
      messenger responsible for this server
    • getHelpMap

      public static HelpMap getHelpMap()
      Gets the HelpMap providing help topics for this server.
      Returns:
      a help map for this server
    • createInventory

      public static Inventory createInventory​(InventoryHolder owner, InventoryType type)
      Creates an empty inventory of the specified type. If the type is InventoryType.CHEST, the new inventory has a size of 27; otherwise the new inventory has the normal size for its type.
      Parameters:
      owner - the holder of the inventory, or null to indicate no holder
      type - the type of inventory to create
      Returns:
      a new inventory
    • createInventory

      public static Inventory createInventory​(InventoryHolder owner, InventoryType type, java.lang.String title)
      Creates an empty inventory with the specified type and title. If the type is InventoryType.CHEST, the new inventory has a size of 27; otherwise the new inventory has the normal size for its type.
      It should be noted that some inventory types do not support titles and may not render with said titles on the Minecraft client.
      Parameters:
      owner - The holder of the inventory; can be null if there's no holder.
      type - The type of inventory to create.
      title - The title of the inventory, to be displayed when it is viewed.
      Returns:
      The new inventory.
    • createInventory

      public static Inventory createInventory​(InventoryHolder owner, int size) throws java.lang.IllegalArgumentException
      Creates an empty inventory of type InventoryType.CHEST with the specified size.
      Parameters:
      owner - the holder of the inventory, or null to indicate no holder
      size - a multiple of 9 as the size of inventory to create
      Returns:
      a new inventory
      Throws:
      java.lang.IllegalArgumentException - if the size is not a multiple of 9
    • createInventory

      public static Inventory createInventory​(InventoryHolder owner, int size, java.lang.String title) throws java.lang.IllegalArgumentException
      Creates an empty inventory of type InventoryType.CHEST with the specified size and title.
      Parameters:
      owner - the holder of the inventory, or null to indicate no holder
      size - a multiple of 9 as the size of inventory to create
      title - the title of the inventory, displayed when inventory is viewed
      Returns:
      a new inventory
      Throws:
      java.lang.IllegalArgumentException - if the size is not a multiple of 9
    • getMonsterSpawnLimit

      public static int getMonsterSpawnLimit()
      Gets user-specified limit for number of monsters that can spawn in a chunk.
      Returns:
      the monster spawn limit
    • getAnimalSpawnLimit

      public static int getAnimalSpawnLimit()
      Gets user-specified limit for number of animals that can spawn in a chunk.
      Returns:
      the animal spawn limit
    • getWaterAnimalSpawnLimit

      public static int getWaterAnimalSpawnLimit()
      Gets user-specified limit for number of water animals that can spawn in a chunk.
      Returns:
      the water animal spawn limit
    • getAmbientSpawnLimit

      public static int getAmbientSpawnLimit()
      Gets user-specified limit for number of ambient mobs that can spawn in a chunk.
      Returns:
      the ambient spawn limit
    • isPrimaryThread

      public static boolean isPrimaryThread()
      Checks the current thread against the expected primary thread for the server.

      Note: this method should not be used to indicate the current synchronized state of the runtime. A current thread matching the main thread indicates that it is synchronized, but a mismatch does not preclude the same assumption.

      Returns:
      true if the current thread matches the expected primary thread, false otherwise
    • getMotd

      public static java.lang.String getMotd()
      Gets the message that is displayed on the server list.
      Returns:
      the servers MOTD
    • getShutdownMessage

      public static java.lang.String getShutdownMessage()
      Gets the default message that is displayed when the server is stopped.
      Returns:
      the shutdown message
    • getWarningState

      public static Warning.WarningState getWarningState()
      Gets the current warning state for the server.
      Returns:
      the configured warning state
    • getItemFactory

      public static ItemFactory getItemFactory()
      Gets the instance of the item factory (for ItemMeta).
      Returns:
      the item factory
      See Also:
      ItemFactory
    • getScoreboardManager

      public static ScoreboardManager getScoreboardManager()
      Gets the instance of the scoreboard manager.

      This will only exist after the first world has loaded.

      Returns:
      the scoreboard manager or null if no worlds are loaded.
    • getServerIcon

      public static CachedServerIcon getServerIcon()
      Gets an instance of the server's default server-icon.
      Returns:
      the default server-icon; null values may be used by the implementation to indicate no defined icon, but this behavior is not guaranteed
    • loadServerIcon

      public static CachedServerIcon loadServerIcon​(java.io.File file) throws java.lang.IllegalArgumentException, java.lang.Exception
      Loads an image from a file, and returns a cached image for the specific server-icon.

      Size and type are implementation defined. An incompatible file is guaranteed to throw an implementation-defined Exception.

      Parameters:
      file - the file to load the from
      Returns:
      a cached server-icon that can be used for a ServerListPingEvent.setServerIcon(CachedServerIcon)
      Throws:
      java.lang.IllegalArgumentException - if image is null
      java.lang.Exception - if the image does not meet current server server-icon specifications
    • loadServerIcon

      public static CachedServerIcon loadServerIcon​(java.awt.image.BufferedImage image) throws java.lang.IllegalArgumentException, java.lang.Exception
      Creates a cached server-icon for the specific image.

      Size and type are implementation defined. An incompatible file is guaranteed to throw an implementation-defined Exception.

      Parameters:
      image - the image to use
      Returns:
      a cached server-icon that can be used for a ServerListPingEvent.setServerIcon(CachedServerIcon)
      Throws:
      java.lang.IllegalArgumentException - if image is null
      java.lang.Exception - if the image does not meet current server server-icon specifications
    • setIdleTimeout

      public static void setIdleTimeout​(int threshold)
      Set the idle kick timeout. Any players idle for the specified amount of time will be automatically kicked.

      A value of 0 will disable the idle kick timeout.

      Parameters:
      threshold - the idle timeout in minutes
    • getIdleTimeout

      public static int getIdleTimeout()
      Gets the idle kick timeout.
      Returns:
      the idle timeout in minutes
    • createChunkData

      public static ChunkGenerator.ChunkData createChunkData​(World world)
      Parameters:
      world - the world to create the ChunkData for
      Returns:
      a new ChunkData for the world
    • getUnsafe

      @Deprecated public static UnsafeValues getUnsafe()
      Deprecated.
      Returns:
      the unsafe values instance
      See Also:
      UnsafeValues
    • spigot

      public static Server.Spigot spigot()