Class BukkitTools

java.lang.Object
com.palmergames.bukkit.util.BukkitTools

public class BukkitTools extends Object
A class of functions related to Bukkit in general.
Version:
1.0
Author:
Shade (Chris H, ElgarL)
  • Constructor Details

    • BukkitTools

      public BukkitTools()
  • Method Details

    • initialize

      public static void initialize(Towny plugin)
    • getOnlinePlayers

      public static Collection<? extends org.bukkit.entity.Player> getOnlinePlayers()
      Get an array of all online players
      Returns:
      array of online players
    • matchPlayer

      public static List<org.bukkit.entity.Player> matchPlayer(String name)
    • getUUIDSafely

      public static UUID getUUIDSafely(String name)
      Given a name this method should only return a UUID that is stored in the server cache, without pinging Mojang servers.
      Parameters:
      name - - Resident/Player name to get a UUID for.
      Returns:
      UUID of player or null if the player is not in the cache.
    • getPlayerExact

      @Nullable public static @Nullable org.bukkit.entity.Player getPlayerExact(String name)
    • getPlayer

      @Nullable public static @Nullable org.bukkit.entity.Player getPlayer(String playerId)
    • getPlayer

      @Nullable public static @Nullable org.bukkit.entity.Player getPlayer(UUID playerUUID)
    • hasVanishedMeta

      public static boolean hasVanishedMeta(@NotNull @NotNull org.bukkit.entity.Player player)
    • playerCanSeePlayer

      public static boolean playerCanSeePlayer(org.bukkit.entity.Player seeing, org.bukkit.entity.Player seen)
      Test whether an Player can see another Player. Staff on servers tend to enjoy their privacy while vanished.
      Parameters:
      seeing - Player who is doing the seeing.
      seen - Player who is potentially vanished from the seeing Player.
      Returns:
      true if the seeing Player can see the seen Player.
    • getVisibleOnlinePlayers

      public static Collection<? extends org.bukkit.entity.Player> getVisibleOnlinePlayers(org.bukkit.command.CommandSender sender)
    • isOnline

      public static boolean isOnline(String name)
      Tests if this player is online.
      Parameters:
      name - the name of the player.
      Returns:
      a true value if online
    • getWorlds

      public static List<org.bukkit.World> getWorlds()
    • getWorld

      public static org.bukkit.World getWorld(String name)
    • getWorld

      public static org.bukkit.World getWorld(UUID worldUID)
    • getWorldUUID

      public static UUID getWorldUUID(String name)
    • getServer

      public static org.bukkit.Server getServer()
    • getPluginManager

      public static org.bukkit.plugin.PluginManager getPluginManager()
    • getPlayersPerWorld

      public static HashMap<String,Integer> getPlayersPerWorld()
      Count the number of players online in each world
      Returns:
      Map of world to online players.
    • calcChunk

      public static int calcChunk(int value)
      Accepts an X or Z value and returns the associated Towny plot value.
      Parameters:
      value - - Value to calculate for X or Z (Integer)
      Returns:
      int of the relevant townblock x/z.
    • hasPlayedBefore

      public static boolean hasPlayedBefore(String name)
    • getOfflinePlayer

      public static org.bukkit.OfflinePlayer getOfflinePlayer(String name)
      Do not use without first using hasPlayedBefore(String)
      Parameters:
      name - - name of resident
      Returns:
      OfflinePlayer
    • getOfflinePlayerIfCached

      @Nullable public static @Nullable org.bukkit.OfflinePlayer getOfflinePlayerIfCached(@NotNull @NotNull String name)
    • getOfflinePlayerForVault

      public static org.bukkit.OfflinePlayer getOfflinePlayerForVault(String name)
    • convertCoordtoXYZ

      public static String convertCoordtoXYZ(org.bukkit.Location loc)
    • getWorldNames

      public static List<String> getWorldNames()
    • getWorldNames

      public static List<String> getWorldNames(boolean lowercased)
    • getBedOrRespawnLocation

      public static org.bukkit.Location getBedOrRespawnLocation(org.bukkit.entity.Player player)
    • potionEffectName

      public static String potionEffectName(@NotNull @NotNull org.bukkit.potion.PotionEffectType type)
    • objective

      public static org.bukkit.scoreboard.Objective objective(org.bukkit.scoreboard.Scoreboard board, @NotNull @NotNull String name, @NotNull @NotNull String displayName)
    • isEventCancelled

      public static boolean isEventCancelled(@NotNull @NotNull org.bukkit.event.Event event)
      Parameters:
      event - The event to call
      Returns:
      true if the event is cancellable and was cancelled, otherwise false.
    • ifCancelledThenThrow

      public static void ifCancelledThenThrow(@NotNull @NotNull CancellableTownyEvent event) throws CancelledEventException
      Parameters:
      event - CancellableTownyEvent to be fired which might be cancelled.
      Throws:
      CancelledEventException - with the Event's cancelMessage.
    • fireEvent

      public static void fireEvent(@NotNull @NotNull org.bukkit.event.Event event)
    • matchMaterialName

      @Nullable public static @Nullable String matchMaterialName(String name)
      Used to parse user-inputted material names into valid material names.
      Parameters:
      name - String which should be a material.
      Returns:
      String name of the material or null if no match could be made.
    • matchRegistry

      @Nullable public static <T extends org.bukkit.Keyed> T matchRegistry(@NotNull @NotNull org.bukkit.Registry<T> registry, @NotNull @NotNull String input)
      Our own copy of Registry.match(String), since this method did not exist on the currently lowest supported version, 1.16.
    • keyAsString

      public static String keyAsString(@NotNull @NotNull org.bukkit.NamespacedKey key)
      Converts a namespaced key into a string. The namespace is included for non minecraft namespaced keys.
      Returns:
      The string representation of the key.
    • getCommandMap

      @NotNull public static @NotNull org.bukkit.command.CommandMap getCommandMap() throws ReflectiveOperationException
      Throws:
      ReflectiveOperationException
    • convertKeyedToString

      @Internal public static Collection<String> convertKeyedToString(@NotNull @NotNull Collection<? extends org.bukkit.Keyed> keys)