API

MegaCreeps now comes with an API.

Events

In order to use events fired from MegaCreeps, you need a class to implement "MegaCreepsInterface" and register it to the running MegaCreeps plugin. I assume everyone using this is already familiar with hooking in bukkit. Requires at least soft dependency.

An example on how to do this:

private boolean setupMCHook(){

		Plugin p=getServer().getPluginManager().getPlugin("MegaCreeps");

		if (p!=null){
			if (p instanceof Main){
				((Main) p).getAPI().registerModSetupLevel(new Megacreepmod(), "elite");
			}
		}

		return p!=null;
	}

List of possible registrations

  • registerHandleDeathEvent(MegaCreepsInterface mci, String world)
  • registerModSetupLevel(MegaCreepsInterface mci,String world)
  • registerModSetup(MegaCreepsInterface mci,String world)
  • registerHandleSpawnEvent(MegaCreepsInterface mci, String world)
  • registerAllEvents(MegaCreepsInterface mci, String world)

Your own MegaCreepsInterface

Methods:

  • handleDeathEvent(MegaCreepInstance m, EntityDeathEvent e)
  • modSetupLevel(CreatureSpawnEvent e, int oldlevel) Runs before registerModSetup
  • modSetup(CreatureSpawnEvent e, MegaCreepSetup oldsetup) Runs before registerHandleSpawnEvent.
  • handleSpawnEvent(MegaCreepInstance m) Runs after a MegaCreep has been created

These methods are the counterparts to the registrations and should be self-explaining. If you don't want to modify the outcome, just return the oldlevel/oldsetup.

API functions

		Plugin p=getServer().getPluginManager().getPlugin("MegaCreeps");

		if (p!=null){
			if (p instanceof Main){
				MegaCreepsAPI mcapi=(Main) p).getAPI();
			}
		}

You can get an Instance of the API to directly access a number of functions that I designed for easier use. If you want to use the public functions of any other MegaCreeps class, do that at your own risk, I won't support it.

Methods:

MegaCreepSetup getRandomCreepByLevel(String world,EntityType e,int i)

Returns a random setup from the ones that are given for the specified world, the specified entitytype and a specified level. Returns null if no matches were found.

int getRandomLevel(String world)

Gets a random level, given the specifications for the world in the config. Returns 0 if none could be found or none are defined.

MegaCreepSetup createSetup(List<String> names,EntityType e,int creatureRating, String setupname)

Creates a setup with the given parameters. Just in case you want to create them out of source code.

MegaCreepSetup getSetup(String setupname)

Returns the setup with the given setupname. Returns null if no such setup could be found in the loaded list.

void addSetup(String name, MegaCreepSetup m)

Add a setup to the main list. It can be accessed during runtime. If you want to use it again after a restart or reload, you should add it to the config.

addSetupToConfig(String setupname)

Attempts to add the given setup to the "general" section of the config.

boolean contains(Entity e)

Checks whether the given entity is listed as a MegaCreep.

MegaCreepInstance getMegaCreep(Entity e)

Gets the related MegaCreepInstance to this entity.

void removeMob(Entity e)

Kicks this entity out of the MegaCreeps' entity list. It won't be taken into calculation any longer.

MegaCreepInstance spawnMob(Location l,String setup)

Creates a MegaCreep at the given location and applies the given setup to it.