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(AProjectile projectile) Adds the projectile to WeaponMechanic's projectile spawner.static org.bukkit.inventory.ItemStackgenerateAmmo(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.ItemStackgenerateWeapon(String weaponTitle) Returns an item corresponding to the givenweaponTitle.static me.deecaad.core.compatibility.ICompatibilityReturns MechanicsCore's compatibility version.static AmmogetCurrentAmmo(org.bukkit.inventory.ItemStack weaponStack) Returns the ammo currently loaded in the weapon, or null if it doesn't use ammo.getCustomSkins(String weaponTitle) Returns a copy of the skin set.static doublegetScopeLevel(org.bukkit.entity.LivingEntity entity) Returns how far theentityis zooming in.static StringgetSkinFor(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 StatsDatagetStats(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 IWeaponCompatibilityReturns WeaponMechanics' compatibility version.static StringgetWeaponTitle(org.bukkit.inventory.ItemStack item) Returns the weapon-title associated with the given item.static voidgiveWeapon(String weaponTitle, org.bukkit.entity.Player player) Gives an item corresponding to the givenweaponTitleto the givenplayer.static booleanisBroken(org.bukkit.block.Block block) Returnstrueif the block at the given location is broken by an explosion, block damage, or otherwise.static booleanisReloading(org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis reloading their weapon.static booleanisScoping(org.bukkit.entity.LivingEntity entity) Returnstrueif the givenentityis zooming in with their weapon.static voidRegenerates all blocks broken by this plugin.static booleansetFullAutoShotsPerSecond(HandData hand, int shotsPerSecond) Attempts to set the full auto rate for the given hand.static booleansetFullAutoShotsPerSecond(org.bukkit.entity.LivingEntity entity, int shotsPerSecond) Attempts to set the full auto rate for the given entity.static booleanAttempts 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 voidShorthand for an entity to shoot a weapon at the given target location.static voidShorthand for an entity to shoot a weapon in the given direction.static booleantryReload(org.bukkit.entity.LivingEntity entity) Forces the givenentityto reload their weapon.
-
Method Details
-
getStats
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:
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 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
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 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 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 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 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
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 String weaponTitle, @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 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) 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
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
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
Returns WeaponMechanics' compatibility version. Useful for dealing with NMS code or otherwise version dependent code.- Returns:
- The non-null weapon compatibility version.
-