Interface NMSHelper


public interface NMSHelper
This class contains some helpers which may help you in solving NMS stuff
  • Method Details

    • getVersion

      int getVersion()
      Returns the minor version of the running server software.

      Example: If it's running 1.8.6, then this method returns 8

      Returns:
      The minor version of the running server software
    • getPatchVersion

      int getPatchVersion()
      Returns the patch version of the running software.

      Example: If it's running 1.8.6, then this method returns 6

      Returns:
      The patch version of the running server software
    • getRevision

      int getRevision()
      Returns the revision number that you can find in NMS packages.
      Example: If it's running "v1_8_R3" then this method returns 3
      Returns:
      The revision number of the running server software
    • isRunningPaper

      boolean isRunningPaper()
      Returns whether or not this server is running paper or a fork of paper
      Returns:
      true when the plugin is running PaperMC or a fork of it
    • getLocale

      String getLocale(Player player)
      Returns the locale of the player that he has configured within his client.
      Parameters:
      player - The given player
      Returns:
      The locale of the player
    • setGlowEffect

      ItemStack setGlowEffect(ItemStack is, boolean glowing)
      Adds or removes a "glow" effect to an item.

      Glow effects basically are simply enchantments added to an item. This method also does some extra little things to improve the glow effect furthermore.

      It's possible that the glow effect gets added to the item that's being passed with this method. If it's eventually a new instance that's getting returned depends on the minecraft version that's running and the material of the item.

      Parameters:
      is - The item to which the glow effect shall be added to / removed from
      glowing - true: Add the effect; false: Remove the effect
      Returns:
      Same or cloned ItemStack instance with or without the glow effect
    • showTitle

      void showTitle(Player player, String title, String subtitle, int fadeIn, int stayTime, int fadeOut)
      Shows the "title" to a player.

      A title is basically a huge text displayed on the players screen.

      Parameters:
      player - The target to whom the text shall be displayed to
      title - The larger text which is located above subtitle
      subtitle - The smaller text which is located below title
      fadeIn - The time in ticks for the "appear" or "fade in" effect
      stayTime - The time in ticks in which the title will be shown
      fadeOut - The time in ticks for the "disappear" or "fade out" effect
    • showTitle

      void showTitle(Player player, String title, String subtitle)
      Shows the "title" to a player.

      A title is basically a huge text displayed on the players screen.

      Parameters:
      player - The target to whom the text shall be displayed to
      title - The larger text which is located above subtitle
      subtitle - The smaller text which is located below title
    • showActionbar

      void showActionbar(Player player, String text)
      Will show a small message above the players hotbar
      Parameters:
      player - The target to whom the text shall be displayed to
      text - The string that shall be shown
    • setSkullTexture

      void setSkullTexture(Skull skull, String texture)
      Applies a custom texture in a base64 format to a skull block.

      Make sure to call BlockState.update() at some point to actually apply it to the block. This method only applies it to the cloned Skull instance and not to the actual block.

      Parameters:
      skull - The skull block to which the texture shall be applied to
      texture - The texture in base64 format
    • getSkullTexture

      @Nullable @Nullable String getSkullTexture(Skull skull)
      Returns the texture of the skull in a base64 format. Might be null when the texture hasn't been loaded yet or when simply none has been applied.
      Parameters:
      skull - The skull block from which we want to fetch the texture
      Returns:
      The texture of the skull. Might be null
    • setSkullTexture

      void setSkullTexture(SkullMeta skullMeta, String texture)
      Applies a custom texture in a base64 format to a skull item
      Parameters:
      skullMeta - The ItemMeta of the skull item to which the texture shall be applied to
      texture - The texture in base64 format
    • getSkullTexture

      @Nullable @Nullable String getSkullTexture(SkullMeta skullMeta)
      Returns the texture of the skull in a base64 format. Might be null when the texture hasn't been loaded yet or when simply none has been applied.
      Parameters:
      skullMeta - The ItemMeta of the skull item from which we want to fetch the texture
      Returns:
      The texture of the skull. Might be null
    • getVanillaDeathMessage

      String getVanillaDeathMessage(Player player)
      Returns the death message that Minecraft would use by default if the player would die at this moment
      Parameters:
      player - The related player
      Returns:
      The vanilla death message of the player
    • setEntityTarget

      void setEntityTarget(Entity entity, @Nullable @Nullable Location target)
      Causes a walkable hologram to walk to a given location. Pass null to make the hologram stop walking.

      Keep in mind that there's maximum radius to which the hologram will walk to.

      Parameters:
      entity - The hologram that shall walk to somewhere
      target - The location to which he shall walk to. null to make him stop
    • sendPacket

      void sendPacket(Player player, Object packet)
      Will send a message to the player. The message must be an instance of net.minecraft.v<version>.Packet
      Parameters:
      player - The player to who we want to send a message to
      packet - The message that shall be send
    • getAttackDamage

      float getAttackDamage(Player player)
      Returns the amount of damage a player would cause at the exact moment with a generic entity.

      Does not consider e.g. the monster damage enchantments as we don't care of the entity type that gets damaged here.

      Parameters:
      player - The player who would deal the damage
      Returns:
      The amount of damage he'd deal with a generic entity
    • getEntityById

      @Nullable @Nullable Entity getEntityById(World world, int entityId)
      Returns the entity whose Entity.getEntityId() is equal to the given one.

      Utilizes NBT for best performance

      Parameters:
      world - The world in which the entity is located in
      entityId - The id of the entity
      Returns:
      The entity with that id. null when there's none
    • simulateChestOpening

      void simulateChestOpening(World world, int x, int y, int z)
      Simulates as if someone would open a container, such as an ender chest, normal chest or a shulker box.

      It'll play an animation and updates the redstone signal. Possibly even more is happening.

      There's an interal numerical counter that checks how many players have opened the chest. It's being used to determinate when the close animation needs to be played. Make sure to call simulateChestClosing(World, int, int, int) equally as often as you called this method and not more or less, as otherwise it'll possibly break. The counter may even reach minus values.

      Parameters:
      world - The world in which the container is located at
      x - The x position of the container block
      y - The y position of the container block
      z - The z position of the container block
    • simulateChestOpening

      default void simulateChestOpening(Block block)
      Simulates as if someone would open a container, such as an ender chest, normal chest or a shulker box.

      It'll play an animation and updates the redstone signal. Possibly even more is happening.

      There's an interal numerical counter that checks how many players have opened the chest. It's being used to determinate when the close animation needs to be played. Make sure to call simulateChestClosing(World, int, int, int) equally as often as you called this method and not more or less, as otherwise it'll possibly break. The counter may even reach minus values.

      Parameters:
      block - The block that represents the container
    • simulateChestClosing

      void simulateChestClosing(World world, int x, int y, int z)
      Simulates as if someone would close a container, such as an ender chest, normal chest or a shulker box.

      It'll play an animation and updates the redstone signal. Possibly even more is happening.

      There's an interal numerical counter that checks how many players have opened the chest. It's being used to determinate when the close animation needs to be played. Make sure to call simulateChestOpening(World, int, int, int) equally as often as you called this method and not more or less, as otherwise it'll possibly break. The counter may even reach minus values.

      Parameters:
      world - The world in which the container is located at
      x - The x position of the container block
      y - The y position of the container block
      z - The z position of the container block
    • simulateChestClosing

      default void simulateChestClosing(Block block)
      Simulates as if someone would close a container, such as an ender chest, normal chest or a shulker box.

      It'll play an animation and updates the redstone signal. Possibly even more is happening.

      There's an interal numerical counter that checks how many players have opened the chest. It's being used to determinate when the close animation needs to be played. Make sure to call simulateChestOpening(World, int, int, int) equally as often as you called this method and not more or less, as otherwise it'll possibly break. The counter may even reach minus values.

      Parameters:
      block - The block that represents the container
    • setServerMotd

      void setServerMotd(String motd)
      This may sound crazy, but Bukkit's API does not allow the direct change of the server's motd.
      Parameters:
      motd - The new motd
    • playItemPickupAnimation

      void playItemPickupAnimation(Entity entity, Entity item, int amount)
      Simulates an item, arrow, exp or whatever getting picked up.

      This method does NOT remove the entity from the memory, it only plays the pickup animation.

      Parameters:
      entity - The entity that picked it up
      item - The entity that got picked up
      amount - The amount that got picked up. For an item it's for instance its amount, for exp it's the amount it represents
    • simulatePlayerClickingRespawn

      void simulatePlayerClickingRespawn(Player player)
      Simulates as if the player would click on the "respawn" button while he's dead.
      Parameters:
      player - The player for whom we want it to simulate
    • setEntityMovementSpeed

      void setEntityMovementSpeed(LivingEntity entity, double speed)
      Changes the movement speed of the given entity.

      Basically only changes the "MOVEMENT_SPEED" attribute. This, however, wasn't possible for all versions in the past and required NMS.

      Parameters:
      entity - The entity for whom the speed shall be changed
      speed - The new movement speed
    • setEntityFollowRange

      void setEntityFollowRange(LivingEntity entity, double range)
      Changes the range in which the entity can follow its target/enemy.

      Basically only changes the "FOLLOW_RANGE" attribute. This, however, wasn't possible for all versions in the past and required NMS.

      Parameters:
      entity - The entity for whom the speed shall be changed
      range - The new target range
    • setEntitySilent

      void setEntitySilent(Entity entity, boolean silent)
      Changes if an entity is silent, or is allowed to make noise.
      Parameters:
      entity - The entity that will be made silent
      silent - Whether the entity shall be silent or not
    • teleportWithoutEvent

      void teleportWithoutEvent(Entity entity, Location location)
      Teleports a given entity to a location without calling EntityTeleportEvent.

      Furthermore, it also doesn't check whether the entity is currently being ridden on (unlike Bukkit's API).

      Parameters:
      entity - The entity that shall be teleported
      location - The target location
    • getItemDamage

      double getItemDamage(ItemStack is)
      Calculates the amount of attack damage this item would theoretically generate.
      Parameters:
      is - The item
      Returns:
      The approx amount of damage it'd generate
    • hideAttributes

      ItemStack hideAttributes(ItemStack is)
      Hides attributes from the item.

      This includes e.g. the damage for swords. It's not possible to tell beforehand whether a new instance will be constructed as this greatly depends on the version the user is using.

      Parameters:
      is - The item whose attributes shall be hidden
      Returns:
      Possibly the equal or a new instance
    • sendWorldTimePacket

      void sendWorldTimePacket(Player player, long time)
      Sends a world time packet to the given player.
      Parameters:
      player - Target player
      time - The new world time
    • getEntityDamageSound

      @Nullable @Nullable Sound getEntityDamageSound(Entity entity)
      Returns the sound that the entity would play if it'd receive damage.
      Parameters:
      entity - The involved entity
      Returns:
      The sound that it'd play. null if it doesn't play any sound in that case
    • getEntityDeathSound

      @Nullable @Nullable Sound getEntityDeathSound(Entity entity)
      Returns the sound that the entity would play if it'd die.
      Parameters:
      entity - The involved entity
      Returns:
      The sound that it'd play. null if it doesn't play any sound in that case
    • getSoundByMinecraftName

      @Nullable @Nullable Sound getSoundByMinecraftName(String vanillaName)
      Tries to parse a Minecraft sound given by it's vanilla id (e.g. minecraft:beacon.activate)
      Parameters:
      vanillaName - The vanilla id of the sound
      Returns:
      The sound that matches to it. null if none has been found
    • getEntityWidth

      float getEntityWidth(Entity entity)
      Get the width of the entity
      Parameters:
      entity - The involved entity
      Returns:
      The width of the entity
    • getEntityHeight

      float getEntityHeight(Entity entity)
      Get the height of the entity
      Parameters:
      entity - The involved entity
      Returns:
      The height of the entity
    • getEffectInfiniteDuration

      int getEffectInfiniteDuration()
      Get the duration that you have to use for infinite potion effects.

      While in the past you could just use Integer.MAX_VALUE, newer versions instead expect -1. This method automatically handles the differentiation for you.

      Returns:
      The duration that you have to use for infinite potion effects
      See Also:
    • get

      static NMSHelper get()
      Contains API/Helper to access NMS stuff
      Returns:
      The global NMSHelper instance