Skip to content

QualityArmory API

Lorenzo edited this page Nov 3, 2021 · 2 revisions

QualityArmory API methods

All API methods are located in the me.zombie_striker.qa.QualityArmory class. With this API, you can:

  • Create new Guns, Ammo, or misc items
  • Get Gun instances to modify
  • Determine if an itemstack is a gun
  • Get the ItemStack instances of guns

isGun/isAmmo/isMisc

Returns whether an ItemStack is a Gun, is an ammo type, or is a misc item.

getGun /getAmmo/getMisc

Returns the Gun/Ammo/ArmroyObject instance for an itemstack. Returns null if the itemstack is not a custom item

getGunItemStack

Using Material and Data values, this method returns an an ItemStack for the gun. Useful if you need to convert an gun back to it's initial state

getAmmoItemStack

Using Material and Data values, this method returns an an ItemStack for the ammo. Useful if you need to convert ammo back to it's initial state

getSkullAmmoItemStack

Using Material and Data values, this method returns an an ItemStack for the gun. Useful if you need to convert a skull that represents ammo back to it's initial state

getAllAmmoTypes

Returns all Ammo types currently registered.

getAllGunTypes

Returns all Guntypes currently registered.

createSimpleGun

Creates a gun.

  • 'name' represents the internal name for the gun.
  • 'mat' represents the material used for the gun
  • 'data' represents the data value used for the item. If the material cannot support multiple data values, set this to 0 and call "setVariant" on the gun instance to differentiate the gun from the base-minecraft item.
  • 'type' represents the WeaponType for the gun. This is useful for categorizing all of the items.
  • 'hasIronSights' represents whether the item should be moved to the offhand when the player aims. Useful if the item has a model that aims down the sights.
  • 'ammoType' represents the ammo type used. This can either be a String or an ammo instance.
  • 'acc' represents the default accuracy for the weapon. Default is 0.3
  • 'swayMultiplier' represents the multiplier applied to the weapon if the player is moving
  • 'maxBullets' represents the maximum bullets the gun can hold on reload.
  • 'damage' represents the damage applied to the target when shot.
  • 'isAutomatic' determines if the gun can go into automatic mode (where shifting+left-click will keep shooting until the player unshifts)
  • 'gunDurability' represents the durability for the gun. Can be any value if you are not using the weapon-degradation system
  • 'cost' represents the cost of the gun in the shot
  • 'sound' represents the sound that will be used when the gun is fired.

QualityArmory ChargingHandlers and ReloadingHandlers

QualityArmroy has ChargingHandlers and ReloadingHandlers, which allow plugin creators to have more control over what the gun does.

Charging Handlers

In this example, this ChargingHandler is used to play custom sounds or apply custom effects when the gun is fired. Here is an example class: `

public class PartyCharger implements ChargingHandler {

public PartyCharger() {
	ChargingManager.add(this);
}

@Override
public boolean isCharging(Player player) {
	return false;
	// represents if the code is currently active.
}

@Override
public boolean shoot(Gun g, final Player player, ItemStack stack) {
	player.playEffect(player.getEyeLocation(), Effect.FIREWORK_SHOOT, 0);
	return false;
	// This return false represents if the code should use the default shooting
	// system. If set to true, QA will not use the default shooting system.
}

@Override
public String getName() {
	return "PartyCharger";
}

}` After this, all that is needed is for 'new PartyCharger' to be called in the onLoad() and all guns with this charger will now play the firework shoot event when the player shoots.

ReloadingHandler

ReloadingHandlers are similar to chargingHandlers.

In this example, this ReloadingHandler will play a sound for every time a bullet needs to be reloaded, and will modify the time needed to reload based on this amount: `public class SingleBulletReloader implements ReloadingHandler {

List<UUID> timeR = new ArrayList<>();

public SingleBulletReloader() {
	ReloadingManager.add(this);
}

@Override
public boolean isReloading(Player player) {
	return timeR.contains(player.getUniqueId());
            //returns if the gun is currently reloading
}

@Override
public double reload(final Player player, Gun g, int amountReloading) {
	double time = ((double) g.getReloadTime()) / g.getMaxBullets();
	double time2 = time * amountReloading;
            //calculate the time needed to reload
	for (int i = 0; i < amountReloading; i++) {
		new BukkitRunnable() {
			@Override
			public void run() {
					player.getWorld().playSound(player.getLocation(), WeaponSounds.RELOAD_BULLET.getName(), 1, 1f);

			}
		}.runTaskLater(Main.getInstance(), (int) (time * i * 20));
	}
	new BukkitRunnable() {
		@Override
		public void run() {
			timeR.remove(player.getUniqueId());

		}
	}.runTaskLater(Main.getInstance(), (int) (time2 * 20) + 5);
	return time2;
            //returns the time needed to reload
}

@Override
public String getName() {

	return "ReloadIndividuallyCharger";
}

`