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.
Hello im sortof new to bukkit and java programming so there might be a stupid error in this, but when i try add in the isDisguised() method inside of onCommand() method it says internal error. This is my code:
if (cmd.getName().equalsIgnoreCase("slowfw")) { if (sender instanceof Player) {
Player player = (Player)sender;
Location loc = player.getTargetBlock(null,20).getLocation();
for(Player p: getServer().getOnlinePlayers()) {
if (dcAPI.isDisguised(p)) { <
-- When i add this in it stops workingLocation loc1 = loc;
Location loc2 = p.getLocation();
double dist = loc1.distance(loc2);
if (dist < 4) { code that shouldnt matter and i deleted } }
} return true;
} }
@funkiben
What is the error log?
@Devil_Boy Error log:
The plugin i am calling it in is called potionthrower
15:42:17 [INFO] funkiben issued server command: /slowfw 15:42:17 [SEVERE] null org.bukkit.command.CommandException: Unhandled exception executing command 'slowfw' in plugin PotionThrower v2.1 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:187) at org.bukkit.craftbukkit.v1_5_R1.CraftServer.dispatchCommand(CraftServer.java:523) at net.minecraft.server.v1_5_R1.PlayerConnection.handleCommand(PlayerConnection.java:967) at net.minecraft.server.v1_5_R1.PlayerConnection.chat(PlayerConnection.java:885) at net.minecraft.server.v1_5_R1.PlayerConnection.a(PlayerConnection.java:840) at net.minecraft.server.v1_5_R1.Packet3Chat.handle(Packet3Chat.java:44) at net.minecraft.server.v1_5_R1.NetworkManager.b(NetworkManager.java:292) at net.minecraft.server.v1_5_R1.PlayerConnection.d(PlayerConnection.java:113) at net.minecraft.server.v1_5_R1.ServerConnection.b(SourceFile:35) at net.minecraft.server.v1_5_R1.DedicatedServerConnection.b(SourceFile:30) at net.minecraft.server.v1_5_R1.MinecraftServer.r(MinecraftServer.java:580) at net.minecraft.server.v1_5_R1.DedicatedServer.r(DedicatedServer.java:225) at net.minecraft.server.v1_5_R1.MinecraftServer.q(MinecraftServer.java:476) at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:409) at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573) Caused by: java.lang.NullPointerException at com.funkiserver.PotionThrower.PotionThrower.onCommand(PotionThrower.java:242) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ... 15 more
@funkiben
Mind showing me the code where it says the NullPointerException is coming up in?
@Devil_Boy
Umm im not sure where its coming up, eclipse doesnt show any errors at all, in the code. All i no is that when i added if (dcAPI.isDisguised(player) to the code i posted below it errors
Nevermind i got it wasnt calling setupDisguiseCraft() in setup() :P Im such an idiot
@funkiben
Ah XD
All fixed now?
So i get this error:
19:39:59 [SEVERE] Error occurred while enabling DvZ v0.1 (Is it up to date?) java.lang.NoClassDefFoundError: net/minecraft/server/v1_5_R1/Packet
at com.shinxs.dvz.DvZ.setupDisguiseCraft(DvZ.java:40)
at com.shinxs.dvz.DvZ.onEnable(DvZ.java:25)
and i have did it all correcly and the softdepend and i added the .jar file to my server but it doesn't work
@Shinxs
Use the latest DisguiseCraft dev build.
@Devil_Boy
edit: I think I found the problem. You are not checking if a disguise was made by a Plugin in WorldChangeUpdater.
"Fixed it" by listening to PlayerUndisguiseEvent and canceling it. (Only when the Player is registred in my plugin of course)
Also is there a good way to reduce lag as 40 Disguised Players are lagging really bad
I tried working on the Permission problem some more. But adding something like that still does not fix it:They get teleported to a new world, but before they are disguised.
The only way to fix this that I'm aware of is by giving the Players permanent Permission using the yml file of the Permissions plugin(seems to happen with everyone).@And_S
Ah, yea keeping track of what makes what disguise didn't sound like a very good idea. So we had the PlayerUndisguiseEvent throw for world changes.
The more recent DisguiseCraft builds are supposed to have some speed improvements. Do you think you could supply me with some timings that I could work with?
New question:
I need to get when a Player rightclicks a disguised Player. But this code is not working:
edit: I just tested it and the event is never called. Is there an alternative?
@And_S
The PlayerInvalidInteractEvent is a custom event from DisguiseCraft/ProtocolLib that is called whenever a disguise is attacked.
How do i use subtypes? Such as disguising someone as a wither skeleton.
@funkiben
Yes I would also really need to able to disguise Players as a Wither Skeleton
I really need to make a entity desguised as another entity is it possible?
@funkiben
@And_S
A wither skeleton is a Skeleton with the subtype: "wither"
hi, is it possible to make a player disguised as a mob, and only a certain player can see it?
@michidk
Not really :/
And I don't think I'm going to implement that in the DisguiseCraft recode either.
I can't think of any good method to handle it efficiently...
Where I need to write this command?