Developer API
This page should give you the basics on obtaining and utilizing the DisguiseCraft API.
Prerequisites
Start off by downloading the latest version of DisguiseCraft. Then, you must add the .jar file to your project's build path. Also make sure to add "depend: [DisguiseCraft]" to your plugin.yml if your plugin needs DisguiseCraft on the server to run. If your DisguiseCraft support is optional, use "softdepend: [DisguiseCraft]" in your plugin.yml.
The API
Here we explain the basics behind the DisguiseCraft API class.
Obtaining the API
The API comes in the form of the DisguiseCraftAPI
class. You obtain it by calling the getAPI() static function in the DisguiseCraft
class.
Here's the recommended function for obtaining and keeping the API variable:
DisguiseCraftAPI dcAPI; public void setupDisguiseCraft() { dcAPI = DisguiseCraft.getAPI(); }
To use it, you just run setupDisguiseCraft() in your onEnable() method.
Using the API
The API contains methods which allow you to obtain and set disguises. We will go over some important ones.
isDisguised(Player player)
This boolean function returns whether or not a player is disguised.
Example usage:
if (dcAPI.isDisguised(player)) { System.out.println(player.getName() + " is disguised!"); } else { System.out.println(player.getName() + " is not disguised!"); }
getDisguise(Player player)
Once you've confirmed that a player is disguised, you can obtain the Disguise
object by using this function.
disguisePlayer(Player player, Disguise disguise)
If a player is not yet disguised, you can disguise him using this function.
A boolean return allows you to tell if the player was disguised. (false means the disguise was cancelled)
changePlayerDisguise(Player player, Disguise newDisguise)
If a player is disguised already, you disguise them using this function.
A boolean return allows you to tell if the player was disguised. (false means the disguise was cancelled)
undisguisePlayer(Player player)
This function allows you to undisguise a disguise player.
A boolean return allows you to tell if the player was undisguised. (false means the undisguise was cancelled)
Disguises
All disguises are represented by the Disguise
class.
There are many packet functions in this class. Unless you know what you are doing, we ask that you avoid using these functions as improper packet creation can crash clients.
Creating a disguise
To create a disguise, you use one of the Disguise
class's constructors.
Mobs
For example, to create a simple mob disguise:
new Disguise(dcAPI.newEntityID(), DisguiseType.Cow)
Players
Player disguises have the players name as the first value of their metadata LinkedList.
This will create a disguise for a player named "PlayerName":
new Disguise(dcAPI.newEntityID(), "PlayerName", DisguiseType.Player);
Notice that we've used the API's newEntityID() function. This gives us a fresh entity ID that shouldn't interfere with other disguises or mobs on the client's end.
Editing a disguise
If a player is already disguised, it is better to clone and edit the disguise than construct a new one.
All the .set methods return the disguise to allow for chaining.
clone()
This function will give you a carbon copy of the Disguise
object that you can freely edit before applying to a player.
isPlayer()
This boolean function allows you to know whether or not a disguise is of another player.
The player's name is stored in the first String of the "data" LinkedList<String>.
setSingleData(String data)
If the disguise is of a player, it is useful to use this method in order to change the name.
setMob(MobType mob)
This method allows you to set the type of mob the Disguise is.
Events
Custom events from DisguiseCraft are handled just like any other event in Bukkit. You create an event-handler which accepts the proper event as an input. There are three basic, cancellable events thrown by DisguiseCraft: Command, Disguise, Undisguise
DCCommandEvent
This event is triggered whenever someone uses a DisguiseCraft command. (e.g. /d Wolf, /undisguise)
When cancelled, the command is not sent to DisguiseCraft's command parser and any output is handled elsewhere.
PlayerDisguiseEvent
This event is triggered whenever a player is to disguise. It is also triggered when a plugin attempts to disguise a player through the API or when a player has successfully used the disguise command.
Cancelling this event prevents the disguising of the player.
PlayerUndisguiseEvent
This event is triggered whenever a player is to be undisguised. However, it is not called when a player is undisguised for leaving the server.
Cancelling this event will prevent the player's undisguise.
Useful Links
- DisguiseCraft JavaDocs <== Always points to the latest generated
- Bukkit JavaDocs
Maven Integreation
If you use maven, here's a link to our Maven repository: http://build.yu8.me:8080/plugin/repository/everything/
Still Need Help?
You'll likely be able to find one of DisguiseCraft's developers in this IRC channel: irc://irc.mibbit.com/pinoygamers
We'd be glad to help you get DisguiseCraft integration working in your plugin.
When a disguised player dies, which event is thrown? EntityDeathEvent or PlayerDeathEvent?
how do u guys do it?
@ZeusAllMighty11
PlayerDeathEvent
This is really awesome, but i have a wierd problem. I submitted a ticket and i hope you can help me :)
Might sound nooby, but is there a way to create a named disguise? Not just a player, but like a villager with a name tag?
How do you put a nametag above a disquise player?
Hi, does anyone know how to disguise another player as a wither skeleton? There doesn't seem to be a subType method, and I can't seem to figure out how to do it. I know it's a skeleton then set as a wither, but how would I do that? :s Thanks!
adding the name on top of the head? plz help DisguiseCraft.getAPI().disguisePlayer((Player) player, new Disguise(dcAPI.newEntityID(), player.getName(), DisguiseType.Cow));
Thanks! :)