QualityArmory API
The me.zombie_striker.qg.api.QualityArmory class provides static methods for interacting with the QualityArmory plugin, allowing other plugins to access information about guns, ammo, armor, and miscellaneous items, as well as perform actions like giving items or checking player states.
Core Item Management & Creation
createAndLoadNewGun(String name, String displayname, Material material, int id, WeaponType type, WeaponSounds sound, boolean hasIronSights, String ammotype, int damage, int maxBullets, int cost)Description: Creates a new gun configuration file (
.yml) in theplugins/QualityArmory/newGuns/directory and immediately attempts to load it into the running server.Parameters:
name: Internal name for the gun (used in commands).displayname: In-game display name (supports color codes).material: BaseMaterialfor the item.id: CustomModelData (1.14+) or Durability (<1.14) value.type: TheWeaponTypeenum value (e.g.,PISTOL,RIFLE).sound: TheWeaponSoundsenum value for firing.hasIronSights:trueif the gun should support aiming down sights.ammotype: Internal name of the requiredAmmoitem.damage: Base damage per bullet.maxBullets: Magazine capacity.cost: Price in the/qa shop.
Returns: A
GunYMLobject representing the created configuration (allows further modification before saving, though this method saves immediately).Note: Creates a file and schedules a task to load it.
createNewGunYML(String name, String displayname, Material material, int id, WeaponType type, WeaponSounds sound, boolean hasIronSights, String ammotype, int damage, int maxBullets, int cost)Description: Creates a
GunYMLobject representing a new gun configuration but does not automatically save or load it. You would need to call methods on the returnedGunYMLobject to save it.Parameters: Same as
createAndLoadNewGun.Returns: A
GunYMLobject representing the potential configuration.
registerNewUsedExpansionItem(Material used, int id)Description: Registers a specific Material/ID combination as being used by an expansion pack or addon. This helps prevent ID conflicts when QualityArmory searches for available IDs. Assumes variant 0.
Parameters:
used: TheMaterialused by the expansion item.id: The CustomModelData/Durability value used.
registerNewUsedExpansionItem(Material used, int id, int var)Description: Registers a specific Material/ID/Variant combination as being used by an expansion pack or addon.
Parameters:
used: TheMaterialused by the expansion item.id: The CustomModelData/Durability value used.var: The variant value used.
registerNewUsedExpansionItem(MaterialStorage ms)Description: Registers a
MaterialStorageobject (which encapsulates Material, ID, and Variant) as being used by an expansion pack or addon.Parameters:
ms: TheMaterialStorageobject representing the item.
Retrieving Registered Items
getGuns(): Returns anIterator<Gun>for all loaded guns.getAmmo(): Returns anIterator<Ammo>for all loaded ammo types.getMisc(): Returns anIterator<CustomBaseObject>for all loaded miscellaneous items (like medkits, ammo bags).getArmor(): Returns anIterator<ArmorObject>for all loaded armor pieces.getCustomItems(): Returns anIterator<CustomBaseObject>containing all loaded guns, ammo, armor, and misc items combined.getCustomItemsAsList(): Returns aList<CustomBaseObject>containing all loaded guns, ammo, armor, and misc items combined.getGun(ItemStack is): Returns theGunobject associated with the givenItemStack, ornullif it's not a QA gun.getAmmo(ItemStack is): Returns theAmmoobject associated with the givenItemStack, ornullif it's not QA ammo.getArmor(ItemStack is): Returns theArmorObjectassociated with the givenItemStack, ornullif it's not QA armor.getMisc(ItemStack is): Returns theCustomBaseObject(often castable to a specific type likeAmmoBag) associated with the givenItemStack, ornullif it's not a QA misc item.getCustomItem(ItemStack is): Returns theCustomBaseObject(Gun, Ammo, Armor, or Misc) associated with the givenItemStack, ornullif it's not a QA item.getCustomItem(Material material, int data, int variant): Returns theCustomBaseObjectmatching the specified Material, CustomModelData/Durability, and Variant, ornull.getCustomItem(MaterialStorage material): Returns theCustomBaseObjectmatching the specifiedMaterialStorage, ornull.getGunByName(String name): Returns theGunobject with the matching internal name, ornull.getAmmoByName(String name): Returns theAmmoobject with the matching internal name, ornull.getArmorByName(String name): Returns theArmorObjectwith the matching internal name, ornull.getMiscByName(String name): Returns theCustomBaseObject(Misc) with the matching internal name, ornull.getCustomItemByName(String name): Returns theCustomBaseObject(any type) with the matching internal name, ornull.getGunInHand(@NotNull HumanEntity entity): Returns theGunthe player is effectively holding (checks main hand and off-hand for iron sights), ornull.
Checking Item Types
isCustomItem(ItemStack is): Returnstrueif theItemStackis any registered QA item (Gun, Ammo, Armor, Misc, or registered Expansion item).isCustomItem(ItemStack is, int dataOffset): Checks if the item would be a custom item if its CustomModelData/Durability were offset bydataOffset. Useful for checking durability changes.isCustomItemNextId(ItemStack is): Checks if an item with the next sequential CustomModelData/Durability value (same material) is a registered QA item.isGun(ItemStack is): Returnstrueif theItemStackis a registered QA gun.isAmmo(ItemStack is): Returnstrueif theItemStackis a registered QA ammo type.isArmor(ItemStack is): Returnstrueif theItemStackis a registered QA armor piece.isMisc(ItemStack is): Returnstrueif theItemStackis a registered QA miscellaneous item.isAmmoBag(ItemStack is): Returnstrueif theItemStackis a registered QA miscellaneous item that is specifically anAmmoBag.isIronSights(ItemStack is): Returnstrueif theItemStackrepresents the temporary item shown when aiming down sights.
Player Interaction & State
sendResourcepack(final Player player, final boolean warning)Description: Sends the appropriate server resource pack to the player after a configured delay (
SecondsTillRPIsSent). Uses the multi-version system if enabled.Parameters:
player: The player to send the pack to.warning: Iftrue, sends warning messages/titles before sending the pack prompt.
Note: Schedules tasks. Relies on
config.ymlsettings for URLs, delays, and behavior. Requires ViaVersion for version detection ifAuto-Detect-Resourcepackis true.
allowGunsInRegion(Location loc)Description: Checks with the registered protection hooks (like WorldGuard) if PvP or gun usage is allowed at the specified location.
Parameters:
loc: TheLocationto check.
Returns:
trueif allowed,falseotherwise. Returnstrueif no protection hooks deny it or if hooks fail.
sendHotbarGunAmmoCount(final Player p, final CustomBaseObject gun, ItemStack usedItem, boolean reloading)Description: Sends the ammo count/status message above the player's hotbar. Uses the format defined in
config.yml.Parameters:
p: The player to send the message to.gun: TheGunorAttachmentBaseobject being used.usedItem: TheItemStackrepresenting the gun in the player's hand.reloading:trueif the player is currently reloading this weapon.
sendHotbarGunAmmoCount(final Player p, final CustomBaseObject gun, ItemStack usedItem, boolean reloading, int currentAmountInGun, int maxAmount)Description: Sends the ammo count/status message above the player's hotbar, allowing manual specification of current/max ammo (useful for custom reload handlers).
Parameters:
p: The player.gun: TheGunorAttachmentBase.usedItem: TheItemStack.reloading:trueif reloading.currentAmountInGun: The current ammo count to display.maxAmount: The maximum ammo capacity to display.
getAmmoInInventory(Player player, Ammo a)Description: Calculates the total amount of a specific
Ammotype the player has in their main inventory, including amounts stored inAmmoBagitems. Returns99999if the player is in Creative mode.Parameters:
player: The player whose inventory to check.a: TheAmmotype to count.
Returns: The total count of the specified ammo.
getAmmoInInventory(Player player, Ammo a, boolean ignoreBag)Description: Calculates the amount of a specific
Ammotype the player has. Can optionally ignore ammo bags.Parameters:
player: The player.a: TheAmmotype.ignoreBag: Iftrue, does not count ammo insideAmmoBagitems.
Returns: The total count of the specified ammo.
getAmmoInBag(@NotNull Player player, Ammo a)Description: Calculates the total amount of a specific
Ammotype stored only withinAmmoBagitems in the player's inventory.Parameters:
player: The player.a: TheAmmotype.
Returns: The total count within ammo bags.
addAmmoToInventory(Player player, Ammo a, int amount)Description: Attempts to add the specified amount of ammo to the player's inventory, stacking with existing ammo items first, then filling empty slots.
Parameters:
player: The player.a: TheAmmotype to add.amount: The quantity to add.
Returns:
trueif all ammo was successfully added,falseif there wasn't enough space.
removeAmmoFromInventory(Player player, Ammo a, int amount)Description: Attempts to remove the specified amount of ammo from the player's inventory, taking from main inventory stacks first, then from
AmmoBagitems if necessary. Does nothing if the player is in Creative mode.Parameters:
player: The player.a: TheAmmotype to remove.amount: The quantity to remove.
Returns:
trueif the specified amount was successfully removed,falseif the player didn't have enough ammo.
getBulletsInHand(Player player): Returns the current ammo count stored in the NBT data of the gun item the player is holding.isOverLimitForPrimaryWeapons(Gun g, Player p)Description: Checks if adding the specified gun (
g) would put the player (p) over the primary or secondary weapon limit configured inconfig.yml(if the limiter is enabled).Parameters:
g: TheGunbeing checked.p: The player.
Returns:
trueif the player is already at or above the limit for that weapon type (primary/secondary),falseotherwise.
giveOrDrop(HumanEntity entity, ItemStack item)Description: Gives the specified
ItemStackto the entity. If their inventory is full, drops the item at their location instead.Parameters:
entity: TheHumanEntity(usually aPlayer) to give the item to.item: TheItemStackto give.
Item & Utility Methods
getCustomItemAsItemStack(String name): Retrieves aCustomBaseObjectby its internal name and returns a freshItemStackrepresentation of it.getCustomItemAsItemStack(CustomBaseObject obj): Returns a freshItemStackrepresentation of the givenCustomBaseObject. Returnsnullif the input object isnull.getIronSightsItemStack(): Returns the specificItemStackused to represent the aiming-down-sights view.findSafeSpot(ItemStack newItem, boolean findHighest, boolean allowPockets): Searches for an unused CustomModelData/Durability value for the given item's Material, starting from the item's current value and searching up (findHighest = true) or down (findHighest = false).allowPocketsdetermines if it searches for any gap or just the absolute highest/lowest used ID. Primarily for internal use or advanced item creation.findSafeSpot(Material newItemtype, int startingData, boolean findHighest, boolean allowPockets): Same as above, but takes Material and starting data directly.findSafeSpotVariant(ItemStack newItem, boolean findHighest): Searches for an unused Variant value for the given item's Material and CustomModelData/Durability, starting from 0 and searching up (findHighest = true) or down (findHighest = false).findSafeSpotVariant(Material newItemtype, int startingData, boolean findHighest): Same as above, but takes Material and data directly.getMaxPagesForGUI(): Calculates the number of pages needed to display all registered QA items in the default shop/GUI layout (5 rows of 9 items per page).repeat(String string, int times): A simple utility method to repeat a given string multiple times. Used internally for formatting reload progress bars.
Last updated
Was this helpful?