Class WeaponMechanicsAPI

java.lang.Object
me.deecaad.weaponmechanics.WeaponMechanicsAPI

public final class WeaponMechanicsAPI extends Object
This class outlines static utility methods to help developers find functions of WeaponMechanics wrapped in one place. The following method's implementations exclusively call "internal" methods to handle the function.

The methods in this class are designed for "general use." If you are looking for a more specific method, you should look at the implementation of the API method, and call the internal methods instead.

Are we missing a method you want? No problem, simply open an issue on GitHub, and we will add it!

  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    Adds the projectile to WeaponMechanic's projectile spawner.
    static org.bukkit.inventory.ItemStack
    generateAmmo(String ammoTitle, boolean magazine)
    Generates the item for the given ammo, or returns null if the ammo does not use items for ammo.
    static org.bukkit.inventory.ItemStack
    generateWeapon(String weaponTitle)
    Returns an item corresponding to the given weaponTitle.
    static me.deecaad.core.compatibility.ICompatibility
    Returns MechanicsCore's compatibility version.
    static Ammo
    getCurrentAmmo(org.bukkit.inventory.ItemStack weaponStack)
    Returns the ammo currently loaded in the weapon, or null if it doesn't use ammo.
    static Set<String>
    getCustomSkins(String weaponTitle)
    Returns a copy of the skin set.
    static double
    getScopeLevel(org.bukkit.entity.LivingEntity entity)
    Returns how far the entity is zooming in.
    static String
    getSkinFor(org.bukkit.entity.Player player, org.bukkit.inventory.ItemStack weaponStack)
    Gets the skin that will be applied to the weapon item for the given player.
    static StatsData
    getStats(org.bukkit.entity.Player player)
    Gets the stats for the given player, or null if the stats have not been loaded (Which can happen randomly if the database falls out of sync, during reloads, player has never joined before, etc.)
    Returns WeaponMechanics' compatibility version.
    static String
    getWeaponTitle(org.bukkit.inventory.ItemStack item)
    Returns the weapon-title associated with the given item.
    static void
    giveWeapon(String weaponTitle, org.bukkit.entity.Player player)
    Gives an item corresponding to the given weaponTitle to the given player.
    static boolean
    isBroken(org.bukkit.block.Block block)
    Returns true if the block at the given location is broken by an explosion, block damage, or otherwise.
    static boolean
    isReloading(org.bukkit.entity.LivingEntity entity)
    Returns true if the given entity is reloading their weapon.
    static boolean
    isScoping(org.bukkit.entity.LivingEntity entity)
    Returns true if the given entity is zooming in with their weapon.
    static void
    Regenerates all blocks broken by this plugin.
    static boolean
    setFullAutoShotsPerSecond(HandData hand, int shotsPerSecond)
    Attempts to set the full auto rate for the given hand.
    static boolean
    setFullAutoShotsPerSecond(org.bukkit.entity.LivingEntity entity, int shotsPerSecond)
    Attempts to set the full auto rate for the given entity.
    static boolean
    setSkin(org.bukkit.entity.Player player, String weaponTitle, String skin)
    Attempts to set the player's skin preference for the given weapon.
    static void
    setSkin(org.bukkit.inventory.ItemStack weaponStack, String skin)
    Sets the skin override for the given weapon item.
    static void
    shoot(org.bukkit.entity.LivingEntity shooter, String weaponTitle)
    Shorthand for an entity to shoot a weapon in the direction the entity is currently facing.
    static void
    shoot(org.bukkit.entity.LivingEntity shooter, String weaponTitle, org.bukkit.Location target)
    Shorthand for an entity to shoot a weapon at the given target location.
    static void
    shoot(org.bukkit.entity.LivingEntity shooter, String weaponTitle, org.bukkit.util.Vector direction)
    Shorthand for an entity to shoot a weapon in the given direction.
    static boolean
    tryReload(org.bukkit.entity.LivingEntity entity)
    Forces the given entity to reload their weapon.

    Methods inherited from class java.lang.Object

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

    • getStats

      @Nullable public static StatsData getStats(@NotNull org.bukkit.entity.Player player)
      Gets the stats for the given player, or null if the stats have not been loaded (Which can happen randomly if the database falls out of sync, during reloads, player has never joined before, etc.)
      Parameters:
      player - The non-null player to get the stats for.
      Returns:
      The nullable stats.
    • getSkinFor

      @NotNull public static String getSkinFor(@NotNull org.bukkit.entity.Player player, @NotNull org.bukkit.inventory.ItemStack weaponStack)
      Gets the skin that will be applied to the weapon item for the given player. This takes the skin override (setSkin(ItemStack, String)) into account.

      This method will throw an exception if the weapon does not use skins.

      Parameters:
      player - The player holding the weapon.
      weaponStack - The weapon item to get the skin for.
      Returns:
      Which skin should be applied, or "default" for no skin.
    • setSkin

      public static void setSkin(@NotNull org.bukkit.inventory.ItemStack weaponStack, @Nullable String skin)
      Sets the skin override for the given weapon item. This will override player preferences (setSkin(Player, String, String)).

      This method simply sets the skin override in the item's nbt data. You can set this value yourself using CustomTag.WEAPON_SKIN. This method will throw an exception if the weapon does not use skins.

      Parameters:
      weaponStack - The weapon item to set the skin for.
      skin - The skin to set. If null, the default skin will be used.
    • setSkin

      public static boolean setSkin(@NotNull org.bukkit.entity.Player player, @NotNull String weaponTitle, @Nullable String skin)
      Attempts to set the player's skin preference for the given weapon.

      This method simply sets the player's skin preference in the database. For skins to work, WeaponMechanicsCosmetics must be installed.

      Parameters:
      player - The player to set the skin preference for.
      weaponTitle - The weapon title to set the skin preference for.
      skin - The skin to set. If null, the default skin will be used.
      Returns:
      true if the skin was set.
    • getCustomSkins

      @NotNull public static Set<String> getCustomSkins(@NotNull String weaponTitle)
      Returns a copy of the skin set. This returned set may be empty if the weapon uses the Skins feature, but does not have any defined skins (Which is very common!).

      Note that the default skin, "default", is not included in the returned set.

      Parameters:
      weaponTitle - The non-null weapon title to get the skins for.
      Returns:
      The non-null set of custom skins.
    • setFullAutoShotsPerSecond

      public static boolean setFullAutoShotsPerSecond(@NotNull org.bukkit.entity.LivingEntity entity, int shotsPerSecond)
      Attempts to set the full auto rate for the given entity. Will try to use the mainhand first, then the offhand. Use shotsPerSecond=0 to stop the full auto.
      Parameters:
      entity - The non-null entity to set the full auto rate for.
      shotsPerSecond - The non-negative shots per second to set.
      Returns:
      true if the full auto rate was set.
    • setFullAutoShotsPerSecond

      public static boolean setFullAutoShotsPerSecond(@NotNull HandData hand, int shotsPerSecond)
      Attempts to set the full auto rate for the given hand.
      Parameters:
      hand - The non-null hand to set the full auto rate for.
      shotsPerSecond - The non-negative shots per second to set.
      Returns:
      true if the full auto rate was set.
    • getScopeLevel

      public static double getScopeLevel(@NotNull org.bukkit.entity.LivingEntity entity)
      Returns how far the entity is zooming in. 0 means that the entity is not scoping at all. Any other number means that the entity is scoping.
      Parameters:
      entity - The non-null living entity to check the scope state of.
      Returns:
      The non-negative zoom amount.
      See Also:
    • isScoping

      public static boolean isScoping(@NotNull org.bukkit.entity.LivingEntity entity)
      Returns true if the given entity is zooming in with their weapon. It doesn't matter if the player is zoom-stacking or not, this method will return true if the entity is zoomed in at all.
      Parameters:
      entity - The non-null living entity to check the scope state of.
      Returns:
      true if the entity is scoping.
    • isReloading

      public static boolean isReloading(@NotNull org.bukkit.entity.LivingEntity entity)
      Returns true if the given entity is reloading their weapon.
      Parameters:
      entity - The non-null living entity to check the reload state of.
      Returns:
      true if the entity is reloading.
    • tryReload

      public static boolean tryReload(@NotNull org.bukkit.entity.LivingEntity entity)
      Forces the given entity to reload their weapon. This method will return true if the entity is now reloading.

      This method may return false if the entity is not holding a weapon, if the entity is already reloading, or for any number of other possibilities.

      Parameters:
      entity - The non-null living entity to force reload.
      Returns:
      true if the reload started
    • generateWeapon

      @NotNull public static org.bukkit.inventory.ItemStack generateWeapon(@NotNull String weaponTitle)
      Returns an item corresponding to the given weaponTitle. The item will have a custom name, lore, enchantments, flags, nbt data, etc.
      Parameters:
      weaponTitle - The non-null weapon-title of the weapon to generate.
      Returns:
      The non-null weapon item.
      See Also:
    • giveWeapon

      public static void giveWeapon(@NotNull String weaponTitle, @NotNull org.bukkit.entity.Player player)
      Gives an item corresponding to the given weaponTitle to the given player. If the player's inventory is full, the item will be dropped via World.dropItemNaturally(Location, ItemStack).
      Parameters:
      weaponTitle - The non-null weapon-title of the weapon to generate.
      player - The non-null weapon item.
    • addProjectile

      public static void addProjectile(@NotNull AProjectile projectile)
      Adds the projectile to WeaponMechanic's projectile spawner.
      Parameters:
      projectile - The non-null projectile to add.
    • isBroken

      public static boolean isBroken(@NotNull org.bukkit.block.Block block)
      Returns true if the block at the given location is broken by an explosion, block damage, or otherwise.
      Parameters:
      block - The non-null block to check.
      Returns:
      true if the block is broken.
      See Also:
    • regenerateAllBlocks

      public static void regenerateAllBlocks()
      Regenerates all blocks broken by this plugin. This is a "dangerous" method to call because this may cause players/entities to get stuck underground, and may cause lag spikes if there are many blocks to regenerate. Consider regenerating a few chunks instead of all blocks BlockDamageData.regenerate(Chunk).
    • getWeaponTitle

      @Nullable public static String getWeaponTitle(@NotNull org.bukkit.inventory.ItemStack item)
      Returns the weapon-title associated with the given item. If the given item is not a WeaponMechanics weapon, this method will return null.

      Note that a weapon-title is the config name of a weapon, and you can use a weapon-title to pull values from config easily.

      Parameters:
      item - The non-null item to get the weapon title from.
      Returns:
      The item's weapon title, or null.
    • getCurrentAmmo

      @Nullable public static Ammo getCurrentAmmo(@NotNull org.bukkit.inventory.ItemStack weaponStack)
      Returns the ammo currently loaded in the weapon, or null if it doesn't use ammo.
      Parameters:
      weaponStack - The non-null weapon item stack.
      Returns:
      The current ammo, or null.
    • generateAmmo

      @Nullable public static org.bukkit.inventory.ItemStack generateAmmo(@NotNull String ammoTitle, boolean magazine)
      Generates the item for the given ammo, or returns null if the ammo does not use items for ammo.
      Parameters:
      ammoTitle - The ammo to generate.
      magazine - true=generate magazine, false=generate bullet.
      Returns:
      The generated item, or null.
    • shoot

      public static void shoot(@NotNull org.bukkit.entity.LivingEntity shooter, @NotNull String weaponTitle, @NotNull org.bukkit.Location target)
      Shorthand for an entity to shoot a weapon at the given target location.
      Parameters:
      shooter - The non-null entity to shoot the weapon.
      weaponTitle - The non-null weapon title to shoot.
      target - The non-null target location to shoot at.
    • shoot

      public static void shoot(@NotNull org.bukkit.entity.LivingEntity shooter, @NotNull String weaponTitle)
      Shorthand for an entity to shoot a weapon in the direction the entity is currently facing.
      Parameters:
      shooter - The non-null entity to shoot the weapon.
      weaponTitle - The non-null weapon title to shoot.
    • shoot

      public static void shoot(@NotNull org.bukkit.entity.LivingEntity shooter, @NotNull String weaponTitle, @NotNull org.bukkit.util.Vector direction)
      Shorthand for an entity to shoot a weapon in the given direction.
      Parameters:
      shooter - The non-null entity to shoot the weapon.
      weaponTitle - The non-null weapon title to shoot.
      direction - The non-null direction to shoot the weapon.
    • getCompatibility

      @NotNull public static me.deecaad.core.compatibility.ICompatibility getCompatibility()
      Returns MechanicsCore's compatibility version. Useful for dealing with NMS code or otherwise version dependent code.
      Returns:
      The non-null compatibility version.
    • getWeaponCompatibility

      @NotNull public static IWeaponCompatibility getWeaponCompatibility()
      Returns WeaponMechanics' compatibility version. Useful for dealing with NMS code or otherwise version dependent code.
      Returns:
      The non-null weapon compatibility version.