Read desc
Now use Entitys completely for the disguising. Now removes the disguise when the entity isn't valid. Deprecated the methods using a object. Added methods to set and get velocity - If packets should be sent.
This commit is contained in:
		@@ -6,6 +6,7 @@ import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
public class UndisguiseCommand implements CommandExecutor {
 | 
			
		||||
@@ -17,7 +18,7 @@ public class UndisguiseCommand implements CommandExecutor {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.undisguise")) {
 | 
			
		||||
            if (DisguiseAPI.isDisguised(sender.getName())) {
 | 
			
		||||
            if (DisguiseAPI.isDisguised((Entity) sender)) {
 | 
			
		||||
                DisguiseAPI.undisguiseToAll((Player) sender);
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You are no longer disguised");
 | 
			
		||||
            } else
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ public class UndisguisePlayerCommand implements CommandExecutor {
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                Player p = Bukkit.getPlayer(args[0]);
 | 
			
		||||
                if (p != null) {
 | 
			
		||||
                    if (DisguiseAPI.isDisguised(p.getName())) {
 | 
			
		||||
                    if (DisguiseAPI.isDisguised(p)) {
 | 
			
		||||
                        DisguiseAPI.undisguiseToAll(p);
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "He is no longer disguised");
 | 
			
		||||
                    } else
 | 
			
		||||
 
 | 
			
		||||
@@ -31,18 +31,19 @@ import com.comphenix.protocol.reflect.StructureModifier;
 | 
			
		||||
 | 
			
		||||
public class DisguiseAPI {
 | 
			
		||||
 | 
			
		||||
    private static HashMap<Object, Disguise> disguises = new HashMap<Object, Disguise>();
 | 
			
		||||
    private static HashMap<Entity, Disguise> disguises = new HashMap<Entity, Disguise>();
 | 
			
		||||
    private static PacketListener packetListener;
 | 
			
		||||
    private static JavaPlugin plugin;
 | 
			
		||||
    private static boolean sendVelocity;
 | 
			
		||||
    private static boolean soundsEnabled;
 | 
			
		||||
 | 
			
		||||
    private synchronized static Disguise access(Object obj, Disguise... object) {
 | 
			
		||||
        if (object.length == 0)
 | 
			
		||||
            return disguises.get(obj);
 | 
			
		||||
        if (object[0] == null)
 | 
			
		||||
            disguises.remove(obj);
 | 
			
		||||
    private synchronized static Disguise access(Entity entity, Disguise... args) {
 | 
			
		||||
        if (args.length == 0)
 | 
			
		||||
            return disguises.get(entity);
 | 
			
		||||
        if (args[0] == null)
 | 
			
		||||
            disguises.remove(entity);
 | 
			
		||||
        else
 | 
			
		||||
            disguises.put(obj, object[0]);
 | 
			
		||||
            disguises.put(entity, args[0]);
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -57,8 +58,11 @@ public class DisguiseAPI {
 | 
			
		||||
            return;
 | 
			
		||||
        if (disguise.getWatcher() != null)
 | 
			
		||||
            disguise = disguise.clone();
 | 
			
		||||
        put(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId(), disguise);
 | 
			
		||||
        disguise.constructWatcher(entity.getType(), entity.getEntityId());
 | 
			
		||||
        Disguise oldDisguise = getDisguise(entity);
 | 
			
		||||
        if (oldDisguise != null)
 | 
			
		||||
            oldDisguise.getScheduler().cancel();
 | 
			
		||||
        put(entity, disguise);
 | 
			
		||||
        disguise.constructWatcher(plugin, entity);
 | 
			
		||||
        refresh(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -73,7 +77,7 @@ public class DisguiseAPI {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Disguise get(Object obj) {
 | 
			
		||||
    private static Disguise get(Entity obj) {
 | 
			
		||||
        return access(obj);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -81,16 +85,15 @@ public class DisguiseAPI {
 | 
			
		||||
     * @param Disguiser
 | 
			
		||||
     * @return Disguise
 | 
			
		||||
     */
 | 
			
		||||
    public static Disguise getDisguise(Object disguiser) {
 | 
			
		||||
        if (disguiser instanceof Entity) {
 | 
			
		||||
            if (disguiser instanceof Player)
 | 
			
		||||
                return get(((Player) disguiser).getName());
 | 
			
		||||
            else
 | 
			
		||||
                return get(((Entity) disguiser).getUniqueId());
 | 
			
		||||
        }
 | 
			
		||||
    public static Disguise getDisguise(Entity disguiser) {
 | 
			
		||||
        return get(disguiser);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static Disguise getDisguise(Object disguiser) {
 | 
			
		||||
        return get((Entity) disguiser);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static void init(JavaPlugin mainPlugin) {
 | 
			
		||||
        plugin = mainPlugin;
 | 
			
		||||
        packetListener = new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL,
 | 
			
		||||
@@ -172,17 +175,20 @@ public class DisguiseAPI {
 | 
			
		||||
     * @param Disguiser
 | 
			
		||||
     * @return boolean - If the disguiser is disguised
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isDisguised(Object disguiser) {
 | 
			
		||||
        if (disguiser instanceof Entity) {
 | 
			
		||||
            if (disguiser instanceof Player)
 | 
			
		||||
                return get(((Player) disguiser).getName()) != null;
 | 
			
		||||
            else
 | 
			
		||||
                return get(((Entity) disguiser).getUniqueId()) != null;
 | 
			
		||||
        }
 | 
			
		||||
    public static boolean isDisguised(Entity disguiser) {
 | 
			
		||||
        return get(disguiser) != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void put(Object obj, Disguise disguise) {
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static boolean isDisguised(Object disguiser) {
 | 
			
		||||
        return get((Entity) disguiser) != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isVelocitySent() {
 | 
			
		||||
        return sendVelocity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void put(Entity obj, Disguise disguise) {
 | 
			
		||||
        access(obj, disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -204,12 +210,22 @@ public class DisguiseAPI {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setVelocitySent(boolean sendVelocityPackets) {
 | 
			
		||||
        sendVelocity = sendVelocityPackets;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @param Disguiser
 | 
			
		||||
     *            - Undisguises him
 | 
			
		||||
     */
 | 
			
		||||
    public static void undisguiseToAll(Entity entity) {
 | 
			
		||||
        put(entity instanceof Player ? ((Player) entity).getName() : entity.getUniqueId(), null);
 | 
			
		||||
        refresh(entity);
 | 
			
		||||
        Disguise disguise = getDisguise(entity);
 | 
			
		||||
        if (disguise == null)
 | 
			
		||||
            return;
 | 
			
		||||
        disguise.getScheduler().cancel();
 | 
			
		||||
        put(entity, null);
 | 
			
		||||
        if (entity.isValid()) {
 | 
			
		||||
            refresh(entity);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user