Class WeaponMechanicsAPI
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 TypeMethodDescriptionstatic voidaddProjectile(@NotNull AProjectile projectile) Adds the given projectile to theProjectilesRunnable.static @Nullable org.bukkit.inventory.ItemStackgenerateAmmo(@NotNull String ammoTitle, boolean magazine) Generates the item for the given ammo, or returns null if the ammo does not use items for ammo.static @NotNull org.bukkit.inventory.ItemStackgenerateWeapon(@NotNull String weaponTitle) Returns an item corresponding to the givenweaponTitle.static @NotNull me.deecaad.core.compatibility.ICompatibilityReturns MechanicsCore's compatibility version.static @Nullable AmmogetCurrentAmmo(@NotNull org.bukkit.inventory.ItemStack weaponStack) Returns the ammo currently loaded in the weapon, or null if it doesn't use ammo.getCustomSkins(@NotNull String weaponTitle) Returns a copy of the skin set.static @NotNull WeaponMechanicsReturns the main WeaponMechanics instance.static @NotNull org.bukkit.plugin.PluginReturns the current WeaponMechanics main plugin instance.static doublegetScopeLevel(@NotNull org.bukkit.entity.LivingEntity entity) Returns how far theentityis zooming in.static @NotNull StringgetSkinFor(@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.static @Nullable StatsDatagetStats(@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.)static @NotNull IWeaponCompatibilityReturns WeaponMechanics' compatibility version.static @Nullable StringgetWeaponTitle(@NotNull org.bukkit.inventory.ItemStack item) Returns the weapon-title associated with the given item.static voidgiveWeapon(@NotNull String weaponTitle, @NotNull org.bukkit.entity.Player player) Gives an item corresponding to the givenweaponTitleto the givenplayer.static booleanisBroken(@NotNull org.bukkit.block.Block block) Returnstrueif the block at the given location is broken by an explosion, block damage, or otherwise.static booleanisReloading(@NotNull org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis reloading their weapon.static booleanisScoping(@NotNull org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis zooming in with their weapon.static voidRegenerates all blocks broken by this plugin.static booleansetFullAutoShotsPerSecond(@NotNull HandData hand, int shotsPerSecond) Attempts to set the full auto rate for the given hand.static booleansetFullAutoShotsPerSecond(@NotNull org.bukkit.entity.LivingEntity entity, int shotsPerSecond) Attempts to set the full auto rate for the given entity.static booleansetSkin(@NotNull org.bukkit.entity.Player player, @NotNull String weaponTitle, @Nullable String skin) Attempts to set the player's skin preference for the given weapon.static voidSets the skin override for the given weapon item.static voidShorthand for an entity to shoot a weapon in the direction the entity is currently facing.static voidshoot(@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.static voidshoot(@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.static booleantryReload(@NotNull org.bukkit.entity.LivingEntity entity) Forces the givenentityto reload their weapon.
-
Method Details
-
getStats
@Nullable public static @Nullable StatsData getStats(@NotNull @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 @NotNull String getSkinFor(@NotNull @NotNull org.bukkit.entity.Player player, @NotNull @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 @NotNull org.bukkit.inventory.ItemStack weaponStack, @Nullable @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 @NotNull org.bukkit.entity.Player player, @NotNull @NotNull String weaponTitle, @Nullable @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:
trueif the skin was set.
-
getCustomSkins
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 @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:
trueif the full auto rate was set.
-
setFullAutoShotsPerSecond
public static boolean setFullAutoShotsPerSecond(@NotNull @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:
trueif the full auto rate was set.
-
getScopeLevel
public static double getScopeLevel(@NotNull @NotNull org.bukkit.entity.LivingEntity entity) Returns how far theentityis 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 @NotNull org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis zooming in with their weapon. It doesn't matter if the player is zoom-stacking or not, this method will returntrueif the entity is zoomed in at all.- Parameters:
entity- The non-null living entity to check the scope state of.- Returns:
trueif the entity is scoping.
-
isReloading
public static boolean isReloading(@NotNull @NotNull org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis reloading their weapon.- Parameters:
entity- The non-null living entity to check the reload state of.- Returns:
trueif the entity is reloading.
-
tryReload
public static boolean tryReload(@NotNull @NotNull org.bukkit.entity.LivingEntity entity) Forces the givenentityto reload their weapon. This method will returntrueif 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 @NotNull org.bukkit.inventory.ItemStack generateWeapon(@NotNull @NotNull String weaponTitle) Returns an item corresponding to the givenweaponTitle. 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 @NotNull String weaponTitle, @NotNull @NotNull org.bukkit.entity.Player player) Gives an item corresponding to the givenweaponTitleto the givenplayer. If the player's inventory is full, the item will be dropped viaWorld.dropItemNaturally(Location, ItemStack).- Parameters:
weaponTitle- The non-null weapon-title of the weapon to generate.player- The non-null weapon item.
-
addProjectile
Adds the given projectile to theProjectilesRunnable. Can be run async.- Parameters:
projectile- The non-null projectile to add.- See Also:
-
isBroken
public static boolean isBroken(@NotNull @NotNull org.bukkit.block.Block block) Returnstrueif the block at the given location is broken by an explosion, block damage, or otherwise.- Parameters:
block- The non-null block to check.- Returns:
trueif 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 blocksBlockDamageData.regenerate(Chunk). -
getWeaponTitle
@Nullable public static @Nullable String getWeaponTitle(@NotNull @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 returnnull.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 @Nullable Ammo getCurrentAmmo(@NotNull @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 @Nullable org.bukkit.inventory.ItemStack generateAmmo(@NotNull @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 @NotNull org.bukkit.entity.LivingEntity shooter, @NotNull @NotNull String weaponTitle, @NotNull @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 @NotNull org.bukkit.entity.LivingEntity shooter, @NotNull @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 @NotNull org.bukkit.entity.LivingEntity shooter, @NotNull @NotNull String weaponTitle, @NotNull @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 @NotNull 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
Returns WeaponMechanics' compatibility version. Useful for dealing with NMS code or otherwise version dependent code.- Returns:
- The non-null weapon compatibility version.
-
getPluginInstance
@NotNull public static @NotNull org.bukkit.plugin.Plugin getPluginInstance()Returns the current WeaponMechanics main plugin instance. If the plugin has not been loaded, or is current reloading, this method will returnnull.- Returns:
- The plugin instance.
-
getInstance
Returns the main WeaponMechanics instance. Good for reloading the plugin.- Returns:
- The plugin instance.
-