iDisguise

MainCommands & PermissionsConfigurationAPI

API

Since the last API rework included in version 2.1.3, there have been a lot more changes to the API. This page shows some basic information on how to use the API. You can find a lot more information in the java documenation:

Don't forget to add depend: iDisguise or softdepend: iDisguise to your plugin.yml.

Since 5.1.1

Creating disguises:

MobtypeCode
player
new PlayerDisguise("Notch", false)
ghost
new PlayerDisguise("Notch", true)
all other mobs
DisguiseType.<your_mobtype>.newInstance()

Example:

import org.bukkit.GameMode;
import org.bukkit.DyeColor;
import org.bukkit.event.*;
import org.bukkit.event.player.*;
import org.bukkit.plugin.java.JavaPlugin;
import de.robingrether.idisguise.api.*;
import de.robingrether.idisguise.disguise.*;

public class MyPlugin extends JavaPlugin implements Listener {
    
    private DisguiseAPI api;
    
    public void onEnable() {
        api = getServer().getServicesManager().getRegistration(DisguiseAPI.class).getProvider();
        getServer().getPluginManager().registerEvents(this, this);
    }
    
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        if(api.isDisguised(event.getPlayer())) {
            api.undisguise(event.getPlayer());
            event.getPlayer().sendMessage("You were undisguised");
        }
    }
    
    // Whenever a player leaves a bed, he is disguised as a black sheep
    @EventHandler
    public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
        SheepDisguise disguise = (SheepDisguise)DisguiseType.SHEEP.newInstance(); // creating a new instance
        disguise.setColor(DyeColor.BLACK); // the sheep will be black
        disguise.setAdult(false); // the sheep will be a baby
        api.disguise(event.getPlayer(), disguise); // apply the disguise
        event.getPlayer().sendMessage("You were disguised!"); // send a message to the player
    }

    @EventHandler
    public void onUndisguise(UndisguiseEvent event) {
        if(!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
            event.setCancelled(true);
            event.getPlayer().sendMessage("You mustn't undisguise in survival or adventure mode!");
        }
    }
    
}

Up to 5.0.4

Creating disguises:

A few people have been wondering how to create instances of Disguise.class and its child classes, so here is a list now:

MobtypeCode
bat
new MobDisguise(DisguiseType.BAT)
blaze
new MobDisguise(DisguiseType.BLAZE)
creeper
new CreeperDisguise()
enderman
new EndermanDisguise()
guardian
new GuardianDisguise()
horse
new HorseDisguise()
magma_cube
new SizedDisguise(DisguiseType.MAGMA_CUBE)
ocelot
new OcelotDisguise()
pig
new PigDisguise()
rabbit
new RabbitDisguise()
sheep
new ColoredDisguise(DisguiseType.SHEEP)
slime
new SizedDisguise(DisguiseType.SLIME)
skeleton
new SkeletonDisguise()
villager
new VillagerDisguise()
wolf
new WolfDisguise()
zombie
new ZombieDisguise()
player
new PlayerDisguise("Notch", false)
ghost
new PlayerDisguise("Notch", true)

Example:

import org.bukkit.GameMode;
import org.bukkit.DyeColor;
import org.bukkit.event.*;
import org.bukkit.event.player.*;
import org.bukkit.plugin.java.JavaPlugin;
import de.robingrether.idisguise.api.*;
import de.robingrether.idisguise.disguise.*;

public class MyPlugin extends JavaPlugin implements Listener {
    
    private DisguiseAPI api;
    
    public void onEnable() {
        api = getServer().getServicesManager().getRegistration(DisguiseAPI.class).getProvider();
        getServer().getPluginManager().registerEvents(this, this);
    }
    
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        if(api.isDisguised(event.getPlayer)) {
            api.undisguiseToAll(event.getPlayer());
            event.getPlayer().sendMessage("You were undisguised");
        }
    }
    
    // Whenever a player leaves a bed, he is disguised as a green sheep
    @EventHandler
    public void onPlayerBedLeave(PlayerBedLeaveEvent event) {
        api.disguiseToAll(event.getPlayer(), new ColoredDisguise(DisguiseType.SHEEP, true, DyeColor.GREEN));
        event.getPlayer().sendMessage("You were disguised!");
    }

    @EventHandler
    public void onUndisguise(UndisguiseEvent event) {
        if(!event.getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
            event.setCancelled(true);
            event.getPlayer().sendMessage("You mustn't undisguise in survival or adventure mode!");
        }
    }
    
}

Please post your comments on the main page.

Facts

Date created
Jan 10, 2013
Last updated
Jun 20, 2016

Author