DeveloperAPI

General

First of all include CustomMobs to your Dependencies/Build-Path.

Note: CustomMobs needs to be loaded and enabled before the API can be used properly.

Getting Access to the API

You may get access to the api with the plugin instance.

Plugin pl = Bukkit.getPluginManager().getPlugin("CustomMobs"); //Getting the plugin instance
if(pl == null) return; //Plugin not found/not installed...
CustomMobsPlugin plugin = (CustomMobsPlugin) pl;
CustomMobsAPI api = plugin.getAPI(); //Getting the API here~

That's basically it.

Functionaliy of the API

With the API you may:

  • Get a CustomMob-object by name
  • Create a new custommob with name and CustomMobType
  • Get access to the CustomMob-TypeRegistry
  • Get access to SpawnSettingsEditor (/cconfig-related stuff)
  • Get access to RespawnEditor (/crespawn stuff)
  • Get access to the SpawnerEditor (/cmob spawner stuff)
  • Get read-only access to the config
  • Get an ItemStack representation of the custommobs-tool
  • Try creating a custommob from a livingEntity.
  • Get File- and SessionEditor for a CustomMob

The ICustomMob

The Object that holds all relevant data of a custommob. Read-only.

You may get a custommob object with CustomMobsAPI.getCustomMob(String name) - which returns you a ICustomMob instance of the named mob.

There are currently (v3.0) 6 sub-interfaces such as ICustomSheep, ICustomSlime, ICustomSkeleton, ICustomWolf, ICustomPigZombie and ICustomCreeper which hold additional data about the specific mob-type.

ICustomMobEditor (File- and SessionEditor)

(nearly) All methods of the ICustomMobEditor return a MobFactoryCallback which holds the relevant data what went wrong or what happened when the method was executed. Personally i'd recommend the implementation of each case if used, however no method may return every possible callback. For example .setFireProof may only return SUCCESS, MOB_DOESNT_EXIST and IO_EXCEPTION. But however i recommend the implementation of each case statement even if it's sometimes not needed/useless.

There are 2 implementations of the CustomMobEditor.

One is the SessionEditor. This editor only changes the mob's data in the current session and not permanently. If a player edits a custommob via command or the FileEditor changes a mob's data, the session will be flushed and recreated which causes a loss to all session-relevant data. Remember that!

The other editor is the FileEditor. Changes made with the FileEditor will be instantly written to the file and will cause a reload of all mobdata to secure 100% up-to-date mobs. Also the current Session will be flushed and recreated.

CustomMobTypeRegistry

With the CustomMobTypeRegistry you can add new CustomMobTypes or get CustomMobTypes by name or EntityType.

If you want to add a new customMobType you'll have to implement the ICustomMobType interface.

You then may register your new mobtype with ICustomMobTypeRegistry.registerNewEntityType(ICustomMobType); The method returns true, if the mobtype wasn't present yet and was successfully added.

SpawnSettingsEditor

With the SpawnSettingsEditor you may do nearly exactly the same as with the /cconfig add and /cconfig remove commands.

To create new ISpawnSettings you have to use the Builder which you get with ISpawnSettingsEditor.newSpawnSettingsBuilder() - The builder itself is pretty straight-forward so i guess no detailed explanation is required here, since it's the same as the /cconfig add command only "code-side"

SpawnerEditor

With the SpawnerEditor you may set or reset a spawner. Its functionality is fully straightforward and doesn't need explanation i think.

Events

CustomMobSpawnEvent

@EventHandler
public void onCmobSpawn(CustomMobSpawnEvent event) {
    ICustomMob mob = event.getSpawned(); //The ICustomMob that spawned.
    LivingEntity entity = event.getEntity(); //The LivingEntity instance that was spawned.
    CustomMobSpawnEvent.SpawnReason reason = event.getReason(); //Specific reason why the mob was spawned
    if(reason.equals(SpawnReason.SPAWNER) {
        Block spawner = event.getSpawner(); //Is only defined when the spawnReason is SPAWNER.
    }
}

CustomMobDeathEvent

Is only fired, when a CustomMob gets killed by a player.

@EventHandler
public void onCmobDeath(CustomMobDeathEvent event) {
    ICustomMob mob = event.getMob(); //The ICustomMob that was killed.
    Player killer = event.getKiller(); //The Player that killed the CustomMob
}

Comments

Posts Quoted:
Reply
Clear All Quotes