Developer API

Developer API for your plugins


How it works

Before jumping into contributing or making your addon, you should be familiar with the "big" sections of WeaponMechanics.

Data Serialization

Instead of pulling values from a YamlConfiguration instance, WeaponMechanics stores a flattened Map<String, Object>, and each weapon uses probably 100 different "serializers." We coded these serializers to check for user errors, and to report them to the console immediately.

Projectiles

WeaponMechanics does not use Minecraft entities. Instead, we use "fake" ray-traced projectiles. When you use a disguise like a snowball or armor stand, WeaponMechanics spawns a fake entity using packets.

Weapon Handlers

The "big chunks of logic" are separated into handlers, like the ShootHandler and the ReloadHandler.


WeaponMechanicsAPI

The WeaponMechanicsAPI class is a list of easy-access examples. If you are looking for a specific method, try tracing the API calls to their source (This will help you find new methods).

Want a new API method added? Submit a feature request!

Checking if a Player is scoping/reloading/whatever

WeaponMechanics has player wrappers. Use WeaponMechanics.getEntityWrapper(entity) to get a wrapper. You probably want to get HandData (use IEntityWrapper#getMainHandData() and IEntityWrapper#getOffHandData()).

Generating/Giving weapon items

The InfoHandler handles weapon generation. Use WeaponMechanics.getWeaponHandler().getInfoHandler(). It can also be used to check if an existing ItemStack is a WeaponMechanics weapon.

Spawning Projectiles

Perhaps you want to spawn in a projectile after implementing your custom projectile or using one of the premade projectile classes. While you can create your own repeating task, this becomes messy. Instead, add projectiles to the ProjectilesRunnable instance (Use WeaponMechanics.getProjectilesRunnable()) then add projectiles through that.

Checking for block regeneration

You probably don't want to interfere with block regeneration when working in protected regions. Or perhaps you are implementing a feature that causes block damage and want to use WeaponMechanic's premade system. Either way, look at BlockDamageData.

Events

For the complete list of events, check out the events package. Most events inherit from the WeaponEvent class.

Last updated