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.
@lordecho
He'd have to edit the source directly...
Using the API alone wouldn't give him the CommandHandler class. Writing that up himself would be a pain.
I'm probably missing it, but how do you find out if a mob u hit is actually a player?
Edit:
Never mind i was right it was right below.... i was using EntityDamageEvent not EntityDamgeByEntity....
@Bimmr
Yea it usually involves checking for an instanceof Player
Do you know if the api starts to bug out after like 5 reloads? because before i reload when a player attacks a player in disguise it'll trigger the playerdamagebyentity event, but after about the 5th reload it doesn't. And i am undisguiseing the player before each reload
@Bimmr
DisguiseCraft isn't reload friendly o.o
It needs a full server restart :/
This is because we need to keep in-sync with the data we store client-side.
@Devil_Boy
That would explain it :P but ya i guess that makes sense
@Bimmr
I guess it's only somewhat reload-friendly as long as nobody is disguised. We don't really know though O.o
I get an error trying to set the thing up!
Caused by: java.lang.ClassNotFoundException: pgDev.bukkit.DisguiseCraft.Disguise Craft Seems like it doesn't find the class!
I think I have it set up correctly :/ Le Picture
@Linus371
Do you have "depend: [DisguiseCraft]" in your plugin.yml ?
@Devil_Boy
Oh, right. Forgot about that. Will try when I get home from school.
@Linus371
Alright XD
Using "depend:" or "soeftdepend:" makes it so that DisguiseCraft is loaded up before your plugin.
I'm getting this error: 2:43:56 PM [SEVERE] Could not pass event PlayerInteractEvent to VampiresPlus v0.1 org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462) at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:177) at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:147) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:620) at net.minecraft.server.Packet15Place.handle(SourceFile:58) at net.minecraft.server.NetworkManager.b(NetworkManager.java:282) at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111) at net.minecraft.server.ServerConnection.b(SourceFile:35) at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30) at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:569) at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:215) at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:486) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:419) at net.minecraft.server.ThreadServerApplication.run(SourceFile:818) Caused by: java.lang.NullPointerException at me.braeden_mollot.vampiresplus.VampiresPlus.onPlayerInteractEvent(VampiresPlus.java:126) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339) ... 16 more
Line 126 of my plugin: if(event.getItem().getType().equals(Material.FERMENTED_SPIDER_EYE)){ Disguise bat=new Disguise(dcAPI.newEntityID(), MobType.Bat);<-line 126 if(dcAPI.isDisguised(p)) dcAPI.undisguisePlayer(p);p.sendMessage("You have changed to your human form."); if(!dcAPI.isDisguised(p)) dcAPI.disguisePlayer(p, bat);p.sendMessage("You have changed to your bat form."); }
@hoohoo4
I need to see more of the code around it and with better formatting :x
@Devil_Boy
The formatting is a bit difficult on my pc for some reason, so here is a pastebin of the entire event: Link
Currently using the DisguiseCraft API with some problems : Everything is working fine except that : Two teams are fighting ( I disguise players from each team ), when someone got killed he respawn, then this player ( still disguise for other players ) can't see anyone except by disconnect/reconnect so he can't continue to play. ( Other Players still see him. ) Any errors, nothing special in game. Any Idea ?
CraftBukkit 1.3.2 R3.0, it do the same with disguisecraft 1.4 and 1.3
@hoohoo4
Did you make sure that the "dcAPI" variable is set?
@Misterx38
I believe I've heard of this issue before. Reports say that it typically happens if the person is using a slow computer or is using Optifine or certain mods. I don't believe it is something within the DisguiseCraft system causing it, because DisguiseCraft no longer hooks into the packet reception part of CraftBukkit. (ProtocolLib does it for us)
@Devil_Boy We don't use any mods on our tests, it seem that every time someone respawn after be killed stop seeing other disguises. On the game end ( remember it's a fighting game ) all players will undisguise correctly and players who got killed will start to see other players again. That could be a ProtocolLib problem ?
@Misterx38
It very well could, but I really have no idea. It's an issue that I'd need to get more reports from different people about. It's hard to pinpoint certain issues...
@Devil_Boy: I tried with a lot of players and the problem occurs every time, event with fast computer ect. I can show you that problem in-game if you want.
@Misterx38
I suppose it could be temporarily patched, by a plugin that implements the DisguiseCraft API. If you happen to be a coder, just PM me and I can tell you what you want to try. For now, I'm just too busy with college.