Convert back to maven
This commit is contained in:
		
							
								
								
									
										534
									
								
								src/me/libraryaddict/disguise/DisguiseAPI.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										534
									
								
								src/me/libraryaddict/disguise/DisguiseAPI.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,534 @@
 | 
			
		||||
package me.libraryaddict.disguise;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.DyeColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.Horse;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.EntityEquipment;
 | 
			
		||||
import org.bukkit.inventory.HorseInventory;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.potion.PotionEffect;
 | 
			
		||||
import org.bukkit.potion.PotionEffectType;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class DisguiseAPI
 | 
			
		||||
{
 | 
			
		||||
    public static Disguise constructDisguise(Entity entity)
 | 
			
		||||
    {
 | 
			
		||||
        return constructDisguise(entity, true, true, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint)
 | 
			
		||||
    {
 | 
			
		||||
        DisguiseType disguiseType = DisguiseType.getType(entity);
 | 
			
		||||
        Disguise disguise;
 | 
			
		||||
 | 
			
		||||
        if (disguiseType.isMisc())
 | 
			
		||||
        {
 | 
			
		||||
            disguise = new MiscDisguise(disguiseType);
 | 
			
		||||
        }
 | 
			
		||||
        else if (disguiseType.isMob())
 | 
			
		||||
        {
 | 
			
		||||
            disguise = new MobDisguise(disguiseType);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            disguise = new PlayerDisguise(entity.getName());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        FlagWatcher watcher = disguise.getWatcher();
 | 
			
		||||
 | 
			
		||||
        if (entity instanceof LivingEntity)
 | 
			
		||||
        {
 | 
			
		||||
            for (PotionEffect effect : ((LivingEntity) entity).getActivePotionEffects())
 | 
			
		||||
            {
 | 
			
		||||
                ((LivingWatcher) watcher).addPotionEffect(effect.getType());
 | 
			
		||||
 | 
			
		||||
                if (effect.getType() == PotionEffectType.INVISIBILITY)
 | 
			
		||||
                {
 | 
			
		||||
                    watcher.setInvisible(true);
 | 
			
		||||
                }
 | 
			
		||||
                else if (effect.getType() == PotionEffectType.GLOWING)
 | 
			
		||||
                {
 | 
			
		||||
                    watcher.setGlowing(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (entity.getFireTicks() > 0)
 | 
			
		||||
        {
 | 
			
		||||
            watcher.setBurning(true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (doEquipment && entity instanceof LivingEntity)
 | 
			
		||||
        {
 | 
			
		||||
            EntityEquipment equip = ((LivingEntity) entity).getEquipment();
 | 
			
		||||
 | 
			
		||||
            watcher.setArmor(equip.getArmorContents());
 | 
			
		||||
            watcher.setItemInMainHand(equip.getItemInMainHand());
 | 
			
		||||
 | 
			
		||||
            if (disguiseType.getEntityType() == EntityType.HORSE)
 | 
			
		||||
            {
 | 
			
		||||
                Horse horse = (Horse) entity;
 | 
			
		||||
                HorseInventory horseInventory = horse.getInventory();
 | 
			
		||||
                ItemStack saddle = horseInventory.getSaddle();
 | 
			
		||||
 | 
			
		||||
                if (saddle != null && saddle.getType() == Material.SADDLE)
 | 
			
		||||
                {
 | 
			
		||||
                    ((HorseWatcher) watcher).setSaddled(true);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                ((HorseWatcher) watcher).setHorseArmor(horseInventory.getArmor());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (Method method : entity.getClass().getMethods())
 | 
			
		||||
        {
 | 
			
		||||
            if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting"))
 | 
			
		||||
                    && method.getParameterTypes().length == 0 && method.getReturnType() != void.class)
 | 
			
		||||
            {
 | 
			
		||||
                Class methodReturn = method.getReturnType();
 | 
			
		||||
 | 
			
		||||
                if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class)
 | 
			
		||||
                {
 | 
			
		||||
                    methodReturn = double.class;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                int firstCapitalMethod = firstCapital(method.getName());
 | 
			
		||||
 | 
			
		||||
                if (firstCapitalMethod > 0)
 | 
			
		||||
                {
 | 
			
		||||
                    for (Method watcherMethod : watcher.getClass().getMethods())
 | 
			
		||||
                    {
 | 
			
		||||
                        if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class
 | 
			
		||||
                                && watcherMethod.getParameterTypes().length == 1)
 | 
			
		||||
                        {
 | 
			
		||||
                            int firstCapitalWatcher = firstCapital(watcherMethod.getName());
 | 
			
		||||
 | 
			
		||||
                            if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
 | 
			
		||||
                                    .equalsIgnoreCase(watcherMethod.getName().substring(firstCapitalWatcher)))
 | 
			
		||||
                            {
 | 
			
		||||
                                Class methodParam = watcherMethod.getParameterTypes()[0];
 | 
			
		||||
 | 
			
		||||
                                if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class)
 | 
			
		||||
                                {
 | 
			
		||||
                                    methodParam = double.class;
 | 
			
		||||
                                }
 | 
			
		||||
                                else if (methodParam == AnimalColor.class)
 | 
			
		||||
                                {
 | 
			
		||||
                                    methodParam = DyeColor.class;
 | 
			
		||||
                                }
 | 
			
		||||
                                if (methodReturn == methodParam)
 | 
			
		||||
                                {
 | 
			
		||||
                                    try
 | 
			
		||||
                                    {
 | 
			
		||||
                                        Object value = method.invoke(entity);
 | 
			
		||||
                                        if (value != null)
 | 
			
		||||
                                        {
 | 
			
		||||
                                            Class toCast = watcherMethod.getParameterTypes()[0];
 | 
			
		||||
                                            if (!(toCast.isInstance(value)))
 | 
			
		||||
                                            {
 | 
			
		||||
                                                if (toCast == float.class)
 | 
			
		||||
                                                {
 | 
			
		||||
                                                    if (value instanceof Float)
 | 
			
		||||
                                                    {
 | 
			
		||||
                                                        value = value;
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                    else
 | 
			
		||||
                                                    {
 | 
			
		||||
                                                        double d = (Double) value;
 | 
			
		||||
                                                        value = (float) d;
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                }
 | 
			
		||||
                                                else if (toCast == double.class)
 | 
			
		||||
                                                {
 | 
			
		||||
                                                    if (!(value instanceof Double))
 | 
			
		||||
                                                    {
 | 
			
		||||
                                                        float d = (Float) value;
 | 
			
		||||
                                                        value = (double) d;
 | 
			
		||||
                                                    }
 | 
			
		||||
                                                }
 | 
			
		||||
                                                else if (toCast == AnimalColor.class)
 | 
			
		||||
                                                {
 | 
			
		||||
                                                    value = AnimalColor.valueOf(((DyeColor) value).name());
 | 
			
		||||
                                                }
 | 
			
		||||
                                            }
 | 
			
		||||
                                            if (value instanceof Boolean && !(Boolean) value
 | 
			
		||||
                                                    && watcherMethod.getDeclaringClass() == FlagWatcher.class)
 | 
			
		||||
                                            {
 | 
			
		||||
                                                continue;
 | 
			
		||||
                                            }
 | 
			
		||||
                                        }
 | 
			
		||||
                                        watcherMethod.invoke(watcher, value);
 | 
			
		||||
                                    }
 | 
			
		||||
                                    catch (Exception ex)
 | 
			
		||||
                                    {
 | 
			
		||||
                                        ex.printStackTrace(System.out);
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseEntity(Entity entity, Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        // If they are trying to disguise a null entity or use a null disguise
 | 
			
		||||
        // Just return.
 | 
			
		||||
        if (entity == null || disguise == null)
 | 
			
		||||
        {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        // The event wasn't cancelled.
 | 
			
		||||
        // If the disguise entity isn't the same as the one we are disguising
 | 
			
		||||
        if (disguise.getEntity() != entity)
 | 
			
		||||
        {
 | 
			
		||||
            // If the disguise entity actually exists
 | 
			
		||||
            if (disguise.getEntity() != null)
 | 
			
		||||
            {
 | 
			
		||||
                // Clone the disguise
 | 
			
		||||
                disguise = disguise.clone();
 | 
			
		||||
            }
 | 
			
		||||
            // Set the disguise's entity
 | 
			
		||||
            disguise.setEntity(entity);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId()))
 | 
			
		||||
        {
 | 
			
		||||
            disguise.setViewSelfDisguise(true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        disguise.startDisguise();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Collection playersToNotSeeDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguise.getEntity() != null)
 | 
			
		||||
        {
 | 
			
		||||
            disguise = disguise.clone();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
 | 
			
		||||
 | 
			
		||||
        for (Object obj : playersToNotSeeDisguise)
 | 
			
		||||
        {
 | 
			
		||||
            if (obj instanceof String)
 | 
			
		||||
            {
 | 
			
		||||
                ((TargetedDisguise) disguise).addPlayer((String) obj);
 | 
			
		||||
            }
 | 
			
		||||
            else if (obj instanceof Player)
 | 
			
		||||
            {
 | 
			
		||||
                ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        disguiseEntity(entity, disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseIgnorePlayers(entity, disguise, (Collection) playersToNotSeeDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, Player... playersToNotSeeDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseIgnorePlayers(entity, disguise, (Collection) Arrays.asList(playersToNotSeeDisguise));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
 | 
			
		||||
     *
 | 
			
		||||
     * @param disguise
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static int disguiseNextEntity(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguise == null)
 | 
			
		||||
        {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (disguise.getEntity() != null || DisguiseUtilities.getDisguises().containsValue(disguise))
 | 
			
		||||
        {
 | 
			
		||||
            disguise = disguise.clone();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
 | 
			
		||||
            DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
 | 
			
		||||
            return id;
 | 
			
		||||
        }
 | 
			
		||||
        catch (IllegalAccessException e)
 | 
			
		||||
        {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disguise this entity with this disguise
 | 
			
		||||
     *
 | 
			
		||||
     * @param entity
 | 
			
		||||
     * @param disguise
 | 
			
		||||
     */
 | 
			
		||||
    public static void disguiseToAll(Entity entity, Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguise.getEntity() != null)
 | 
			
		||||
        {
 | 
			
		||||
            disguise = disguise.clone();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
 | 
			
		||||
        ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
 | 
			
		||||
 | 
			
		||||
        for (String observer : ((TargetedDisguise) disguise).getObservers())
 | 
			
		||||
        {
 | 
			
		||||
            ((TargetedDisguise) disguise).removePlayer(observer);
 | 
			
		||||
        }
 | 
			
		||||
        disguiseEntity(entity, disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseToPlayers(Entity entity, Disguise disguise, Collection playersToViewDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguise.getEntity() != null)
 | 
			
		||||
        {
 | 
			
		||||
            disguise = disguise.clone();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
 | 
			
		||||
 | 
			
		||||
        for (Object obj : playersToViewDisguise)
 | 
			
		||||
        {
 | 
			
		||||
            if (obj instanceof String)
 | 
			
		||||
            {
 | 
			
		||||
                ((TargetedDisguise) disguise).addPlayer((String) obj);
 | 
			
		||||
            }
 | 
			
		||||
            else if (obj instanceof Player)
 | 
			
		||||
            {
 | 
			
		||||
                ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        disguiseEntity(entity, disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseToPlayers(entity, disguise, (Collection) playersToViewDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseToPlayers(Entity entity, Disguise disguise, Player... playersToViewDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseToPlayers(entity, disguise, (Collection) Arrays.asList(playersToViewDisguise));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static int firstCapital(String str)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = 0; i < str.length(); i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (Character.isUpperCase(str.charAt(i)))
 | 
			
		||||
            {
 | 
			
		||||
                return i;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the disguise of a entity
 | 
			
		||||
     *
 | 
			
		||||
     * @param disguised
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static Disguise getDisguise(Entity disguised)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguised == null)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return DisguiseUtilities.getMainDisguise(disguised.getUniqueId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the disguise of a entity
 | 
			
		||||
     *
 | 
			
		||||
     * @param observer
 | 
			
		||||
     * @param disguised
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static Disguise getDisguise(Player observer, Entity disguised)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguised == null || observer == null)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return DisguiseUtilities.getDisguise(observer, disguised);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the disguises of a entity
 | 
			
		||||
     *
 | 
			
		||||
     * @param disguised
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static Disguise[] getDisguises(Entity disguised)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguised == null)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return DisguiseUtilities.getDisguises(disguised.getUniqueId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the ID of a fake disguise for a entityplayer
 | 
			
		||||
     *
 | 
			
		||||
     * @param entityId
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static int getFakeDisguise(UUID entityId)
 | 
			
		||||
    {
 | 
			
		||||
        return -10;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int getSelfDisguiseId()
 | 
			
		||||
    {
 | 
			
		||||
        return -10;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is this entity disguised
 | 
			
		||||
     *
 | 
			
		||||
     * @param disguised
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isDisguised(Entity disguised)
 | 
			
		||||
    {
 | 
			
		||||
        return getDisguise(disguised) != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is this entity disguised
 | 
			
		||||
     *
 | 
			
		||||
     * @param observer
 | 
			
		||||
     * @param disguised
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isDisguised(Player observer, Entity disguised)
 | 
			
		||||
    {
 | 
			
		||||
        return getDisguise(observer, disguised) != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isDisguiseInUse(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        return disguise.isDisguiseInUse();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isSelfDisguised(Player player)
 | 
			
		||||
    {
 | 
			
		||||
        return DisguiseUtilities.getSelfDisguised().contains(player.getUniqueId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns true if the entitiy has /disguiseviewself toggled on.
 | 
			
		||||
     *
 | 
			
		||||
     * @param entity
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isViewSelfToggled(Entity entity)
 | 
			
		||||
    {
 | 
			
		||||
        return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible()
 | 
			
		||||
                : Disguise.getViewSelf().contains(entity.getUniqueId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Undisguise the entity. This doesn't let you cancel the UndisguiseEvent if the entity is no longer valid. Aka removed from
 | 
			
		||||
     * the world.
 | 
			
		||||
     *
 | 
			
		||||
     * @param entity
 | 
			
		||||
     */
 | 
			
		||||
    public static void undisguiseToAll(Entity entity)
 | 
			
		||||
    {
 | 
			
		||||
        Disguise[] disguises = getDisguises(entity);
 | 
			
		||||
 | 
			
		||||
        for (Disguise disguise : disguises)
 | 
			
		||||
        {
 | 
			
		||||
            disguise.removeDisguise();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set whether this player can see his own disguise or not.
 | 
			
		||||
     *
 | 
			
		||||
     * @param entity
 | 
			
		||||
     * @param toggled
 | 
			
		||||
     */
 | 
			
		||||
    public static void setViewDisguiseToggled(Entity entity, boolean toggled)
 | 
			
		||||
    {
 | 
			
		||||
        if (isDisguised(entity))
 | 
			
		||||
        {
 | 
			
		||||
            Disguise disguise = getDisguise(entity);
 | 
			
		||||
            disguise.setViewSelfDisguise(toggled);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (toggled)
 | 
			
		||||
        {
 | 
			
		||||
            if (!Disguise.getViewSelf().contains(entity.getUniqueId()))
 | 
			
		||||
            {
 | 
			
		||||
                Disguise.getViewSelf().add(entity.getUniqueId());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            Disguise.getViewSelf().remove(entity.getUniqueId());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DisguiseAPI()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										541
									
								
								src/me/libraryaddict/disguise/DisguiseConfig.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										541
									
								
								src/me/libraryaddict/disguise/DisguiseConfig.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,541 @@
 | 
			
		||||
package me.libraryaddict.disguise;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.configuration.ConfigurationSection;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.utilities.PacketsManager;
 | 
			
		||||
 | 
			
		||||
public class DisguiseConfig
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    private static boolean animationEnabled;
 | 
			
		||||
    private static boolean bedEnabled;
 | 
			
		||||
    private static boolean blowDisguisesOnAttack;
 | 
			
		||||
    private static boolean collectEnabled;
 | 
			
		||||
    private static boolean colorizeSheep;
 | 
			
		||||
    private static boolean colorizeWolf;
 | 
			
		||||
    private static String disguiseBlownMessage;
 | 
			
		||||
    private static int disguiseCloneExpire;
 | 
			
		||||
    private static int disguiseEntityExpire;
 | 
			
		||||
    private static boolean entityAnimationsAdded;
 | 
			
		||||
    private static boolean entityStatusEnabled;
 | 
			
		||||
    private static boolean equipmentEnabled;
 | 
			
		||||
    private static boolean hearSelfDisguise;
 | 
			
		||||
    private static boolean viewSelfDisguise;
 | 
			
		||||
    private static boolean hidingArmor;
 | 
			
		||||
    private static boolean hidingHeldItem;
 | 
			
		||||
    private static boolean keepDisguiseEntityDespawn;
 | 
			
		||||
    private static boolean keepDisguisePlayerDeath;
 | 
			
		||||
    private static boolean keepDisguisePlayerLogout;
 | 
			
		||||
    private static int maxClonedDisguises;
 | 
			
		||||
    private static boolean maxHealthIsDisguisedEntity;
 | 
			
		||||
    private static boolean miscDisguisesForLivingEnabled;
 | 
			
		||||
    private static boolean modifyBoundingBox;
 | 
			
		||||
    private static boolean movementEnabled;
 | 
			
		||||
    private static boolean sendsEntityMetadata;
 | 
			
		||||
    private static boolean sendVelocity;
 | 
			
		||||
    private static boolean showNameAboveHead;
 | 
			
		||||
    private static boolean showNameAboveHeadAlwaysVisible;
 | 
			
		||||
    private static boolean targetDisguises;
 | 
			
		||||
    private static boolean undisguiseSwitchWorlds;
 | 
			
		||||
    private static boolean stopShulkerDisguisesFromMoving;
 | 
			
		||||
    private static String updateMessage = ChatColor.RED + "[LibsDisguises] " + ChatColor.DARK_RED
 | 
			
		||||
            + "There is a update ready to be downloaded! You are using " + ChatColor.RED + "v%s" + ChatColor.DARK_RED
 | 
			
		||||
            + ", the new version is " + ChatColor.RED + "%s" + ChatColor.DARK_RED + "!";
 | 
			
		||||
    private static String updateNotificationPermission;
 | 
			
		||||
    private static boolean witherSkullEnabled;
 | 
			
		||||
 | 
			
		||||
    public static String getDisguiseBlownMessage()
 | 
			
		||||
    {
 | 
			
		||||
        return disguiseBlownMessage;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int getDisguiseCloneExpire()
 | 
			
		||||
    {
 | 
			
		||||
        return disguiseCloneExpire;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int getDisguiseEntityExpire()
 | 
			
		||||
    {
 | 
			
		||||
        return disguiseEntityExpire;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static int getMaxClonedDisguises()
 | 
			
		||||
    {
 | 
			
		||||
        return maxClonedDisguises;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getUpdateMessage()
 | 
			
		||||
    {
 | 
			
		||||
        return updateMessage;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static String getUpdateNotificationPermission()
 | 
			
		||||
    {
 | 
			
		||||
        return updateNotificationPermission;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void initConfig(ConfigurationSection config)
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        setSoundsEnabled(config.getBoolean("DisguiseSounds"));
 | 
			
		||||
        setVelocitySent(config.getBoolean("SendVelocity"));
 | 
			
		||||
        setViewDisguises(config.getBoolean("ViewSelfDisguises")); // Since we can now toggle, the view disguises listener must
 | 
			
		||||
                                                                  // always be on
 | 
			
		||||
        PacketsManager.setViewDisguisesListener(true);
 | 
			
		||||
        setHearSelfDisguise(config.getBoolean("HearSelfDisguise"));
 | 
			
		||||
        setHideArmorFromSelf(config.getBoolean("RemoveArmor"));
 | 
			
		||||
        setHideHeldItemFromSelf(config.getBoolean("RemoveHeldItem"));
 | 
			
		||||
        setAddEntityAnimations(config.getBoolean("AddEntityAnimations"));
 | 
			
		||||
        setNameOfPlayerShownAboveDisguise(config.getBoolean("ShowNamesAboveDisguises"));
 | 
			
		||||
        setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible"));
 | 
			
		||||
        setModifyBoundingBox(config.getBoolean("ModifyBoundingBox"));
 | 
			
		||||
        setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises"));
 | 
			
		||||
        setDisguiseBlownOnAttack(config.getBoolean("BlowDisguises"));
 | 
			
		||||
        setDisguiseBlownMessage(ChatColor.translateAlternateColorCodes('&', config.getString("BlownDisguiseMessage")));
 | 
			
		||||
        setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath"));
 | 
			
		||||
        setKeepDisguiseOnPlayerLogout(config.getBoolean("KeepDisguises.PlayerLogout"));
 | 
			
		||||
        setKeepDisguiseOnEntityDespawn(config.getBoolean("KeepDisguises.EntityDespawn"));
 | 
			
		||||
        setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving"));
 | 
			
		||||
        setMovementPacketsEnabled(config.getBoolean("PacketsEnabled.Movement"));
 | 
			
		||||
        setWitherSkullPacketsEnabled(config.getBoolean("PacketsEnabled.WitherSkull"));
 | 
			
		||||
        setEquipmentPacketsEnabled(config.getBoolean("PacketsEnabled.Equipment"));
 | 
			
		||||
        setAnimationPacketsEnabled(config.getBoolean("PacketsEnabled.Animation"));
 | 
			
		||||
        setBedPacketsEnabled(config.getBoolean("PacketsEnabled.Bed"));
 | 
			
		||||
        setEntityStatusPacketsEnabled(config.getBoolean("PacketsEnabled.EntityStatus"));
 | 
			
		||||
        setCollectPacketsEnabled(config.getBoolean("PacketsEnabled.Collect"));
 | 
			
		||||
        setMetadataPacketsEnabled(config.getBoolean("PacketsEnabled.Metadata"));
 | 
			
		||||
        setMaxHealthDeterminedByDisguisedEntity(config.getBoolean("MaxHealthDeterminedByEntity"));
 | 
			
		||||
        setDisguiseEntityExpire(config.getInt("DisguiseEntityExpire"));
 | 
			
		||||
        setDisguiseCloneExpire(config.getInt("DisguiseCloneExpire"));
 | 
			
		||||
        setMaxClonedDisguises(config.getInt("DisguiseCloneSize"));
 | 
			
		||||
        setSheepDyeable(config.getBoolean("DyeableSheep"));
 | 
			
		||||
        setWolfDyeable(config.getBoolean("DyeableWolf"));
 | 
			
		||||
        setUndisguiseOnWorldChange(config.getBoolean("UndisguiseOnWorldChange"));
 | 
			
		||||
        setUpdateNotificationPermission(config.getString("Permission"));
 | 
			
		||||
        setStopShulkerDisguisesFromMoving(config.getBoolean("StopShulkerDisguisesFromMoving", true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isAnimationPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return animationEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isBedPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return bedEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isCollectPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return collectEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isDisguiseBlownOnAttack()
 | 
			
		||||
    {
 | 
			
		||||
        return blowDisguisesOnAttack;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @deprecated Spelling mistake.
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static boolean isEnquipmentPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return equipmentEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isEntityAnimationsAdded()
 | 
			
		||||
    {
 | 
			
		||||
        return entityAnimationsAdded;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isEntityStatusPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return entityStatusEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isEquipmentPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return equipmentEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is the plugin modifying the inventory packets so that players when self disguised, do not see their armor floating around
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isHidingArmorFromSelf()
 | 
			
		||||
    {
 | 
			
		||||
        return hidingArmor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isHidingHeldItemFromSelf()
 | 
			
		||||
    {
 | 
			
		||||
        return hidingHeldItem;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isKeepDisguiseOnEntityDespawn()
 | 
			
		||||
    {
 | 
			
		||||
        return keepDisguiseEntityDespawn;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isKeepDisguiseOnPlayerDeath()
 | 
			
		||||
    {
 | 
			
		||||
        return keepDisguisePlayerDeath;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isKeepDisguiseOnPlayerLogout()
 | 
			
		||||
    {
 | 
			
		||||
        return keepDisguisePlayerLogout;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isMaxHealthDeterminedByDisguisedEntity()
 | 
			
		||||
    {
 | 
			
		||||
        return maxHealthIsDisguisedEntity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isMetadataPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return sendsEntityMetadata;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isMiscDisguisesForLivingEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return miscDisguisesForLivingEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isModifyBoundingBox()
 | 
			
		||||
    {
 | 
			
		||||
        return modifyBoundingBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isMonstersIgnoreDisguises()
 | 
			
		||||
    {
 | 
			
		||||
        return targetDisguises;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isMovementPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return movementEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isNameAboveHeadAlwaysVisible()
 | 
			
		||||
    {
 | 
			
		||||
        return showNameAboveHeadAlwaysVisible;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isNameOfPlayerShownAboveDisguise()
 | 
			
		||||
    {
 | 
			
		||||
        return showNameAboveHead;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isSelfDisguisesSoundsReplaced()
 | 
			
		||||
    {
 | 
			
		||||
        return hearSelfDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isSheepDyeable()
 | 
			
		||||
    {
 | 
			
		||||
        return colorizeSheep;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is the sound packets caught and modified
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isSoundEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return PacketsManager.isHearDisguisesEnabled();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isUndisguiseOnWorldChange()
 | 
			
		||||
    {
 | 
			
		||||
        return undisguiseSwitchWorlds;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is the velocity packets sent
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isVelocitySent()
 | 
			
		||||
    {
 | 
			
		||||
        return sendVelocity;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The default value if a player views his own disguise
 | 
			
		||||
     *
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isViewDisguises()
 | 
			
		||||
    {
 | 
			
		||||
        return viewSelfDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isWitherSkullPacketsEnabled()
 | 
			
		||||
    {
 | 
			
		||||
        return witherSkullEnabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isWolfDyeable()
 | 
			
		||||
    {
 | 
			
		||||
        return colorizeWolf;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setAddEntityAnimations(boolean isEntityAnimationsAdded)
 | 
			
		||||
    {
 | 
			
		||||
        entityAnimationsAdded = isEntityAnimationsAdded;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setAnimationPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isAnimationPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            animationEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setBedPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isBedPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            bedEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setCollectPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isCollectPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            collectEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDisguiseBlownMessage(String newMessage)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseBlownMessage = newMessage;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDisguiseBlownOnAttack(boolean blowDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        blowDisguisesOnAttack = blowDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDisguiseCloneExpire(int newExpires)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseCloneExpire = newExpires;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setDisguiseEntityExpire(int newExpires)
 | 
			
		||||
    {
 | 
			
		||||
        disguiseEntityExpire = newExpires;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public static void setEnquipmentPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        setEquipmentPacketsEnabled(enabled);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setEntityStatusPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isEntityStatusPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            entityStatusEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setEquipmentPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isEquipmentPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            equipmentEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Can players hear their own disguises
 | 
			
		||||
     */
 | 
			
		||||
    public static void setHearSelfDisguise(boolean replaceSound)
 | 
			
		||||
    {
 | 
			
		||||
        if (hearSelfDisguise != replaceSound)
 | 
			
		||||
        {
 | 
			
		||||
            hearSelfDisguise = replaceSound;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the plugin to hide self disguises armor from theirselves
 | 
			
		||||
     */
 | 
			
		||||
    public static void setHideArmorFromSelf(boolean hideArmor)
 | 
			
		||||
    {
 | 
			
		||||
        if (hidingArmor != hideArmor)
 | 
			
		||||
        {
 | 
			
		||||
            hidingArmor = hideArmor;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Does the plugin appear to remove the item they are holding, to prevent a floating sword when they are viewing self disguise
 | 
			
		||||
     */
 | 
			
		||||
    public static void setHideHeldItemFromSelf(boolean hideHelditem)
 | 
			
		||||
    {
 | 
			
		||||
        if (hidingHeldItem != hideHelditem)
 | 
			
		||||
        {
 | 
			
		||||
            hidingHeldItem = hideHelditem;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setInventoryListenerEnabled(isHidingHeldItemFromSelf() || isHidingArmorFromSelf());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setKeepDisguiseOnEntityDespawn(boolean keepDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        keepDisguiseEntityDespawn = keepDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setKeepDisguiseOnPlayerDeath(boolean keepDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        keepDisguisePlayerDeath = keepDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setKeepDisguiseOnPlayerLogout(boolean keepDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        keepDisguisePlayerLogout = keepDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMaxClonedDisguises(int newMax)
 | 
			
		||||
    {
 | 
			
		||||
        maxClonedDisguises = newMax;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMaxHealthDeterminedByDisguisedEntity(boolean isDetermined)
 | 
			
		||||
    {
 | 
			
		||||
        maxHealthIsDisguisedEntity = isDetermined;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMetadataPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        sendsEntityMetadata = enabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMiscDisguisesForLivingEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isMiscDisguisesForLivingEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            miscDisguisesForLivingEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setModifyBoundingBox(boolean modifyBounding)
 | 
			
		||||
    {
 | 
			
		||||
        modifyBoundingBox = modifyBounding;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMonstersIgnoreDisguises(boolean ignore)
 | 
			
		||||
    {
 | 
			
		||||
        targetDisguises = ignore;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setMovementPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        if (enabled != isMovementPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            movementEnabled = enabled;
 | 
			
		||||
 | 
			
		||||
            PacketsManager.setupMainPacketsListener();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setNameAboveHeadAlwaysVisible(boolean alwaysVisible)
 | 
			
		||||
    {
 | 
			
		||||
        showNameAboveHeadAlwaysVisible = alwaysVisible;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setNameOfPlayerShownAboveDisguise(boolean showNames)
 | 
			
		||||
    {
 | 
			
		||||
        showNameAboveHead = showNames;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setSheepDyeable(boolean color)
 | 
			
		||||
    {
 | 
			
		||||
        colorizeSheep = color;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set if the disguises play sounds when hurt
 | 
			
		||||
     */
 | 
			
		||||
    public static void setSoundsEnabled(boolean isSoundsEnabled)
 | 
			
		||||
    {
 | 
			
		||||
        PacketsManager.setHearDisguisesListener(isSoundsEnabled);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setUndisguiseOnWorldChange(boolean isUndisguise)
 | 
			
		||||
    {
 | 
			
		||||
        undisguiseSwitchWorlds = isUndisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setUpdateMessage(String newMessage)
 | 
			
		||||
    {
 | 
			
		||||
        updateMessage = newMessage;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setUpdateNotificationPermission(String newPermission)
 | 
			
		||||
    {
 | 
			
		||||
        updateNotificationPermission = newPermission;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setStopShulkerDisguisesFromMoving(boolean stopShulkerDisguisesFromMoving)
 | 
			
		||||
    {
 | 
			
		||||
        DisguiseConfig.stopShulkerDisguisesFromMoving = stopShulkerDisguisesFromMoving;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static boolean isStopShulkerDisguisesFromMoving()
 | 
			
		||||
    {
 | 
			
		||||
        return stopShulkerDisguisesFromMoving;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disable velocity packets being sent for w/e reason. Maybe you want every ounce of performance you can get?
 | 
			
		||||
     *
 | 
			
		||||
     * @param sendVelocityPackets
 | 
			
		||||
     */
 | 
			
		||||
    public static void setVelocitySent(boolean sendVelocityPackets)
 | 
			
		||||
    {
 | 
			
		||||
        sendVelocity = sendVelocityPackets;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setViewDisguises(boolean seeOwnDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        viewSelfDisguise = seeOwnDisguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setWitherSkullPacketsEnabled(boolean enabled)
 | 
			
		||||
    {
 | 
			
		||||
        witherSkullEnabled = enabled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static void setWolfDyeable(boolean color)
 | 
			
		||||
    {
 | 
			
		||||
        colorizeWolf = color;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DisguiseConfig()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										430
									
								
								src/me/libraryaddict/disguise/DisguiseListener.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										430
									
								
								src/me/libraryaddict/disguise/DisguiseListener.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,430 @@
 | 
			
		||||
package me.libraryaddict.disguise;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Location;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.event.EventHandler;
 | 
			
		||||
import org.bukkit.event.EventPriority;
 | 
			
		||||
import org.bukkit.event.Listener;
 | 
			
		||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
 | 
			
		||||
import org.bukkit.event.entity.EntityTargetEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerJoinEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerMoveEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerQuitEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerRespawnEvent;
 | 
			
		||||
import org.bukkit.event.player.PlayerTeleportEvent;
 | 
			
		||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
 | 
			
		||||
import org.bukkit.event.vehicle.VehicleExitEvent;
 | 
			
		||||
import org.bukkit.scheduler.BukkitRunnable;
 | 
			
		||||
import org.bukkit.scheduler.BukkitTask;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.ProtocolLibrary;
 | 
			
		||||
import com.comphenix.protocol.events.PacketContainer;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.UpdateChecker;
 | 
			
		||||
 | 
			
		||||
public class DisguiseListener implements Listener {
 | 
			
		||||
 | 
			
		||||
    private String currentVersion;
 | 
			
		||||
    private HashMap<String, Boolean[]> disguiseClone = new HashMap<>();
 | 
			
		||||
    private HashMap<String, Disguise> disguiseEntity = new HashMap<>();
 | 
			
		||||
    private HashMap<String, BukkitRunnable> disguiseRunnable = new HashMap<>();
 | 
			
		||||
    private String latestVersion;
 | 
			
		||||
    private LibsDisguises plugin;
 | 
			
		||||
    private BukkitTask updaterTask;
 | 
			
		||||
 | 
			
		||||
    public DisguiseListener(LibsDisguises libsDisguises) {
 | 
			
		||||
        plugin = libsDisguises;
 | 
			
		||||
        if (plugin.getConfig().getBoolean("NotifyUpdate")) {
 | 
			
		||||
            currentVersion = plugin.getDescription().getVersion();
 | 
			
		||||
            updaterTask = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() {
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run() {
 | 
			
		||||
                    try {
 | 
			
		||||
                        UpdateChecker updateChecker = new UpdateChecker();
 | 
			
		||||
                        updateChecker.checkUpdate("v" + currentVersion);
 | 
			
		||||
                        latestVersion = updateChecker.getLatestVersion();
 | 
			
		||||
                        if (latestVersion != null) {
 | 
			
		||||
                            latestVersion = "v" + latestVersion;
 | 
			
		||||
                            Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
			
		||||
                                @Override
 | 
			
		||||
                                public void run() {
 | 
			
		||||
                                    for (Player p : Bukkit.getOnlinePlayers()) {
 | 
			
		||||
                                        if (p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) {
 | 
			
		||||
                                            p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion,
 | 
			
		||||
                                                    latestVersion));
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            });
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (Exception ex) {
 | 
			
		||||
                        System.out.print(String.format("[LibsDisguises] Failed to check for update: %s", ex.getMessage()));
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }, 0, (20 * 60 * 60 * 6)); // Check every 6 hours
 | 
			
		||||
            // 20 ticks * 60 seconds * 60 minutes * 6 hours
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void cleanup() {
 | 
			
		||||
        for (BukkitRunnable r : disguiseRunnable.values()) {
 | 
			
		||||
            r.cancel();
 | 
			
		||||
        }
 | 
			
		||||
        for (Disguise d : disguiseEntity.values()) {
 | 
			
		||||
            d.removeDisguise();
 | 
			
		||||
        }
 | 
			
		||||
        disguiseClone.clear();
 | 
			
		||||
        updaterTask.cancel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void checkPlayerCanBlowDisguise(Player entity) {
 | 
			
		||||
        Disguise[] disguises = DisguiseAPI.getDisguises(entity);
 | 
			
		||||
        if (disguises.length > 0) {
 | 
			
		||||
            DisguiseAPI.undisguiseToAll(entity);
 | 
			
		||||
            if (DisguiseConfig.getDisguiseBlownMessage().length() > 0) {
 | 
			
		||||
                entity.sendMessage(DisguiseConfig.getDisguiseBlownMessage());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void chunkMove(Player player, Location newLoc, Location oldLoc) {
 | 
			
		||||
        try {
 | 
			
		||||
            for (PacketContainer packet : DisguiseUtilities.getBedChunkPacket(newLoc, oldLoc)) {
 | 
			
		||||
                ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
 | 
			
		||||
            }
 | 
			
		||||
            if (newLoc != null) {
 | 
			
		||||
                for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) {
 | 
			
		||||
                    for (TargetedDisguise disguise : list) {
 | 
			
		||||
                        if (disguise.isPlayerDisguise() && disguise.canSee(player)
 | 
			
		||||
                                && ((PlayerDisguise) disguise).getWatcher().isSleeping()
 | 
			
		||||
                                && DisguiseUtilities.getPerverts(disguise).contains(player)) {
 | 
			
		||||
                            PacketContainer[] packets = DisguiseUtilities.getBedPackets(player,
 | 
			
		||||
                                    disguise.getEntity() == player ? newLoc : disguise.getEntity().getLocation(), newLoc,
 | 
			
		||||
                                    (PlayerDisguise) disguise);
 | 
			
		||||
                            if (disguise.getEntity() == player) {
 | 
			
		||||
                                for (PacketContainer packet : packets) {
 | 
			
		||||
                                    packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            for (PacketContainer packet : packets) {
 | 
			
		||||
                                ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } catch (InvocationTargetException e) {
 | 
			
		||||
            e.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
 | 
			
		||||
    public void onAttack(EntityDamageByEntityEvent event) {
 | 
			
		||||
        if (DisguiseConfig.isDisguiseBlownOnAttack()) {
 | 
			
		||||
            if (event.getEntity() instanceof Player) {
 | 
			
		||||
                checkPlayerCanBlowDisguise((Player) event.getEntity());
 | 
			
		||||
            }
 | 
			
		||||
            if (event.getDamager() instanceof Player) {
 | 
			
		||||
                checkPlayerCanBlowDisguise((Player) event.getDamager());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onJoin(PlayerJoinEvent event) {
 | 
			
		||||
        Player p = event.getPlayer();
 | 
			
		||||
        if (latestVersion != null && p.hasPermission(DisguiseConfig.getUpdateNotificationPermission())) {
 | 
			
		||||
            p.sendMessage(String.format(DisguiseConfig.getUpdateMessage(), currentVersion, latestVersion));
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isBedPacketsEnabled()) {
 | 
			
		||||
            chunkMove(p, p.getLocation(), null);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Most likely faster if we don't bother doing checks if he sees a player disguise
 | 
			
		||||
     */
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onMove(PlayerMoveEvent event) {
 | 
			
		||||
        if (DisguiseConfig.isBedPacketsEnabled()) {
 | 
			
		||||
            Location to = event.getTo();
 | 
			
		||||
            Location from = event.getFrom();
 | 
			
		||||
            int x1 = (int) Math.floor(to.getX() / 16D) - 17;
 | 
			
		||||
            int x2 = (int) Math.floor(from.getX() / 16D) - 17;
 | 
			
		||||
            int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
 | 
			
		||||
            int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
 | 
			
		||||
            if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) {
 | 
			
		||||
                chunkMove(event.getPlayer(), to, from);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (DisguiseConfig.isStopShulkerDisguisesFromMoving()) {
 | 
			
		||||
            Disguise disguise;
 | 
			
		||||
            if ((disguise = DisguiseAPI.getDisguise(event.getPlayer())) != null) {
 | 
			
		||||
                if (disguise.getType() == DisguiseType.SHULKER) { //Stop Shulker disguises from moving their coordinates
 | 
			
		||||
                    Location from = event.getFrom();
 | 
			
		||||
                    Location to = event.getTo();
 | 
			
		||||
                    to.setX(from.getX());
 | 
			
		||||
                    to.setZ(from.getZ());
 | 
			
		||||
                    event.setTo(to);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onQuit(PlayerQuitEvent event) {
 | 
			
		||||
        ReflectionManager.removePlayer(event.getPlayer());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onRespawn(PlayerRespawnEvent event) {
 | 
			
		||||
        Disguise[] disguises = DisguiseAPI.getDisguises(event.getPlayer());
 | 
			
		||||
        for (Disguise disguise : disguises) {
 | 
			
		||||
            if (disguise.isRemoveDisguiseOnDeath()) {
 | 
			
		||||
                disguise.removeDisguise();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onRightClick(PlayerInteractEntityEvent event) {
 | 
			
		||||
        if (disguiseEntity.containsKey(event.getPlayer().getName()) || disguiseClone.containsKey(event.getPlayer().getName())) {
 | 
			
		||||
            Player p = event.getPlayer();
 | 
			
		||||
            event.setCancelled(true);
 | 
			
		||||
            disguiseRunnable.remove(p.getName()).cancel();
 | 
			
		||||
            Entity entity = event.getRightClicked();
 | 
			
		||||
            String entityName;
 | 
			
		||||
            if (entity instanceof Player && !disguiseClone.containsKey(p.getName())) {
 | 
			
		||||
                entityName = entity.getName();
 | 
			
		||||
            } else {
 | 
			
		||||
                entityName = DisguiseType.getType(entity).toReadable();
 | 
			
		||||
            }
 | 
			
		||||
            if (disguiseClone.containsKey(p.getName())) {
 | 
			
		||||
                Boolean[] options = disguiseClone.remove(p.getName());
 | 
			
		||||
                Disguise disguise = DisguiseAPI.getDisguise(p, entity);
 | 
			
		||||
                if (disguise == null) {
 | 
			
		||||
                    disguise = DisguiseAPI.constructDisguise(entity, options[0], options[1], options[2]);
 | 
			
		||||
                } else {
 | 
			
		||||
                    disguise = disguise.clone();
 | 
			
		||||
                }
 | 
			
		||||
                char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
 | 
			
		||||
                String reference = null;
 | 
			
		||||
                int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D));
 | 
			
		||||
                int attempts = 0;
 | 
			
		||||
                while (reference == null && attempts++ < 1000) {
 | 
			
		||||
                    reference = "@";
 | 
			
		||||
                    for (int i = 0; i < referenceLength; i++) {
 | 
			
		||||
                        reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
 | 
			
		||||
                    }
 | 
			
		||||
                    if (DisguiseUtilities.getClonedDisguise(reference) != null) {
 | 
			
		||||
                        reference = null;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) {
 | 
			
		||||
                    p.sendMessage(ChatColor.RED + "Constructed a " + entityName + " disguise! Your reference is " + reference);
 | 
			
		||||
                    p.sendMessage(ChatColor.RED + "Example usage: /disguise " + reference);
 | 
			
		||||
                } else {
 | 
			
		||||
                    p.sendMessage(ChatColor.RED
 | 
			
		||||
                            + "Failed to store the reference due to lack of size. Please set this in the config");
 | 
			
		||||
                }
 | 
			
		||||
            } else if (disguiseEntity.containsKey(p.getName())) {
 | 
			
		||||
                Disguise disguise = disguiseEntity.remove(p.getName());
 | 
			
		||||
                if (disguise != null) {
 | 
			
		||||
                    if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
 | 
			
		||||
                            && entity instanceof LivingEntity) {
 | 
			
		||||
                        p.sendMessage(ChatColor.RED
 | 
			
		||||
                                + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
 | 
			
		||||
                    } else {
 | 
			
		||||
                        if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
 | 
			
		||||
                            if (disguise.getWatcher() instanceof LivingWatcher) {
 | 
			
		||||
                                disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
 | 
			
		||||
                                if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
 | 
			
		||||
                                    disguise.getWatcher().setCustomNameVisible(true);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        DisguiseAPI.disguiseToAll(entity, disguise);
 | 
			
		||||
                        String disguiseName = "a ";
 | 
			
		||||
                        if (disguise instanceof PlayerDisguise) {
 | 
			
		||||
                            disguiseName = "the player " + ((PlayerDisguise) disguise).getName();
 | 
			
		||||
                        } else {
 | 
			
		||||
                            disguiseName += disguise.getType().toReadable();
 | 
			
		||||
                        }
 | 
			
		||||
                        if (disguise.isDisguiseInUse()) {
 | 
			
		||||
                            p.sendMessage(ChatColor.RED + "Disguised " + (entity instanceof Player ? "" : "the ") + entityName
 | 
			
		||||
                                    + " as " + disguiseName + "!");
 | 
			
		||||
                        } else {
 | 
			
		||||
                            p.sendMessage(ChatColor.RED + "Failed to disguise " + (entity instanceof Player ? "" : "the ")
 | 
			
		||||
                                    + entityName + " as " + disguiseName + "!");
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (DisguiseAPI.isDisguised(entity)) {
 | 
			
		||||
                        DisguiseAPI.undisguiseToAll(entity);
 | 
			
		||||
                        p.sendMessage(ChatColor.RED + "Undisguised " + (entity instanceof Player ? "" : "the ") + entityName);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        p.sendMessage(ChatColor.RED + (entity instanceof Player ? "" : "the") + entityName + " isn't disguised!");
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler
 | 
			
		||||
    public void onTarget(EntityTargetEvent event) {
 | 
			
		||||
        if (DisguiseConfig.isMonstersIgnoreDisguises() && event.getTarget() != null && event.getTarget() instanceof Player
 | 
			
		||||
                && DisguiseAPI.isDisguised(event.getTarget())) {
 | 
			
		||||
            switch (event.getReason()) {
 | 
			
		||||
                case TARGET_ATTACKED_ENTITY:
 | 
			
		||||
                case TARGET_ATTACKED_OWNER:
 | 
			
		||||
                case OWNER_ATTACKED_TARGET:
 | 
			
		||||
                case CUSTOM:
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    event.setCancelled(true);
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onTeleport(final PlayerTeleportEvent event) {
 | 
			
		||||
        if (!DisguiseAPI.isDisguised(event.getPlayer())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        Location to = event.getTo();
 | 
			
		||||
        Location from = event.getFrom();
 | 
			
		||||
        if (DisguiseConfig.isBedPacketsEnabled()) {
 | 
			
		||||
            int x1 = (int) Math.floor(to.getX() / 16D) - 17;
 | 
			
		||||
            int x2 = (int) Math.floor(from.getX() / 16D) - 17;
 | 
			
		||||
            int z1 = (int) Math.floor(to.getZ() / 16D) - 17;
 | 
			
		||||
            int z2 = (int) Math.floor(from.getZ() / 16D) - 17;
 | 
			
		||||
            if (x1 - (x1 % 8) != x2 - (x2 % 8) || z1 - (z1 % 8) != z2 - (z2 % 8)) {
 | 
			
		||||
                chunkMove(event.getPlayer(), null, from);
 | 
			
		||||
                Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        if (!event.isCancelled()) {
 | 
			
		||||
                            chunkMove(event.getPlayer(), event.getTo(), null);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isUndisguiseOnWorldChange() && to.getWorld() != null && from.getWorld() != null
 | 
			
		||||
                && to.getWorld() != from.getWorld()) {
 | 
			
		||||
            for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
 | 
			
		||||
                disguise.removeDisguise();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onVehicleEnter(VehicleEnterEvent event) {
 | 
			
		||||
        if (event.getEntered() instanceof Player && DisguiseAPI.isDisguised((Player) event.getEntered(), event.getEntered())) {
 | 
			
		||||
            DisguiseUtilities.removeSelfDisguise((Player) event.getEntered());
 | 
			
		||||
            ((Player) event.getEntered()).updateInventory();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onVehicleLeave(VehicleExitEvent event) {
 | 
			
		||||
        if (event.getExited() instanceof Player) {
 | 
			
		||||
            final Disguise disguise = DisguiseAPI.getDisguise((Player) event.getExited(), event.getExited());
 | 
			
		||||
            if (disguise != null) {
 | 
			
		||||
                Bukkit.getScheduler().runTask(plugin, new Runnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        DisguiseUtilities.setupFakeDisguise(disguise);
 | 
			
		||||
                        ((Player) disguise.getEntity()).updateInventory();
 | 
			
		||||
                    }
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
 | 
			
		||||
    public void onWorldSwitch(final PlayerChangedWorldEvent event) {
 | 
			
		||||
        if (!DisguiseAPI.isDisguised(event.getPlayer())) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isBedPacketsEnabled()) {
 | 
			
		||||
            chunkMove(event.getPlayer(), event.getPlayer().getLocation(), null);
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isUndisguiseOnWorldChange()) {
 | 
			
		||||
            for (Disguise disguise : DisguiseAPI.getDisguises(event.getPlayer())) {
 | 
			
		||||
                disguise.removeDisguise();
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            //Stupid hack to fix worldswitch invisibility bug
 | 
			
		||||
            final boolean viewSelfToggled = DisguiseAPI.isViewSelfToggled(event.getPlayer());
 | 
			
		||||
            if (viewSelfToggled) {
 | 
			
		||||
                final Disguise disguise = DisguiseAPI.getDisguise(event.getPlayer());
 | 
			
		||||
                disguise.setViewSelfDisguise(false);
 | 
			
		||||
                Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void run() {
 | 
			
		||||
                        disguise.setViewSelfDisguise(true);
 | 
			
		||||
                    }
 | 
			
		||||
                }, 20L); //I wish I could use lambdas here, so badly
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDisguiseClone(final String player, Boolean[] options) {
 | 
			
		||||
        if (disguiseRunnable.containsKey(player)) {
 | 
			
		||||
            BukkitRunnable run = disguiseRunnable.remove(player);
 | 
			
		||||
            run.cancel();
 | 
			
		||||
            run.run();
 | 
			
		||||
        }
 | 
			
		||||
        BukkitRunnable runnable = new BukkitRunnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                disguiseClone.remove(player);
 | 
			
		||||
                disguiseRunnable.remove(player);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseCloneExpire());
 | 
			
		||||
        disguiseRunnable.put(player, runnable);
 | 
			
		||||
        disguiseClone.put(player, options);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDisguiseEntity(final String player, Disguise disguise) {
 | 
			
		||||
        if (disguiseRunnable.containsKey(player)) {
 | 
			
		||||
            BukkitRunnable run = disguiseRunnable.remove(player);
 | 
			
		||||
            run.cancel();
 | 
			
		||||
            run.run();
 | 
			
		||||
        }
 | 
			
		||||
        BukkitRunnable runnable = new BukkitRunnable() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void run() {
 | 
			
		||||
                disguiseEntity.remove(player);
 | 
			
		||||
                disguiseRunnable.remove(player);
 | 
			
		||||
            }
 | 
			
		||||
        };
 | 
			
		||||
        runnable.runTaskLater(plugin, 20 * DisguiseConfig.getDisguiseEntityExpire());
 | 
			
		||||
        disguiseRunnable.put(player, runnable);
 | 
			
		||||
        disguiseEntity.put(player, disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										386
									
								
								src/me/libraryaddict/disguise/LibsDisguises.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										386
									
								
								src/me/libraryaddict/disguise/LibsDisguises.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,386 @@
 | 
			
		||||
package me.libraryaddict.disguise;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.lang.reflect.Field;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.entity.Ageable;
 | 
			
		||||
import org.bukkit.entity.Damageable;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Tameable;
 | 
			
		||||
import org.bukkit.entity.Zombie;
 | 
			
		||||
import org.bukkit.event.HandlerList;
 | 
			
		||||
import org.bukkit.plugin.java.JavaPlugin;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.reflect.FieldAccessException;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.commands.CloneDisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.DisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.DisguiseViewSelf;
 | 
			
		||||
import me.libraryaddict.disguise.commands.EntityDisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.HelpDisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.PlayerDisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.RadiusDisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.UndisguiseCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
 | 
			
		||||
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.GuardianWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.HorseWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseSound;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseValues;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.FakeBoundingBox;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.Metrics;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.PacketsManager;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class LibsDisguises extends JavaPlugin
 | 
			
		||||
{
 | 
			
		||||
    private static LibsDisguises instance;
 | 
			
		||||
    private DisguiseListener listener;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onEnable()
 | 
			
		||||
    {
 | 
			
		||||
        getLogger().info("Discovered MC version: " + ReflectionManager.getBukkitVersion());
 | 
			
		||||
 | 
			
		||||
        saveDefaultConfig();
 | 
			
		||||
 | 
			
		||||
        PacketsManager.init(this);
 | 
			
		||||
        DisguiseUtilities.init(this);
 | 
			
		||||
 | 
			
		||||
        DisguiseConfig.initConfig(getConfig());
 | 
			
		||||
 | 
			
		||||
        PacketsManager.addPacketListeners();
 | 
			
		||||
 | 
			
		||||
        listener = new DisguiseListener(this);
 | 
			
		||||
 | 
			
		||||
        Bukkit.getPluginManager().registerEvents(listener, this);
 | 
			
		||||
 | 
			
		||||
        getCommand("disguise").setExecutor(new DisguiseCommand());
 | 
			
		||||
        getCommand("undisguise").setExecutor(new UndisguiseCommand());
 | 
			
		||||
        getCommand("disguiseplayer").setExecutor(new PlayerDisguiseCommand());
 | 
			
		||||
        getCommand("undisguiseplayer").setExecutor(new UndisguisePlayerCommand());
 | 
			
		||||
        getCommand("undisguiseentity").setExecutor(new UndisguiseEntityCommand());
 | 
			
		||||
        getCommand("disguiseentity").setExecutor(new EntityDisguiseCommand());
 | 
			
		||||
        getCommand("disguiseradius").setExecutor(new RadiusDisguiseCommand(getConfig().getInt("DisguiseRadiusMax")));
 | 
			
		||||
        getCommand("undisguiseradius").setExecutor(new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
 | 
			
		||||
        getCommand("disguisehelp").setExecutor(new HelpDisguiseCommand());
 | 
			
		||||
        getCommand("disguiseclone").setExecutor(new CloneDisguiseCommand());
 | 
			
		||||
        getCommand("libsdisguises").setExecutor(new LibsDisguisesCommand());
 | 
			
		||||
        getCommand("disguiseviewself").setExecutor(new DisguiseViewSelf());
 | 
			
		||||
 | 
			
		||||
        registerValues();
 | 
			
		||||
 | 
			
		||||
        instance = this;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            Metrics metrics = new Metrics(this);
 | 
			
		||||
            metrics.start();
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException e)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Reloads the config with new config options.
 | 
			
		||||
     */
 | 
			
		||||
    public void reload()
 | 
			
		||||
    {
 | 
			
		||||
        HandlerList.unregisterAll(listener);
 | 
			
		||||
 | 
			
		||||
        reloadConfig();
 | 
			
		||||
        DisguiseConfig.initConfig(getConfig());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Here we create a nms entity for each disguise. Then grab their default values in their datawatcher. Then their sound volume
 | 
			
		||||
     * for mob noises. As well as setting their watcher class and entity size.
 | 
			
		||||
     */
 | 
			
		||||
    private void registerValues()
 | 
			
		||||
    {
 | 
			
		||||
        for (DisguiseType disguiseType : DisguiseType.values())
 | 
			
		||||
        {
 | 
			
		||||
            if (disguiseType.getEntityType() == null)
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Class watcherClass = null;
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                switch (disguiseType)
 | 
			
		||||
                {
 | 
			
		||||
                case ITEM_FRAME: // Not really supported...
 | 
			
		||||
                    break;
 | 
			
		||||
                case MINECART_CHEST:
 | 
			
		||||
                case MINECART_COMMAND:
 | 
			
		||||
                case MINECART_FURNACE:
 | 
			
		||||
                case MINECART_HOPPER:
 | 
			
		||||
                case MINECART_MOB_SPAWNER:
 | 
			
		||||
                case MINECART_TNT:
 | 
			
		||||
                    watcherClass = MinecartWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case DONKEY:
 | 
			
		||||
                case MULE:
 | 
			
		||||
                case UNDEAD_HORSE:
 | 
			
		||||
                case SKELETON_HORSE:
 | 
			
		||||
                    watcherClass = HorseWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case ZOMBIE_VILLAGER:
 | 
			
		||||
                case PIG_ZOMBIE:
 | 
			
		||||
                    watcherClass = ZombieWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case MAGMA_CUBE:
 | 
			
		||||
                    watcherClass = SlimeWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case ELDER_GUARDIAN:
 | 
			
		||||
                    watcherClass = GuardianWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case ENDERMITE:
 | 
			
		||||
                    watcherClass = LivingWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                case WITHER_SKELETON:
 | 
			
		||||
                    watcherClass = SkeletonWatcher.class;
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    watcherClass = Class.forName(
 | 
			
		||||
                            "me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "Watcher");
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            catch (ClassNotFoundException ex)
 | 
			
		||||
            {
 | 
			
		||||
                // There is no explicit watcher for this entity.
 | 
			
		||||
                Class entityClass = disguiseType.getEntityType().getEntityClass();
 | 
			
		||||
 | 
			
		||||
                if (entityClass != null)
 | 
			
		||||
                {
 | 
			
		||||
                    if (Tameable.class.isAssignableFrom(entityClass))
 | 
			
		||||
                    {
 | 
			
		||||
                        watcherClass = TameableWatcher.class;
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (Ageable.class.isAssignableFrom(entityClass))
 | 
			
		||||
                    {
 | 
			
		||||
                        watcherClass = AgeableWatcher.class;
 | 
			
		||||
                    }
 | 
			
		||||
                    else if (LivingEntity.class.isAssignableFrom(entityClass))
 | 
			
		||||
                    {
 | 
			
		||||
                        watcherClass = LivingWatcher.class;
 | 
			
		||||
                    }
 | 
			
		||||
                    else
 | 
			
		||||
                    {
 | 
			
		||||
                        watcherClass = FlagWatcher.class;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    watcherClass = FlagWatcher.class; // Disguise is unknown type
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            disguiseType.setWatcherClass(watcherClass);
 | 
			
		||||
 | 
			
		||||
            if (DisguiseValues.getDisguiseValues(disguiseType) != null)
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String nmsEntityName = toReadable(disguiseType.name());
 | 
			
		||||
 | 
			
		||||
            switch (disguiseType)
 | 
			
		||||
            {
 | 
			
		||||
            case WITHER_SKELETON:
 | 
			
		||||
            case ZOMBIE_VILLAGER:
 | 
			
		||||
            case DONKEY:
 | 
			
		||||
            case MULE:
 | 
			
		||||
            case UNDEAD_HORSE:
 | 
			
		||||
            case SKELETON_HORSE:
 | 
			
		||||
                continue;
 | 
			
		||||
            case PRIMED_TNT:
 | 
			
		||||
                nmsEntityName = "TNTPrimed";
 | 
			
		||||
                break;
 | 
			
		||||
            case MINECART_TNT:
 | 
			
		||||
                nmsEntityName = "MinecartTNT";
 | 
			
		||||
                break;
 | 
			
		||||
            case MINECART:
 | 
			
		||||
                nmsEntityName = "MinecartRideable";
 | 
			
		||||
                break;
 | 
			
		||||
            case FIREWORK:
 | 
			
		||||
                nmsEntityName = "Fireworks";
 | 
			
		||||
                break;
 | 
			
		||||
            case SPLASH_POTION:
 | 
			
		||||
                nmsEntityName = "Potion";
 | 
			
		||||
                break;
 | 
			
		||||
            case GIANT:
 | 
			
		||||
                nmsEntityName = "GiantZombie";
 | 
			
		||||
                break;
 | 
			
		||||
            case DROPPED_ITEM:
 | 
			
		||||
                nmsEntityName = "Item";
 | 
			
		||||
                break;
 | 
			
		||||
            case FIREBALL:
 | 
			
		||||
                nmsEntityName = "LargeFireball";
 | 
			
		||||
                break;
 | 
			
		||||
            case LEASH_HITCH:
 | 
			
		||||
                nmsEntityName = "Leash";
 | 
			
		||||
                break;
 | 
			
		||||
            case ELDER_GUARDIAN:
 | 
			
		||||
                nmsEntityName = "Guardian";
 | 
			
		||||
                break;
 | 
			
		||||
            case ARROW:
 | 
			
		||||
                nmsEntityName = "TippedArrow";
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                if (nmsEntityName.equalsIgnoreCase("Unknown"))
 | 
			
		||||
                {
 | 
			
		||||
                    DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
 | 
			
		||||
 | 
			
		||||
                    disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
 | 
			
		||||
 | 
			
		||||
                    DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
 | 
			
		||||
 | 
			
		||||
                    if (sound != null)
 | 
			
		||||
                    {
 | 
			
		||||
                        sound.setDamageAndIdleSoundVolume(1f);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
 | 
			
		||||
 | 
			
		||||
                if (nmsEntity == null)
 | 
			
		||||
                {
 | 
			
		||||
                    getLogger().warning("Entity not found! (" + nmsEntityName + ")");
 | 
			
		||||
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
 | 
			
		||||
                int entitySize = 0;
 | 
			
		||||
 | 
			
		||||
                for (Field field : ReflectionManager.getNmsClass("Entity").getFields())
 | 
			
		||||
                {
 | 
			
		||||
                    if (field.getType().getName().equals("EnumEntitySize"))
 | 
			
		||||
                    {
 | 
			
		||||
                        Enum enumEntitySize = (Enum) field.get(nmsEntity);
 | 
			
		||||
 | 
			
		||||
                        entitySize = enumEntitySize.ordinal();
 | 
			
		||||
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                DisguiseValues disguiseValues = new DisguiseValues(disguiseType, nmsEntity.getClass(), entitySize,
 | 
			
		||||
                        bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
 | 
			
		||||
 | 
			
		||||
                WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
 | 
			
		||||
 | 
			
		||||
                for (WrappedWatchableObject watch : watcher.getWatchableObjects())
 | 
			
		||||
                {
 | 
			
		||||
                    disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
 | 
			
		||||
                    // Uncomment when I need to find the new datawatcher values for a class..
 | 
			
		||||
                    // int id = watch.getIndex();
 | 
			
		||||
                    // Object val = watch.getValue();
 | 
			
		||||
                    // Class<?> valClazz = val != null ? watch.getValue().getClass() : null;
 | 
			
		||||
                    // try {
 | 
			
		||||
                    // val = val.toString();
 | 
			
		||||
                    // } catch (Exception e) {
 | 
			
		||||
                    // val = val != null ? val.getClass() : "null";
 | 
			
		||||
                    // }
 | 
			
		||||
                    // System.out.println("Disguise: " + disguiseType + ", ID: " + id + ", Class: " + (val == null ? "null" :
 | 
			
		||||
                    // valClazz) + ", Value: " + val);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                DisguiseSound sound = DisguiseSound.getType(disguiseType.name());
 | 
			
		||||
 | 
			
		||||
                if (sound != null)
 | 
			
		||||
                {
 | 
			
		||||
                    Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
 | 
			
		||||
 | 
			
		||||
                    if (soundStrength != null)
 | 
			
		||||
                    {
 | 
			
		||||
                        sound.setDamageAndIdleSoundVolume(soundStrength);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Get the bounding box
 | 
			
		||||
                disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
 | 
			
		||||
 | 
			
		||||
                if (bukkitEntity instanceof Ageable)
 | 
			
		||||
                {
 | 
			
		||||
                    ((Ageable) bukkitEntity).setBaby();
 | 
			
		||||
 | 
			
		||||
                    disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
 | 
			
		||||
                }
 | 
			
		||||
                else if (bukkitEntity instanceof Zombie)
 | 
			
		||||
                {
 | 
			
		||||
                    ((Zombie) bukkitEntity).setBaby(true);
 | 
			
		||||
 | 
			
		||||
                    disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                disguiseValues.setEntitySize(ReflectionManager.getSize(bukkitEntity));
 | 
			
		||||
            }
 | 
			
		||||
            catch (SecurityException | IllegalArgumentException | IllegalAccessException | FieldAccessException ex)
 | 
			
		||||
            {
 | 
			
		||||
                System.out.print(
 | 
			
		||||
                        "[LibsDisguises] Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
 | 
			
		||||
                System.out.print("[LibsDisguises] Before reporting this error, "
 | 
			
		||||
                        + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
 | 
			
		||||
                System.out.print("[LibsDisguises] Development builds are available at (ProtocolLib) "
 | 
			
		||||
                        + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) http://server.o2gaming.com:8080/job/LibsDisguises%201.9+/");
 | 
			
		||||
 | 
			
		||||
                ex.printStackTrace(System.out);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String toReadable(String string)
 | 
			
		||||
    {
 | 
			
		||||
        StringBuilder builder = new StringBuilder();
 | 
			
		||||
 | 
			
		||||
        for (String s : string.split("_"))
 | 
			
		||||
        {
 | 
			
		||||
            builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return builder.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public DisguiseListener getListener()
 | 
			
		||||
    {
 | 
			
		||||
        return listener;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * External APIs shouldn't actually need this instance. DisguiseAPI should be enough to handle most cases.
 | 
			
		||||
     *
 | 
			
		||||
     * @return The instance of this plugin
 | 
			
		||||
     */
 | 
			
		||||
    public static LibsDisguises getInstance()
 | 
			
		||||
    {
 | 
			
		||||
        return instance;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										767
									
								
								src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										767
									
								
								src/me/libraryaddict/disguise/commands/BaseDisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,767 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.Map.Entry;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.block.BlockFace;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Ageable;
 | 
			
		||||
import org.bukkit.entity.Animals;
 | 
			
		||||
import org.bukkit.entity.Monster;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.permissions.PermissionAttachmentInfo;
 | 
			
		||||
import org.bukkit.potion.PotionEffectType;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.MiscDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.MobDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author libraryaddict
 | 
			
		||||
 */
 | 
			
		||||
public abstract class BaseDisguiseCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    public class DisguiseParseException extends Exception {
 | 
			
		||||
 | 
			
		||||
        private static final long serialVersionUID = 1276971370793124510L;
 | 
			
		||||
 | 
			
		||||
        public DisguiseParseException() {
 | 
			
		||||
            super();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DisguiseParseException(String string) {
 | 
			
		||||
            super(string);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected ArrayList<String> getAllowedDisguises(HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> hashMap) {
 | 
			
		||||
        ArrayList<String> allowedDisguises = new ArrayList<>();
 | 
			
		||||
        for (DisguiseType type : hashMap.keySet()) {
 | 
			
		||||
            allowedDisguises.add(type.toReadable().replace(" ", "_"));
 | 
			
		||||
        }
 | 
			
		||||
        Collections.sort(allowedDisguises, String.CASE_INSENSITIVE_ORDER);
 | 
			
		||||
        return allowedDisguises;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender) {
 | 
			
		||||
        return getPermissions(sender, "libsdisguises." + getClass().getSimpleName().replace("Command", "").toLowerCase() + ".");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected HashMap<String, Boolean> getDisguisePermission(CommandSender sender, DisguiseType type) {
 | 
			
		||||
        switch (type) {
 | 
			
		||||
            case PLAYER:
 | 
			
		||||
            case FALLING_BLOCK:
 | 
			
		||||
            case PAINTING:
 | 
			
		||||
            case SPLASH_POTION:
 | 
			
		||||
            case FISHING_HOOK:
 | 
			
		||||
            case DROPPED_ITEM:
 | 
			
		||||
                HashMap<String, Boolean> returns = new HashMap<>();
 | 
			
		||||
                String beginning = "libsdisguises.options." + getClass().getSimpleName().toLowerCase().replace("command", "") + ".";
 | 
			
		||||
                for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
 | 
			
		||||
                    String lowerPerm = permission.getPermission().toLowerCase();
 | 
			
		||||
                    if (lowerPerm.startsWith(beginning)) {
 | 
			
		||||
                        String[] split = lowerPerm.substring(beginning.length()).split("\\.");
 | 
			
		||||
                        if (split.length > 1) {
 | 
			
		||||
                            if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) {
 | 
			
		||||
                                for (int i = 1; i < split.length; i++) {
 | 
			
		||||
                                    returns.put(split[i], permission.getValue());
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                return returns;
 | 
			
		||||
            default:
 | 
			
		||||
                return new HashMap<>();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected Method[] getDisguiseWatcherMethods(Class<? extends FlagWatcher> watcherClass) {
 | 
			
		||||
        Method[] methods = watcherClass.getMethods();
 | 
			
		||||
        methods = Arrays.copyOf(methods, methods.length + 4);
 | 
			
		||||
        int i = 4;
 | 
			
		||||
        for (String methodName : new String[]{"setViewSelfDisguise", "setHideHeldItemFromSelf", "setHideArmorFromSelf",
 | 
			
		||||
                "setHearSelfDisguise"}) {
 | 
			
		||||
            try {
 | 
			
		||||
                methods[methods.length - i--] = Disguise.class.getMethod(methodName, boolean.class);
 | 
			
		||||
            } catch (Exception ex) {
 | 
			
		||||
                ex.printStackTrace(System.out);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return methods;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get perms for the node. Returns a hashmap of allowed disguisetypes and their options
 | 
			
		||||
     *
 | 
			
		||||
     * @param sender
 | 
			
		||||
     * @param permissionNode
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    protected HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> getPermissions(CommandSender sender, String permissionNode) {
 | 
			
		||||
        HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> singleDisguises = new HashMap<>();
 | 
			
		||||
        HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> rangeDisguises = new HashMap<>();
 | 
			
		||||
        HashMap<String, Boolean> perms = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
        for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
 | 
			
		||||
            String perm = permission.getPermission().toLowerCase();
 | 
			
		||||
            if (perm.startsWith(permissionNode) && (!perms.containsKey(perm) || !permission.getValue())) {
 | 
			
		||||
                perms.put(perm, permission.getValue());
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!perms.containsKey(permissionNode + "*") && sender.hasPermission(permissionNode + "*")) {
 | 
			
		||||
            perms.put(permissionNode + "*", true);
 | 
			
		||||
        }
 | 
			
		||||
        if (!perms.containsKey(permissionNode + "*.*") && sender.hasPermission(permissionNode + "*.*")) {
 | 
			
		||||
            perms.put(permissionNode + "*.*", true);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (String perm : perms.keySet()) {
 | 
			
		||||
            if (perms.get(perm)) {
 | 
			
		||||
                perm = perm.substring(permissionNode.length());
 | 
			
		||||
                String disguiseType = perm.split("\\.")[0];
 | 
			
		||||
                DisguiseType dType = null;
 | 
			
		||||
                for (DisguiseType t : DisguiseType.values()) {
 | 
			
		||||
                    if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) {
 | 
			
		||||
                        dType = t;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (dType != null) {
 | 
			
		||||
                    HashMap<ArrayList<String>, Boolean> list;
 | 
			
		||||
                    if (singleDisguises.containsKey(dType)) {
 | 
			
		||||
                        list = singleDisguises.get(dType);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        list = new HashMap<>();
 | 
			
		||||
                        singleDisguises.put(dType, list);
 | 
			
		||||
                    }
 | 
			
		||||
                    HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
 | 
			
		||||
                    list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
 | 
			
		||||
                } else {
 | 
			
		||||
                    for (DisguiseType type : DisguiseType.values()) {
 | 
			
		||||
                        HashMap<ArrayList<String>, Boolean> options = null;
 | 
			
		||||
                        Class entityClass = type.getEntityClass();
 | 
			
		||||
                        if (disguiseType.equals("mob")) {
 | 
			
		||||
                            if (type.isMob()) {
 | 
			
		||||
                                options = getOptions(perm);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (disguiseType.equals("animal") || disguiseType.equals("animals")) {
 | 
			
		||||
                            if (Animals.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                options = getOptions(perm);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (disguiseType.equals("monster") || disguiseType.equals("monsters")) {
 | 
			
		||||
                            if (Monster.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                options = getOptions(perm);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (disguiseType.equals("misc")) {
 | 
			
		||||
                            if (type.isMisc()) {
 | 
			
		||||
                                options = getOptions(perm);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (disguiseType.equals("ageable")) {
 | 
			
		||||
                            if (Ageable.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                options = getOptions(perm);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (disguiseType.equals("*")) {
 | 
			
		||||
                            options = getOptions(perm);
 | 
			
		||||
                        }
 | 
			
		||||
                        if (options != null) {
 | 
			
		||||
                            HashMap<ArrayList<String>, Boolean> list;
 | 
			
		||||
                            if (rangeDisguises.containsKey(type)) {
 | 
			
		||||
                                list = rangeDisguises.get(type);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                list = new HashMap<>();
 | 
			
		||||
                                rangeDisguises.put(type, list);
 | 
			
		||||
                            }
 | 
			
		||||
                            HashMap<ArrayList<String>, Boolean> map1 = getOptions(perm);
 | 
			
		||||
                            list.put(map1.keySet().iterator().next(), map1.values().iterator().next());
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        for (String perm : perms.keySet()) {
 | 
			
		||||
            if (!perms.get(perm)) {
 | 
			
		||||
                perm = perm.substring(permissionNode.length());
 | 
			
		||||
                String disguiseType = perm.split("\\.")[0];
 | 
			
		||||
                DisguiseType dType = null;
 | 
			
		||||
                for (DisguiseType t : DisguiseType.values()) {
 | 
			
		||||
                    if (t.name().replace("_", "").equalsIgnoreCase(disguiseType.replace("_", ""))) {
 | 
			
		||||
                        dType = t;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (dType != null) {
 | 
			
		||||
                    singleDisguises.remove(dType);
 | 
			
		||||
                    rangeDisguises.remove(dType);
 | 
			
		||||
                } else {
 | 
			
		||||
                    for (DisguiseType type : DisguiseType.values()) {
 | 
			
		||||
                        boolean foundHim = false;
 | 
			
		||||
                        Class entityClass = type.getEntityClass();
 | 
			
		||||
                        switch (disguiseType) {
 | 
			
		||||
                            case "mob":
 | 
			
		||||
                                if (type.isMob()) {
 | 
			
		||||
                                    foundHim = true;
 | 
			
		||||
                                }
 | 
			
		||||
                                break;
 | 
			
		||||
                            case "animal":
 | 
			
		||||
                            case "animals":
 | 
			
		||||
                                if (Animals.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                    foundHim = true;
 | 
			
		||||
                                }
 | 
			
		||||
                                break;
 | 
			
		||||
                            case "monster":
 | 
			
		||||
                            case "monsters":
 | 
			
		||||
                                if (Monster.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                    foundHim = true;
 | 
			
		||||
                                }
 | 
			
		||||
                                break;
 | 
			
		||||
                            case "misc":
 | 
			
		||||
                                if (type.isMisc()) {
 | 
			
		||||
                                    foundHim = true;
 | 
			
		||||
                                }
 | 
			
		||||
                                break;
 | 
			
		||||
                            case "ageable":
 | 
			
		||||
                                if (Ageable.class.isAssignableFrom(entityClass)) {
 | 
			
		||||
                                    foundHim = true;
 | 
			
		||||
                                }
 | 
			
		||||
                                break;
 | 
			
		||||
                            case "*":
 | 
			
		||||
                                foundHim = true;
 | 
			
		||||
                                break;
 | 
			
		||||
                        }
 | 
			
		||||
                        if (foundHim) {
 | 
			
		||||
                            rangeDisguises.remove(type);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = new HashMap<>();
 | 
			
		||||
        for (DisguiseType type : DisguiseType.values()) {
 | 
			
		||||
            HashMap<ArrayList<String>, Boolean> temp = new HashMap<>();
 | 
			
		||||
            if (singleDisguises.containsKey(type)) {
 | 
			
		||||
                temp.putAll(singleDisguises.get(type));
 | 
			
		||||
            }
 | 
			
		||||
            if (rangeDisguises.containsKey(type)) {
 | 
			
		||||
                temp.putAll(rangeDisguises.get(type));
 | 
			
		||||
            }
 | 
			
		||||
            if (!temp.isEmpty()) {
 | 
			
		||||
                map.put(type, temp);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return map;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private HashMap<ArrayList<String>, Boolean> getOptions(String perm) {
 | 
			
		||||
        ArrayList<String> list = new ArrayList<>();
 | 
			
		||||
        boolean isRemove = true;
 | 
			
		||||
        String[] split = perm.split("\\.");
 | 
			
		||||
        for (int i = 1; i < split.length; i++) {
 | 
			
		||||
            String option = split[i];
 | 
			
		||||
            boolean value = option.startsWith("-");
 | 
			
		||||
            if (value) {
 | 
			
		||||
                option = option.substring(1);
 | 
			
		||||
                isRemove = false;
 | 
			
		||||
            }
 | 
			
		||||
            if (option.equals("baby")) {
 | 
			
		||||
                option = "setbaby";
 | 
			
		||||
            }
 | 
			
		||||
            list.add(option);
 | 
			
		||||
        }
 | 
			
		||||
        HashMap<ArrayList<String>, Boolean> options = new HashMap<>();
 | 
			
		||||
        options.put(list, isRemove);
 | 
			
		||||
        return options;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean isDouble(String string) {
 | 
			
		||||
        try {
 | 
			
		||||
            Float.parseFloat(string);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean isNumeric(String string) {
 | 
			
		||||
        try {
 | 
			
		||||
            Integer.parseInt(string);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the disguise if it all parsed correctly. Returns a exception with a complete message if it didn't. The commandsender is purely used for checking permissions. Would defeat the purpose otherwise. To reach this point, the disguise has been feed a proper disguisetype.
 | 
			
		||||
     *
 | 
			
		||||
     * @param sender
 | 
			
		||||
     * @param args
 | 
			
		||||
     * @param map
 | 
			
		||||
     * @return
 | 
			
		||||
     * @throws BaseDisguiseCommand.DisguiseParseException
 | 
			
		||||
     * @throws java.lang.IllegalAccessException
 | 
			
		||||
     * @throws java.lang.reflect.InvocationTargetException
 | 
			
		||||
     */
 | 
			
		||||
    protected Disguise parseDisguise(CommandSender sender, String[] args, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) throws DisguiseParseException,
 | 
			
		||||
            IllegalAccessException, InvocationTargetException {
 | 
			
		||||
        if (map.isEmpty()) {
 | 
			
		||||
            throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        if (args.length == 0) {
 | 
			
		||||
            sendCommandUsage(sender, map);
 | 
			
		||||
            throw new DisguiseParseException();
 | 
			
		||||
        }
 | 
			
		||||
        // How many args to skip due to the disugise being constructed
 | 
			
		||||
        // Time to start constructing the disguise.
 | 
			
		||||
        // We will need to check between all 3 kinds of disguises
 | 
			
		||||
        int toSkip = 1;
 | 
			
		||||
        ArrayList<String> usedOptions = new ArrayList<>();
 | 
			
		||||
        Disguise disguise = null;
 | 
			
		||||
        HashMap<ArrayList<String>, Boolean> optionPermissions;
 | 
			
		||||
        if (args[0].startsWith("@")) {
 | 
			
		||||
            if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
 | 
			
		||||
                disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase());
 | 
			
		||||
                if (disguise == null) {
 | 
			
		||||
                    throw new DisguiseParseException(ChatColor.RED + "Cannot find a disguise under the reference " + args[0]);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "You do not have perimssion to use disguise references!");
 | 
			
		||||
            }
 | 
			
		||||
            optionPermissions = (map.containsKey(disguise.getType()) ? map.get(disguise.getType())
 | 
			
		||||
                    : new HashMap<ArrayList<String>, Boolean>());
 | 
			
		||||
        } else {
 | 
			
		||||
            DisguiseType disguiseType = null;
 | 
			
		||||
            if (args[0].equalsIgnoreCase("p")) {
 | 
			
		||||
                disguiseType = DisguiseType.PLAYER;
 | 
			
		||||
            } else {
 | 
			
		||||
                for (DisguiseType type : DisguiseType.values()) {
 | 
			
		||||
                    if (args[0].equalsIgnoreCase(type.name()) || args[0].equalsIgnoreCase(type.name().replace("_", ""))) {
 | 
			
		||||
                        disguiseType = type;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (disguiseType == null) {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0]
 | 
			
		||||
                        + ChatColor.RED + " doesn't exist!");
 | 
			
		||||
            }
 | 
			
		||||
            if (disguiseType.isUnknown()) {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!");
 | 
			
		||||
            }
 | 
			
		||||
            if (disguiseType.getEntityType() == null) {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "Error! This version of minecraft does not have that disguise!");
 | 
			
		||||
            }
 | 
			
		||||
            if (!map.containsKey(disguiseType)) {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this disguise.");
 | 
			
		||||
            }
 | 
			
		||||
            optionPermissions = map.get(disguiseType);
 | 
			
		||||
            HashMap<String, Boolean> disguiseOptions = this.getDisguisePermission(sender, disguiseType);
 | 
			
		||||
            if (disguiseType.isPlayer()) {
 | 
			
		||||
                // If he is doing a player disguise
 | 
			
		||||
                if (args.length == 1) {
 | 
			
		||||
                    // He needs to give the player name
 | 
			
		||||
                    throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!");
 | 
			
		||||
                } else {
 | 
			
		||||
                    if (!disguiseOptions.isEmpty()
 | 
			
		||||
                            && (!disguiseOptions.containsKey(args[1].toLowerCase()) || !disguiseOptions
 | 
			
		||||
                            .get(args[1].toLowerCase()))) {
 | 
			
		||||
                        throw new DisguiseParseException(ChatColor.RED + "Error! You don't have permission to use that name!");
 | 
			
		||||
                    }
 | 
			
		||||
                    args[1] = args[1].replace("\\_", " ");
 | 
			
		||||
                    // Construct the player disguise
 | 
			
		||||
                    disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
 | 
			
		||||
                    toSkip++;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                if (disguiseType.isMob()) { // Its a mob, use the mob constructor
 | 
			
		||||
                    boolean adult = true;
 | 
			
		||||
                    if (args.length > 1) {
 | 
			
		||||
                        if (args[1].equalsIgnoreCase("baby") || args[1].equalsIgnoreCase("adult")) {
 | 
			
		||||
                            usedOptions.add("setbaby");
 | 
			
		||||
                            doCheck(optionPermissions, usedOptions);
 | 
			
		||||
                            adult = args[1].equalsIgnoreCase("adult");
 | 
			
		||||
                            toSkip++;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    disguise = new MobDisguise(disguiseType, adult);
 | 
			
		||||
                } else if (disguiseType.isMisc()) {
 | 
			
		||||
                    // Its a misc, we are going to use the MiscDisguise constructor.
 | 
			
		||||
                    int miscId = -1;
 | 
			
		||||
                    int miscData = -1;
 | 
			
		||||
                    String secondArg = null;
 | 
			
		||||
                    if (args.length > 1) {
 | 
			
		||||
                        // They have defined more arguments!
 | 
			
		||||
                        // If the first arg is a number
 | 
			
		||||
                        if (args[1].contains(":")) {
 | 
			
		||||
                            String[] split = args[1].split(":");
 | 
			
		||||
                            if (isNumeric(split[1])) {
 | 
			
		||||
                                secondArg = split[1];
 | 
			
		||||
                            }
 | 
			
		||||
                            args[1] = split[0];
 | 
			
		||||
                        }
 | 
			
		||||
                        if (isNumeric(args[1])) {
 | 
			
		||||
                            miscId = Integer.parseInt(args[1]);
 | 
			
		||||
                        } else {
 | 
			
		||||
                            if (disguiseType == DisguiseType.FALLING_BLOCK || disguiseType == DisguiseType.DROPPED_ITEM) {
 | 
			
		||||
                                for (Material mat : Material.values()) {
 | 
			
		||||
                                    if (mat.name().replace("_", "").equalsIgnoreCase(args[1].replace("_", ""))) {
 | 
			
		||||
                                        miscId = mat.getId();
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        if (miscId != -1) {
 | 
			
		||||
                            switch (disguiseType) {
 | 
			
		||||
                                case PAINTING:
 | 
			
		||||
                                case FALLING_BLOCK:
 | 
			
		||||
                                case SPLASH_POTION:
 | 
			
		||||
                                case DROPPED_ITEM:
 | 
			
		||||
                                case FISHING_HOOK:
 | 
			
		||||
                                case ARROW:
 | 
			
		||||
                                case TIPPED_ARROW:
 | 
			
		||||
                                case SPECTRAL_ARROW:
 | 
			
		||||
                                case SMALL_FIREBALL:
 | 
			
		||||
                                case FIREBALL:
 | 
			
		||||
                                case WITHER_SKULL:
 | 
			
		||||
                                    break;
 | 
			
		||||
                                default:
 | 
			
		||||
                                    throw new DisguiseParseException(ChatColor.RED + "Error! " + disguiseType.toReadable()
 | 
			
		||||
                                            + " doesn't know what to do with " + args[1] + "!");
 | 
			
		||||
                            }
 | 
			
		||||
                            toSkip++;
 | 
			
		||||
                            // If they also defined a data value
 | 
			
		||||
                            if (args.length > 2 && secondArg == null && isNumeric(args[2])) {
 | 
			
		||||
                                secondArg = args[2];
 | 
			
		||||
                                toSkip++;
 | 
			
		||||
                            }
 | 
			
		||||
                            if (secondArg != null) {
 | 
			
		||||
                                if (disguiseType != DisguiseType.FALLING_BLOCK && disguiseType != DisguiseType.DROPPED_ITEM) {
 | 
			
		||||
                                    throw new DisguiseParseException(ChatColor.RED + "Error! Only the disguises "
 | 
			
		||||
                                            + DisguiseType.FALLING_BLOCK.toReadable() + " and "
 | 
			
		||||
                                            + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!");
 | 
			
		||||
                                }
 | 
			
		||||
                                miscData = Integer.parseInt(secondArg);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (!disguiseOptions.isEmpty() && miscId != -1) {
 | 
			
		||||
                        String toCheck = "" + miscId;
 | 
			
		||||
                        if (miscData == 0 || miscData == -1) {
 | 
			
		||||
                            if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
 | 
			
		||||
                                toCheck += ":0";
 | 
			
		||||
                            }
 | 
			
		||||
                        } else {
 | 
			
		||||
                            toCheck += ":" + miscData;
 | 
			
		||||
                        }
 | 
			
		||||
                        if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
 | 
			
		||||
                            throw new DisguiseParseException(ChatColor.RED
 | 
			
		||||
                                    + "Error! You do not have permission to use the parameter " + toCheck + " on the "
 | 
			
		||||
                                    + disguiseType.toReadable() + " disguise!");
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (miscId != -1) {
 | 
			
		||||
                        if (disguiseType == DisguiseType.FALLING_BLOCK) {
 | 
			
		||||
                            usedOptions.add("setblock");
 | 
			
		||||
                            doCheck(optionPermissions, usedOptions);
 | 
			
		||||
                        } else if (disguiseType == DisguiseType.PAINTING) {
 | 
			
		||||
                            usedOptions.add("setpainting");
 | 
			
		||||
                            doCheck(optionPermissions, usedOptions);
 | 
			
		||||
                        } else if (disguiseType == DisguiseType.SPLASH_POTION) {
 | 
			
		||||
                            usedOptions.add("setpotionid");
 | 
			
		||||
                            doCheck(optionPermissions, usedOptions);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    // Construct the disguise
 | 
			
		||||
                    disguise = new MiscDisguise(disguiseType, miscId, miscData);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // Copy strings to their new range
 | 
			
		||||
        String[] newArgs = new String[args.length - toSkip];
 | 
			
		||||
        System.arraycopy(args, toSkip, newArgs, 0, args.length - toSkip);
 | 
			
		||||
        args = newArgs;
 | 
			
		||||
        Method[] methods = this.getDisguiseWatcherMethods(disguise.getWatcher().getClass());
 | 
			
		||||
        for (int i = 0; i < args.length; i += 2) {
 | 
			
		||||
            String methodName = args[i];
 | 
			
		||||
            String valueString = (args.length - 1 == i ? null : args[i + 1]);
 | 
			
		||||
            Method methodToUse = null;
 | 
			
		||||
            Object value = null;
 | 
			
		||||
            DisguiseParseException storedEx = null;
 | 
			
		||||
            int c = 0;
 | 
			
		||||
            while (c < methods.length) {
 | 
			
		||||
                try {
 | 
			
		||||
                    Entry<Method, Integer> entry = getMethod(methods, methodName, c);
 | 
			
		||||
                    if (entry == null) {
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    methodToUse = entry.getKey();
 | 
			
		||||
                    c = entry.getValue();
 | 
			
		||||
                    methodName = methodToUse.getName();
 | 
			
		||||
                    Class<?>[] types = methodToUse.getParameterTypes();
 | 
			
		||||
                    Class param = types[0];
 | 
			
		||||
                    if (valueString != null) {
 | 
			
		||||
                        if (int.class == param) {
 | 
			
		||||
                            // Parse to integer
 | 
			
		||||
                            if (isNumeric(valueString)) {
 | 
			
		||||
                                value = Integer.parseInt(valueString);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                throw parseToException("number", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (float.class == param || double.class == param) {
 | 
			
		||||
                            // Parse to number
 | 
			
		||||
                            if (isDouble(valueString)) {
 | 
			
		||||
                                float obj = Float.parseFloat(valueString);
 | 
			
		||||
                                if (param == float.class) {
 | 
			
		||||
                                    value = obj;
 | 
			
		||||
                                } else if (param == double.class) {
 | 
			
		||||
                                    value = (double) obj;
 | 
			
		||||
                                }
 | 
			
		||||
                            } else {
 | 
			
		||||
                                throw parseToException("number.0", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (param == String.class) {
 | 
			
		||||
                            // Parse to string
 | 
			
		||||
                            value = ChatColor.translateAlternateColorCodes('&', valueString);
 | 
			
		||||
                        } else if (param == AnimalColor.class) {
 | 
			
		||||
                            // Parse to animal color
 | 
			
		||||
                            try {
 | 
			
		||||
                                value = AnimalColor.valueOf(valueString.toUpperCase());
 | 
			
		||||
                            } catch (Exception ex) {
 | 
			
		||||
                                throw parseToException("animal color", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (param == ItemStack.class) {
 | 
			
		||||
                            // Parse to itemstack
 | 
			
		||||
                            try {
 | 
			
		||||
                                value = parseToItemstack(valueString);
 | 
			
		||||
                            } catch (Exception ex) {
 | 
			
		||||
                                throw new DisguiseParseException(String.format(ex.getMessage(), methodName));
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (param == ItemStack[].class) {
 | 
			
		||||
                            // Parse to itemstack array
 | 
			
		||||
                            ItemStack[] items = new ItemStack[4];
 | 
			
		||||
                            String[] split = valueString.split(",");
 | 
			
		||||
                            if (split.length == 4) {
 | 
			
		||||
                                for (int a = 0; a < 4; a++) {
 | 
			
		||||
                                    try {
 | 
			
		||||
                                        items[a] = parseToItemstack(split[a]);
 | 
			
		||||
                                    } catch (Exception ex) {
 | 
			
		||||
                                        throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
 | 
			
		||||
                                                + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                            } else {
 | 
			
		||||
                                throw parseToException("item ID,ID,ID,ID" + ChatColor.RED + " or " + ChatColor.GREEN
 | 
			
		||||
                                        + "ID:Data,ID:Data,ID:Data,ID:Data combo", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                            value = items;
 | 
			
		||||
                        } else if (param.getSimpleName().equals("Color")) {
 | 
			
		||||
                            // Parse to horse color
 | 
			
		||||
                            value = callValueOf(param, valueString, methodName, "a horse color");
 | 
			
		||||
                        } else if (param.getSimpleName().equals("Style")) {
 | 
			
		||||
                            // Parse to horse style
 | 
			
		||||
                            value = callValueOf(param, valueString, methodName, "a horse style");
 | 
			
		||||
                        } else if (param.getSimpleName().equals("Profession")) {
 | 
			
		||||
                            // Parse to villager profession
 | 
			
		||||
                            value = callValueOf(param, valueString, methodName, "a villager profession");
 | 
			
		||||
                        } else if (param.getSimpleName().equals("Art")) {
 | 
			
		||||
                            // Parse to art type
 | 
			
		||||
                            value = callValueOf(param, valueString, methodName, "a painting art");
 | 
			
		||||
                        } else if (param.getSimpleName().equals("Type")) {
 | 
			
		||||
                            // Parse to ocelot type
 | 
			
		||||
                            value = callValueOf(param, valueString, methodName, "a ocelot type");
 | 
			
		||||
                        } else if (param == PotionEffectType.class) {
 | 
			
		||||
                            // Parse to potion effect
 | 
			
		||||
                            try {
 | 
			
		||||
                                PotionEffectType potionType = PotionEffectType.getByName(valueString.toUpperCase());
 | 
			
		||||
                                if (potionType == null && isNumeric(valueString)) {
 | 
			
		||||
                                    potionType = PotionEffectType.getById(Integer.parseInt(valueString));
 | 
			
		||||
                                }
 | 
			
		||||
                                if (potionType == null) {
 | 
			
		||||
                                    throw new DisguiseParseException();
 | 
			
		||||
                                }
 | 
			
		||||
                                value = potionType;
 | 
			
		||||
                            } catch (Exception ex) {
 | 
			
		||||
                                throw parseToException("a potioneffect type", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (param == int[].class) {
 | 
			
		||||
                            String[] split = valueString.split(",");
 | 
			
		||||
                            int[] values = new int[split.length];
 | 
			
		||||
                            for (int b = 0; b < values.length; b++) {
 | 
			
		||||
                                try {
 | 
			
		||||
                                    values[b] = Integer.parseInt(split[b]);
 | 
			
		||||
                                } catch (NumberFormatException ex) {
 | 
			
		||||
                                    throw parseToException("Number,Number,Number...", valueString, methodName);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                            value = values;
 | 
			
		||||
                        } else if (param == BlockFace.class) {
 | 
			
		||||
                            try {
 | 
			
		||||
                                BlockFace face = BlockFace.valueOf(valueString.toUpperCase());
 | 
			
		||||
                                if (face.ordinal() > 4) {
 | 
			
		||||
                                    throw new DisguiseParseException();
 | 
			
		||||
                                }
 | 
			
		||||
                                value = face;
 | 
			
		||||
                            } catch (Exception ex) {
 | 
			
		||||
                                throw parseToException("a direction (north, east, south, west, up)", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        } else if (param == RabbitType.class) {
 | 
			
		||||
                            try {
 | 
			
		||||
                                for (RabbitType type : RabbitType.values()) {
 | 
			
		||||
                                    if (type.name().replace("_", "")
 | 
			
		||||
                                            .equalsIgnoreCase(valueString.replace("_", "").replace(" ", ""))) {
 | 
			
		||||
                                        value = type;
 | 
			
		||||
                                        break;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                                if (value == null) {
 | 
			
		||||
                                    throw new Exception();
 | 
			
		||||
                                }
 | 
			
		||||
                            } catch (Exception ex) {
 | 
			
		||||
                                throw parseToException("rabbit type (white, brown, patches...)", valueString, methodName);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (value == null && boolean.class == param) {
 | 
			
		||||
                        if (valueString == null) {
 | 
			
		||||
                            value = true;
 | 
			
		||||
                            i--;
 | 
			
		||||
                        } else if (valueString.equalsIgnoreCase("true")) {
 | 
			
		||||
                            value = true;
 | 
			
		||||
                        } else if (valueString.equalsIgnoreCase("false")) {
 | 
			
		||||
                            value = false;
 | 
			
		||||
                        } else {
 | 
			
		||||
                            if (getMethod(methods, valueString, 0) == null) {
 | 
			
		||||
                                throw parseToException("true/false", valueString, methodName);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                value = true;
 | 
			
		||||
                                i--;
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (value != null) {
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                } catch (DisguiseParseException ex) {
 | 
			
		||||
                    storedEx = ex;
 | 
			
		||||
                    methodToUse = null;
 | 
			
		||||
                } catch (Exception ex) {
 | 
			
		||||
                    ex.printStackTrace(System.out);
 | 
			
		||||
                    methodToUse = null;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (methodToUse == null) {
 | 
			
		||||
                if (storedEx != null) {
 | 
			
		||||
                    throw storedEx;
 | 
			
		||||
                }
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "Cannot find the option " + methodName);
 | 
			
		||||
            }
 | 
			
		||||
            if (value == null) {
 | 
			
		||||
                throw new DisguiseParseException(ChatColor.RED + "No value was given for the option " + methodName);
 | 
			
		||||
            }
 | 
			
		||||
            if (!usedOptions.contains(methodName.toLowerCase())) {
 | 
			
		||||
                usedOptions.add(methodName.toLowerCase());
 | 
			
		||||
            }
 | 
			
		||||
            doCheck(optionPermissions, usedOptions);
 | 
			
		||||
            if (FlagWatcher.class.isAssignableFrom(methodToUse.getDeclaringClass())) {
 | 
			
		||||
                methodToUse.invoke(disguise.getWatcher(), value);
 | 
			
		||||
            } else {
 | 
			
		||||
                methodToUse.invoke(disguise, value);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // Alright. We've constructed our disguise.
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Entry<Method, Integer> getMethod(Method[] methods, String methodName, int toStart) {
 | 
			
		||||
        for (int i = toStart; i < methods.length; i++) {
 | 
			
		||||
            Method method = methods[i];
 | 
			
		||||
            if (!method.getName().startsWith("get") && method.getName().equalsIgnoreCase(methodName)
 | 
			
		||||
                    && method.getAnnotation(Deprecated.class) == null && method.getParameterTypes().length == 1) {
 | 
			
		||||
                return new HashMap.SimpleEntry(method, ++i);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Object callValueOf(Class<?> param, String valueString, String methodName, String description)
 | 
			
		||||
            throws DisguiseParseException {
 | 
			
		||||
        Object value;
 | 
			
		||||
        try {
 | 
			
		||||
            value = param.getMethod("valueOf", String.class).invoke(null, valueString.toUpperCase());
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            throw parseToException(description, valueString, methodName);
 | 
			
		||||
        }
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean passesCheck(HashMap<ArrayList<String>, Boolean> map1, ArrayList<String> usedOptions) {
 | 
			
		||||
        boolean hasPermission = false;
 | 
			
		||||
        for (ArrayList<String> list : map1.keySet()) {
 | 
			
		||||
            boolean myPerms = true;
 | 
			
		||||
            for (String option : usedOptions) {
 | 
			
		||||
                if (!(map1.get(list) && list.contains("*")) && (list.contains(option) != map1.get(list))) {
 | 
			
		||||
                    myPerms = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            if (myPerms) {
 | 
			
		||||
                hasPermission = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return hasPermission;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void doCheck(HashMap<ArrayList<String>, Boolean> optionPermissions, ArrayList<String> usedOptions)
 | 
			
		||||
            throws DisguiseParseException {
 | 
			
		||||
        if (!passesCheck(optionPermissions, usedOptions)) {
 | 
			
		||||
            throw new DisguiseParseException(ChatColor.RED + "You do not have the permission to use the option "
 | 
			
		||||
                    + usedOptions.get(usedOptions.size() - 1));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private DisguiseParseException parseToException(String expectedValue, String receivedInstead, String methodName) {
 | 
			
		||||
        return new DisguiseParseException(ChatColor.RED + "Expected " + ChatColor.GREEN + expectedValue + ChatColor.RED
 | 
			
		||||
                + ", received " + ChatColor.GREEN + receivedInstead + ChatColor.RED + " instead for " + ChatColor.GREEN
 | 
			
		||||
                + methodName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ItemStack parseToItemstack(String string) throws Exception {
 | 
			
		||||
        String[] split = string.split(":", -1);
 | 
			
		||||
        if (isNumeric(split[0])) {
 | 
			
		||||
            int itemId = Integer.parseInt(split[0]);
 | 
			
		||||
            short itemDura = 0;
 | 
			
		||||
            if (split.length > 1) {
 | 
			
		||||
                if (isNumeric(split[1])) {
 | 
			
		||||
                    itemDura = Short.parseShort(split[1]);
 | 
			
		||||
                } else {
 | 
			
		||||
                    throw parseToException("item ID:Durability combo", string, "%s");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            return new ItemStack(itemId, 1, itemDura);
 | 
			
		||||
        } else {
 | 
			
		||||
            if (split.length == 1) {
 | 
			
		||||
                throw parseToException("item ID", string, "%s");
 | 
			
		||||
            } else {
 | 
			
		||||
                throw parseToException("item ID:Durability combo", string, "%s");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected abstract void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map);
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,65 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
 | 
			
		||||
public class CloneDisguiseCommand extends BaseDisguiseCommand {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
 | 
			
		||||
            boolean doEquipment = true;
 | 
			
		||||
            boolean doSneak = false;
 | 
			
		||||
            boolean doSprint = false;
 | 
			
		||||
            for (String option : args) {
 | 
			
		||||
                if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip")
 | 
			
		||||
                        || StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) {
 | 
			
		||||
                    doEquipment = false;
 | 
			
		||||
                } else if (option.equalsIgnoreCase("doSneakSprint")) {
 | 
			
		||||
                    doSneak = true;
 | 
			
		||||
                    doSprint = true;
 | 
			
		||||
                } else if (option.equalsIgnoreCase("doSneak")) {
 | 
			
		||||
                    doSneak = true;
 | 
			
		||||
                } else if (option.equalsIgnoreCase("doSprint")) {
 | 
			
		||||
                    doSprint = true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option
 | 
			
		||||
                            + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), new Boolean[]{doEquipment, doSneak, doSprint});
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire()
 | 
			
		||||
                    + " seconds to grab the disguise reference!");
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN
 | 
			
		||||
                + "Right click a entity to get a disguise reference you can pass to other disguise commands!");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN
 | 
			
		||||
                + "Security note: Any references you create will be available to all players able to use disguise references.");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN
 | 
			
		||||
                + "Optional" + ChatColor.DARK_GREEN + ")");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										72
									
								
								src/me/libraryaddict/disguise/commands/DisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								src/me/libraryaddict/disguise/commands/DisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
 | 
			
		||||
public class DisguiseCommand extends BaseDisguiseCommand {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        Disguise disguise;
 | 
			
		||||
        try {
 | 
			
		||||
            disguise = parseDisguise(sender, args, getPermissions(sender));
 | 
			
		||||
        } catch (DisguiseParseException ex) {
 | 
			
		||||
            if (ex.getMessage() != null) {
 | 
			
		||||
                sender.sendMessage(ex.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
 | 
			
		||||
            if (disguise.getWatcher() instanceof LivingWatcher) {
 | 
			
		||||
                disguise.getWatcher().setCustomName(((Player) sender).getDisplayName());
 | 
			
		||||
                if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
 | 
			
		||||
                    disguise.getWatcher().setCustomNameVisible(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        DisguiseAPI.disguiseToAll((Player) sender, disguise);
 | 
			
		||||
        if (disguise.isDisguiseInUse()) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable());
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable());
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
 | 
			
		||||
        ArrayList<String> allowedDisguises = getAllowedDisguises(map);
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
 | 
			
		||||
                + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
 | 
			
		||||
        if (allowedDisguises.contains("player")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>");
 | 
			
		||||
        }
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>");
 | 
			
		||||
        if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										34
									
								
								src/me/libraryaddict/disguise/commands/DisguiseViewSelf.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/me/libraryaddict/disguise/commands/DisguiseViewSelf.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class DisguiseViewSelf implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        Player player = (Player) sender;
 | 
			
		||||
        if (DisguiseAPI.isViewSelfToggled(player)) {
 | 
			
		||||
            DisguiseAPI.setViewDisguiseToggled(player, false);
 | 
			
		||||
            sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise off!");
 | 
			
		||||
        } else {
 | 
			
		||||
            DisguiseAPI.setViewDisguiseToggled(player, true);
 | 
			
		||||
            sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise on!");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,64 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
 | 
			
		||||
public class EntityDisguiseCommand extends BaseDisguiseCommand {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        Disguise disguise;
 | 
			
		||||
        try {
 | 
			
		||||
            disguise = parseDisguise(sender, args, getPermissions(sender));
 | 
			
		||||
        } catch (DisguiseParseException ex) {
 | 
			
		||||
            if (ex.getMessage() != null) {
 | 
			
		||||
                sender.sendMessage(ex.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (IllegalAccessException | InvocationTargetException ex) {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
 | 
			
		||||
        sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseEntityExpire()
 | 
			
		||||
                + " seconds to disguise it as a " + disguise.getType().toReadable() + "!");
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     *
 | 
			
		||||
     * @param sender
 | 
			
		||||
     * @param map
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
 | 
			
		||||
        ArrayList<String> allowedDisguises = getAllowedDisguises(map);
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
 | 
			
		||||
                + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
 | 
			
		||||
        if (allowedDisguises.contains("player")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>");
 | 
			
		||||
        }
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>");
 | 
			
		||||
        if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										283
									
								
								src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										283
									
								
								src/me/libraryaddict/disguise/commands/HelpDisguiseCommand.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,283 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.block.BlockFace;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
import org.bukkit.potion.PotionEffectType;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
 | 
			
		||||
public class HelpDisguiseCommand extends BaseDisguiseCommand {
 | 
			
		||||
 | 
			
		||||
    private class EnumHelp {
 | 
			
		||||
 | 
			
		||||
        private String enumDescription;
 | 
			
		||||
        private String enumName;
 | 
			
		||||
        private String[] enums;
 | 
			
		||||
        private String readableEnum;
 | 
			
		||||
 | 
			
		||||
        public EnumHelp(String enumName, String enumReadable, String enumDescription, Enum[] enums) {
 | 
			
		||||
            String[] strings = new String[enums.length];
 | 
			
		||||
            for (int i = 0; i < strings.length; i++) {
 | 
			
		||||
                strings[i] = toReadable(enums[i].name());
 | 
			
		||||
            }
 | 
			
		||||
            this.enumName = enumName;
 | 
			
		||||
            this.enumDescription = enumDescription;
 | 
			
		||||
            this.enums = strings;
 | 
			
		||||
            this.readableEnum = enumReadable;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public EnumHelp(String enumName, String enumReadable, String enumDescription, String[] enums) {
 | 
			
		||||
            this.enumName = enumName;
 | 
			
		||||
            this.enumDescription = enumDescription;
 | 
			
		||||
            this.enums = enums;
 | 
			
		||||
            this.readableEnum = enumReadable;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getEnumDescription() {
 | 
			
		||||
            return enumDescription;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getEnumName() {
 | 
			
		||||
            return enumName;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String[] getEnums() {
 | 
			
		||||
            return enums;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public String getReadableEnum() {
 | 
			
		||||
            return readableEnum;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private ArrayList<EnumHelp> enumHelp = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public HelpDisguiseCommand() {
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("AnimalColor", "Animal colors", ChatColor.RED + "/disguisehelp AnimalColors "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the colors you can use for a animal color", AnimalColor.values()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("Art", "Arts", ChatColor.RED + "/disguisehelp Art " + ChatColor.GREEN
 | 
			
		||||
                    + "- View all the painting arts you can use on a painting disguise", (Enum[]) Class.forName("org.bukkit.Art")
 | 
			
		||||
                    .getEnumConstants()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("HorseColor", "Horse colors", ChatColor.RED + "/disguisehelp HorseColors "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the colors you can use for a horses color", (Enum[]) Class.forName(
 | 
			
		||||
                            "org.bukkit.entity.Horse$Color").getEnumConstants()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("HorseStyle", "Horse styles", ChatColor.RED + "/disguisehelp HorseStyles "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the styles you can use for a horses style", (Enum[]) Class.forName(
 | 
			
		||||
                            "org.bukkit.entity.Horse$Style").getEnumConstants()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("OcelotType", "Ocelot types", ChatColor.RED + "/disguisehelp OcelotTypes "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the ocelot types you can use for ocelots", (Enum[]) Class.forName(
 | 
			
		||||
                            "org.bukkit.entity.Ocelot$Type").getEnumConstants()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            ArrayList<String> enumReturns = new ArrayList<>();
 | 
			
		||||
            for (PotionEffectType potionType : PotionEffectType.values()) {
 | 
			
		||||
                if (potionType != null) {
 | 
			
		||||
                    enumReturns.add(toReadable(potionType.getName()) + ChatColor.RED + "(" + ChatColor.GREEN + potionType.getId()
 | 
			
		||||
                            + ChatColor.RED + ")");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            enumHelp.add(new EnumHelp("PotionEffect", "PotionEffect", ChatColor.RED + "/disguisehelp PotionEffect "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the potion effects you can set", enumReturns.toArray(new String[enumReturns
 | 
			
		||||
                            .size()])));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            enumHelp.add(new EnumHelp("Profession", "Villager professions", ChatColor.RED + "/disguisehelp Professions "
 | 
			
		||||
                    + ChatColor.GREEN + "- View all the professions you can set on a villager", (Enum[]) Class.forName(
 | 
			
		||||
                            "org.bukkit.entity.Villager$Profession").getEnumConstants()));
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
        }
 | 
			
		||||
        enumHelp.add(new EnumHelp("Direction", "Directions", ChatColor.RED + "/disguisehelp Directions " + ChatColor.GREEN
 | 
			
		||||
                + "- View the five directions usable on player setsleeping disguise", Arrays.copyOf(BlockFace.values(), 5)));
 | 
			
		||||
        enumHelp.add(new EnumHelp("RabbitType", "RabbitType", ChatColor.RED + "/disguisehelp RabbitType " + ChatColor.GREEN
 | 
			
		||||
                + "View the kinds of rabbits you can turn into", RabbitType.values()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
 | 
			
		||||
            HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> permMap = getPermissions(sender, "libsdisguises." + node
 | 
			
		||||
                    + ".");
 | 
			
		||||
            if (!permMap.isEmpty()) {
 | 
			
		||||
                if (args.length == 0) {
 | 
			
		||||
                    sendCommandUsage(sender, null);
 | 
			
		||||
                    return true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    EnumHelp help = null;
 | 
			
		||||
                    for (EnumHelp s : enumHelp) {
 | 
			
		||||
                        if (args[0].equalsIgnoreCase(s.getEnumName()) || args[0].equalsIgnoreCase(s.getEnumName() + "s")) {
 | 
			
		||||
                            help = s;
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (help != null) {
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + help.getReadableEnum() + ": " + ChatColor.GREEN
 | 
			
		||||
                                + StringUtils.join(help.getEnums(), ChatColor.RED + ", " + ChatColor.GREEN));
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    DisguiseType type = null;
 | 
			
		||||
                    for (DisguiseType disguiseType : DisguiseType.values()) {
 | 
			
		||||
                        if (args[0].equalsIgnoreCase(disguiseType.name())
 | 
			
		||||
                                || disguiseType.name().replace("_", "").equalsIgnoreCase(args[0])) {
 | 
			
		||||
                            type = disguiseType;
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    if (type == null) {
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]);
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    if (!permMap.containsKey(type)) {
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!");
 | 
			
		||||
                        return true;
 | 
			
		||||
                    }
 | 
			
		||||
                    ArrayList<String> methods = new ArrayList<>();
 | 
			
		||||
                    HashMap<String, ChatColor> map = new HashMap<>();
 | 
			
		||||
                    Class watcher = type.getWatcherClass();
 | 
			
		||||
                    int ignored = 0;
 | 
			
		||||
                    try {
 | 
			
		||||
                        for (Method method : this.getDisguiseWatcherMethods(watcher)) {
 | 
			
		||||
                            if (!method.getName().startsWith("get") && method.getParameterTypes().length == 1
 | 
			
		||||
                                    && method.getAnnotation(Deprecated.class) == null) {
 | 
			
		||||
                                if (args.length < 2 || !args[1].equalsIgnoreCase("show")) {
 | 
			
		||||
                                    boolean allowed = false;
 | 
			
		||||
                                    for (ArrayList<String> key : permMap.get(type).keySet()) {
 | 
			
		||||
                                        if (permMap.get(type).get(key)) {
 | 
			
		||||
                                            if (key.contains("*") || key.contains(method.getName().toLowerCase())) {
 | 
			
		||||
                                                allowed = true;
 | 
			
		||||
                                                break;
 | 
			
		||||
                                            }
 | 
			
		||||
                                        } else if (!key.contains(method.getName().toLowerCase())) {
 | 
			
		||||
                                            allowed = true;
 | 
			
		||||
                                            break;
 | 
			
		||||
                                        }
 | 
			
		||||
                                    }
 | 
			
		||||
                                    if (!allowed) {
 | 
			
		||||
                                        ignored++;
 | 
			
		||||
                                        continue;
 | 
			
		||||
                                    }
 | 
			
		||||
                                }
 | 
			
		||||
                                Class c = method.getParameterTypes()[0];
 | 
			
		||||
                                String valueType = null;
 | 
			
		||||
                                if (c == String.class) {
 | 
			
		||||
                                    valueType = "String";
 | 
			
		||||
                                } else if (boolean.class == c) {
 | 
			
		||||
                                    valueType = "True/False";
 | 
			
		||||
                                } else if (int.class == c) {
 | 
			
		||||
                                    valueType = "Number";
 | 
			
		||||
                                } else if (float.class == c || double.class == c) {
 | 
			
		||||
                                    valueType = "Decimal";
 | 
			
		||||
                                } else if (AnimalColor.class == c) {
 | 
			
		||||
                                    valueType = "Color";
 | 
			
		||||
                                } else if (ItemStack.class == c) {
 | 
			
		||||
                                    valueType = "Item (id:damage)";
 | 
			
		||||
                                } else if (ItemStack[].class == c) {
 | 
			
		||||
                                    valueType = "4 items (id:damage,id,...)";
 | 
			
		||||
                                } else if (c.getSimpleName().equals("Style")) {
 | 
			
		||||
                                    valueType = "Horse Style";
 | 
			
		||||
                                } else if (c.getSimpleName().equals("Color")) {
 | 
			
		||||
                                    valueType = "Horse Color";
 | 
			
		||||
                                } else if (c.getSimpleName().equals("Type")) {
 | 
			
		||||
                                    valueType = "Ocelot type";
 | 
			
		||||
                                } else if (c.getSimpleName().equals("Profession")) {
 | 
			
		||||
                                    valueType = "Villager Profession";
 | 
			
		||||
                                } else if (PotionEffectType.class == c) {
 | 
			
		||||
                                    valueType = "Potion effect";
 | 
			
		||||
                                } else if (c == int[].class) {
 | 
			
		||||
                                    valueType = "number,number,number...";
 | 
			
		||||
                                } else if (c == BlockFace.class) {
 | 
			
		||||
                                    valueType = "direction";
 | 
			
		||||
                                } else if (c == RabbitType.class) {
 | 
			
		||||
                                    valueType = "rabbit type";
 | 
			
		||||
                                }
 | 
			
		||||
                                if (valueType != null) {
 | 
			
		||||
                                    ChatColor methodColor = ChatColor.YELLOW;
 | 
			
		||||
                                    Class<?> declaring = method.getDeclaringClass();
 | 
			
		||||
                                    if (declaring == LivingWatcher.class) {
 | 
			
		||||
                                        methodColor = ChatColor.AQUA;
 | 
			
		||||
                                    } else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) {
 | 
			
		||||
                                        methodColor = ChatColor.GRAY;
 | 
			
		||||
                                    }
 | 
			
		||||
                                    String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + valueType
 | 
			
		||||
                                            + ChatColor.DARK_RED + ")";
 | 
			
		||||
                                    map.put(str, methodColor);
 | 
			
		||||
                                    methods.add(str);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } catch (Exception ex) {
 | 
			
		||||
                        ex.printStackTrace(System.out);
 | 
			
		||||
                    }
 | 
			
		||||
                    Collections.sort(methods, String.CASE_INSENSITIVE_ORDER);
 | 
			
		||||
                    for (int i = 0; i < methods.size(); i++) {
 | 
			
		||||
                        methods.set(i, map.get(methods.get(i)) + methods.get(i));
 | 
			
		||||
                    }
 | 
			
		||||
                    if (methods.isEmpty()) {
 | 
			
		||||
                        methods.add(ChatColor.RED + "No options with permission to use");
 | 
			
		||||
                    }
 | 
			
		||||
                    sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: "
 | 
			
		||||
                            + StringUtils.join(methods, ChatColor.DARK_RED + ", "));
 | 
			
		||||
                    if (ignored > 0) {
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "Ignored " + ignored
 | 
			
		||||
                                + " options you do not have permission to view. Add 'show' to view unusable options.");
 | 
			
		||||
                    }
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
 | 
			
		||||
        sender.sendMessage(ChatColor.RED
 | 
			
		||||
                + "/disguisehelp <DisguiseType> "
 | 
			
		||||
                + ChatColor.GREEN
 | 
			
		||||
                + "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use");
 | 
			
		||||
        for (EnumHelp s : enumHelp) {
 | 
			
		||||
            sender.sendMessage(s.getEnumDescription());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String toReadable(String string) {
 | 
			
		||||
        String[] split = string.split("_");
 | 
			
		||||
        for (int i = 0; i < split.length; i++) {
 | 
			
		||||
            split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
 | 
			
		||||
        }
 | 
			
		||||
        return StringUtils.join(split, "_");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
			
		||||
 | 
			
		||||
public class LibsDisguisesCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (args.length == 0) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN
 | 
			
		||||
                    + "This server is running "
 | 
			
		||||
                    + "Lib's Disguises v."
 | 
			
		||||
                    + Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion()
 | 
			
		||||
                    + " by libraryaddict, maintained by NavidK0.\n"
 | 
			
		||||
                    + "Use /libsdisguises reload to reload the config. All disguises will be blown by doing this.");
 | 
			
		||||
        } else if (args.length > 0) {
 | 
			
		||||
            if (sender.hasPermission("libsdisguises.reload")) {
 | 
			
		||||
                if (args[0].equalsIgnoreCase("reload")) {
 | 
			
		||||
                    LibsDisguises.getInstance().reload();
 | 
			
		||||
                    sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config.");
 | 
			
		||||
                    return true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "[LibsDisguises] That command doesn't exist!");
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,97 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
 | 
			
		||||
public class PlayerDisguiseCommand extends BaseDisguiseCommand {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
 | 
			
		||||
        if (map.isEmpty()) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (args.length == 0) {
 | 
			
		||||
            sendCommandUsage(sender, map);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (args.length == 1) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the player");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        Player player = Bukkit.getPlayer(args[0]);
 | 
			
		||||
        if (player == null) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        String[] newArgs = new String[args.length - 1];
 | 
			
		||||
        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
 | 
			
		||||
        Disguise disguise;
 | 
			
		||||
        try {
 | 
			
		||||
            disguise = parseDisguise(sender, newArgs, map);
 | 
			
		||||
        } catch (DisguiseParseException ex) {
 | 
			
		||||
            if (ex.getMessage() != null) {
 | 
			
		||||
                sender.sendMessage(ex.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED
 | 
			
		||||
                    + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseConfig.isNameOfPlayerShownAboveDisguise()) {
 | 
			
		||||
            if (disguise.getWatcher() instanceof LivingWatcher) {
 | 
			
		||||
                disguise.getWatcher().setCustomName(player.getDisplayName());
 | 
			
		||||
                if (DisguiseConfig.isNameAboveHeadAlwaysVisible()) {
 | 
			
		||||
                    disguise.getWatcher().setCustomNameVisible(true);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        DisguiseAPI.disguiseToAll(player, disguise);
 | 
			
		||||
        if (disguise.isDisguiseInUse()) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a "
 | 
			
		||||
                    + disguise.getType().toReadable() + "!");
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Failed to disguise " + player.getName() + " as a "
 | 
			
		||||
                    + disguise.getType().toReadable() + "!");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map) {
 | 
			
		||||
        ArrayList<String> allowedDisguises = getAllowedDisguises(map);
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
 | 
			
		||||
                + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
 | 
			
		||||
        if (allowedDisguises.contains("player")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>");
 | 
			
		||||
        }
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>");
 | 
			
		||||
        if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN
 | 
			
		||||
                    + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,254 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ClassGetter;
 | 
			
		||||
 | 
			
		||||
public class RadiusDisguiseCommand extends BaseDisguiseCommand
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    private int maxRadius = 30;
 | 
			
		||||
    private ArrayList<Class> validClasses = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
    public RadiusDisguiseCommand(int maxRadius)
 | 
			
		||||
    {
 | 
			
		||||
        this.maxRadius = maxRadius;
 | 
			
		||||
 | 
			
		||||
        for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity"))
 | 
			
		||||
        {
 | 
			
		||||
            if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null)
 | 
			
		||||
            {
 | 
			
		||||
                validClasses.add(c);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
 | 
			
		||||
    {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE"))
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
 | 
			
		||||
 | 
			
		||||
        if (map.isEmpty())
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args.length == 0)
 | 
			
		||||
        {
 | 
			
		||||
            sendCommandUsage(sender, map);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args[0].equalsIgnoreCase("entitytype") || args[0].equalsIgnoreCase("entitytypes"))
 | 
			
		||||
        {
 | 
			
		||||
            ArrayList<String> classes = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
            for (Class c : validClasses)
 | 
			
		||||
            {
 | 
			
		||||
                classes.add(c.getSimpleName());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Collections.sort(classes);
 | 
			
		||||
 | 
			
		||||
            sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN
 | 
			
		||||
                    + StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + ".");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Class entityClass = Entity.class;
 | 
			
		||||
        EntityType type = null;
 | 
			
		||||
        int starting = 0;
 | 
			
		||||
 | 
			
		||||
        if (!isNumeric(args[0]))
 | 
			
		||||
        {
 | 
			
		||||
            for (Class c : validClasses)
 | 
			
		||||
            {
 | 
			
		||||
                if (c.getSimpleName().equalsIgnoreCase(args[0]))
 | 
			
		||||
                {
 | 
			
		||||
                    entityClass = c;
 | 
			
		||||
                    starting = 1;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (starting == 0)
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    type = EntityType.valueOf(args[0].toUpperCase());
 | 
			
		||||
                }
 | 
			
		||||
                catch (Exception ex)
 | 
			
		||||
                {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (type == null)
 | 
			
		||||
                {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]);
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (args.length == starting + 1)
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius"
 | 
			
		||||
                    + (starting != 0 ? " and EntityType" : ""));
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!isNumeric(args[starting]))
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + args[starting] + " is not a number");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        int radius = Integer.parseInt(args[starting]);
 | 
			
		||||
 | 
			
		||||
        if (radius > maxRadius)
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?");
 | 
			
		||||
            radius = maxRadius;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        String[] newArgs = new String[args.length - (starting + 1)];
 | 
			
		||||
        System.arraycopy(args, starting + 1, newArgs, 0, newArgs.length);
 | 
			
		||||
        Disguise disguise;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            disguise = parseDisguise(sender, newArgs, map);
 | 
			
		||||
        }
 | 
			
		||||
        catch (DisguiseParseException ex)
 | 
			
		||||
        {
 | 
			
		||||
            if (ex.getMessage() != null)
 | 
			
		||||
            {
 | 
			
		||||
                sender.sendMessage(ex.getMessage());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Time to use it!
 | 
			
		||||
        int disguisedEntitys = 0;
 | 
			
		||||
        int miscDisguises = 0;
 | 
			
		||||
 | 
			
		||||
        for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius))
 | 
			
		||||
        {
 | 
			
		||||
            if (entity == sender)
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass()))
 | 
			
		||||
            {
 | 
			
		||||
                if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()
 | 
			
		||||
                        && entity instanceof LivingEntity)
 | 
			
		||||
                {
 | 
			
		||||
                    miscDisguises++;
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                disguise = disguise.clone();
 | 
			
		||||
 | 
			
		||||
                if (entity instanceof Player && DisguiseConfig.isNameOfPlayerShownAboveDisguise())
 | 
			
		||||
                {
 | 
			
		||||
                    if (disguise.getWatcher() instanceof LivingWatcher)
 | 
			
		||||
                    {
 | 
			
		||||
                        disguise.getWatcher().setCustomName(((Player) entity).getDisplayName());
 | 
			
		||||
                        if (DisguiseConfig.isNameAboveHeadAlwaysVisible())
 | 
			
		||||
                        {
 | 
			
		||||
                            disguise.getWatcher().setCustomNameVisible(true);
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                DisguiseAPI.disguiseToAll(entity, disguise);
 | 
			
		||||
 | 
			
		||||
                if (disguise.isDisguiseInUse())
 | 
			
		||||
                {
 | 
			
		||||
                    disguisedEntitys++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (disguisedEntitys > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!");
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (miscDisguises > 0)
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Failed to disguise " + miscDisguises
 | 
			
		||||
                    + " entities because the option to disguise a living entity as a non-living has been disabled in the config");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Send the player the information
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void sendCommandUsage(CommandSender sender, HashMap<DisguiseType, HashMap<ArrayList<String>, Boolean>> map)
 | 
			
		||||
    {
 | 
			
		||||
        ArrayList<String> allowedDisguises = getAllowedDisguises(map);
 | 
			
		||||
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at 30 blocks!");
 | 
			
		||||
        sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN
 | 
			
		||||
                + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
 | 
			
		||||
 | 
			
		||||
        String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
 | 
			
		||||
 | 
			
		||||
        if (allowedDisguises.contains("player"))
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>")
 | 
			
		||||
                    .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby"
 | 
			
		||||
                + optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
 | 
			
		||||
 | 
			
		||||
        if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block"))
 | 
			
		||||
        {
 | 
			
		||||
            sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional
 | 
			
		||||
                    + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">")
 | 
			
		||||
                            .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">"));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        sender.sendMessage(
 | 
			
		||||
                ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,32 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
 | 
			
		||||
public class UndisguiseCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.undisguise")) {
 | 
			
		||||
            if (DisguiseAPI.isDisguised((Entity) sender)) {
 | 
			
		||||
                DisguiseAPI.undisguiseToAll((Player) sender);
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You are no longer disguised");
 | 
			
		||||
            } else {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "You are not disguised!");
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,26 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
			
		||||
 | 
			
		||||
public class UndisguiseEntityCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.undisguiseentity")) {
 | 
			
		||||
            LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!");
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,37 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
import org.bukkit.command.Command;
 | 
			
		||||
import org.bukkit.command.CommandExecutor;
 | 
			
		||||
import org.bukkit.command.CommandSender;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
 | 
			
		||||
public class UndisguisePlayerCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.undisguiseplayer")) {
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                Player p = Bukkit.getPlayer(args[0]);
 | 
			
		||||
                if (p != null) {
 | 
			
		||||
                    if (DisguiseAPI.isDisguised(p)) {
 | 
			
		||||
                        DisguiseAPI.undisguiseToAll(p);
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "The player is no longer disguised");
 | 
			
		||||
                    } else {
 | 
			
		||||
                        sender.sendMessage(ChatColor.RED + "The player is not disguised!");
 | 
			
		||||
                    }
 | 
			
		||||
                } else {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "Player not found");
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>");
 | 
			
		||||
            }
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,66 @@
 | 
			
		||||
package me.libraryaddict.disguise.commands;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
 | 
			
		||||
public class UndisguiseRadiusCommand implements CommandExecutor {
 | 
			
		||||
 | 
			
		||||
    private int maxRadius = 30;
 | 
			
		||||
 | 
			
		||||
    public UndisguiseRadiusCommand(int maxRadius) {
 | 
			
		||||
        this.maxRadius = maxRadius;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isNumeric(String string) {
 | 
			
		||||
        try {
 | 
			
		||||
            Integer.parseInt(string);
 | 
			
		||||
            return true;
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
 | 
			
		||||
        if (sender.getName().equals("CONSOLE")) {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (sender.hasPermission("libsdisguises.undisguiseradius")) {
 | 
			
		||||
            int radius = maxRadius;
 | 
			
		||||
            if (args.length > 0) {
 | 
			
		||||
                if (!isNumeric(args[0])) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED
 | 
			
		||||
                            + " is not a number!");
 | 
			
		||||
                    return true;
 | 
			
		||||
                }
 | 
			
		||||
                radius = Integer.parseInt(args[0]);
 | 
			
		||||
                if (radius > maxRadius) {
 | 
			
		||||
                    sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius
 | 
			
		||||
                            + "! Don't want to make too much lag right?");
 | 
			
		||||
                    radius = maxRadius;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            int disguisedEntitys = 0;
 | 
			
		||||
            for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
 | 
			
		||||
                if (entity == sender) {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
                if (DisguiseAPI.isDisguised(entity)) {
 | 
			
		||||
                    DisguiseAPI.undisguiseToAll(entity);
 | 
			
		||||
                    disguisedEntitys++;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!");
 | 
			
		||||
        } else {
 | 
			
		||||
            sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										35
									
								
								src/me/libraryaddict/disguise/disguisetypes/AnimalColor.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/me/libraryaddict/disguise/disguisetypes/AnimalColor.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
public enum AnimalColor
 | 
			
		||||
{
 | 
			
		||||
    BLACK(15), BLUE(11), BROWN(12), CYAN(9), GRAY(7), GREEN(13), LIGHT_BLUE(3), LIME(5), MAGENTA(2), ORANGE(1), PINK(6), PURPLE(
 | 
			
		||||
            10), RED(14), SILVER(8), WHITE(0), YELLOW(4);
 | 
			
		||||
 | 
			
		||||
    public static AnimalColor getColor(int nmsId)
 | 
			
		||||
    {
 | 
			
		||||
        for (AnimalColor color : values())
 | 
			
		||||
        {
 | 
			
		||||
            if (color.getId() == nmsId)
 | 
			
		||||
            {
 | 
			
		||||
                return color;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int value;
 | 
			
		||||
 | 
			
		||||
    AnimalColor(int newValue)
 | 
			
		||||
    {
 | 
			
		||||
        value = newValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The color ID as defined by nms internals.
 | 
			
		||||
     */
 | 
			
		||||
    public int getId()
 | 
			
		||||
    {
 | 
			
		||||
        return value;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1034
									
								
								src/me/libraryaddict/disguise/disguisetypes/Disguise.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1034
									
								
								src/me/libraryaddict/disguise/disguisetypes/Disguise.java
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										389
									
								
								src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										389
									
								
								src/me/libraryaddict/disguise/disguisetypes/DisguiseType.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,389 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.StringUtils;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.Guardian;
 | 
			
		||||
import org.bukkit.entity.Horse;
 | 
			
		||||
import org.bukkit.entity.Skeleton;
 | 
			
		||||
import org.bukkit.entity.Skeleton.SkeletonType;
 | 
			
		||||
import org.bukkit.entity.Zombie;
 | 
			
		||||
 | 
			
		||||
public enum DisguiseType
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    AREA_EFFECT_CLOUD(3, 0),
 | 
			
		||||
 | 
			
		||||
    ARMOR_STAND(78),
 | 
			
		||||
 | 
			
		||||
    ARROW(60, 0),
 | 
			
		||||
 | 
			
		||||
    BAT,
 | 
			
		||||
 | 
			
		||||
    BLAZE,
 | 
			
		||||
 | 
			
		||||
    BOAT(1),
 | 
			
		||||
 | 
			
		||||
    CAVE_SPIDER,
 | 
			
		||||
 | 
			
		||||
    CHICKEN,
 | 
			
		||||
 | 
			
		||||
    COW,
 | 
			
		||||
 | 
			
		||||
    CREEPER,
 | 
			
		||||
 | 
			
		||||
    DONKEY,
 | 
			
		||||
 | 
			
		||||
    DRAGON_FIREBALL(93),
 | 
			
		||||
 | 
			
		||||
    DROPPED_ITEM(2, 1),
 | 
			
		||||
 | 
			
		||||
    EGG(62),
 | 
			
		||||
 | 
			
		||||
    ELDER_GUARDIAN,
 | 
			
		||||
 | 
			
		||||
    ENDER_CRYSTAL(51),
 | 
			
		||||
 | 
			
		||||
    ENDER_DRAGON,
 | 
			
		||||
 | 
			
		||||
    ENDER_PEARL(65),
 | 
			
		||||
 | 
			
		||||
    ENDER_SIGNAL(72),
 | 
			
		||||
 | 
			
		||||
    ENDERMAN,
 | 
			
		||||
 | 
			
		||||
    ENDERMITE,
 | 
			
		||||
 | 
			
		||||
    EXPERIENCE_ORB,
 | 
			
		||||
 | 
			
		||||
    FALLING_BLOCK(70, 1),
 | 
			
		||||
 | 
			
		||||
    FIREBALL(63),
 | 
			
		||||
 | 
			
		||||
    FIREWORK(76),
 | 
			
		||||
 | 
			
		||||
    FISHING_HOOK(90),
 | 
			
		||||
 | 
			
		||||
    GHAST,
 | 
			
		||||
 | 
			
		||||
    GIANT,
 | 
			
		||||
 | 
			
		||||
    GUARDIAN,
 | 
			
		||||
 | 
			
		||||
    HORSE,
 | 
			
		||||
 | 
			
		||||
    IRON_GOLEM,
 | 
			
		||||
 | 
			
		||||
    ITEM_FRAME(71),
 | 
			
		||||
 | 
			
		||||
    LEASH_HITCH(77),
 | 
			
		||||
 | 
			
		||||
    MAGMA_CUBE,
 | 
			
		||||
 | 
			
		||||
    MINECART(10),
 | 
			
		||||
 | 
			
		||||
    MINECART_CHEST(10, 1),
 | 
			
		||||
 | 
			
		||||
    MINECART_COMMAND(10, 6),
 | 
			
		||||
 | 
			
		||||
    MINECART_FURNACE(10, 2),
 | 
			
		||||
 | 
			
		||||
    MINECART_HOPPER(10, 5),
 | 
			
		||||
 | 
			
		||||
    MINECART_MOB_SPAWNER(10, 4),
 | 
			
		||||
 | 
			
		||||
    MINECART_TNT(10, 3),
 | 
			
		||||
 | 
			
		||||
    MULE,
 | 
			
		||||
 | 
			
		||||
    MUSHROOM_COW,
 | 
			
		||||
 | 
			
		||||
    OCELOT,
 | 
			
		||||
 | 
			
		||||
    PAINTING,
 | 
			
		||||
 | 
			
		||||
    PIG,
 | 
			
		||||
 | 
			
		||||
    PIG_ZOMBIE,
 | 
			
		||||
 | 
			
		||||
    PLAYER,
 | 
			
		||||
 | 
			
		||||
    PRIMED_TNT(50),
 | 
			
		||||
 | 
			
		||||
    RABBIT,
 | 
			
		||||
 | 
			
		||||
    SHEEP,
 | 
			
		||||
 | 
			
		||||
    SHULKER,
 | 
			
		||||
 | 
			
		||||
    SHULKER_BULLET(67),
 | 
			
		||||
 | 
			
		||||
    SILVERFISH,
 | 
			
		||||
 | 
			
		||||
    SKELETON,
 | 
			
		||||
 | 
			
		||||
    SKELETON_HORSE,
 | 
			
		||||
 | 
			
		||||
    SLIME,
 | 
			
		||||
 | 
			
		||||
    SMALL_FIREBALL(63),
 | 
			
		||||
 | 
			
		||||
    SNOWBALL(61),
 | 
			
		||||
 | 
			
		||||
    SNOWMAN,
 | 
			
		||||
 | 
			
		||||
    SPECTRAL_ARROW(91),
 | 
			
		||||
 | 
			
		||||
    SPIDER,
 | 
			
		||||
 | 
			
		||||
    SPLASH_POTION(73, 0),
 | 
			
		||||
 | 
			
		||||
    SQUID,
 | 
			
		||||
 | 
			
		||||
    TIPPED_ARROW(92),
 | 
			
		||||
 | 
			
		||||
    THROWN_EXP_BOTTLE(75),
 | 
			
		||||
 | 
			
		||||
    UNDEAD_HORSE,
 | 
			
		||||
 | 
			
		||||
    VILLAGER,
 | 
			
		||||
 | 
			
		||||
    WITCH,
 | 
			
		||||
 | 
			
		||||
    WITHER,
 | 
			
		||||
 | 
			
		||||
    WITHER_SKELETON,
 | 
			
		||||
 | 
			
		||||
    WITHER_SKULL(66),
 | 
			
		||||
 | 
			
		||||
    WOLF,
 | 
			
		||||
 | 
			
		||||
    ZOMBIE,
 | 
			
		||||
 | 
			
		||||
    ZOMBIE_VILLAGER,
 | 
			
		||||
 | 
			
		||||
    UNKNOWN;
 | 
			
		||||
 | 
			
		||||
    static
 | 
			
		||||
    {
 | 
			
		||||
        // We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older versions of MC.
 | 
			
		||||
        // Without erroring up everything.
 | 
			
		||||
 | 
			
		||||
        for (DisguiseType type : values())
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                DisguiseType toUse = type;
 | 
			
		||||
                String name;
 | 
			
		||||
 | 
			
		||||
                switch (type)
 | 
			
		||||
                {
 | 
			
		||||
                // Disguise item frame isn't supported. So we don't give it a entity type which should prevent it from being..
 | 
			
		||||
                // Usable.
 | 
			
		||||
                case ITEM_FRAME:
 | 
			
		||||
                    break;
 | 
			
		||||
                case DONKEY:
 | 
			
		||||
                case MULE:
 | 
			
		||||
                case UNDEAD_HORSE:
 | 
			
		||||
                case SKELETON_HORSE:
 | 
			
		||||
                    toUse = DisguiseType.HORSE;
 | 
			
		||||
                    break;
 | 
			
		||||
                case ZOMBIE_VILLAGER:
 | 
			
		||||
                    toUse = DisguiseType.ZOMBIE;
 | 
			
		||||
                    break;
 | 
			
		||||
                case WITHER_SKELETON:
 | 
			
		||||
                    toUse = DisguiseType.SKELETON;
 | 
			
		||||
                    break;
 | 
			
		||||
                case ELDER_GUARDIAN:
 | 
			
		||||
                    toUse = DisguiseType.GUARDIAN;
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                name = toUse.name();
 | 
			
		||||
 | 
			
		||||
                type.setEntityType(EntityType.valueOf(name));
 | 
			
		||||
            }
 | 
			
		||||
            catch (Throwable ex)
 | 
			
		||||
            {
 | 
			
		||||
                // This version of Spigot doesn't have the disguise.
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static DisguiseType getType(Entity entity)
 | 
			
		||||
    {
 | 
			
		||||
        DisguiseType disguiseType = getType(entity.getType());
 | 
			
		||||
 | 
			
		||||
        switch (disguiseType)
 | 
			
		||||
        {
 | 
			
		||||
        case ZOMBIE:
 | 
			
		||||
 | 
			
		||||
            if (((Zombie) entity).isVillager())
 | 
			
		||||
            {
 | 
			
		||||
                disguiseType = DisguiseType.ZOMBIE_VILLAGER;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case HORSE:
 | 
			
		||||
 | 
			
		||||
            disguiseType = DisguiseType.valueOf(((Horse) entity).getVariant().name());
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case SKELETON:
 | 
			
		||||
 | 
			
		||||
            if (((Skeleton) entity).getSkeletonType() == SkeletonType.WITHER)
 | 
			
		||||
            {
 | 
			
		||||
                disguiseType = DisguiseType.WITHER_SKELETON;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
        case GUARDIAN:
 | 
			
		||||
 | 
			
		||||
            if (((Guardian) entity).isElder())
 | 
			
		||||
            {
 | 
			
		||||
                disguiseType = DisguiseType.ELDER_GUARDIAN;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return disguiseType;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static DisguiseType getType(EntityType entityType)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return valueOf(entityType.name().toUpperCase());
 | 
			
		||||
        }
 | 
			
		||||
        catch (Throwable ex)
 | 
			
		||||
        {
 | 
			
		||||
            return DisguiseType.UNKNOWN;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int objectId = -1, defaultData = 0;
 | 
			
		||||
 | 
			
		||||
    private EntityType entityType;
 | 
			
		||||
 | 
			
		||||
    private Class<? extends FlagWatcher> watcherClass;
 | 
			
		||||
 | 
			
		||||
    DisguiseType(int... ints)
 | 
			
		||||
    {
 | 
			
		||||
        for (int i = 0; i < ints.length; i++)
 | 
			
		||||
        {
 | 
			
		||||
            int value = ints[i];
 | 
			
		||||
 | 
			
		||||
            switch (i)
 | 
			
		||||
            {
 | 
			
		||||
            case 0:
 | 
			
		||||
                objectId = value;
 | 
			
		||||
 | 
			
		||||
                break;
 | 
			
		||||
            case 1:
 | 
			
		||||
                defaultData = value;
 | 
			
		||||
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getDefaultData()
 | 
			
		||||
    {
 | 
			
		||||
        return defaultData;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Class<? extends Entity> getEntityClass()
 | 
			
		||||
    {
 | 
			
		||||
        if (entityType != null)
 | 
			
		||||
        {
 | 
			
		||||
            return getEntityType().getEntityClass();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return Entity.class;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public EntityType getEntityType()
 | 
			
		||||
    {
 | 
			
		||||
        return entityType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The TYPE id of this entity. Different from the Object Id send in spawn packets when spawning miscs.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public int getTypeId()
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getEntityType().getTypeId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The object type send in packets when spawning a misc entity. Otherwise, -1.
 | 
			
		||||
     * 
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public int getObjectId()
 | 
			
		||||
    {
 | 
			
		||||
        return objectId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Class getWatcherClass()
 | 
			
		||||
    {
 | 
			
		||||
        return watcherClass;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isMisc()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityType() != null && !getEntityType().isAlive();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isMob()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityType() != null && getEntityType().isAlive() && !isPlayer();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isPlayer()
 | 
			
		||||
    {
 | 
			
		||||
        return this == DisguiseType.PLAYER;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isUnknown()
 | 
			
		||||
    {
 | 
			
		||||
        return this == DisguiseType.UNKNOWN;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setEntityType(EntityType entityType)
 | 
			
		||||
    {
 | 
			
		||||
        this.entityType = entityType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setWatcherClass(Class<? extends FlagWatcher> c)
 | 
			
		||||
    {
 | 
			
		||||
        watcherClass = c;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String toReadable()
 | 
			
		||||
    {
 | 
			
		||||
        String[] split = name().split("_");
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < split.length; i++)
 | 
			
		||||
        {
 | 
			
		||||
            split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return StringUtils.join(split, " ");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										636
									
								
								src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										636
									
								
								src/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,636 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.LivingEntity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.EntityEquipment;
 | 
			
		||||
import org.bukkit.inventory.EquipmentSlot;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.PacketType.Play.Server;
 | 
			
		||||
import com.comphenix.protocol.ProtocolLibrary;
 | 
			
		||||
import com.comphenix.protocol.events.PacketContainer;
 | 
			
		||||
import com.comphenix.protocol.reflect.StructureModifier;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.PacketsManager;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class FlagWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    private boolean addEntityAnimations = DisguiseConfig.isEntityAnimationsAdded();
 | 
			
		||||
    /**
 | 
			
		||||
     * These are the entity values I need to add else it could crash them..
 | 
			
		||||
     */
 | 
			
		||||
    private HashMap<Integer, Object> backupEntityValues = new HashMap<>();
 | 
			
		||||
    private TargetedDisguise disguise;
 | 
			
		||||
    private HashMap<Integer, Object> entityValues = new HashMap<>();
 | 
			
		||||
    private boolean hasDied;
 | 
			
		||||
    public EntityEquipment equipment;
 | 
			
		||||
    private HashSet<Integer> modifiedEntityAnimations = new HashSet<>();
 | 
			
		||||
    private List<WrappedWatchableObject> watchableObjects;
 | 
			
		||||
 | 
			
		||||
    public FlagWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        this.disguise = (TargetedDisguise) disguise;
 | 
			
		||||
        equipment = ReflectionManager.createEntityEquipment(disguise.getEntity());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private byte addEntityAnimations(byte originalValue, byte entityValue)
 | 
			
		||||
    {
 | 
			
		||||
        byte valueByte = originalValue;
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i < 6; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if ((entityValue & 1 << i) != 0 && !modifiedEntityAnimations.contains(i))
 | 
			
		||||
            {
 | 
			
		||||
                valueByte = (byte) (valueByte | 1 << i);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        originalValue = valueByte;
 | 
			
		||||
 | 
			
		||||
        return originalValue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public FlagWatcher clone(Disguise owningDisguise)
 | 
			
		||||
    {
 | 
			
		||||
        FlagWatcher cloned;
 | 
			
		||||
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            cloned = getClass().getConstructor(Disguise.class).newInstance(getDisguise());
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception e)
 | 
			
		||||
        {
 | 
			
		||||
            e.printStackTrace(System.out);
 | 
			
		||||
            cloned = new FlagWatcher(getDisguise());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        cloned.entityValues = (HashMap<Integer, Object>) entityValues.clone();
 | 
			
		||||
        cloned.equipment = ReflectionManager.createEntityEquipment(cloned.getDisguise().getEntity());
 | 
			
		||||
        cloned.modifiedEntityAnimations = (HashSet<Integer>) modifiedEntityAnimations.clone();
 | 
			
		||||
        cloned.addEntityAnimations = addEntityAnimations;
 | 
			
		||||
 | 
			
		||||
        return cloned;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<WrappedWatchableObject> convert(List<WrappedWatchableObject> list)
 | 
			
		||||
    {
 | 
			
		||||
        List<WrappedWatchableObject> newList = new ArrayList<>();
 | 
			
		||||
        HashSet<Integer> sentValues = new HashSet<>();
 | 
			
		||||
        boolean sendAllCustom = false;
 | 
			
		||||
 | 
			
		||||
        for (WrappedWatchableObject watch : list)
 | 
			
		||||
        {
 | 
			
		||||
            int id = watch.getIndex();
 | 
			
		||||
            sentValues.add(id);
 | 
			
		||||
 | 
			
		||||
            // Its sending the air metadata. This is the least commonly sent metadata which all entitys still share.
 | 
			
		||||
            // I send my custom values if I see this!
 | 
			
		||||
            if (id == 1)
 | 
			
		||||
            {
 | 
			
		||||
                sendAllCustom = true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Object value = null;
 | 
			
		||||
 | 
			
		||||
            if (entityValues.containsKey(id))
 | 
			
		||||
            {
 | 
			
		||||
                if (entityValues.get(id) == null)
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                value = entityValues.get(id);
 | 
			
		||||
            }
 | 
			
		||||
            else if (backupEntityValues.containsKey(id))
 | 
			
		||||
            {
 | 
			
		||||
                if (backupEntityValues.get(id) == null)
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                value = backupEntityValues.get(id);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (value != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (isEntityAnimationsAdded() && id == 0)
 | 
			
		||||
                {
 | 
			
		||||
                    value = this.addEntityAnimations((byte) value, (byte) watch.getValue());
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                boolean isDirty = watch.getDirtyState();
 | 
			
		||||
 | 
			
		||||
                watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
 | 
			
		||||
 | 
			
		||||
                if (!isDirty)
 | 
			
		||||
                {
 | 
			
		||||
                    watch.setDirtyState(false);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                boolean isDirty = watch.getDirtyState();
 | 
			
		||||
 | 
			
		||||
                watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue()));
 | 
			
		||||
 | 
			
		||||
                if (!isDirty)
 | 
			
		||||
                {
 | 
			
		||||
                    watch.setDirtyState(false);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            newList.add(watch);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (sendAllCustom)
 | 
			
		||||
        {
 | 
			
		||||
            // Its sending the entire meta data. Better add the custom meta
 | 
			
		||||
            for (int id : entityValues.keySet())
 | 
			
		||||
            {
 | 
			
		||||
                if (sentValues.contains(id))
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                Object value = entityValues.get(id);
 | 
			
		||||
 | 
			
		||||
                if (value == null)
 | 
			
		||||
                {
 | 
			
		||||
                    continue;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
 | 
			
		||||
 | 
			
		||||
                newList.add(watch);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // Here we check for if there is a health packet that says they died.
 | 
			
		||||
        if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null
 | 
			
		||||
                && getDisguise().getEntity() instanceof Player)
 | 
			
		||||
        {
 | 
			
		||||
            for (WrappedWatchableObject watch : newList)
 | 
			
		||||
            {
 | 
			
		||||
                // Its a health packet
 | 
			
		||||
                if (watch.getIndex() == 6)
 | 
			
		||||
                {
 | 
			
		||||
                    Object value = watch.getValue();
 | 
			
		||||
 | 
			
		||||
                    if (value != null && value instanceof Float)
 | 
			
		||||
                    {
 | 
			
		||||
                        float newHealth = (Float) value;
 | 
			
		||||
 | 
			
		||||
                        if (newHealth > 0 && hasDied)
 | 
			
		||||
                        {
 | 
			
		||||
                            hasDied = false;
 | 
			
		||||
                            DisguiseUtilities.sendSelfDisguise((Player) getDisguise().getEntity(), disguise);
 | 
			
		||||
                        }
 | 
			
		||||
                        else if (newHealth <= 0 && !hasDied)
 | 
			
		||||
                        {
 | 
			
		||||
                            hasDied = true;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return newList;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack[] getArmor()
 | 
			
		||||
    {
 | 
			
		||||
        ItemStack[] armor = new ItemStack[4];
 | 
			
		||||
        System.arraycopy(armor, 0, armor, 0, 4);
 | 
			
		||||
 | 
			
		||||
        return armor;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getCustomName()
 | 
			
		||||
    {
 | 
			
		||||
        return (String) getValue(2, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected TargetedDisguise getDisguise()
 | 
			
		||||
    {
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean getEntityFlag(int byteValue)
 | 
			
		||||
    {
 | 
			
		||||
        return ((byte) getValue(0, (byte) 0) & 1 << byteValue) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getItemInMainHand()
 | 
			
		||||
    {
 | 
			
		||||
        if (equipment == null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        return equipment.getItemInMainHand();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getItemInOffHand()
 | 
			
		||||
    {
 | 
			
		||||
        if (equipment == null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        return equipment.getItemInOffHand();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public EntityEquipment getEquipment()
 | 
			
		||||
    {
 | 
			
		||||
        return equipment;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected <Y> Y getValue(int no, Y backup)
 | 
			
		||||
    {
 | 
			
		||||
        if (entityValues.containsKey(no))
 | 
			
		||||
        {
 | 
			
		||||
            return (Y) entityValues.get(no);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return backup;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<WrappedWatchableObject> getWatchableObjects()
 | 
			
		||||
    {
 | 
			
		||||
        if (watchableObjects == null)
 | 
			
		||||
        {
 | 
			
		||||
            rebuildWatchableObjects();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return watchableObjects;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasCustomName()
 | 
			
		||||
    {
 | 
			
		||||
        return getCustomName() != null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean hasValue(int no)
 | 
			
		||||
    {
 | 
			
		||||
        return entityValues.containsKey(no);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isCustomNameVisible()
 | 
			
		||||
    {
 | 
			
		||||
        return (boolean) getValue(3, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isEntityAnimationsAdded()
 | 
			
		||||
    {
 | 
			
		||||
        return addEntityAnimations;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBurning()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSneaking()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSprinting()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(3);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRightClicking()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isInvisible()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isGlowing()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isFlyingWithElytra()
 | 
			
		||||
    {
 | 
			
		||||
        return getEntityFlag(7);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void rebuildWatchableObjects()
 | 
			
		||||
    {
 | 
			
		||||
        watchableObjects = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (int i = 0; i <= 31; i++)
 | 
			
		||||
        {
 | 
			
		||||
            WrappedWatchableObject watchable = null;
 | 
			
		||||
 | 
			
		||||
            if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null)
 | 
			
		||||
            {
 | 
			
		||||
                watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
 | 
			
		||||
            }
 | 
			
		||||
            else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null)
 | 
			
		||||
            {
 | 
			
		||||
                watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (watchable != null)
 | 
			
		||||
            {
 | 
			
		||||
                watchableObjects.add(watchable);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void sendData(int... dataValues)
 | 
			
		||||
    {
 | 
			
		||||
        if (!DisguiseAPI.isDisguiseInUse(getDisguise()) || getDisguise().getWatcher() != this)
 | 
			
		||||
        {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        List<WrappedWatchableObject> list = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (int data : dataValues)
 | 
			
		||||
        {
 | 
			
		||||
            if (!entityValues.containsKey(data) || entityValues.get(data) == null)
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            Object value = entityValues.get(data);
 | 
			
		||||
 | 
			
		||||
            if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0)
 | 
			
		||||
            {
 | 
			
		||||
                if (!PacketsManager.isStaticMetadataDisguiseType(disguise))
 | 
			
		||||
                {
 | 
			
		||||
                    value = addEntityAnimations((byte) value,
 | 
			
		||||
                            WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value));
 | 
			
		||||
 | 
			
		||||
            list.add(watch);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!list.isEmpty())
 | 
			
		||||
        {
 | 
			
		||||
            PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
 | 
			
		||||
 | 
			
		||||
            StructureModifier<Object> mods = packet.getModifier();
 | 
			
		||||
            mods.write(0, getDisguise().getEntity().getEntityId());
 | 
			
		||||
 | 
			
		||||
            packet.getWatchableCollectionModifier().write(0, list);
 | 
			
		||||
 | 
			
		||||
            for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
                }
 | 
			
		||||
                catch (InvocationTargetException e)
 | 
			
		||||
                {
 | 
			
		||||
                    e.printStackTrace(System.out);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAddEntityAnimations(boolean isEntityAnimationsAdded)
 | 
			
		||||
    {
 | 
			
		||||
        this.addEntityAnimations = isEntityAnimationsAdded;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setArmor(ItemStack[] itemstack)
 | 
			
		||||
    {
 | 
			
		||||
        setItemStack(EquipmentSlot.HEAD, itemstack[0]);
 | 
			
		||||
        setItemStack(EquipmentSlot.CHEST, itemstack[1]);
 | 
			
		||||
        setItemStack(EquipmentSlot.LEGS, itemstack[2]);
 | 
			
		||||
        setItemStack(EquipmentSlot.FEET, itemstack[3]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void setBackupValue(int no, Object value)
 | 
			
		||||
    {
 | 
			
		||||
        backupEntityValues.put(no, value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBurning(boolean setBurning)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(0, setBurning);
 | 
			
		||||
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCustomName(String name)
 | 
			
		||||
    {
 | 
			
		||||
        if (name != null && name.length() > 64)
 | 
			
		||||
        {
 | 
			
		||||
            name = name.substring(0, 64);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        setValue(2, name);
 | 
			
		||||
        sendData(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCustomNameVisible(boolean display)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(3, display);
 | 
			
		||||
        sendData(3);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setEntityFlag(int byteValue, boolean flag)
 | 
			
		||||
    {
 | 
			
		||||
        modifiedEntityAnimations.add(byteValue);
 | 
			
		||||
 | 
			
		||||
        byte b0 = (byte) getValue(0, (byte) 0);
 | 
			
		||||
 | 
			
		||||
        if (flag)
 | 
			
		||||
        {
 | 
			
		||||
            setValue(0, (byte) (b0 | 1 << byteValue));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            setValue(0, (byte) (b0 & ~(1 << byteValue)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setInvisible(boolean setInvis)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(5, setInvis);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setGlowing(boolean glowing)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(6, glowing);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFlyingWithElytra(boolean flying)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(7, flying);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Don't use this, use setItemInMainHand instead
 | 
			
		||||
     *
 | 
			
		||||
     * @param itemstack
 | 
			
		||||
     */
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public void setItemInHand(ItemStack itemstack)
 | 
			
		||||
    {
 | 
			
		||||
        setItemInMainHand(itemstack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemInMainHand(ItemStack itemstack)
 | 
			
		||||
    {
 | 
			
		||||
        setItemStack(EquipmentSlot.HAND, itemstack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemInOffHand(ItemStack itemstack)
 | 
			
		||||
    {
 | 
			
		||||
        setItemStack(EquipmentSlot.OFF_HAND, itemstack);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemStack(EquipmentSlot slot, ItemStack itemStack)
 | 
			
		||||
    {
 | 
			
		||||
        if (equipment == null)
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        // Itemstack which is null means that its not replacing the disguises itemstack.
 | 
			
		||||
        if (itemStack == null)
 | 
			
		||||
        {
 | 
			
		||||
            // Find the item to replace it with
 | 
			
		||||
            if (getDisguise().getEntity() instanceof LivingEntity)
 | 
			
		||||
            {
 | 
			
		||||
                EntityEquipment equipment = ((LivingEntity) getDisguise().getEntity()).getEquipment();
 | 
			
		||||
                setItemStack(equipment, slot, itemStack);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Object itemToSend = null;
 | 
			
		||||
 | 
			
		||||
        if (itemStack != null && itemStack.getTypeId() != 0)
 | 
			
		||||
        {
 | 
			
		||||
            itemToSend = ReflectionManager.getNmsItem(itemStack);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        setItemStack(equipment, slot, itemStack);
 | 
			
		||||
 | 
			
		||||
        if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
 | 
			
		||||
        {
 | 
			
		||||
            PacketContainer packet = new PacketContainer(Server.ENTITY_EQUIPMENT);
 | 
			
		||||
 | 
			
		||||
            StructureModifier<Object> mods = packet.getModifier();
 | 
			
		||||
 | 
			
		||||
            mods.write(0, getDisguise().getEntity().getEntityId());
 | 
			
		||||
            mods.write(1, ReflectionManager.createEnumItemSlot(slot));
 | 
			
		||||
            mods.write(2, itemToSend);
 | 
			
		||||
 | 
			
		||||
            for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
                }
 | 
			
		||||
                catch (InvocationTargetException e)
 | 
			
		||||
                {
 | 
			
		||||
                    e.printStackTrace(System.out);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setItemStack(EntityEquipment equipment, EquipmentSlot slot, ItemStack itemStack)
 | 
			
		||||
    {
 | 
			
		||||
        if (equipment == null)
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        switch (slot)
 | 
			
		||||
        {
 | 
			
		||||
        case CHEST:
 | 
			
		||||
            equipment.setChestplate(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        case FEET:
 | 
			
		||||
            equipment.setBoots(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        case HAND:
 | 
			
		||||
            equipment.setItemInMainHand(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        case HEAD:
 | 
			
		||||
            equipment.setHelmet(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        case LEGS:
 | 
			
		||||
            equipment.setLeggings(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        case OFF_HAND:
 | 
			
		||||
            equipment.setItemInOffHand(itemStack);
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getItemStack(EquipmentSlot slot)
 | 
			
		||||
    {
 | 
			
		||||
        if (equipment == null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        switch (slot)
 | 
			
		||||
        {
 | 
			
		||||
        case CHEST:
 | 
			
		||||
            return equipment.getChestplate();
 | 
			
		||||
        case FEET:
 | 
			
		||||
            return equipment.getBoots();
 | 
			
		||||
        case HAND:
 | 
			
		||||
            return equipment.getItemInMainHand();
 | 
			
		||||
        case HEAD:
 | 
			
		||||
            return equipment.getHelmet();
 | 
			
		||||
        case LEGS:
 | 
			
		||||
            return equipment.getLeggings();
 | 
			
		||||
        case OFF_HAND:
 | 
			
		||||
            return equipment.getItemInOffHand();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRightClicking(boolean setRightClicking)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(4, setRightClicking);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSneaking(boolean setSneaking)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(1, setSneaking);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSprinting(boolean setSprinting)
 | 
			
		||||
    {
 | 
			
		||||
        setEntityFlag(3, setSprinting);
 | 
			
		||||
        sendData(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void setValue(int id, Object value)
 | 
			
		||||
    {
 | 
			
		||||
        entityValues.put(id, value);
 | 
			
		||||
 | 
			
		||||
        if (!DisguiseConfig.isMetadataPacketsEnabled())
 | 
			
		||||
        {
 | 
			
		||||
            this.rebuildWatchableObjects();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										207
									
								
								src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										207
									
								
								src/me/libraryaddict/disguise/disguisetypes/MiscDisguise.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,207 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import java.security.InvalidParameterException;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Art;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.DroppedItemWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.FallingBlockWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.PaintingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.SplashPotionWatcher;
 | 
			
		||||
 | 
			
		||||
public class MiscDisguise extends TargetedDisguise {
 | 
			
		||||
 | 
			
		||||
    private int id = -1, data = 0;
 | 
			
		||||
 | 
			
		||||
    public MiscDisguise(DisguiseType disguiseType) {
 | 
			
		||||
        this(disguiseType, -1, disguiseType.getDefaultData());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MiscDisguise(DisguiseType disguiseType, int id) {
 | 
			
		||||
        this(disguiseType, id, disguiseType.getDefaultData());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MiscDisguise(DisguiseType disguiseType, int id, int data) {
 | 
			
		||||
        if (!disguiseType.isMisc()) {
 | 
			
		||||
            throw new InvalidParameterException("Expected a non-living DisguiseType while constructing MiscDisguise. Received "
 | 
			
		||||
                    + disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MobDisguise")
 | 
			
		||||
                    + " instead");
 | 
			
		||||
        }
 | 
			
		||||
        createDisguise(disguiseType);
 | 
			
		||||
        this.id = getType().getTypeId();
 | 
			
		||||
        this.data = getType().getDefaultData();
 | 
			
		||||
        switch (disguiseType) {
 | 
			
		||||
            // The only disguises which should use a custom data.
 | 
			
		||||
            case PAINTING:
 | 
			
		||||
                ((PaintingWatcher) getWatcher()).setArt(Art.values()[Math.max(0, id) % Art.values().length]);
 | 
			
		||||
                break;
 | 
			
		||||
            case FALLING_BLOCK:
 | 
			
		||||
                ((FallingBlockWatcher) getWatcher()).setBlock(new ItemStack(Math.max(1, id), 1, (short) Math.max(0,
 | 
			
		||||
                        data)));
 | 
			
		||||
                break;
 | 
			
		||||
            case SPLASH_POTION:
 | 
			
		||||
                ((SplashPotionWatcher) getWatcher()).setPotionId(Math.max(0, id));
 | 
			
		||||
                break;
 | 
			
		||||
            case DROPPED_ITEM:
 | 
			
		||||
                if (id > 0) {
 | 
			
		||||
                    ((DroppedItemWatcher) getWatcher()).setItemStack(new ItemStack(id, Math.max(0, data)));
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case FISHING_HOOK: // Entity ID of whoever is holding fishing rod
 | 
			
		||||
            case ARROW:
 | 
			
		||||
            case TIPPED_ARROW: // Entity ID of shooter. Used for "Is he on this scoreboard team and do I render it moving through his body?"
 | 
			
		||||
            case SPECTRAL_ARROW:
 | 
			
		||||
            case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
 | 
			
		||||
            case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
 | 
			
		||||
            case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter
 | 
			
		||||
                this.data = id;
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise addPlayer(Player player) {
 | 
			
		||||
        return (MiscDisguise) super.addPlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise addPlayer(String playername) {
 | 
			
		||||
        return (MiscDisguise) super.addPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise clone() {
 | 
			
		||||
        MiscDisguise disguise = new MiscDisguise(getType(), getData());
 | 
			
		||||
        disguise.setReplaceSounds(isSoundsReplaced());
 | 
			
		||||
        disguise.setViewSelfDisguise(isSelfDisguiseVisible());
 | 
			
		||||
        disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
 | 
			
		||||
        disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
 | 
			
		||||
        disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
 | 
			
		||||
        disguise.setVelocitySent(isVelocitySent());
 | 
			
		||||
        disguise.setModifyBoundingBox(isModifyBoundingBox());
 | 
			
		||||
        disguise.setWatcher(getWatcher().clone(disguise));
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * This is the getId of everything but falling block.
 | 
			
		||||
     */
 | 
			
		||||
    public int getData() {
 | 
			
		||||
        switch (getType()) {
 | 
			
		||||
            case FALLING_BLOCK:
 | 
			
		||||
                return (int) ((FallingBlockWatcher) getWatcher()).getBlock().getDurability();
 | 
			
		||||
            case PAINTING:
 | 
			
		||||
                return ((PaintingWatcher) getWatcher()).getArt().getId();
 | 
			
		||||
            case SPLASH_POTION:
 | 
			
		||||
                return ((SplashPotionWatcher) getWatcher()).getPotionId();
 | 
			
		||||
            default:
 | 
			
		||||
                return data;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Only falling block should use this
 | 
			
		||||
     */
 | 
			
		||||
    public int getId() {
 | 
			
		||||
        if (getType() == DisguiseType.FALLING_BLOCK) {
 | 
			
		||||
            return ((FallingBlockWatcher) getWatcher()).getBlock().getTypeId();
 | 
			
		||||
        }
 | 
			
		||||
        return id;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isMiscDisguise() {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise removePlayer(Player player) {
 | 
			
		||||
        return (MiscDisguise) super.removePlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise removePlayer(String playername) {
 | 
			
		||||
        return (MiscDisguise) super.removePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setDisguiseTarget(TargetType newTargetType) {
 | 
			
		||||
        return (MiscDisguise) super.setDisguiseTarget(newTargetType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setEntity(Entity entity) {
 | 
			
		||||
        return (MiscDisguise) super.setEntity(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
 | 
			
		||||
        return (MiscDisguise) super.setHearSelfDisguise(hearSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setHideArmorFromSelf(boolean hideArmor) {
 | 
			
		||||
        return (MiscDisguise) super.setHideArmorFromSelf(hideArmor);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
 | 
			
		||||
        return (MiscDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
 | 
			
		||||
        return (MiscDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
 | 
			
		||||
        return (MiscDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
 | 
			
		||||
        return (MiscDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setModifyBoundingBox(boolean modifyBox) {
 | 
			
		||||
        return (MiscDisguise) super.setModifyBoundingBox(modifyBox);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setReplaceSounds(boolean areSoundsReplaced) {
 | 
			
		||||
        return (MiscDisguise) super.setReplaceSounds(areSoundsReplaced);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setVelocitySent(boolean sendVelocity) {
 | 
			
		||||
        return (MiscDisguise) super.setVelocitySent(sendVelocity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
 | 
			
		||||
        return (MiscDisguise) super.setViewSelfDisguise(viewSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise setWatcher(FlagWatcher newWatcher) {
 | 
			
		||||
        return (MiscDisguise) super.setWatcher(newWatcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise silentlyAddPlayer(String playername) {
 | 
			
		||||
        return (MiscDisguise) super.silentlyAddPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MiscDisguise silentlyRemovePlayer(String playername) {
 | 
			
		||||
        return (MiscDisguise) super.silentlyRemovePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										187
									
								
								src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										187
									
								
								src/me/libraryaddict/disguise/disguisetypes/MobDisguise.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,187 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import java.security.InvalidParameterException;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.EntityType;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
 | 
			
		||||
 | 
			
		||||
public class MobDisguise extends TargetedDisguise {
 | 
			
		||||
 | 
			
		||||
    private boolean isAdult;
 | 
			
		||||
 | 
			
		||||
    public MobDisguise(DisguiseType disguiseType) {
 | 
			
		||||
        this(disguiseType, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public MobDisguise(DisguiseType disguiseType, boolean isAdult) {
 | 
			
		||||
        if (!disguiseType.isMob()) {
 | 
			
		||||
            throw new InvalidParameterException("Expected a living DisguiseType while constructing MobDisguise. Received "
 | 
			
		||||
                    + disguiseType + " instead. Please use " + (disguiseType.isPlayer() ? "PlayerDisguise" : "MiscDisguise")
 | 
			
		||||
                    + " instead");
 | 
			
		||||
        }
 | 
			
		||||
        this.isAdult = isAdult;
 | 
			
		||||
        createDisguise(disguiseType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public MobDisguise(DisguiseType disguiseType, boolean isAdult, boolean replaceSounds) {
 | 
			
		||||
        this(disguiseType, isAdult);
 | 
			
		||||
        this.setReplaceSounds(replaceSounds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public MobDisguise(EntityType entityType) {
 | 
			
		||||
        this(entityType, true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public MobDisguise(EntityType entityType, boolean isAdult) {
 | 
			
		||||
        this(DisguiseType.getType(entityType), isAdult);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public MobDisguise(EntityType entityType, boolean isAdult, boolean replaceSounds) {
 | 
			
		||||
        this(entityType, isAdult);
 | 
			
		||||
        this.setReplaceSounds(replaceSounds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise addPlayer(Player player) {
 | 
			
		||||
        return (MobDisguise) super.addPlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise addPlayer(String playername) {
 | 
			
		||||
        return (MobDisguise) super.addPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise clone() {
 | 
			
		||||
        MobDisguise disguise = new MobDisguise(getType(), isAdult());
 | 
			
		||||
        disguise.setReplaceSounds(isSoundsReplaced());
 | 
			
		||||
        disguise.setViewSelfDisguise(isSelfDisguiseVisible());
 | 
			
		||||
        disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
 | 
			
		||||
        disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
 | 
			
		||||
        disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
 | 
			
		||||
        disguise.setVelocitySent(isVelocitySent());
 | 
			
		||||
        disguise.setModifyBoundingBox(isModifyBoundingBox());
 | 
			
		||||
        disguise.setWatcher(getWatcher().clone(disguise));
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean doesDisguiseAge() {
 | 
			
		||||
        return getWatcher() != null && (getWatcher() instanceof AgeableWatcher || getWatcher() instanceof ZombieWatcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public LivingWatcher getWatcher() {
 | 
			
		||||
        return (LivingWatcher) super.getWatcher();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAdult() {
 | 
			
		||||
        if (getWatcher() != null) {
 | 
			
		||||
            if (getWatcher() instanceof AgeableWatcher) {
 | 
			
		||||
                return ((AgeableWatcher) getWatcher()).isAdult();
 | 
			
		||||
            } else if (getWatcher() instanceof ZombieWatcher) {
 | 
			
		||||
                return ((ZombieWatcher) getWatcher()).isAdult();
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        return isAdult;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isMobDisguise() {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise removePlayer(Player player) {
 | 
			
		||||
        return (MobDisguise) super.removePlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise removePlayer(String playername) {
 | 
			
		||||
        return (MobDisguise) super.removePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setDisguiseTarget(TargetType newTargetType) {
 | 
			
		||||
        return (MobDisguise) super.setDisguiseTarget(newTargetType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setEntity(Entity entity) {
 | 
			
		||||
        return (MobDisguise) super.setEntity(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
 | 
			
		||||
        return (MobDisguise) super.setHearSelfDisguise(hearSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setHideArmorFromSelf(boolean hideArmor) {
 | 
			
		||||
        return (MobDisguise) super.setHideArmorFromSelf(hideArmor);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
 | 
			
		||||
        return (MobDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
 | 
			
		||||
        return (MobDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
 | 
			
		||||
        return (MobDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
 | 
			
		||||
        return (MobDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setModifyBoundingBox(boolean modifyBox) {
 | 
			
		||||
        return (MobDisguise) super.setModifyBoundingBox(modifyBox);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setReplaceSounds(boolean areSoundsReplaced) {
 | 
			
		||||
        return (MobDisguise) super.setReplaceSounds(areSoundsReplaced);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setVelocitySent(boolean sendVelocity) {
 | 
			
		||||
        return (MobDisguise) super.setVelocitySent(sendVelocity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
 | 
			
		||||
        return (MobDisguise) super.setViewSelfDisguise(viewSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise setWatcher(FlagWatcher newWatcher) {
 | 
			
		||||
        return (MobDisguise) super.setWatcher(newWatcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise silentlyAddPlayer(String playername) {
 | 
			
		||||
        return (MobDisguise) super.silentlyAddPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public MobDisguise silentlyRemovePlayer(String playername) {
 | 
			
		||||
        return (MobDisguise) super.silentlyRemovePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										244
									
								
								src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										244
									
								
								src/me/libraryaddict/disguise/disguisetypes/PlayerDisguise.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,244 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang.Validate;
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.LibsDisguises;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.LibsProfileLookup;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class PlayerDisguise extends TargetedDisguise {
 | 
			
		||||
 | 
			
		||||
    private LibsProfileLookup currentLookup;
 | 
			
		||||
    private WrappedGameProfile gameProfile;
 | 
			
		||||
    private String playerName;
 | 
			
		||||
    private String skinToUse;
 | 
			
		||||
 | 
			
		||||
    public PlayerDisguise(String name) {
 | 
			
		||||
        if (name.length() > 16) {
 | 
			
		||||
            name = name.substring(0, 16);
 | 
			
		||||
        }
 | 
			
		||||
        playerName = name;
 | 
			
		||||
        createDisguise(DisguiseType.PLAYER);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public PlayerDisguise(String name, boolean replaceSounds) {
 | 
			
		||||
        this(name);
 | 
			
		||||
        this.setReplaceSounds(replaceSounds);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PlayerDisguise(String name, String skinToUse) {
 | 
			
		||||
        this(name);
 | 
			
		||||
        setSkin(skinToUse);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PlayerDisguise(WrappedGameProfile gameProfile) {
 | 
			
		||||
        this(gameProfile.getName());
 | 
			
		||||
        this.gameProfile = gameProfile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise addPlayer(Player player) {
 | 
			
		||||
        return (PlayerDisguise) super.addPlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise addPlayer(String playername) {
 | 
			
		||||
        return (PlayerDisguise) super.addPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise clone() {
 | 
			
		||||
        PlayerDisguise disguise = new PlayerDisguise(getName());
 | 
			
		||||
        if (disguise.currentLookup == null && disguise.gameProfile != null) {
 | 
			
		||||
            disguise.skinToUse = getSkin();
 | 
			
		||||
            disguise.gameProfile = gameProfile;
 | 
			
		||||
        } else {
 | 
			
		||||
            disguise.setSkin(getSkin());
 | 
			
		||||
        }
 | 
			
		||||
        disguise.setReplaceSounds(isSoundsReplaced());
 | 
			
		||||
        disguise.setViewSelfDisguise(isSelfDisguiseVisible());
 | 
			
		||||
        disguise.setHearSelfDisguise(isSelfDisguiseSoundsReplaced());
 | 
			
		||||
        disguise.setHideArmorFromSelf(isHidingArmorFromSelf());
 | 
			
		||||
        disguise.setHideHeldItemFromSelf(isHidingHeldItemFromSelf());
 | 
			
		||||
        disguise.setVelocitySent(isVelocitySent());
 | 
			
		||||
        disguise.setModifyBoundingBox(isModifyBoundingBox());
 | 
			
		||||
        disguise.setWatcher(getWatcher().clone(disguise));
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setGameProfile(WrappedGameProfile gameProfile) {
 | 
			
		||||
        this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, gameProfile.getName(), gameProfile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public WrappedGameProfile getGameProfile() {
 | 
			
		||||
        if (gameProfile == null) {
 | 
			
		||||
            if (getSkin() != null) {
 | 
			
		||||
                gameProfile = ReflectionManager.getGameProfile(null, getName());
 | 
			
		||||
            } else {
 | 
			
		||||
                gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), DisguiseUtilities.getProfileFromMojang(this));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return gameProfile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getName() {
 | 
			
		||||
        return playerName;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSkin() {
 | 
			
		||||
        return skinToUse;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerWatcher getWatcher() {
 | 
			
		||||
        return (PlayerWatcher) super.getWatcher();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isPlayerDisguise() {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise removePlayer(Player player) {
 | 
			
		||||
        return (PlayerDisguise) super.removePlayer(player);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise removePlayer(String playername) {
 | 
			
		||||
        return (PlayerDisguise) super.removePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setDisguiseTarget(TargetType newTargetType) {
 | 
			
		||||
        return (PlayerDisguise) super.setDisguiseTarget(newTargetType);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setEntity(Entity entity) {
 | 
			
		||||
        return (PlayerDisguise) super.setEntity(entity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setHearSelfDisguise(boolean hearSelfDisguise) {
 | 
			
		||||
        return (PlayerDisguise) super.setHearSelfDisguise(hearSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setHideArmorFromSelf(boolean hideArmor) {
 | 
			
		||||
        return (PlayerDisguise) super.setHideArmorFromSelf(hideArmor);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setHideHeldItemFromSelf(boolean hideHeldItem) {
 | 
			
		||||
        return (PlayerDisguise) super.setHideHeldItemFromSelf(hideHeldItem);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setKeepDisguiseOnEntityDespawn(boolean keepDisguise) {
 | 
			
		||||
        return (PlayerDisguise) super.setKeepDisguiseOnEntityDespawn(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setKeepDisguiseOnPlayerDeath(boolean keepDisguise) {
 | 
			
		||||
        return (PlayerDisguise) super.setKeepDisguiseOnPlayerDeath(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setKeepDisguiseOnPlayerLogout(boolean keepDisguise) {
 | 
			
		||||
        return (PlayerDisguise) super.setKeepDisguiseOnPlayerLogout(keepDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setModifyBoundingBox(boolean modifyBox) {
 | 
			
		||||
        return (PlayerDisguise) super.setModifyBoundingBox(modifyBox);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setReplaceSounds(boolean areSoundsReplaced) {
 | 
			
		||||
        return (PlayerDisguise) super.setReplaceSounds(areSoundsReplaced);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public PlayerDisguise setSkin(String skinToUse) {
 | 
			
		||||
        this.skinToUse = skinToUse;
 | 
			
		||||
        if (skinToUse == null) {
 | 
			
		||||
            this.currentLookup = null;
 | 
			
		||||
            this.gameProfile = null;
 | 
			
		||||
        } else {
 | 
			
		||||
            if (skinToUse.length() > 16) {
 | 
			
		||||
                this.skinToUse = skinToUse.substring(0, 16);
 | 
			
		||||
            }
 | 
			
		||||
            if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) {
 | 
			
		||||
                currentLookup = new LibsProfileLookup() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public void onLookup(WrappedGameProfile gameProfile) {
 | 
			
		||||
                        if (currentLookup == this && gameProfile != null) {
 | 
			
		||||
                            setSkin(gameProfile);
 | 
			
		||||
                            if (!gameProfile.getProperties().isEmpty() && DisguiseUtilities.isDisguiseInUse(PlayerDisguise.this)) {
 | 
			
		||||
                                DisguiseUtilities.refreshTrackers(PlayerDisguise.this);
 | 
			
		||||
                            }
 | 
			
		||||
                            currentLookup = null;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                };
 | 
			
		||||
                WrappedGameProfile gameProfile = DisguiseUtilities.getProfileFromMojang(this.skinToUse, currentLookup);
 | 
			
		||||
                if (gameProfile != null) {
 | 
			
		||||
                    setSkin(gameProfile);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Set the GameProfile, without tampering.
 | 
			
		||||
     *
 | 
			
		||||
     * @param gameProfile GameProfile
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public PlayerDisguise setSkin(WrappedGameProfile gameProfile) {
 | 
			
		||||
        if (gameProfile == null) {
 | 
			
		||||
            this.gameProfile = null;
 | 
			
		||||
            this.skinToUse = null;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
        if (LibsDisguises.getInstance().getConfig().getBoolean("ContactMojangServers", true)) {
 | 
			
		||||
            Validate.notEmpty(gameProfile.getName(), "Name must be set");
 | 
			
		||||
            this.skinToUse = gameProfile.getName();
 | 
			
		||||
            this.gameProfile = ReflectionManager.getGameProfileWithThisSkin(null, getName(), gameProfile);
 | 
			
		||||
        }
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setVelocitySent(boolean sendVelocity) {
 | 
			
		||||
        return (PlayerDisguise) super.setVelocitySent(sendVelocity);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setViewSelfDisguise(boolean viewSelfDisguise) {
 | 
			
		||||
        return (PlayerDisguise) super.setViewSelfDisguise(viewSelfDisguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise setWatcher(FlagWatcher newWatcher) {
 | 
			
		||||
        return (PlayerDisguise) super.setWatcher(newWatcher);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise silentlyAddPlayer(String playername) {
 | 
			
		||||
        return (PlayerDisguise) super.silentlyAddPlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerDisguise silentlyRemovePlayer(String playername) {
 | 
			
		||||
        return (PlayerDisguise) super.silentlyRemovePlayer(playername);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										32
									
								
								src/me/libraryaddict/disguise/disguisetypes/RabbitType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/me/libraryaddict/disguise/disguisetypes/RabbitType.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
public enum RabbitType
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    BLACK(2), BROWN(0), GOLD(4), KILLER_BUNNY(99), PATCHES(3), PEPPER(5), WHITE(1);
 | 
			
		||||
 | 
			
		||||
    public static RabbitType getType(int id)
 | 
			
		||||
    {
 | 
			
		||||
        for (RabbitType type : values())
 | 
			
		||||
        {
 | 
			
		||||
            if (type.getTypeId() == id)
 | 
			
		||||
            {
 | 
			
		||||
                return type;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int type;
 | 
			
		||||
 | 
			
		||||
    RabbitType(int type)
 | 
			
		||||
    {
 | 
			
		||||
        this.type = type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getTypeId()
 | 
			
		||||
    {
 | 
			
		||||
        return type;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,127 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public abstract class TargetedDisguise extends Disguise
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public enum TargetType
 | 
			
		||||
    {
 | 
			
		||||
        HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS, SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private List<String> disguiseViewers = new ArrayList<>();
 | 
			
		||||
    private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise addPlayer(Player player)
 | 
			
		||||
    {
 | 
			
		||||
        addPlayer(player.getName());
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise addPlayer(String playername)
 | 
			
		||||
    {
 | 
			
		||||
        if (!disguiseViewers.contains(playername))
 | 
			
		||||
        {
 | 
			
		||||
            disguiseViewers.add(playername);
 | 
			
		||||
 | 
			
		||||
            if (DisguiseAPI.isDisguiseInUse(this))
 | 
			
		||||
            {
 | 
			
		||||
                DisguiseUtilities.checkConflicts(this, playername);
 | 
			
		||||
                DisguiseUtilities.refreshTracker(this, playername);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean canSee(Player player)
 | 
			
		||||
    {
 | 
			
		||||
        return canSee(player.getName());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean canSee(String playername)
 | 
			
		||||
    {
 | 
			
		||||
        boolean hasPlayer = disguiseViewers.contains(playername);
 | 
			
		||||
 | 
			
		||||
        if (targetType == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS)
 | 
			
		||||
        {
 | 
			
		||||
            return !hasPlayer;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return hasPlayer;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetType getDisguiseTarget()
 | 
			
		||||
    {
 | 
			
		||||
        return targetType;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public List<String> getObservers()
 | 
			
		||||
    {
 | 
			
		||||
        return Collections.unmodifiableList(disguiseViewers);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise removePlayer(Player player)
 | 
			
		||||
    {
 | 
			
		||||
        removePlayer(player.getName());
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise removePlayer(String playername)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguiseViewers.contains(playername))
 | 
			
		||||
        {
 | 
			
		||||
            disguiseViewers.remove(playername);
 | 
			
		||||
 | 
			
		||||
            if (DisguiseAPI.isDisguiseInUse(this))
 | 
			
		||||
            {
 | 
			
		||||
                DisguiseUtilities.checkConflicts(this, playername);
 | 
			
		||||
                DisguiseUtilities.refreshTracker(this, playername);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise setDisguiseTarget(TargetType newTargetType)
 | 
			
		||||
    {
 | 
			
		||||
        if (DisguiseUtilities.isDisguiseInUse(this))
 | 
			
		||||
        {
 | 
			
		||||
            throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        targetType = newTargetType;
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise silentlyAddPlayer(String playername)
 | 
			
		||||
    {
 | 
			
		||||
        if (!disguiseViewers.contains(playername))
 | 
			
		||||
        {
 | 
			
		||||
            disguiseViewers.add(playername);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public TargetedDisguise silentlyRemovePlayer(String playername)
 | 
			
		||||
    {
 | 
			
		||||
        if (disguiseViewers.contains(playername))
 | 
			
		||||
        {
 | 
			
		||||
            disguiseViewers.remove(playername);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return this;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,36 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class AgeableWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public AgeableWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        Entity e;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAdult() {
 | 
			
		||||
        return !isBaby();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBaby() {
 | 
			
		||||
        return (boolean) getValue(11, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAdult() {
 | 
			
		||||
        setBaby(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBaby() {
 | 
			
		||||
        setBaby(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBaby(boolean isBaby) {
 | 
			
		||||
        setValue(11, isBaby);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class AreaEffectCloudWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public AreaEffectCloudWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getRadius() {
 | 
			
		||||
        return (float) getValue(5, 0f);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getColor() {
 | 
			
		||||
        return (int) getValue(6, Color.BLACK.getRGB());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isIgnoreRadius() {
 | 
			
		||||
        return (boolean) getValue(7, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getParticleId() {
 | 
			
		||||
        return (int) getValue(8, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRadius(float radius) {
 | 
			
		||||
        setValue(5, radius);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setColor(int color) {
 | 
			
		||||
        setValue(6, color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIgnoreRadius(boolean ignore) {
 | 
			
		||||
        setValue(7, ignore);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setParticleId(int particleId) {
 | 
			
		||||
        setValue(8, particleId);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,88 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class ArmorStandWatcher extends LivingWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public ArmorStandWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean getArmorStandFlag(int value)
 | 
			
		||||
    {
 | 
			
		||||
        return (getValue(10, 0) & value) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isNoBasePlate()
 | 
			
		||||
    {
 | 
			
		||||
        return getArmorStandFlag(8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isNoGravity()
 | 
			
		||||
    {
 | 
			
		||||
        return getArmorStandFlag(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isShowArms()
 | 
			
		||||
    {
 | 
			
		||||
        return getArmorStandFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSmall()
 | 
			
		||||
    {
 | 
			
		||||
        return getArmorStandFlag(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isMarker()
 | 
			
		||||
    {
 | 
			
		||||
        return getArmorStandFlag(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setArmorStandFlag(int value, boolean isTrue)
 | 
			
		||||
    {
 | 
			
		||||
        byte b1 = (byte) getValue(10, (byte) 0);
 | 
			
		||||
        if (isTrue)
 | 
			
		||||
        {
 | 
			
		||||
            b1 = (byte) (b1 | value);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            b1 = (byte) (b1 & value);
 | 
			
		||||
        }
 | 
			
		||||
        setValue(10, b1);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNoBasePlate(boolean noBasePlate)
 | 
			
		||||
    {
 | 
			
		||||
        setArmorStandFlag(8, noBasePlate);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setNoGravity(boolean noGravity)
 | 
			
		||||
    {
 | 
			
		||||
        setArmorStandFlag(2, noGravity);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setShowArms(boolean showArms)
 | 
			
		||||
    {
 | 
			
		||||
        setArmorStandFlag(4, showArms);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSmall(boolean isSmall)
 | 
			
		||||
    {
 | 
			
		||||
        setArmorStandFlag(1, isSmall);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMarker(boolean isMarker)
 | 
			
		||||
    {
 | 
			
		||||
        setArmorStandFlag(10, isMarker);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
public class ArrowWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public ArrowWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isCritical() {
 | 
			
		||||
        return (byte) getValue(5, (byte) 0) == 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCritical(boolean critical) {
 | 
			
		||||
        setValue(5, (byte) (critical ? 1 : 0));
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class BatWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public BatWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setHanging(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isHanging() {
 | 
			
		||||
        return ((byte)getValue(11, (byte) 1)) == 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setHanging(boolean hanging) {
 | 
			
		||||
        setValue(11, hanging ? (byte) 1 : (byte) 0);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class BlazeWatcher extends LivingWatcher
 | 
			
		||||
{
 | 
			
		||||
    public BlazeWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBlazing()
 | 
			
		||||
    {
 | 
			
		||||
        return (boolean) getValue(11, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBlazing(boolean isBlazing)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(11, isBlazing);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,27 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
public class BoatWatcher extends FlagWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    // TODO: Add stuff for new boat values
 | 
			
		||||
 | 
			
		||||
    public BoatWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getDamage()
 | 
			
		||||
    {
 | 
			
		||||
        return getValue(7, 40F);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDamage(float dmg)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(7, dmg);
 | 
			
		||||
        sendData(7);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,29 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class CreeperWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public CreeperWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isIgnited() {
 | 
			
		||||
        return (boolean) getValue(13, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isPowered() {
 | 
			
		||||
        return (boolean) getValue(12, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setIgnited(boolean ignited) {
 | 
			
		||||
        setValue(13, ignited);
 | 
			
		||||
        sendData(13);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPowered(boolean powered) {
 | 
			
		||||
        setValue(12, powered);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
//TODO: Add support for custom items instead of just stone
 | 
			
		||||
public class DroppedItemWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public DroppedItemWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getItemStack() {
 | 
			
		||||
        return (ItemStack) getValue(5, new ItemStack(1));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemStack(ItemStack item) {
 | 
			
		||||
        setValue(5, item);
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,41 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.wrappers.BlockPosition;
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class EnderCrystalWatcher extends FlagWatcher
 | 
			
		||||
{
 | 
			
		||||
    public EnderCrystalWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBeamTarget(BlockPosition position)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(5, Optional.of(position));
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<BlockPosition> getBeamTarget()
 | 
			
		||||
    {
 | 
			
		||||
        return (Optional) getValue(5, Optional.absent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setShowBottom(boolean bool)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(6, bool);
 | 
			
		||||
        sendData(6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isShowBottom()
 | 
			
		||||
    {
 | 
			
		||||
        return (boolean) getValue(6, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class EnderDragonWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public EnderDragonWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getPhase() {
 | 
			
		||||
        return (int) getValue(11, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPhase(int phase) {
 | 
			
		||||
        setValue(11, phase);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,53 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.lang3.tuple.Pair;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class EndermanWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public EndermanWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public ItemStack getItemInMainHand() {
 | 
			
		||||
        Optional<Integer> value = (Optional<Integer>) getValue(11, Optional.of(1));
 | 
			
		||||
        if (value.isPresent()) {
 | 
			
		||||
            Pair<Integer, Integer> pair = ReflectionManager.getFromCombinedId(value.get());
 | 
			
		||||
            int id = pair.getLeft();
 | 
			
		||||
            int data = pair.getRight();
 | 
			
		||||
            return new ItemStack(id, 1, (short) data);
 | 
			
		||||
        } else {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setItemInMainHand(ItemStack itemstack) {
 | 
			
		||||
        setItemInMainHand(itemstack.getTypeId(), itemstack.getDurability());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemInMainHand(int typeId) {
 | 
			
		||||
        setItemInMainHand(typeId, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItemInMainHand(int typeId, int data) {
 | 
			
		||||
        int combined = ReflectionManager.getCombinedId(typeId, data);
 | 
			
		||||
        setValue(11, Optional.of(combined));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAggressive() {
 | 
			
		||||
        return (boolean) getValue(12, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAggressive(boolean isAggressive) {
 | 
			
		||||
        setValue(12, isAggressive);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,39 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class FallingBlockWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    private ItemStack block;
 | 
			
		||||
 | 
			
		||||
    public FallingBlockWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public FallingBlockWatcher clone(Disguise disguise) {
 | 
			
		||||
        FallingBlockWatcher watcher = (FallingBlockWatcher) super.clone(disguise);
 | 
			
		||||
        watcher.setBlock(getBlock());
 | 
			
		||||
        return watcher;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getBlock() {
 | 
			
		||||
        return block;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBlock(ItemStack block) {
 | 
			
		||||
        this.block = block;
 | 
			
		||||
        if (block.getType() == null || block.getType() == Material.AIR) {
 | 
			
		||||
            block.setType(Material.STONE);
 | 
			
		||||
        }
 | 
			
		||||
        if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
 | 
			
		||||
            DisguiseUtilities.refreshTrackers(getDisguise());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,20 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class GhastWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public GhastWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAggressive() {
 | 
			
		||||
        return (boolean) getValue(11, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAggressive(boolean isAggressive) {
 | 
			
		||||
        setValue(11, isAggressive);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,72 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class GuardianWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public GuardianWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is this guardian targetting someone?
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isTarget() {
 | 
			
		||||
        return ((int)getValue(12, 0)) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Shoot a beam at the given entityId.
 | 
			
		||||
     * @param entityId
 | 
			
		||||
     */
 | 
			
		||||
    public void setTarget(int entityId) {
 | 
			
		||||
        setValue(12, entityId);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Shoot a beam at the given player name.
 | 
			
		||||
     * @param playername
 | 
			
		||||
     */
 | 
			
		||||
    public void setTarget(String playername) {
 | 
			
		||||
        Player player = Bukkit.getPlayer(playername);
 | 
			
		||||
        if (player == null) return;
 | 
			
		||||
        setValue(12, player.getEntityId());
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRetractingSpikes() {
 | 
			
		||||
        return isGuardianFlag(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRetractingSpikes(boolean isRetracting) {
 | 
			
		||||
        setGuardianFlag(2, isRetracting);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isElder() {
 | 
			
		||||
        return isGuardianFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setElder(boolean isGuardian) {
 | 
			
		||||
        setGuardianFlag(4, isGuardian);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean isGuardianFlag(int no) {
 | 
			
		||||
        return ((byte) getValue(11, (byte) 0) & no) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void setGuardianFlag(int no, boolean flag) {
 | 
			
		||||
        byte b0 = (byte) getValue(11, (byte) 0);
 | 
			
		||||
        if (flag) {
 | 
			
		||||
            setValue(11, (byte) (b0 | no));
 | 
			
		||||
        } else {
 | 
			
		||||
            setValue(11, (byte) (b0 & -(no + 1)));
 | 
			
		||||
        }
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,223 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Material;
 | 
			
		||||
import org.bukkit.entity.Horse.Color;
 | 
			
		||||
import org.bukkit.entity.Horse.Style;
 | 
			
		||||
import org.bukkit.entity.Horse.Variant;
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class HorseWatcher extends AgeableWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public HorseWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
 | 
			
		||||
        setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Variant getVariant()
 | 
			
		||||
    {
 | 
			
		||||
        return Variant.values()[(int) getValue(13, 0)];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setVariant(Variant variant)
 | 
			
		||||
    {
 | 
			
		||||
        setVariant(variant.ordinal());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setVariant(int variant)
 | 
			
		||||
    {
 | 
			
		||||
        if (variant < 0 || variant > 4)
 | 
			
		||||
        {
 | 
			
		||||
            variant = 0; // Crashing people is mean
 | 
			
		||||
        }
 | 
			
		||||
        setValue(13, variant);
 | 
			
		||||
        sendData(13);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Color getColor()
 | 
			
		||||
    {
 | 
			
		||||
        return Color.values()[((Integer) getValue(14, 0) & 0xFF)];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getHorseArmor()
 | 
			
		||||
    {
 | 
			
		||||
        int horseValue = getHorseArmorAsInt();
 | 
			
		||||
        switch (horseValue)
 | 
			
		||||
        {
 | 
			
		||||
        case 1:
 | 
			
		||||
            return new ItemStack(Material.getMaterial("IRON_BARDING"));
 | 
			
		||||
        case 2:
 | 
			
		||||
            return new ItemStack(Material.getMaterial("GOLD_BARDING"));
 | 
			
		||||
        case 3:
 | 
			
		||||
            return new ItemStack(Material.getMaterial("DIAMOND_BARDING"));
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected int getHorseArmorAsInt()
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getValue(16, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<UUID> getOwner()
 | 
			
		||||
    {
 | 
			
		||||
        return getValue(15, Optional.<UUID> absent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Style getStyle()
 | 
			
		||||
    {
 | 
			
		||||
        return Style.values()[((int) getValue(14, 0) >>> 8)];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasChest()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBreedable()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(16);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isGrazing()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(32);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isMouthOpen()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(128);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRearing()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(64);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSaddled()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isTamed()
 | 
			
		||||
    {
 | 
			
		||||
        return isHorseFlag(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private boolean isHorseFlag(int i)
 | 
			
		||||
    {
 | 
			
		||||
        return (getHorseFlag() & i) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private byte getHorseFlag()
 | 
			
		||||
    {
 | 
			
		||||
        return (byte) getValue(12, (byte) 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCanBreed(boolean breed)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(16, breed);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCarryingChest(boolean chest)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(8, chest);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setColor(Color color)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(14, color.ordinal() & 0xFF | getStyle().ordinal() << 8);
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setHorseFlag(int i, boolean flag)
 | 
			
		||||
    {
 | 
			
		||||
        byte j = (byte) getValue(12, (byte) 0);
 | 
			
		||||
        if (flag)
 | 
			
		||||
        {
 | 
			
		||||
            setValue(12, (byte) (j | i));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            setValue(12, (byte) (j & ~i));
 | 
			
		||||
        }
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setGrazing(boolean grazing)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(32, grazing);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void setHorseArmor(int armor)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(16, armor);
 | 
			
		||||
        sendData(16);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setHorseArmor(ItemStack item)
 | 
			
		||||
    {
 | 
			
		||||
        int value = 0;
 | 
			
		||||
        if (item != null)
 | 
			
		||||
        {
 | 
			
		||||
            Material mat = item.getType();
 | 
			
		||||
            if (mat == Material.IRON_BARDING)
 | 
			
		||||
            {
 | 
			
		||||
                value = 1;
 | 
			
		||||
            }
 | 
			
		||||
            else if (mat == Material.GOLD_BARDING)
 | 
			
		||||
            {
 | 
			
		||||
                value = 2;
 | 
			
		||||
            }
 | 
			
		||||
            else if (mat == Material.DIAMOND_BARDING)
 | 
			
		||||
            {
 | 
			
		||||
                value = 3;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        setHorseArmor(value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMouthOpen(boolean mouthOpen)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(128, mouthOpen);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOwner(UUID uuid)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(15, Optional.of(uuid));
 | 
			
		||||
        sendData(15);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRearing(boolean rear)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(64, rear);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSaddled(boolean saddled)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(4, saddled);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setStyle(Style style)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(14, getColor().ordinal() & 0xFF | style.ordinal() << 8);
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTamed(boolean tamed)
 | 
			
		||||
    {
 | 
			
		||||
        setHorseFlag(2, tamed);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,40 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
public class ItemFrameWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public ItemFrameWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getItem() {
 | 
			
		||||
        if (getValue(5, null) == null) {
 | 
			
		||||
            return new ItemStack(0);
 | 
			
		||||
        }
 | 
			
		||||
        return (ItemStack) getValue(5, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getRotation() {
 | 
			
		||||
        return (int) getValue(6, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setItem(ItemStack newItem) {
 | 
			
		||||
        if (newItem == null) {
 | 
			
		||||
            newItem = new ItemStack(0);
 | 
			
		||||
        }
 | 
			
		||||
        newItem = newItem.clone();
 | 
			
		||||
        newItem.setAmount(1);
 | 
			
		||||
        setValue(5, newItem);
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRotation(int rotation) {
 | 
			
		||||
        setValue(6, (byte) (rotation % 4));
 | 
			
		||||
        sendData(6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,219 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.lang.reflect.Method;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
import org.bukkit.potion.PotionEffectType;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.PacketType.Play.Server;
 | 
			
		||||
import com.comphenix.protocol.ProtocolLibrary;
 | 
			
		||||
import com.comphenix.protocol.events.PacketContainer;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedAttribute.Builder;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.ReflectionManager;
 | 
			
		||||
 | 
			
		||||
public class LivingWatcher extends FlagWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    static Map<Integer, Object> list = new HashMap<>();
 | 
			
		||||
    static Method getId;
 | 
			
		||||
 | 
			
		||||
    static
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            getId = ReflectionManager.getNmsMethod("MobEffectList", "getId", ReflectionManager.getNmsClass("MobEffectList"));
 | 
			
		||||
            Object REGISTRY = ReflectionManager.getNmsField("MobEffectList", "REGISTRY").get(null);
 | 
			
		||||
            for (Object next : ((Iterable) REGISTRY))
 | 
			
		||||
            {
 | 
			
		||||
                int id = (int) getId.invoke(null, next);
 | 
			
		||||
                list.put(id, next);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private double maxHealth;
 | 
			
		||||
    private boolean maxHealthSet;
 | 
			
		||||
    private HashSet<Integer> potionEffects = new HashSet<>();
 | 
			
		||||
 | 
			
		||||
    public LivingWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void addPotionEffect(PotionEffectType potionEffect)
 | 
			
		||||
    {
 | 
			
		||||
        if (!hasPotionEffect(potionEffect))
 | 
			
		||||
        {
 | 
			
		||||
            removePotionEffect(potionEffect);
 | 
			
		||||
            potionEffects.add(potionEffect.getId());
 | 
			
		||||
 | 
			
		||||
            sendPotionEffects();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public LivingWatcher clone(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        LivingWatcher clone = (LivingWatcher) super.clone(disguise);
 | 
			
		||||
        clone.potionEffects = (HashSet<Integer>) potionEffects.clone();
 | 
			
		||||
        clone.maxHealth = maxHealth;
 | 
			
		||||
        clone.maxHealthSet = maxHealthSet;
 | 
			
		||||
 | 
			
		||||
        return clone;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getHealth()
 | 
			
		||||
    {
 | 
			
		||||
        return (float) getValue(6, 0F);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getMaxHealth()
 | 
			
		||||
    {
 | 
			
		||||
        return maxHealth;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isPotionParticlesAmbient()
 | 
			
		||||
    {
 | 
			
		||||
        return (boolean) getValue(8, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private int getPotions()
 | 
			
		||||
    {
 | 
			
		||||
        int m = 3694022;
 | 
			
		||||
 | 
			
		||||
        if (potionEffects.isEmpty())
 | 
			
		||||
        {
 | 
			
		||||
            return m;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        float f1 = 0.0F;
 | 
			
		||||
        float f2 = 0.0F;
 | 
			
		||||
        float f3 = 0.0F;
 | 
			
		||||
        float f4 = 0.0F;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            for (int localMobEffect : potionEffects)
 | 
			
		||||
            {
 | 
			
		||||
                int n = (Integer) getId.invoke(list.get(localMobEffect));
 | 
			
		||||
                f1 += (n >> 16 & 0xFF) / 255.0F;
 | 
			
		||||
                f2 += (n >> 8 & 0xFF) / 255.0F;
 | 
			
		||||
                f3 += (n & 0xFF) / 255.0F;
 | 
			
		||||
                f4 += 1.0F;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        f1 = f1 / f4 * 255.0F;
 | 
			
		||||
        f2 = f2 / f4 * 255.0F;
 | 
			
		||||
        f3 = f3 / f4 * 255.0F;
 | 
			
		||||
 | 
			
		||||
        return (int) f1 << 16 | (int) f2 << 8 | (int) f3;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean hasPotionEffect(PotionEffectType type)
 | 
			
		||||
    {
 | 
			
		||||
        return potionEffects.contains(type.getId());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isMaxHealthSet()
 | 
			
		||||
    {
 | 
			
		||||
        return maxHealthSet;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removePotionEffect(PotionEffectType type)
 | 
			
		||||
    {
 | 
			
		||||
        if (potionEffects.contains(type.getId()))
 | 
			
		||||
        {
 | 
			
		||||
            potionEffects.remove(type.getId());
 | 
			
		||||
            sendPotionEffects();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPotionParticlesAmbient(boolean particles)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(8, particles);
 | 
			
		||||
        sendData(8);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void sendPotionEffects()
 | 
			
		||||
    {
 | 
			
		||||
        setValue(7, getPotions());
 | 
			
		||||
        sendData(7);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setHealth(float health)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(6, health);
 | 
			
		||||
        sendData(6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getArrowsSticking()
 | 
			
		||||
    {
 | 
			
		||||
        return (int) getValue(9, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setArrowsSticking(int arrowsNo)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(9, arrowsNo);
 | 
			
		||||
        sendData(9);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMaxHealth(double newHealth)
 | 
			
		||||
    {
 | 
			
		||||
        this.maxHealth = newHealth;
 | 
			
		||||
        this.maxHealthSet = true;
 | 
			
		||||
 | 
			
		||||
        if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this)
 | 
			
		||||
        {
 | 
			
		||||
            PacketContainer packet = new PacketContainer(Server.UPDATE_ATTRIBUTES);
 | 
			
		||||
 | 
			
		||||
            List<WrappedAttribute> attributes = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
            Builder builder;
 | 
			
		||||
            builder = WrappedAttribute.newBuilder();
 | 
			
		||||
            builder.attributeKey("generic.maxHealth");
 | 
			
		||||
            builder.baseValue(getMaxHealth());
 | 
			
		||||
            builder.packet(packet);
 | 
			
		||||
 | 
			
		||||
            attributes.add(builder.build());
 | 
			
		||||
 | 
			
		||||
            Entity entity = getDisguise().getEntity();
 | 
			
		||||
 | 
			
		||||
            packet.getIntegers().write(0, entity.getEntityId());
 | 
			
		||||
            packet.getAttributeCollectionModifier().write(0, attributes);
 | 
			
		||||
 | 
			
		||||
            for (Player player : DisguiseUtilities.getPerverts(getDisguise()))
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
 | 
			
		||||
                }
 | 
			
		||||
                catch (InvocationTargetException e)
 | 
			
		||||
                {
 | 
			
		||||
                    e.printStackTrace(System.out);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,50 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.inventory.ItemStack;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
public class MinecartWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public MinecartWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public ItemStack getBlockInCart() {
 | 
			
		||||
        int id = (int) getValue(8, 0) & 0xffff;
 | 
			
		||||
        int data = (int) getValue(8, 0) >> 16;
 | 
			
		||||
        return new ItemStack(id, 1, (short) data);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getBlockYOffset() {
 | 
			
		||||
        return (int) getValue(9, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isViewBlockInCart() {
 | 
			
		||||
        return (boolean) getValue(10, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBlockInCart(ItemStack item) {
 | 
			
		||||
        int id = item.getTypeId();
 | 
			
		||||
        int data = item.getDurability();
 | 
			
		||||
        setValue(8, id & 0xffff | data << 16);
 | 
			
		||||
        setValue(10, true); //Show block
 | 
			
		||||
        sendData(8, 10);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBlockOffset(int i) {
 | 
			
		||||
        setValue(9, i);
 | 
			
		||||
        sendData(9);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Deprecated
 | 
			
		||||
    public void setBlockOffSet(int i) {
 | 
			
		||||
        setBlockOffset(i);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setViewBlockInCart(boolean viewBlock) {
 | 
			
		||||
        setValue(10, viewBlock);
 | 
			
		||||
        sendData(10);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,22 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Ocelot;
 | 
			
		||||
import org.bukkit.entity.Ocelot.Type;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class OcelotWatcher extends TameableWatcher {
 | 
			
		||||
 | 
			
		||||
    public OcelotWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Type getType() {
 | 
			
		||||
        return Ocelot.Type.getType((int) getValue(14, 0));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setType(Type newType) {
 | 
			
		||||
        setValue(14, newType.getId());
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,35 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Art;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class PaintingWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    private Art painting;
 | 
			
		||||
 | 
			
		||||
    public PaintingWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PaintingWatcher clone(Disguise disguise) {
 | 
			
		||||
        PaintingWatcher watcher = (PaintingWatcher) super.clone(disguise);
 | 
			
		||||
        watcher.setArt(getArt());
 | 
			
		||||
        return watcher;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Art getArt() {
 | 
			
		||||
        return painting;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setArt(Art newPainting) {
 | 
			
		||||
        this.painting = newPainting;
 | 
			
		||||
        if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
 | 
			
		||||
            DisguiseUtilities.refreshTrackers(getDisguise());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,19 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class PigWatcher extends AgeableWatcher {
 | 
			
		||||
 | 
			
		||||
    public PigWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSaddled() {
 | 
			
		||||
        return (boolean) getValue(12, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSaddled(boolean isSaddled) {
 | 
			
		||||
        setValue(12, isSaddled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,199 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.BlockFace;
 | 
			
		||||
import org.bukkit.entity.Player;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.PacketType.Play.Server;
 | 
			
		||||
import com.comphenix.protocol.ProtocolLibrary;
 | 
			
		||||
import com.comphenix.protocol.events.PacketContainer;
 | 
			
		||||
import com.comphenix.protocol.reflect.StructureModifier;
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseAPI;
 | 
			
		||||
import me.libraryaddict.disguise.DisguiseConfig;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class PlayerWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    private boolean isInBed;
 | 
			
		||||
    private BlockFace sleepingDirection;
 | 
			
		||||
 | 
			
		||||
    public PlayerWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public PlayerWatcher clone(Disguise disguise) {
 | 
			
		||||
        PlayerWatcher watcher = (PlayerWatcher) super.clone(disguise);
 | 
			
		||||
        watcher.isInBed = isInBed;
 | 
			
		||||
        return watcher;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BlockFace getSleepingDirection() {
 | 
			
		||||
        if (sleepingDirection == null) {
 | 
			
		||||
            if (this.getDisguise().getEntity() != null && isSleeping()) {
 | 
			
		||||
                this.sleepingDirection = BlockFace.values()[Math
 | 
			
		||||
                        .round(this.getDisguise().getEntity().getLocation().getYaw() / 90F) & 0x3];
 | 
			
		||||
            } else {
 | 
			
		||||
                return BlockFace.EAST;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return sleepingDirection;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//     Bit 0 (0x01): Cape enabled
 | 
			
		||||
//     Bit 1 (0x02): Jacket enabled
 | 
			
		||||
//     Bit 2 (0x04): Left Sleeve enabled
 | 
			
		||||
//     Bit 3 (0x08): Right Sleeve enabled
 | 
			
		||||
//     Bit 4 (0x10): Left Pants Leg enabled
 | 
			
		||||
//     Bit 5 (0x20): Right Pants Leg enabled
 | 
			
		||||
//     Bit 6 (0x40): Hat enabled
 | 
			
		||||
 | 
			
		||||
    private boolean isSkinFlag(int i) {
 | 
			
		||||
        return ((byte) getValue(12, (byte) 0) & 1 << i) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isCapeEnabled() {
 | 
			
		||||
        return isSkinFlag(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isJackedEnabled() {
 | 
			
		||||
        return isSkinFlag(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isLeftSleeveEnabled() {
 | 
			
		||||
        return isSkinFlag(3);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRightSleeveEnabled() {
 | 
			
		||||
        return isSkinFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isLeftPantsEnabled() {
 | 
			
		||||
        return isSkinFlag(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isRightPantsEnabled() {
 | 
			
		||||
        return isSkinFlag(6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isHatEnabled() {
 | 
			
		||||
        return isSkinFlag(7);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCapeEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(1, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setJackedEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(2, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLeftSleeveEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(3, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRightSleeveEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(4, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setLeftPantsEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(5, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setRightPantsEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(6, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setHatEnabled(boolean enabled) {
 | 
			
		||||
        setSkinFlags(7, enabled);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public boolean isSleeping() {
 | 
			
		||||
        return isInBed;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSkin(String playerName) {
 | 
			
		||||
        ((PlayerDisguise) getDisguise()).setSkin(playerName);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSkin(WrappedGameProfile profile) {
 | 
			
		||||
        ((PlayerDisguise) getDisguise()).setSkin(profile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSleeping(BlockFace sleepingDirection) {
 | 
			
		||||
        setSleeping(true, sleepingDirection);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSleeping(boolean sleep) {
 | 
			
		||||
        setSleeping(sleep, null);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * If no BlockFace is supplied. It grabs it from the entities facing direction if applicable.
 | 
			
		||||
     *
 | 
			
		||||
     * @param sleeping
 | 
			
		||||
     * @param sleepingDirection
 | 
			
		||||
     */
 | 
			
		||||
    public void setSleeping(boolean sleeping, BlockFace sleepingDirection) {
 | 
			
		||||
        if (sleepingDirection != null) {
 | 
			
		||||
            this.sleepingDirection = BlockFace.values()[sleepingDirection.ordinal() % 4];
 | 
			
		||||
        }
 | 
			
		||||
        if (sleeping != isSleeping()) {
 | 
			
		||||
            isInBed = sleeping;
 | 
			
		||||
            if (DisguiseConfig.isBedPacketsEnabled() && DisguiseUtilities.isDisguiseInUse(getDisguise())) {
 | 
			
		||||
                try {
 | 
			
		||||
                    if (isSleeping()) {
 | 
			
		||||
                        for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
 | 
			
		||||
                            PacketContainer[] packets = DisguiseUtilities.getBedPackets(player, this.getDisguise().getEntity()
 | 
			
		||||
                                    .getLocation(), player.getLocation(), (PlayerDisguise) this.getDisguise());
 | 
			
		||||
                            if (getDisguise().getEntity() == player) {
 | 
			
		||||
                                for (PacketContainer packet : packets) {
 | 
			
		||||
                                    packet = packet.shallowClone();
 | 
			
		||||
                                    packet.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
 | 
			
		||||
                                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
                                }
 | 
			
		||||
                            } else {
 | 
			
		||||
                                for (PacketContainer packet : packets) {
 | 
			
		||||
                                    ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        PacketContainer packet = new PacketContainer(Server.ANIMATION);
 | 
			
		||||
                        StructureModifier<Integer> mods = packet.getIntegers();
 | 
			
		||||
                        mods.write(0, getDisguise().getEntity().getEntityId());
 | 
			
		||||
                        mods.write(1, 3);
 | 
			
		||||
                        for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
 | 
			
		||||
                            ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
 | 
			
		||||
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                } catch (Exception ex) {
 | 
			
		||||
                    ex.printStackTrace(System.out);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void setSkinFlags(int i, boolean flag) {
 | 
			
		||||
        byte b0 = (byte) getValue(12, (byte) 0);
 | 
			
		||||
        if (flag) {
 | 
			
		||||
            setValue(12, (byte) (b0 | 1 << i));
 | 
			
		||||
        } else {
 | 
			
		||||
            setValue(12, (byte) (b0 & (~1 << i)));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,23 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.RabbitType;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class RabbitWatcher extends AgeableWatcher {
 | 
			
		||||
 | 
			
		||||
    public RabbitWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public RabbitType getType() {
 | 
			
		||||
        return RabbitType.getType((int) getValue(18, 0));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setType(RabbitType type) {
 | 
			
		||||
        setValue(12, type.getTypeId());
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,42 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.DyeColor;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class SheepWatcher extends AgeableWatcher {
 | 
			
		||||
 | 
			
		||||
    public SheepWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setValue(12, (byte) 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public AnimalColor getColor() {
 | 
			
		||||
        return AnimalColor.getColor(((int) getValue(12, (byte) 0) & 15));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSheared() {
 | 
			
		||||
        return ((byte) getValue(12, (byte) 0) & 16) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setColor(AnimalColor color) {
 | 
			
		||||
        setColor(DyeColor.getByWoolData((byte) color.getId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setColor(DyeColor color) {
 | 
			
		||||
        byte b0 = (byte) getValue(12, (byte) 0);
 | 
			
		||||
        setValue(12, (byte) (b0 & 240 | color.getWoolData() & 15));
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSheared(boolean flag) {
 | 
			
		||||
        byte b0 = (byte) getValue(12, (byte) 0);
 | 
			
		||||
        if (flag) {
 | 
			
		||||
            setValue(12, (byte) (b0 | 16));
 | 
			
		||||
        } else {
 | 
			
		||||
            setValue(12, (byte) (b0 & -17));
 | 
			
		||||
        }
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,44 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.block.BlockFace;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.wrappers.BlockPosition;
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
//TODO: Add the appropriate data values to this class
 | 
			
		||||
public class ShulkerWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public ShulkerWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public BlockFace getFacingDirection() {
 | 
			
		||||
        return BlockFace.UP;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setFacingDirection() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<BlockPosition> getAttachmentPosition() {
 | 
			
		||||
        return Optional.absent();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAttachmentPosition(BlockPosition pos) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public byte getShieldHeight() {
 | 
			
		||||
        return 0x00;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setShieldHeight() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Skeleton.SkeletonType;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class SkeletonWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public SkeletonWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setType(SkeletonType type) {
 | 
			
		||||
        setValue(11, type.getId());
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public SkeletonType getType() {
 | 
			
		||||
        return SkeletonType.getType((int) getValue(11, SkeletonType.NORMAL.getId()));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,25 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class SlimeWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public SlimeWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setSize(DisguiseUtilities.random.nextInt(4) + 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getSize() {
 | 
			
		||||
        return (int) getValue(11, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSize(int size) {
 | 
			
		||||
        if (size <= 0 || size >= 128) {
 | 
			
		||||
            size = 1;
 | 
			
		||||
        }
 | 
			
		||||
        setValue(11, size);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,33 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class SplashPotionWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    private int potionId;
 | 
			
		||||
 | 
			
		||||
    public SplashPotionWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public SplashPotionWatcher clone(Disguise disguise) {
 | 
			
		||||
        SplashPotionWatcher watcher = (SplashPotionWatcher) super.clone(disguise);
 | 
			
		||||
        watcher.setPotionId(getPotionId());
 | 
			
		||||
        return watcher;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getPotionId() {
 | 
			
		||||
        return potionId;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setPotionId(int newPotionId) {
 | 
			
		||||
        this.potionId = newPotionId;
 | 
			
		||||
        if (getDisguise().getEntity() != null && getDisguise().getWatcher() == this) {
 | 
			
		||||
            DisguiseUtilities.refreshTrackers(getDisguise());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,67 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Optional;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class TameableWatcher extends AgeableWatcher
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public TameableWatcher(Disguise disguise)
 | 
			
		||||
    {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Optional<UUID> getOwner()
 | 
			
		||||
    {
 | 
			
		||||
        return getValue(13, Optional.<UUID> absent());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isSitting()
 | 
			
		||||
    {
 | 
			
		||||
        return isTameableFlag(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isTamed()
 | 
			
		||||
    {
 | 
			
		||||
        return isTameableFlag(4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected boolean isTameableFlag(int no)
 | 
			
		||||
    {
 | 
			
		||||
        return ((byte) getValue(12, (byte) 0) & no) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected void setTameableFlag(int no, boolean flag)
 | 
			
		||||
    {
 | 
			
		||||
        byte value = (byte) getValue(12, (byte) 0);
 | 
			
		||||
        if (flag)
 | 
			
		||||
        {
 | 
			
		||||
            setValue(12, (byte) (value | no));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            setValue(12, (byte) (value & -(no + 1)));
 | 
			
		||||
        }
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setOwner(UUID owner)
 | 
			
		||||
    {
 | 
			
		||||
        setValue(13, Optional.of(owner));
 | 
			
		||||
        sendData(13);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSitting(boolean sitting)
 | 
			
		||||
    {
 | 
			
		||||
        setTameableFlag(1, sitting);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTamed(boolean tamed)
 | 
			
		||||
    {
 | 
			
		||||
        setTameableFlag(4, tamed);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,30 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Color;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class TippedArrowWatcher extends ArrowWatcher {
 | 
			
		||||
 | 
			
		||||
    public TippedArrowWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        int r = DisguiseUtilities.random.nextInt(256);
 | 
			
		||||
        int g = DisguiseUtilities.random.nextInt(256);
 | 
			
		||||
        int b = DisguiseUtilities.random.nextInt(256);
 | 
			
		||||
        setColor(Color.fromRGB(r, g, b));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Color getColor() {
 | 
			
		||||
        int color = (int) getValue(5, Color.WHITE.asRGB());
 | 
			
		||||
        return Color.fromRGB(color);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setColor(Color color) {
 | 
			
		||||
        setValue(5, color.asRGB());
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,27 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Villager.Profession;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
 | 
			
		||||
 | 
			
		||||
public class VillagerWatcher extends AgeableWatcher {
 | 
			
		||||
 | 
			
		||||
    public VillagerWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
        setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Profession getProfession() {
 | 
			
		||||
        return Profession.getProfession((int) getValue(16, 0));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setProfession(int professionId) {
 | 
			
		||||
        setValue(12, professionId);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setProfession(Profession newProfession) {
 | 
			
		||||
        setProfession(newProfession.getId());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * @author Navid
 | 
			
		||||
 */
 | 
			
		||||
public class WitchWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public WitchWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public boolean isAggressive() {
 | 
			
		||||
        return (boolean) getValue(11, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAggressive(boolean aggressive) {
 | 
			
		||||
        setValue(11, aggressive);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,21 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
 | 
			
		||||
 | 
			
		||||
public class WitherSkullWatcher extends FlagWatcher {
 | 
			
		||||
 | 
			
		||||
    public WitherSkullWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBlue() {
 | 
			
		||||
        return (boolean) getValue(5, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBlue(boolean blue) {
 | 
			
		||||
        setValue(5, blue);
 | 
			
		||||
        sendData(5);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,46 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import java.security.InvalidParameterException;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.ChatColor;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class WitherWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public WitherWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the amount of time this Wither is invulnerable for
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public int getInvulnerability() {
 | 
			
		||||
        return (int) getValue(14, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int[] getTargets() {
 | 
			
		||||
        return new int[]{(Integer) getValue(11, 0), (Integer) getValue(12, 0), (Integer) getValue(13, 0)};
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the amount of time this Wither is invulnerable for
 | 
			
		||||
     */
 | 
			
		||||
    public void setInvulnerability(int invulnerability) {
 | 
			
		||||
        setValue(14, invulnerability);
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setTargets(int... targets) {
 | 
			
		||||
        if (targets.length != 3) {
 | 
			
		||||
            throw new InvalidParameterException(ChatColor.RED + "Expected 3 numbers for wither setTargets. Received "
 | 
			
		||||
                    + targets.length);
 | 
			
		||||
        }
 | 
			
		||||
        setValue(11, targets[0]);
 | 
			
		||||
        setValue(12, targets[1]);
 | 
			
		||||
        setValue(13, targets[2]);
 | 
			
		||||
        sendData(11, 12, 13);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,66 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.DyeColor;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.AnimalColor;
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class WolfWatcher extends TameableWatcher {
 | 
			
		||||
 | 
			
		||||
    public WolfWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public AnimalColor getCollarColor() {
 | 
			
		||||
        return AnimalColor.getColor((int) getValue(16, 14));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Used for tail rotation.
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public float getDamageTaken() {
 | 
			
		||||
        return (float) getValue(14, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Used for tail rotation.
 | 
			
		||||
     * @param damage
 | 
			
		||||
     */
 | 
			
		||||
    public void setDamageTaken(float damage) {
 | 
			
		||||
        setValue(14, damage);
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBegging() {
 | 
			
		||||
        return (boolean) getValue(15, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBegging(boolean begging) {
 | 
			
		||||
        setValue(15, begging);
 | 
			
		||||
        sendData(15);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAngry() {
 | 
			
		||||
        return isTameableFlag(2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAngry(boolean angry) {
 | 
			
		||||
        setTameableFlag(2, angry);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCollarColor(AnimalColor color) {
 | 
			
		||||
        setCollarColor(DyeColor.getByWoolData((byte) color.getId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setCollarColor(DyeColor newColor) {
 | 
			
		||||
        if (!isTamed()) {
 | 
			
		||||
            setTamed(true);
 | 
			
		||||
        }
 | 
			
		||||
        if (newColor.getWoolData() != getCollarColor().getId()) {
 | 
			
		||||
            setValue(16, (int) newColor.getDyeData());
 | 
			
		||||
            sendData(16);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,89 @@
 | 
			
		||||
package me.libraryaddict.disguise.disguisetypes.watchers;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Villager.Profession;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class ZombieWatcher extends LivingWatcher {
 | 
			
		||||
 | 
			
		||||
    public ZombieWatcher(Disguise disguise) {
 | 
			
		||||
        super(disguise);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAdult() {
 | 
			
		||||
        return !isBaby();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isBaby() {
 | 
			
		||||
        return (boolean) getValue(11, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isShaking() {
 | 
			
		||||
        return (boolean) getValue(14, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Is this zombie a villager?
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isVillager() {
 | 
			
		||||
        return ((int)getValue(12, 0)) != 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isAggressive() {
 | 
			
		||||
        return (boolean) getValue(14, false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Only returns a valid value if this zombie
 | 
			
		||||
     * is a villager.
 | 
			
		||||
     * @return
 | 
			
		||||
     */
 | 
			
		||||
    public Profession getProfession() {
 | 
			
		||||
        return Profession.getProfession((int) getValue(12, 0));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAdult() {
 | 
			
		||||
        setBaby(false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBaby() {
 | 
			
		||||
        setBaby(true);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBaby(boolean baby) {
 | 
			
		||||
        setValue(11, baby);
 | 
			
		||||
        sendData(11);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setShaking(boolean shaking) {
 | 
			
		||||
        setValue(13, (byte) (shaking ? 1 : 0));
 | 
			
		||||
        sendData(13);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the profession of this zombie, in turn
 | 
			
		||||
     * turning it into a Zombie Villager
 | 
			
		||||
     * @param id
 | 
			
		||||
     */
 | 
			
		||||
    public void setProfession(int id) {
 | 
			
		||||
        setValue(12, id);
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sets the profession of this zombie, in turn
 | 
			
		||||
     * turning it into a Zombie Villager
 | 
			
		||||
     * @param profession
 | 
			
		||||
     */
 | 
			
		||||
    public void setProfession(Profession profession) {
 | 
			
		||||
        setValue(12, profession.getId());
 | 
			
		||||
        sendData(12);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAggressive(boolean handsup) {
 | 
			
		||||
        setValue(14, handsup);
 | 
			
		||||
        sendData(14);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								src/me/libraryaddict/disguise/events/DisguiseEvent.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/me/libraryaddict/disguise/events/DisguiseEvent.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
package me.libraryaddict.disguise.events;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.event.Cancellable;
 | 
			
		||||
import org.bukkit.event.Event;
 | 
			
		||||
import org.bukkit.event.HandlerList;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class DisguiseEvent extends Event implements Cancellable {
 | 
			
		||||
 | 
			
		||||
    private static final HandlerList handlers = new HandlerList();
 | 
			
		||||
 | 
			
		||||
    public static HandlerList getHandlerList() {
 | 
			
		||||
        return handlers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Disguise disguise;
 | 
			
		||||
    private Entity disguised;
 | 
			
		||||
    private boolean isCancelled;
 | 
			
		||||
 | 
			
		||||
    public DisguiseEvent(Entity entity, Disguise disguise) {
 | 
			
		||||
        this.disguised = entity;
 | 
			
		||||
        this.disguise = disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Disguise getDisguise() {
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Entity getEntity() {
 | 
			
		||||
        return disguised;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public HandlerList getHandlers() {
 | 
			
		||||
        return handlers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isCancelled() {
 | 
			
		||||
        return isCancelled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setCancelled(boolean cancelled) {
 | 
			
		||||
        isCancelled = cancelled;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										49
									
								
								src/me/libraryaddict/disguise/events/UndisguiseEvent.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/me/libraryaddict/disguise/events/UndisguiseEvent.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
package me.libraryaddict.disguise.events;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
import org.bukkit.event.Cancellable;
 | 
			
		||||
import org.bukkit.event.Event;
 | 
			
		||||
import org.bukkit.event.HandlerList;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
 | 
			
		||||
 | 
			
		||||
public class UndisguiseEvent extends Event implements Cancellable {
 | 
			
		||||
 | 
			
		||||
    private static final HandlerList handlers = new HandlerList();
 | 
			
		||||
 | 
			
		||||
    public static HandlerList getHandlerList() {
 | 
			
		||||
        return handlers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private Disguise disguise;
 | 
			
		||||
    private Entity disguised;
 | 
			
		||||
    private boolean isCancelled;
 | 
			
		||||
 | 
			
		||||
    public UndisguiseEvent(Entity entity, Disguise disguise) {
 | 
			
		||||
        this.disguised = entity;
 | 
			
		||||
        this.disguise = disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Disguise getDisguise() {
 | 
			
		||||
        return disguise;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Entity getEntity() {
 | 
			
		||||
        return disguised;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public HandlerList getHandlers() {
 | 
			
		||||
        return handlers;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean isCancelled() {
 | 
			
		||||
        return isCancelled;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void setCancelled(boolean cancelled) {
 | 
			
		||||
        isCancelled = cancelled;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										89
									
								
								src/me/libraryaddict/disguise/utilities/ClassGetter.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										89
									
								
								src/me/libraryaddict/disguise/utilities/ClassGetter.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,89 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.URLDecoder;
 | 
			
		||||
import java.security.CodeSource;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Enumeration;
 | 
			
		||||
import java.util.jar.JarEntry;
 | 
			
		||||
import java.util.jar.JarFile;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.entity.Entity;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * User: Austin Date: 4/22/13 Time: 11:47 PM (c) lazertester
 | 
			
		||||
 */
 | 
			
		||||
// Code for this taken and slightly modified from
 | 
			
		||||
// https://github.com/ddopson/java-class-enumerator
 | 
			
		||||
public class ClassGetter
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    public static ArrayList<Class<?>> getClassesForPackage(String pkgname)
 | 
			
		||||
    {
 | 
			
		||||
        ArrayList<Class<?>> classes = new ArrayList<>();
 | 
			
		||||
        // String relPath = pkgname.replace('.', '/');
 | 
			
		||||
 | 
			
		||||
        // Get a File object for the package
 | 
			
		||||
        CodeSource src = Entity.class.getProtectionDomain().getCodeSource();
 | 
			
		||||
 | 
			
		||||
        if (src != null)
 | 
			
		||||
        {
 | 
			
		||||
            URL resource = src.getLocation();
 | 
			
		||||
            resource.getPath();
 | 
			
		||||
            processJarfile(resource, pkgname, classes);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return classes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static Class<?> loadClass(String className)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return Class.forName(className);
 | 
			
		||||
        }
 | 
			
		||||
        catch (ClassNotFoundException e)
 | 
			
		||||
        {
 | 
			
		||||
            throw new RuntimeException("Unexpected ClassNotFoundException loading class '" + className + "'");
 | 
			
		||||
        }
 | 
			
		||||
        catch (NoClassDefFoundError e)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static void processJarfile(URL resource, String pkgname, ArrayList<Class<?>> classes)
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            String relPath = pkgname.replace('.', '/');
 | 
			
		||||
            String resPath = URLDecoder.decode(resource.getPath(), "UTF-8");
 | 
			
		||||
            String jarPath = resPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", "");
 | 
			
		||||
            JarFile jarFile = new JarFile(jarPath);
 | 
			
		||||
            Enumeration<JarEntry> entries = jarFile.entries();
 | 
			
		||||
            while (entries.hasMoreElements())
 | 
			
		||||
            {
 | 
			
		||||
                JarEntry entry = entries.nextElement();
 | 
			
		||||
                String entryName = entry.getName();
 | 
			
		||||
                String className = null;
 | 
			
		||||
                if (entryName.endsWith(".class") && entryName.startsWith(relPath)
 | 
			
		||||
                        && entryName.length() > (relPath.length() + "/".length()))
 | 
			
		||||
                {
 | 
			
		||||
                    className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
 | 
			
		||||
                }
 | 
			
		||||
                if (className != null)
 | 
			
		||||
                {
 | 
			
		||||
                    Class<?> c = loadClass(className);
 | 
			
		||||
                    if (c != null)
 | 
			
		||||
                    {
 | 
			
		||||
                        classes.add(c);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            ex.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										308
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseSound.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										308
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseSound.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,308 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Sound;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Only living disguises go in here!
 | 
			
		||||
 */
 | 
			
		||||
public enum DisguiseSound
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
 | 
			
		||||
 | 
			
		||||
    BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
			
		||||
            Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
 | 
			
		||||
 | 
			
		||||
    BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
			
		||||
            Sound.ENTITY_PLAYER_BIG_FALL),
 | 
			
		||||
 | 
			
		||||
    CAVE_SPIDER(Sound.ENTITY_SPIDER_AMBIENT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    CHICKEN(Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_STEP, Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_CHICKEN_EGG, Sound.ENTITY_PLAYER_BIG_FALL),
 | 
			
		||||
 | 
			
		||||
    COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    CREEPER(Sound.ENTITY_CREEPER_HURT, "step.grass", Sound.ENTITY_CREEPER_DEATH, null),
 | 
			
		||||
 | 
			
		||||
    DONKEY(Sound.ENTITY_DONKEY_HURT, "step.grass", Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
 | 
			
		||||
            Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
 | 
			
		||||
 | 
			
		||||
    ELDER_GUARDIAN(Sound.ENTITY_ELDER_GUARDIAN_HURT, null, Sound.ENTITY_ELDER_GUARDIAN_DEATH,
 | 
			
		||||
            Sound.ENTITY_ELDER_GUARDIAN_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    ENDER_DRAGON(Sound.ENTITY_ENDERDRAGON_HURT, null, Sound.ENTITY_ENDERDRAGON_DEATH, Sound.ENTITY_ENDERDRAGON_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_ENDERDRAGON_FLAP, Sound.ENTITY_PLAYER_BIG_FALL),
 | 
			
		||||
 | 
			
		||||
    ENDERMAN(Sound.ENTITY_ENDERMEN_HURT, "step.grass", Sound.ENTITY_ENDERMEN_DEATH, Sound.ENTITY_ENDERMEN_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_ENDERMEN_SCREAM, Sound.ENTITY_ENDERMEN_TELEPORT, Sound.ENTITY_ENDERMEN_STARE),
 | 
			
		||||
 | 
			
		||||
    ENDERMITE(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
 | 
			
		||||
            Sound.ENTITY_ENDERMITE_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
			
		||||
            Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN),
 | 
			
		||||
 | 
			
		||||
    GIANT(Sound.ENTITY_PLAYER_HURT, "step.grass", null, null),
 | 
			
		||||
 | 
			
		||||
    GUARDIAN(Sound.ENTITY_GUARDIAN_HURT, null, Sound.ENTITY_GUARDIAN_DEATH, Sound.ENTITY_ELDER_GUARDIAN_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    HORSE(Sound.ENTITY_HORSE_HURT, "step.grass", Sound.ENTITY_HORSE_DEATH, Sound.ENTITY_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
 | 
			
		||||
            Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR,
 | 
			
		||||
            Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
 | 
			
		||||
 | 
			
		||||
    IRON_GOLEM(Sound.ENTITY_IRONGOLEM_HURT, Sound.ENTITY_IRONGOLEM_STEP, Sound.ENTITY_IRONGOLEM_DEATH,
 | 
			
		||||
            Sound.ENTITY_IRONGOLEM_ATTACK),
 | 
			
		||||
 | 
			
		||||
    MAGMA_CUBE(Sound.ENTITY_MAGMACUBE_HURT, Sound.ENTITY_MAGMACUBE_JUMP, null, null),
 | 
			
		||||
 | 
			
		||||
    MULE(Sound.ENTITY_MULE_HURT, "step.grass", Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    MUSHROOM_COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    OCELOT(Sound.ENTITY_CAT_HURT, "step.grass", Sound.ENTITY_CAT_HURT, Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR,
 | 
			
		||||
            Sound.ENTITY_CAT_PURREOW),
 | 
			
		||||
 | 
			
		||||
    PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIG_HURT, null, Sound.ENTITY_ZOMBIE_PIG_DEATH, Sound.ENTITY_ZOMBIE_PIG_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_ZOMBIE_PIG_ANGRY),
 | 
			
		||||
 | 
			
		||||
    PLAYER(Sound.ENTITY_PLAYER_HURT, "step.grass", Sound.ENTITY_PLAYER_DEATH, null),
 | 
			
		||||
 | 
			
		||||
    RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    SHEEP(Sound.ENTITY_SHEEP_HURT, Sound.ENTITY_SHEEP_STEP, null, Sound.ENTITY_SHEEP_AMBIENT, Sound.ENTITY_SHEEP_SHEAR),
 | 
			
		||||
 | 
			
		||||
    SHULKER(Sound.ENTITY_SHULKER_HURT, null, Sound.ENTITY_SHULKER_DEATH, Sound.ENTITY_SHULKER_AMBIENT, Sound.ENTITY_SHULKER_OPEN,
 | 
			
		||||
            Sound.ENTITY_SHULKER_CLOSE, Sound.ENTITY_SHULKER_HURT_CLOSED, Sound.ENTITY_SHULKER_TELEPORT),
 | 
			
		||||
 | 
			
		||||
    SILVERFISH(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_SILVERFISH_STEP, Sound.ENTITY_SILVERFISH_DEATH,
 | 
			
		||||
            Sound.ENTITY_SILVERFISH_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    SKELETON(Sound.ENTITY_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH, Sound.ENTITY_SKELETON_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    SKELETON_HORSE(Sound.ENTITY_SKELETON_HORSE_HURT, "step.grass", Sound.ENTITY_SKELETON_HORSE_DEATH,
 | 
			
		||||
            Sound.ENTITY_SKELETON_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY,
 | 
			
		||||
            Sound.ENTITY_HORSE_STEP_WOOD, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
 | 
			
		||||
            Sound.ENTITY_HORSE_ANGRY),
 | 
			
		||||
 | 
			
		||||
    SLIME(Sound.ENTITY_SLIME_HURT, Sound.ENTITY_SLIME_JUMP, Sound.ENTITY_SLIME_DEATH, null),
 | 
			
		||||
 | 
			
		||||
    SNOWMAN(Sound.ENTITY_SNOWMAN_HURT, null, Sound.ENTITY_SNOWMAN_DEATH, Sound.ENTITY_SNOWMAN_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_SNOWMAN_SHOOT),
 | 
			
		||||
 | 
			
		||||
    SPIDER(Sound.ENTITY_SPIDER_AMBIENT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    SQUID(Sound.ENTITY_SQUID_HURT, null, Sound.ENTITY_SQUID_DEATH, Sound.ENTITY_SQUID_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    UNDEAD_HORSE(Sound.ENTITY_ZOMBIE_HORSE_HURT, "step.grass", Sound.ENTITY_ZOMBIE_HORSE_DEATH, Sound.ENTITY_ZOMBIE_HORSE_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_STEP_WOOD,
 | 
			
		||||
            Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY),
 | 
			
		||||
 | 
			
		||||
    VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_VILLAGER_TRADING, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
 | 
			
		||||
 | 
			
		||||
    WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
 | 
			
		||||
            Sound.ENTITY_WITHER_SPAWN, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_WITHER_SHOOT),
 | 
			
		||||
 | 
			
		||||
    WITHER_SKELETON(Sound.ENTITY_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH,
 | 
			
		||||
            Sound.ENTITY_SKELETON_AMBIENT),
 | 
			
		||||
 | 
			
		||||
    WOLF(Sound.ENTITY_WOLF_HURT, Sound.ENTITY_WOLF_STEP, Sound.ENTITY_WOLF_DEATH, Sound.ENTITY_WOLF_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_WOLF_GROWL, Sound.ENTITY_WOLF_PANT, Sound.ENTITY_WOLF_HOWL, Sound.ENTITY_WOLF_SHAKE,
 | 
			
		||||
            Sound.ENTITY_WOLF_WHINE),
 | 
			
		||||
 | 
			
		||||
    ZOMBIE(Sound.ENTITY_ZOMBIE_HURT, Sound.ENTITY_ZOMBIE_STEP, Sound.ENTITY_ZOMBIE_DEATH, Sound.ENTITY_ZOMBIE_AMBIENT,
 | 
			
		||||
            Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
 | 
			
		||||
            Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR), ZOMBIE_VILLAGER(Sound.ENTITY_ZOMBIE_VILLAGER_HURT,
 | 
			
		||||
                    Sound.ENTITY_ZOMBIE_VILLAGER_STEP, Sound.ENTITY_ZOMBIE_VILLAGER_DEATH, Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT,
 | 
			
		||||
                    Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD,
 | 
			
		||||
                    Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
 | 
			
		||||
 | 
			
		||||
    public enum SoundType
 | 
			
		||||
    {
 | 
			
		||||
        CANCEL, DEATH, HURT, IDLE, STEP
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static DisguiseSound getType(String name)
 | 
			
		||||
    {
 | 
			
		||||
        // TODO: FIX the disguise sounds
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            return valueOf(name);
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception ex)
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private HashSet<String> cancelSounds = new HashSet<>();
 | 
			
		||||
    private float damageSoundVolume = 1F;
 | 
			
		||||
    private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds)
 | 
			
		||||
    {
 | 
			
		||||
        addSound(hurt, SoundType.HURT);
 | 
			
		||||
        addSound(step, SoundType.STEP);
 | 
			
		||||
        addSound(death, SoundType.DEATH);
 | 
			
		||||
        addSound(idle, SoundType.IDLE);
 | 
			
		||||
 | 
			
		||||
        for (Object obj : sounds)
 | 
			
		||||
        {
 | 
			
		||||
            addSound(obj, SoundType.CANCEL);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void addSound(Object sound, SoundType type)
 | 
			
		||||
    {
 | 
			
		||||
        String s;
 | 
			
		||||
 | 
			
		||||
        if (sound == null)
 | 
			
		||||
        {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        else if (sound instanceof String)
 | 
			
		||||
        {
 | 
			
		||||
            s = (String) sound;
 | 
			
		||||
        }
 | 
			
		||||
        else if (sound instanceof Sound)
 | 
			
		||||
        {
 | 
			
		||||
            s = ReflectionManager.getCraftSound((Sound) sound);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            throw new RuntimeException("Was given a unknown object " + sound);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switch (type)
 | 
			
		||||
        {
 | 
			
		||||
        case HURT:
 | 
			
		||||
            disguiseSounds.put(SoundType.HURT, s);
 | 
			
		||||
            break;
 | 
			
		||||
        case STEP:
 | 
			
		||||
            disguiseSounds.put(SoundType.STEP, s);
 | 
			
		||||
            break;
 | 
			
		||||
        case DEATH:
 | 
			
		||||
            disguiseSounds.put(SoundType.DEATH, s);
 | 
			
		||||
            break;
 | 
			
		||||
        case IDLE:
 | 
			
		||||
            disguiseSounds.put(SoundType.IDLE, s);
 | 
			
		||||
            break;
 | 
			
		||||
        case CANCEL:
 | 
			
		||||
            cancelSounds.add(s);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float getDamageAndIdleSoundVolume()
 | 
			
		||||
    {
 | 
			
		||||
        return damageSoundVolume;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getSound(SoundType type)
 | 
			
		||||
    {
 | 
			
		||||
        if (type == null || !disguiseSounds.containsKey(type))
 | 
			
		||||
        {
 | 
			
		||||
            return null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return disguiseSounds.get(type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public HashSet<String> getSoundsToCancel()
 | 
			
		||||
    {
 | 
			
		||||
        return cancelSounds;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Used to check if this sound name is owned by this disguise sound.
 | 
			
		||||
     */
 | 
			
		||||
    public SoundType getType(String sound, boolean ignoreDamage)
 | 
			
		||||
    {
 | 
			
		||||
        if (sound == null)
 | 
			
		||||
            return SoundType.CANCEL;
 | 
			
		||||
 | 
			
		||||
        if (isCancelSound(sound))
 | 
			
		||||
        {
 | 
			
		||||
            return SoundType.CANCEL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
 | 
			
		||||
                && sound.startsWith("step."))
 | 
			
		||||
        {
 | 
			
		||||
            return SoundType.STEP;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        for (SoundType type : SoundType.values())
 | 
			
		||||
        {
 | 
			
		||||
            if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT))
 | 
			
		||||
            {
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            String s = disguiseSounds.get(type);
 | 
			
		||||
 | 
			
		||||
            if (s != null)
 | 
			
		||||
            {
 | 
			
		||||
                if (s.equals(sound))
 | 
			
		||||
                {
 | 
			
		||||
                    return type;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean isCancelSound(String sound)
 | 
			
		||||
    {
 | 
			
		||||
        return getSoundsToCancel().contains(sound);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removeSound(SoundType type, Sound sound)
 | 
			
		||||
    {
 | 
			
		||||
        removeSound(type, ReflectionManager.getCraftSound(sound));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void removeSound(SoundType type, String sound)
 | 
			
		||||
    {
 | 
			
		||||
        if (type == SoundType.CANCEL)
 | 
			
		||||
        {
 | 
			
		||||
            cancelSounds.remove(sound);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            disguiseSounds.remove(type);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setDamageAndIdleSoundVolume(float strength)
 | 
			
		||||
    {
 | 
			
		||||
        this.damageSoundVolume = strength;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSound(SoundType type, Sound sound)
 | 
			
		||||
    {
 | 
			
		||||
        setSound(type, ReflectionManager.getCraftSound(sound));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setSound(SoundType type, String sound)
 | 
			
		||||
    {
 | 
			
		||||
        if (type == SoundType.CANCEL)
 | 
			
		||||
        {
 | 
			
		||||
            cancelSounds.add(sound);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            disguiseSounds.put(type, sound);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1472
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1472
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseUtilities.java
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										146
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseValues.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										146
									
								
								src/me/libraryaddict/disguise/utilities/DisguiseValues.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,146 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
 | 
			
		||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
 | 
			
		||||
 | 
			
		||||
public class DisguiseValues {
 | 
			
		||||
 | 
			
		||||
    private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
 | 
			
		||||
 | 
			
		||||
    public static DisguiseValues getDisguiseValues(DisguiseType type) {
 | 
			
		||||
        switch (type) {
 | 
			
		||||
            case DONKEY:
 | 
			
		||||
            case MULE:
 | 
			
		||||
            case UNDEAD_HORSE:
 | 
			
		||||
            case SKELETON_HORSE:
 | 
			
		||||
                type = DisguiseType.HORSE;
 | 
			
		||||
                break;
 | 
			
		||||
            case MINECART_CHEST:
 | 
			
		||||
            case MINECART_COMMAND:
 | 
			
		||||
            case MINECART_FURNACE:
 | 
			
		||||
            case MINECART_HOPPER:
 | 
			
		||||
            case MINECART_TNT:
 | 
			
		||||
            case MINECART_MOB_SPAWNER:
 | 
			
		||||
                type = DisguiseType.MINECART;
 | 
			
		||||
                break;
 | 
			
		||||
            case WITHER_SKELETON:
 | 
			
		||||
                type = DisguiseType.SKELETON;
 | 
			
		||||
                break;
 | 
			
		||||
            case ZOMBIE_VILLAGER:
 | 
			
		||||
                type = DisguiseType.ZOMBIE;
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        return values.get(type);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static HashMap<Integer, Object> getMetaValues(DisguiseType type) {
 | 
			
		||||
        return getDisguiseValues(type).getMetaValues();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static Class getNmsEntityClass(DisguiseType type) {
 | 
			
		||||
        return getDisguiseValues(type).getNmsEntityClass();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private FakeBoundingBox adultBox;
 | 
			
		||||
    private FakeBoundingBox babyBox;
 | 
			
		||||
    private float[] entitySize;
 | 
			
		||||
    private int enumEntitySize;
 | 
			
		||||
    private double maxHealth;
 | 
			
		||||
    private HashMap<Integer, Object> metaValues = new HashMap<>();
 | 
			
		||||
    private Class nmsEntityClass;
 | 
			
		||||
 | 
			
		||||
    @SuppressWarnings("LeakingThisInConstructor")
 | 
			
		||||
    public DisguiseValues(DisguiseType type, Class classType, int entitySize, double maxHealth) {
 | 
			
		||||
        values.put(type, this);
 | 
			
		||||
        enumEntitySize = entitySize;
 | 
			
		||||
        nmsEntityClass = classType;
 | 
			
		||||
        this.maxHealth = maxHealth;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public FakeBoundingBox getAdultBox() {
 | 
			
		||||
        return adultBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public FakeBoundingBox getBabyBox() {
 | 
			
		||||
        return babyBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public float[] getEntitySize() {
 | 
			
		||||
        return entitySize;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int getEntitySize(double paramDouble) {
 | 
			
		||||
        double d = paramDouble - (((int) Math.floor(paramDouble)) + 0.5D);
 | 
			
		||||
 | 
			
		||||
        switch (enumEntitySize) {
 | 
			
		||||
            case 1:
 | 
			
		||||
                if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
 | 
			
		||||
                    return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
            case 2:
 | 
			
		||||
                if (d < 0.0D ? d < -0.3125D : d < 0.3125D) {
 | 
			
		||||
                    return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
            case 3:
 | 
			
		||||
                if (d > 0.0D) {
 | 
			
		||||
                    return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
            case 4:
 | 
			
		||||
                if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
 | 
			
		||||
                    return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
            case 5:
 | 
			
		||||
                if (d < 0.0D ? d < -0.1875D : d < 0.1875D) {
 | 
			
		||||
                    return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
        if (d > 0.0D) {
 | 
			
		||||
            return (int) Math.ceil(paramDouble * 32.0D);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return (int) Math.floor(paramDouble * 32.0D);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getMaxHealth() {
 | 
			
		||||
        return maxHealth;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public HashMap<Integer, Object> getMetaValues() {
 | 
			
		||||
        return metaValues;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Class getNmsEntityClass() {
 | 
			
		||||
        return nmsEntityClass;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setAdultBox(FakeBoundingBox newBox) {
 | 
			
		||||
        adultBox = newBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setBabyBox(FakeBoundingBox newBox) {
 | 
			
		||||
        babyBox = newBox;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setEntitySize(float[] size) {
 | 
			
		||||
        this.entitySize = size;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void setMetaValue(int id, Object value) {
 | 
			
		||||
        metaValues.put(id, value);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								src/me/libraryaddict/disguise/utilities/FakeBoundingBox.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
public class FakeBoundingBox {
 | 
			
		||||
 | 
			
		||||
    private double xMod;
 | 
			
		||||
    private double yMod;
 | 
			
		||||
    private double zMod;
 | 
			
		||||
 | 
			
		||||
    public FakeBoundingBox(double xMod, double yMod, double zMod) {
 | 
			
		||||
        this.xMod = xMod;
 | 
			
		||||
        this.yMod = yMod;
 | 
			
		||||
        this.zMod = zMod;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getX() {
 | 
			
		||||
        return xMod / 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getY() {
 | 
			
		||||
        return yMod;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getZ() {
 | 
			
		||||
        return zMod / 2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
 | 
			
		||||
 | 
			
		||||
public interface LibsProfileLookup {
 | 
			
		||||
 | 
			
		||||
    void onLookup(WrappedGameProfile gameProfile);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,24 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
 | 
			
		||||
import com.mojang.authlib.GameProfile;
 | 
			
		||||
import com.mojang.authlib.ProfileLookupCallback;
 | 
			
		||||
 | 
			
		||||
public class LibsProfileLookupCaller implements ProfileLookupCallback {
 | 
			
		||||
 | 
			
		||||
    private WrappedGameProfile gameProfile;
 | 
			
		||||
 | 
			
		||||
    public WrappedGameProfile getGameProfile() {
 | 
			
		||||
        return gameProfile;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onProfileLookupFailed(GameProfile gameProfile, Exception arg1) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onProfileLookupSucceeded(GameProfile profile) {
 | 
			
		||||
        gameProfile = WrappedGameProfile.fromHandle(profile);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										790
									
								
								src/me/libraryaddict/disguise/utilities/Metrics.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										790
									
								
								src/me/libraryaddict/disguise/utilities/Metrics.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,790 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Copyright 2011-2013 Tyler Blair. All rights reserved.
 | 
			
		||||
 *
 | 
			
		||||
 * Redistribution and use in source and binary forms, with or without modification, are
 | 
			
		||||
 * permitted provided that the following conditions are met:
 | 
			
		||||
 *
 | 
			
		||||
 * 1. Redistributions of source code must retain the above copyright notice, this list of
 | 
			
		||||
 * conditions and the following disclaimer.
 | 
			
		||||
 *
 | 
			
		||||
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
 | 
			
		||||
 * of conditions and the following disclaimer in the documentation and/or other materials
 | 
			
		||||
 * provided with the distribution.
 | 
			
		||||
 *
 | 
			
		||||
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
 | 
			
		||||
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR
 | 
			
		||||
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 | 
			
		||||
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 | 
			
		||||
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 | 
			
		||||
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 | 
			
		||||
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 | 
			
		||||
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 | 
			
		||||
 *
 | 
			
		||||
 * The views and conclusions contained in the software and documentation are those of the
 | 
			
		||||
 * authors and contributors and should not be interpreted as representing official policies,
 | 
			
		||||
 * either expressed or implied, of anybody else.
 | 
			
		||||
 */
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.File;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.io.UnsupportedEncodingException;
 | 
			
		||||
import java.net.Proxy;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.net.URLConnection;
 | 
			
		||||
import java.net.URLEncoder;
 | 
			
		||||
import java.util.Collections;
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.LinkedHashSet;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
import java.util.logging.Level;
 | 
			
		||||
import java.util.zip.GZIPOutputStream;
 | 
			
		||||
 | 
			
		||||
import org.bukkit.Bukkit;
 | 
			
		||||
import org.bukkit.configuration.InvalidConfigurationException;
 | 
			
		||||
import org.bukkit.configuration.file.YamlConfiguration;
 | 
			
		||||
import org.bukkit.plugin.Plugin;
 | 
			
		||||
import org.bukkit.plugin.PluginDescriptionFile;
 | 
			
		||||
import org.bukkit.scheduler.BukkitTask;
 | 
			
		||||
 | 
			
		||||
public class Metrics
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * The current revision number
 | 
			
		||||
     */
 | 
			
		||||
    private final static int REVISION = 7;
 | 
			
		||||
    /**
 | 
			
		||||
     * The base url of the metrics domain
 | 
			
		||||
     */
 | 
			
		||||
    private static final String BASE_URL = "http://report.mcstats.org";
 | 
			
		||||
    /**
 | 
			
		||||
     * The url used to report a server's status
 | 
			
		||||
     */
 | 
			
		||||
    private static final String REPORT_URL = "/plugin/%s";
 | 
			
		||||
    /**
 | 
			
		||||
     * Interval of time to ping (in minutes)
 | 
			
		||||
     */
 | 
			
		||||
    private static final int PING_INTERVAL = 15;
 | 
			
		||||
    /**
 | 
			
		||||
     * The plugin this metrics submits for
 | 
			
		||||
     */
 | 
			
		||||
    private final Plugin plugin;
 | 
			
		||||
    /**
 | 
			
		||||
     * All of the custom graphs to submit to metrics
 | 
			
		||||
     */
 | 
			
		||||
    private final Set<Graph> graphs = Collections.synchronizedSet(new HashSet<Graph>());
 | 
			
		||||
    /**
 | 
			
		||||
     * The plugin configuration file
 | 
			
		||||
     */
 | 
			
		||||
    private final YamlConfiguration configuration;
 | 
			
		||||
    /**
 | 
			
		||||
     * The plugin configuration file
 | 
			
		||||
     */
 | 
			
		||||
    private final File configurationFile;
 | 
			
		||||
    /**
 | 
			
		||||
     * Unique server id
 | 
			
		||||
     */
 | 
			
		||||
    private final String guid;
 | 
			
		||||
    /**
 | 
			
		||||
     * Debug mode
 | 
			
		||||
     */
 | 
			
		||||
    private final boolean debug;
 | 
			
		||||
    /**
 | 
			
		||||
     * Lock for synchronization
 | 
			
		||||
     */
 | 
			
		||||
    private final Object optOutLock = new Object();
 | 
			
		||||
    /**
 | 
			
		||||
     * The scheduled task
 | 
			
		||||
     */
 | 
			
		||||
    private volatile BukkitTask task = null;
 | 
			
		||||
 | 
			
		||||
    public Metrics(final Plugin plugin) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        if (plugin == null)
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalArgumentException("Plugin cannot be null");
 | 
			
		||||
        }
 | 
			
		||||
        this.plugin = plugin;
 | 
			
		||||
        // load the config
 | 
			
		||||
        configurationFile = getConfigFile();
 | 
			
		||||
        configuration = YamlConfiguration.loadConfiguration(configurationFile);
 | 
			
		||||
        // add some defaults
 | 
			
		||||
        configuration.addDefault("opt-out", false);
 | 
			
		||||
        configuration.addDefault("guid", UUID.randomUUID().toString());
 | 
			
		||||
        configuration.addDefault("debug", false);
 | 
			
		||||
        // Do we need to create the file?
 | 
			
		||||
        if (configuration.get("guid", null) == null)
 | 
			
		||||
        {
 | 
			
		||||
            configuration.options().header("http://mcstats.org").copyDefaults(true);
 | 
			
		||||
            configuration.save(configurationFile);
 | 
			
		||||
        }
 | 
			
		||||
        // Load the guid then
 | 
			
		||||
        guid = configuration.getString("guid");
 | 
			
		||||
        debug = configuration.getBoolean("debug", false);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Construct and create a Graph that can be used to separate specific plotters to their own graphs on the metrics website.
 | 
			
		||||
     * Plotters can be added to the graph object returned.
 | 
			
		||||
     *
 | 
			
		||||
     * @param name
 | 
			
		||||
     *            The name of the graph
 | 
			
		||||
     * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given
 | 
			
		||||
     */
 | 
			
		||||
    public Graph createGraph(final String name)
 | 
			
		||||
    {
 | 
			
		||||
        if (name == null)
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalArgumentException("Graph name cannot be null");
 | 
			
		||||
        }
 | 
			
		||||
        // Construct the graph object
 | 
			
		||||
        final Graph graph = new Graph(name);
 | 
			
		||||
        // Now we can add our graph
 | 
			
		||||
        graphs.add(graph);
 | 
			
		||||
        // and return back
 | 
			
		||||
        return graph;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add a Graph object to BukkitMetrics that represents data for the plugin that should be sent to the backend
 | 
			
		||||
     *
 | 
			
		||||
     * @param graph
 | 
			
		||||
     *            The name of the graph
 | 
			
		||||
     */
 | 
			
		||||
    public void addGraph(final Graph graph)
 | 
			
		||||
    {
 | 
			
		||||
        if (graph == null)
 | 
			
		||||
        {
 | 
			
		||||
            throw new IllegalArgumentException("Graph cannot be null");
 | 
			
		||||
        }
 | 
			
		||||
        graphs.add(graph);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Start measuring statistics. This will immediately create an async repeating task as the plugin and send the initial data to
 | 
			
		||||
     * the metrics backend, and then after that it will post in increments of PING_INTERVAL * 1200 ticks.
 | 
			
		||||
     *
 | 
			
		||||
     * @return True if statistics measuring is running, otherwise false.
 | 
			
		||||
     */
 | 
			
		||||
    public boolean start()
 | 
			
		||||
    {
 | 
			
		||||
        synchronized (optOutLock)
 | 
			
		||||
        {
 | 
			
		||||
            // Did we opt out?
 | 
			
		||||
            if (isOptOut())
 | 
			
		||||
            {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            // Is metrics already running?
 | 
			
		||||
            if (task != null)
 | 
			
		||||
            {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            // Begin hitting the server with glorious data
 | 
			
		||||
            task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable()
 | 
			
		||||
            {
 | 
			
		||||
                private boolean firstPost = true;
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void run()
 | 
			
		||||
                {
 | 
			
		||||
                    try
 | 
			
		||||
                    {
 | 
			
		||||
                        // This has to be synchronized or it can collide with the disable method.
 | 
			
		||||
                        synchronized (optOutLock)
 | 
			
		||||
                        {
 | 
			
		||||
                            // Disable Task, if it is running and the server owner decided to opt-out
 | 
			
		||||
                            if (isOptOut() && task != null)
 | 
			
		||||
                            {
 | 
			
		||||
                                task.cancel();
 | 
			
		||||
                                task = null;
 | 
			
		||||
                                // Tell all plotters to stop gathering information.
 | 
			
		||||
                                for (Graph graph : graphs)
 | 
			
		||||
                                {
 | 
			
		||||
                                    graph.onOptOut();
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                        // We use the inverse of firstPost because if it is the first time we are posting,
 | 
			
		||||
                        // it is not a interval ping, so it evaluates to FALSE
 | 
			
		||||
                        // Each time thereafter it will evaluate to TRUE, i.e PING!
 | 
			
		||||
                        postPlugin(!firstPost);
 | 
			
		||||
                        // After the first post we set firstPost to false
 | 
			
		||||
                        // Each post thereafter will be a ping
 | 
			
		||||
                        firstPost = false;
 | 
			
		||||
                    }
 | 
			
		||||
                    catch (IOException e)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (debug)
 | 
			
		||||
                        {
 | 
			
		||||
                            Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage());
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }, 0, PING_INTERVAL * 1200);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Has the server owner denied plugin metrics?
 | 
			
		||||
     *
 | 
			
		||||
     * @return true if metrics should be opted out of it
 | 
			
		||||
     */
 | 
			
		||||
    public boolean isOptOut()
 | 
			
		||||
    {
 | 
			
		||||
        synchronized (optOutLock)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                // Reload the metrics file
 | 
			
		||||
                configuration.load(getConfigFile());
 | 
			
		||||
            }
 | 
			
		||||
            catch (IOException | InvalidConfigurationException ex)
 | 
			
		||||
            {
 | 
			
		||||
                if (debug)
 | 
			
		||||
                {
 | 
			
		||||
                    Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage());
 | 
			
		||||
                }
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
            return configuration.getBoolean("opt-out", false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws java.io.IOException
 | 
			
		||||
     */
 | 
			
		||||
    public void enable() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        // This has to be synchronized or it can collide with the check in the task.
 | 
			
		||||
        synchronized (optOutLock)
 | 
			
		||||
        {
 | 
			
		||||
            // Check if the server owner has already set opt-out, if not, set it.
 | 
			
		||||
            if (isOptOut())
 | 
			
		||||
            {
 | 
			
		||||
                configuration.set("opt-out", false);
 | 
			
		||||
                configuration.save(configurationFile);
 | 
			
		||||
            }
 | 
			
		||||
            // Enable Task, if it is not running
 | 
			
		||||
            if (task == null)
 | 
			
		||||
            {
 | 
			
		||||
                start();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task.
 | 
			
		||||
     *
 | 
			
		||||
     * @throws java.io.IOException
 | 
			
		||||
     */
 | 
			
		||||
    public void disable() throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        // This has to be synchronized or it can collide with the check in the task.
 | 
			
		||||
        synchronized (optOutLock)
 | 
			
		||||
        {
 | 
			
		||||
            // Check if the server owner has already set opt-out, if not, set it.
 | 
			
		||||
            if (!isOptOut())
 | 
			
		||||
            {
 | 
			
		||||
                configuration.set("opt-out", true);
 | 
			
		||||
                configuration.save(configurationFile);
 | 
			
		||||
            }
 | 
			
		||||
            // Disable Task, if it is running
 | 
			
		||||
            if (task != null)
 | 
			
		||||
            {
 | 
			
		||||
                task.cancel();
 | 
			
		||||
                task = null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status
 | 
			
		||||
     *
 | 
			
		||||
     * @return the File object for the config file
 | 
			
		||||
     */
 | 
			
		||||
    public File getConfigFile()
 | 
			
		||||
    {
 | 
			
		||||
        // I believe the easiest way to get the base folder (e.g Spigot set via -P) for plugins to use
 | 
			
		||||
        // is to abuse the plugin object we already have
 | 
			
		||||
        // plugin.getDataFolder() => base/plugins/PluginA/
 | 
			
		||||
        // pluginsFolder => base/plugins/
 | 
			
		||||
        // The base is not necessarily relative to the startup directory.
 | 
			
		||||
        File pluginsFolder = plugin.getDataFolder().getParentFile();
 | 
			
		||||
        // return => base/plugins/PluginMetrics/config.yml
 | 
			
		||||
        return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Generic method that posts a plugin to the metrics website
 | 
			
		||||
     */
 | 
			
		||||
    private void postPlugin(final boolean isPing) throws IOException
 | 
			
		||||
    {
 | 
			
		||||
        // Server software specific section
 | 
			
		||||
        PluginDescriptionFile description = plugin.getDescription();
 | 
			
		||||
        String pluginName = description.getName();
 | 
			
		||||
        boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled
 | 
			
		||||
        String pluginVersion = description.getVersion();
 | 
			
		||||
        String serverVersion = Bukkit.getVersion();
 | 
			
		||||
        int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
 | 
			
		||||
        // END server software specific section -- all code below does not use any code outside of this class / Java
 | 
			
		||||
        // Construct the post data
 | 
			
		||||
        StringBuilder json = new StringBuilder(1024);
 | 
			
		||||
        json.append('{');
 | 
			
		||||
        // The plugin's description file containg all of the plugin data such as name, version, author, etc
 | 
			
		||||
        appendJSONPair(json, "guid", guid);
 | 
			
		||||
        appendJSONPair(json, "plugin_version", pluginVersion);
 | 
			
		||||
        appendJSONPair(json, "server_version", serverVersion);
 | 
			
		||||
        appendJSONPair(json, "players_online", Integer.toString(playersOnline));
 | 
			
		||||
        // New data as of R6
 | 
			
		||||
        String osname = System.getProperty("os.name");
 | 
			
		||||
        String osarch = System.getProperty("os.arch");
 | 
			
		||||
        String osversion = System.getProperty("os.version");
 | 
			
		||||
        String java_version = System.getProperty("java.version");
 | 
			
		||||
        int coreCount = Runtime.getRuntime().availableProcessors();
 | 
			
		||||
        // normalize os arch .. amd64 -> x86_64
 | 
			
		||||
        if (osarch.equals("amd64"))
 | 
			
		||||
        {
 | 
			
		||||
            osarch = "x86_64";
 | 
			
		||||
        }
 | 
			
		||||
        appendJSONPair(json, "osname", osname);
 | 
			
		||||
        appendJSONPair(json, "osarch", osarch);
 | 
			
		||||
        appendJSONPair(json, "osversion", osversion);
 | 
			
		||||
        appendJSONPair(json, "cores", Integer.toString(coreCount));
 | 
			
		||||
        appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0");
 | 
			
		||||
        appendJSONPair(json, "java_version", java_version);
 | 
			
		||||
        // If we're pinging, append it
 | 
			
		||||
        if (isPing)
 | 
			
		||||
        {
 | 
			
		||||
            appendJSONPair(json, "ping", "1");
 | 
			
		||||
        }
 | 
			
		||||
        if (graphs.size() > 0)
 | 
			
		||||
        {
 | 
			
		||||
            synchronized (graphs)
 | 
			
		||||
            {
 | 
			
		||||
                json.append(',');
 | 
			
		||||
                json.append('"');
 | 
			
		||||
                json.append("graphs");
 | 
			
		||||
                json.append('"');
 | 
			
		||||
                json.append(':');
 | 
			
		||||
                json.append('{');
 | 
			
		||||
                boolean firstGraph = true;
 | 
			
		||||
                for (Graph graph : graphs)
 | 
			
		||||
                {
 | 
			
		||||
                    StringBuilder graphJson = new StringBuilder();
 | 
			
		||||
                    graphJson.append('{');
 | 
			
		||||
                    for (Plotter plotter : graph.getPlotters())
 | 
			
		||||
                    {
 | 
			
		||||
                        appendJSONPair(graphJson, plotter.getColumnName(), Integer.toString(plotter.getValue()));
 | 
			
		||||
                    }
 | 
			
		||||
                    graphJson.append('}');
 | 
			
		||||
                    if (!firstGraph)
 | 
			
		||||
                    {
 | 
			
		||||
                        json.append(',');
 | 
			
		||||
                    }
 | 
			
		||||
                    json.append(escapeJSON(graph.getName()));
 | 
			
		||||
                    json.append(':');
 | 
			
		||||
                    json.append(graphJson);
 | 
			
		||||
                    firstGraph = false;
 | 
			
		||||
                }
 | 
			
		||||
                json.append('}');
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // close json
 | 
			
		||||
        json.append('}');
 | 
			
		||||
        // Create the url
 | 
			
		||||
        URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName)));
 | 
			
		||||
        // Connect to the website
 | 
			
		||||
        URLConnection connection;
 | 
			
		||||
        // Mineshafter creates a socks proxy, so we can safely bypass it
 | 
			
		||||
        // It does not reroute POST requests so we need to go around it
 | 
			
		||||
        if (isMineshafterPresent())
 | 
			
		||||
        {
 | 
			
		||||
            connection = url.openConnection(Proxy.NO_PROXY);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            connection = url.openConnection();
 | 
			
		||||
        }
 | 
			
		||||
        byte[] uncompressed = json.toString().getBytes();
 | 
			
		||||
        byte[] compressed = gzip(json.toString());
 | 
			
		||||
        // Headers
 | 
			
		||||
        connection.addRequestProperty("User-Agent", "MCStats/" + REVISION);
 | 
			
		||||
        connection.addRequestProperty("Content-Type", "application/json");
 | 
			
		||||
        connection.addRequestProperty("Content-Encoding", "gzip");
 | 
			
		||||
        connection.addRequestProperty("Content-Length", Integer.toString(compressed.length));
 | 
			
		||||
        connection.addRequestProperty("Accept", "application/json");
 | 
			
		||||
        connection.addRequestProperty("Connection", "close");
 | 
			
		||||
        connection.setDoOutput(true);
 | 
			
		||||
        if (debug)
 | 
			
		||||
        {
 | 
			
		||||
            System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length
 | 
			
		||||
                    + " compressed=" + compressed.length);
 | 
			
		||||
        }
 | 
			
		||||
        // Write the data
 | 
			
		||||
        OutputStream os = connection.getOutputStream();
 | 
			
		||||
        os.write(compressed);
 | 
			
		||||
        os.flush();
 | 
			
		||||
        String response;
 | 
			
		||||
        try ( // Now read the response
 | 
			
		||||
                BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
 | 
			
		||||
        {
 | 
			
		||||
            response = reader.readLine();
 | 
			
		||||
            // close resources
 | 
			
		||||
            os.close();
 | 
			
		||||
        }
 | 
			
		||||
        if (response == null || response.startsWith("ERR") || response.startsWith("7"))
 | 
			
		||||
        {
 | 
			
		||||
            if (response == null)
 | 
			
		||||
            {
 | 
			
		||||
                response = "null";
 | 
			
		||||
            }
 | 
			
		||||
            else if (response.startsWith("7"))
 | 
			
		||||
            {
 | 
			
		||||
                response = response.substring(response.startsWith("7,") ? 2 : 1);
 | 
			
		||||
            }
 | 
			
		||||
            throw new IOException(response);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            // Is this the first update this hour?
 | 
			
		||||
            if (response.equals("1") || response.contains("This is your first update this hour"))
 | 
			
		||||
            {
 | 
			
		||||
                synchronized (graphs)
 | 
			
		||||
                {
 | 
			
		||||
                    for (Graph graph : graphs)
 | 
			
		||||
                    {
 | 
			
		||||
                        for (Plotter plotter : graph.getPlotters())
 | 
			
		||||
                        {
 | 
			
		||||
                            plotter.reset();
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * GZip compress a string of bytes
 | 
			
		||||
     *
 | 
			
		||||
     * @param input
 | 
			
		||||
     * @return byte[]
 | 
			
		||||
     */
 | 
			
		||||
    public static byte[] gzip(String input)
 | 
			
		||||
    {
 | 
			
		||||
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
 | 
			
		||||
        GZIPOutputStream gzos = null;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            gzos = new GZIPOutputStream(baos);
 | 
			
		||||
            gzos.write(input.getBytes("UTF-8"));
 | 
			
		||||
        }
 | 
			
		||||
        catch (IOException e)
 | 
			
		||||
        {
 | 
			
		||||
            e.printStackTrace(System.out);
 | 
			
		||||
        }
 | 
			
		||||
        finally
 | 
			
		||||
        {
 | 
			
		||||
            if (gzos != null)
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    gzos.close();
 | 
			
		||||
                }
 | 
			
		||||
                catch (IOException ignore)
 | 
			
		||||
                {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return baos.toByteArray();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Check if mineshafter is present. If it is, we need to bypass it to send POST requests
 | 
			
		||||
     *
 | 
			
		||||
     * @return true if mineshafter is installed on the server
 | 
			
		||||
     */
 | 
			
		||||
    private boolean isMineshafterPresent()
 | 
			
		||||
    {
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            Class.forName("mineshafter.MineServer");
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        catch (Exception e)
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Appends a json encoded key/value pair to the given string builder.
 | 
			
		||||
     *
 | 
			
		||||
     * @param json
 | 
			
		||||
     * @param key
 | 
			
		||||
     * @param value
 | 
			
		||||
     * @throws UnsupportedEncodingException
 | 
			
		||||
     */
 | 
			
		||||
    private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException
 | 
			
		||||
    {
 | 
			
		||||
        boolean isValueNumeric = false;
 | 
			
		||||
        try
 | 
			
		||||
        {
 | 
			
		||||
            if (value.equals("0") || !value.endsWith("0"))
 | 
			
		||||
            {
 | 
			
		||||
                Double.parseDouble(value);
 | 
			
		||||
                isValueNumeric = true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        catch (NumberFormatException e)
 | 
			
		||||
        {
 | 
			
		||||
            isValueNumeric = false;
 | 
			
		||||
        }
 | 
			
		||||
        if (json.charAt(json.length() - 1) != '{')
 | 
			
		||||
        {
 | 
			
		||||
            json.append(',');
 | 
			
		||||
        }
 | 
			
		||||
        json.append(escapeJSON(key));
 | 
			
		||||
        json.append(':');
 | 
			
		||||
        if (isValueNumeric)
 | 
			
		||||
        {
 | 
			
		||||
            json.append(value);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            json.append(escapeJSON(value));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Escape a string to create a valid JSON string
 | 
			
		||||
     *
 | 
			
		||||
     * @param text
 | 
			
		||||
     * @return String
 | 
			
		||||
     */
 | 
			
		||||
    private static String escapeJSON(String text)
 | 
			
		||||
    {
 | 
			
		||||
        StringBuilder builder = new StringBuilder();
 | 
			
		||||
        builder.append('"');
 | 
			
		||||
        for (int index = 0; index < text.length(); index++)
 | 
			
		||||
        {
 | 
			
		||||
            char chr = text.charAt(index);
 | 
			
		||||
            switch (chr)
 | 
			
		||||
            {
 | 
			
		||||
            case '"':
 | 
			
		||||
            case '\\':
 | 
			
		||||
                builder.append('\\');
 | 
			
		||||
                builder.append(chr);
 | 
			
		||||
                break;
 | 
			
		||||
            case '\b':
 | 
			
		||||
                builder.append("\\b");
 | 
			
		||||
                break;
 | 
			
		||||
            case '\t':
 | 
			
		||||
                builder.append("\\t");
 | 
			
		||||
                break;
 | 
			
		||||
            case '\n':
 | 
			
		||||
                builder.append("\\n");
 | 
			
		||||
                break;
 | 
			
		||||
            case '\r':
 | 
			
		||||
                builder.append("\\r");
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                if (chr < ' ')
 | 
			
		||||
                {
 | 
			
		||||
                    String t = "000" + Integer.toHexString(chr);
 | 
			
		||||
                    builder.append("\\u").append(t.substring(t.length() - 4));
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    builder.append(chr);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        builder.append('"');
 | 
			
		||||
        return builder.toString();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Encode text as UTF-8
 | 
			
		||||
     *
 | 
			
		||||
     * @param text
 | 
			
		||||
     *            the text to encode
 | 
			
		||||
     * @return the encoded text, as UTF-8
 | 
			
		||||
     */
 | 
			
		||||
    private static String urlEncode(final String text) throws UnsupportedEncodingException
 | 
			
		||||
    {
 | 
			
		||||
        return URLEncoder.encode(text, "UTF-8");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Represents a custom graph on the website
 | 
			
		||||
     */
 | 
			
		||||
    public static class Graph
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * The graph's name, alphanumeric and spaces only :) If it does not comply to the above when submitted, it is rejected
 | 
			
		||||
         */
 | 
			
		||||
        private final String name;
 | 
			
		||||
        /**
 | 
			
		||||
         * The set of plotters that are contained within this graph
 | 
			
		||||
         */
 | 
			
		||||
        private final Set<Plotter> plotters = new LinkedHashSet<>();
 | 
			
		||||
 | 
			
		||||
        private Graph(final String name)
 | 
			
		||||
        {
 | 
			
		||||
            this.name = name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Gets the graph's name
 | 
			
		||||
         *
 | 
			
		||||
         * @return the Graph's name
 | 
			
		||||
         */
 | 
			
		||||
        public String getName()
 | 
			
		||||
        {
 | 
			
		||||
            return name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Add a plotter to the graph, which will be used to plot entries
 | 
			
		||||
         *
 | 
			
		||||
         * @param plotter
 | 
			
		||||
         *            the plotter to add to the graph
 | 
			
		||||
         */
 | 
			
		||||
        public void addPlotter(final Plotter plotter)
 | 
			
		||||
        {
 | 
			
		||||
            plotters.add(plotter);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Remove a plotter from the graph
 | 
			
		||||
         *
 | 
			
		||||
         * @param plotter
 | 
			
		||||
         *            the plotter to remove from the graph
 | 
			
		||||
         */
 | 
			
		||||
        public void removePlotter(final Plotter plotter)
 | 
			
		||||
        {
 | 
			
		||||
            plotters.remove(plotter);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Gets an <b>unmodifiable</b> set of the plotter objects in the graph
 | 
			
		||||
         *
 | 
			
		||||
         * @return an unmodifiable {@link java.util.Set} of the plotter objects
 | 
			
		||||
         */
 | 
			
		||||
        public Set<Plotter> getPlotters()
 | 
			
		||||
        {
 | 
			
		||||
            return Collections.unmodifiableSet(plotters);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public int hashCode()
 | 
			
		||||
        {
 | 
			
		||||
            return name.hashCode();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean equals(final Object object)
 | 
			
		||||
        {
 | 
			
		||||
            if (!(object instanceof Graph))
 | 
			
		||||
            {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            final Graph graph = (Graph) object;
 | 
			
		||||
            return graph.name.equals(name);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Called when the server owner decides to opt-out of BukkitMetrics while the server is running.
 | 
			
		||||
         */
 | 
			
		||||
        protected void onOptOut()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Interface used to collect custom data for a plugin
 | 
			
		||||
     */
 | 
			
		||||
    public static abstract class Plotter
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * The plot's name
 | 
			
		||||
         */
 | 
			
		||||
        private final String name;
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Construct a plotter with the default plot name
 | 
			
		||||
         */
 | 
			
		||||
        public Plotter()
 | 
			
		||||
        {
 | 
			
		||||
            this("Default");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Construct a plotter with a specific plot name
 | 
			
		||||
         *
 | 
			
		||||
         * @param name
 | 
			
		||||
         *            the name of the plotter to use, which will show up on the website
 | 
			
		||||
         */
 | 
			
		||||
        public Plotter(final String name)
 | 
			
		||||
        {
 | 
			
		||||
            this.name = name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Get the current value for the plotted point. Since this function defers to an external function it may or may not
 | 
			
		||||
         * return immediately thus cannot be guaranteed to be thread friendly or safe. This function can be called from any thread
 | 
			
		||||
         * so care should be taken when accessing resources that need to be synchronized.
 | 
			
		||||
         *
 | 
			
		||||
         * @return the current value for the point to be plotted.
 | 
			
		||||
         */
 | 
			
		||||
        public abstract int getValue();
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Get the column name for the plotted point
 | 
			
		||||
         *
 | 
			
		||||
         * @return the plotted point's column name
 | 
			
		||||
         */
 | 
			
		||||
        public String getColumnName()
 | 
			
		||||
        {
 | 
			
		||||
            return name;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /**
 | 
			
		||||
         * Called after the website graphs have been updated
 | 
			
		||||
         */
 | 
			
		||||
        public void reset()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public int hashCode()
 | 
			
		||||
        {
 | 
			
		||||
            return getColumnName().hashCode();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean equals(final Object object)
 | 
			
		||||
        {
 | 
			
		||||
            if (!(object instanceof Plotter))
 | 
			
		||||
            {
 | 
			
		||||
                return false;
 | 
			
		||||
            }
 | 
			
		||||
            final Plotter plotter = (Plotter) object;
 | 
			
		||||
            return plotter.name.equals(name) && plotter.getValue() == getValue();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										2194
									
								
								src/me/libraryaddict/disguise/utilities/PacketsManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2194
									
								
								src/me/libraryaddict/disguise/utilities/PacketsManager.java
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1031
									
								
								src/me/libraryaddict/disguise/utilities/ReflectionManager.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1031
									
								
								src/me/libraryaddict/disguise/utilities/ReflectionManager.java
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										60
									
								
								src/me/libraryaddict/disguise/utilities/UpdateChecker.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								src/me/libraryaddict/disguise/utilities/UpdateChecker.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
package me.libraryaddict.disguise.utilities;
 | 
			
		||||
 | 
			
		||||
import java.io.BufferedReader;
 | 
			
		||||
import java.io.InputStreamReader;
 | 
			
		||||
import java.net.HttpURLConnection;
 | 
			
		||||
import java.net.URL;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
public class UpdateChecker {
 | 
			
		||||
 | 
			
		||||
    private String latestVersion;
 | 
			
		||||
 | 
			
		||||
    private boolean checkHigher(String currentVersion, String newVersion) {
 | 
			
		||||
        String current = toReadable(currentVersion);
 | 
			
		||||
        String newVers = toReadable(newVersion);
 | 
			
		||||
        return current.compareTo(newVers) < 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void checkUpdate(String currentVersion) {
 | 
			
		||||
        String version = getSpigotVersion();
 | 
			
		||||
        if (version != null) {
 | 
			
		||||
            if (checkHigher(currentVersion, version)) {
 | 
			
		||||
                latestVersion = version;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getLatestVersion() {
 | 
			
		||||
        return latestVersion;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Asks spigot for the version
 | 
			
		||||
     */
 | 
			
		||||
    private String getSpigotVersion() {
 | 
			
		||||
        try {
 | 
			
		||||
            HttpURLConnection con = (HttpURLConnection) new URL("http://www.spigotmc.org/api/general.php").openConnection();
 | 
			
		||||
            con.setDoOutput(true);
 | 
			
		||||
            con.setRequestMethod("POST");
 | 
			
		||||
            con.getOutputStream().write(
 | 
			
		||||
                    ("key=98BE0FE67F88AB82B4C197FAF1DC3B69206EFDCC4D3B80FC83A00037510B99B4&resource=81").getBytes("UTF-8"));
 | 
			
		||||
            String version = new BufferedReader(new InputStreamReader(con.getInputStream())).readLine();
 | 
			
		||||
            if (version.length() <= 7) {
 | 
			
		||||
                return version;
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception ex) {
 | 
			
		||||
            System.out.print("[LibsDisguises] Failed to check for a update on spigot. Now checking bukkit..");
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private String toReadable(String version) {
 | 
			
		||||
        String[] split = Pattern.compile(".", Pattern.LITERAL).split(version.replace("v", ""));
 | 
			
		||||
        version = "";
 | 
			
		||||
        for (String s : split) {
 | 
			
		||||
            version += String.format("%4s", s);
 | 
			
		||||
        }
 | 
			
		||||
        return version;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user