Class WorldUtils

java.lang.Object
ua.mcchickenstudio.opencreative.utils.world.WorldUtils

public final class WorldUtils extends Object

WorldUtils

This class contains methods for changing or manipulating worlds, like checking if world is a planet.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static @NotNull Map<String,Double>
    fromLocationToMap(@NotNull org.bukkit.Location location)
    Converts location to map with x, y, z, yaw, pitch values.
    static double
    fromTextToCoordinate(@NotNull String text, double defaultValue)
    Converts text coordinate to numeric double.
    static int
    Returns a unique numeric ID for new planet.
    static org.bukkit.NamespacedKey
    Returns key, that will be used in entities, that mustn't damage any entity.
    static @NotNull String
    getPlanetIdFromName(@NotNull org.bukkit.World world)
    Returns planet id from world's name by splitting it and removing path to planets folder.
    static boolean
    isDevPlanet(@NotNull String worldName)
    Checks if the world is a dev planet by checking whether it's name ends with "dev" word.
    static boolean
    isDevPlanet(@NotNull org.bukkit.World world)
    Checks if the world is a dev planet by checking whether it's name ends with "dev" word.
    static boolean
    isEntityHostile(@Nullable org.bukkit.entity.Entity entity)
    Checks if entity is a hostile one, that can attack player.
    static boolean
    isLobbyWorld(@NotNull org.bukkit.World world)
    Checks if the world is a lobby world, where players will be teleported on server connection or by /spawn command.
    static boolean
    isOpenCreativeWorld(@NotNull org.bukkit.World world)
    Checks if the world is a planet, or dev planet, or lobby world.
    static boolean
    isPlanet(@NotNull String worldName)
    Checks if the world is a planet by checking whether it's name contains a typical planets folder path.
    static boolean
    isPlanet(@NotNull org.bukkit.World world)
    Checks if the world is a planet by checking whether it's name contains a typical planets folder path.
    static @NotNull org.bukkit.Location
    roundLocation(@NotNull org.bukkit.Location location)
    Rounds location numbers: x, y, z, yaw, pitch.
    static void
    summonFireworks(int times, int period)
    Summons fireworks around players in world.
    static void
    summonFireworks(@NotNull org.bukkit.World world, int amount)
    Summons fireworks around players in world.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WorldUtils

      public WorldUtils()
  • Method Details

    • getDoNotHurtAnyoneKey

      public static org.bukkit.NamespacedKey getDoNotHurtAnyoneKey()
      Returns key, that will be used in entities, that mustn't damage any entity.
      Returns:
      namespaced key of not hurting anyone.
    • summonFireworks

      public static void summonFireworks(@NotNull @NotNull org.bukkit.World world, int amount)
      Summons fireworks around players in world. They won't damage players or entities.
      Parameters:
      world - world to summon.
      amount - amount of fireworks.
    • summonFireworks

      public static void summonFireworks(int times, int period)
      Summons fireworks around players in world. They won't damage players or entities.
      Parameters:
      times - how many times summon fireworks.
      period - period of time, that should pass before every time.
    • getPlanetIdFromName

      @NotNull public static @NotNull String getPlanetIdFromName(@NotNull @NotNull org.bukkit.World world)
      Returns planet id from world's name by splitting it and removing path to planets folder.
      Parameters:
      world - world to get id.
      Returns:
      planet id.
    • roundLocation

      @NotNull public static @NotNull org.bukkit.Location roundLocation(@NotNull @NotNull org.bukkit.Location location)
      Rounds location numbers: x, y, z, yaw, pitch.
      Parameters:
      location - location to round.
      Returns:
      location with rounded coordinates.
    • fromTextToCoordinate

      public static double fromTextToCoordinate(@NotNull @NotNull String text, double defaultValue)
      Converts text coordinate to numeric double.

      If it starts with ~ symbol, it will add specified value to default value.

      If it fails to get number from text, it will return default value.

      Parameters:
      text - text with number to convert.
      defaultValue - default value.
      Returns:
      coordinate double value.
    • fromLocationToMap

      @NotNull public static @NotNull Map<String,Double> fromLocationToMap(@NotNull @NotNull org.bukkit.Location location)
      Converts location to map with x, y, z, yaw, pitch values.
      Parameters:
      location - location to convert to map.
      Returns:
      map with x, y, z, yaw, pitch values.
    • isPlanet

      public static boolean isPlanet(@NotNull @NotNull org.bukkit.World world)
      Checks if the world is a planet by checking whether it's name contains a typical planets folder path.
      Parameters:
      world - world to check.
      Returns:
      true - should be a planet, false - not a planet.
    • isPlanet

      public static boolean isPlanet(@NotNull @NotNull String worldName)
      Checks if the world is a planet by checking whether it's name contains a typical planets folder path.
      Parameters:
      worldName - name of world to check.
      Returns:
      true - should be a planet, false - not a planet.
    • isDevPlanet

      public static boolean isDevPlanet(@NotNull @NotNull String worldName)
      Checks if the world is a dev planet by checking whether it's name ends with "dev" word.
      Parameters:
      worldName - world to check.
      Returns:
      true - should be a dev planet, false - not a dev planet.
    • isOpenCreativeWorld

      public static boolean isOpenCreativeWorld(@NotNull @NotNull org.bukkit.World world)
      Checks if the world is a planet, or dev planet, or lobby world.
      Parameters:
      world - world to check.
      Returns:
      true - it's spawn, planet, dev planet world, false - not plugin's world.
    • isEntityHostile

      public static boolean isEntityHostile(@Nullable @Nullable org.bukkit.entity.Entity entity)
      Checks if entity is a hostile one, that can attack player.
      Parameters:
      entity - entity to check.
      Returns:
      true - entity is angry, false - entity is friendly or null.
    • isDevPlanet

      public static boolean isDevPlanet(@NotNull @NotNull org.bukkit.World world)
      Checks if the world is a dev planet by checking whether it's name ends with "dev" word.
      Parameters:
      world - world to check.
      Returns:
      true - should be a dev planet, false - not a dev planet.
    • isLobbyWorld

      public static boolean isLobbyWorld(@NotNull @NotNull org.bukkit.World world)
      Checks if the world is a lobby world, where players will be teleported on server connection or by /spawn command.
      Parameters:
      world - world to check.
      Returns:
      true - it's lobby world, false - not lobby world.
    • generateWorldID

      public static int generateWorldID()
      Returns a unique numeric ID for new planet. It gets a last numeric ID from config and increases it while checking is number free. Immediately will replace last numeric ID with result.
      Returns:
      unique numeric ID.