diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index 707104ea..a9cf132a 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -1,6 +1,8 @@ package me.libraryaddict.disguise; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedGameProfile; +import com.comphenix.protocol.wrappers.WrappedWatchableObject; import lombok.Getter; import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType; @@ -94,11 +96,11 @@ public class DisguiseAPI { @Deprecated public static Disguise constructDisguise(Entity entity) { - return constructDisguise(entity, true, true, true); + return constructDisguise(entity, true, false); } @Deprecated - public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doSneak, boolean doSprint) { + public static Disguise constructDisguise(Entity entity, boolean doEquipment, boolean doAddedAnimations) { DisguiseType disguiseType = DisguiseType.getType(entity); Disguise disguise; @@ -112,98 +114,38 @@ public class DisguiseAPI { 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(); + ItemStack mainItem = equip.getItemInMainHand(); - if (saddle != null && saddle.getType() == Material.SADDLE) { - ((AbstractHorseWatcher) watcher).setSaddled(true); - } + if (mainItem != null && mainItem.getType() != Material.AIR) { + watcher.setItemInMainHand(mainItem); + } + + ItemStack offItem = equip.getItemInMainHand(); + + if (offItem != null && offItem.getType() != Material.AIR) { + watcher.setItemInOffHand(offItem); } } - 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; - } + WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(entity); - int firstCapitalMethod = firstCapital(method.getName()); + for (WrappedWatchableObject obj : dataWatcher.getWatchableObjects()) { + MetaIndex index = MetaIndex.getMetaIndex(watcher.getClass(), obj.getIndex()); - 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)) { - 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(); - } - } - } - } - } - } + if (index == null) { + continue; } + + if (index.getDefault() == obj.getValue() || index.getDefault() == obj.getRawValue()) { + continue; + } + + watcher.setUnsafeData(index, obj.getRawValue()); } return disguise; diff --git a/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java index 45658590..0376c8b8 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/utils/DisguiseCloneCommand.java @@ -33,8 +33,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp } boolean doEquipment = true; - boolean doSneak = false; - boolean doSprint = false; + boolean doAdded = false; Player player = null; if (args.length > 0) { @@ -45,20 +44,15 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp String option = args[i]; if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) { doEquipment = false; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) { - doSneak = true; - doSprint = true; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) { - doSneak = true; - } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) { - doSprint = true; - } else { + } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_ADDEDANIMATIONS.get())) { + doAdded = true; + } else { LibsMsg.INVALID_CLONE.send(sender, option); return true; } } - Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint}; + Boolean[] options = new Boolean[]{doEquipment, doAdded}; if (player != null) { DisguiseUtilities.createClonedDisguise((Player) sender, player, options); @@ -91,9 +85,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp } tabs.add(LibsMsg.DCLONE_EQUIP.get()); - tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get()); - tabs.add(LibsMsg.DCLONE_SNEAK.get()); - tabs.add(LibsMsg.DCLONE_SPRINT.get()); + tabs.add(LibsMsg.DCLONE_ADDEDANIMATIONS.get()); return filterTabs(tabs, origArgs); } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index e5167e15..ca09ce41 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -990,6 +990,11 @@ public class FlagWatcher { } } + @Deprecated + public void setUnsafeData(MetaIndex id, Y value) { + setData(id, value); + } + protected void setData(MetaIndex id, Y value) { if (id == null) { return; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index 8e3fb8a5..84c747a8 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -558,7 +558,7 @@ public class DisguiseUtilities { Disguise disguise = DisguiseAPI.getDisguise(player, toClone); if (disguise == null) { - disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1], options[2]); + disguise = DisguiseAPI.constructDisguise(toClone, options[0], options[1]); } else { disguise = disguise.clone(); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 57ed2eb1..33a173f0 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -1895,7 +1895,7 @@ public class ReflectionManager { for (MetaIndex index : indexes) { DisguiseUtilities.getLogger() - .warning(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex()); + .severe(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex()); } SoundGroup sound = SoundGroup.getGroup(disguiseType.name()); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java index 69e95dad..6a41f49b 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/translations/LibsMsg.java @@ -82,9 +82,7 @@ public enum LibsMsg { DHELP_SHOW("Show"), DHELP_NO_OPTIONS(ChatColor.RED + "No options with permission to use"), DCLONE_EQUIP("ignoreEquip"), - DCLONE_SNEAKSPRINT("doSneakSprint"), - DCLONE_SNEAK("doSneak"), - DCLONE_SPRINT("doSprint"), + DCLONE_ADDEDANIMATIONS("doAddedAnimations"), DMODRADIUS_HELP2((ChatColor.DARK_GREEN + "/disguisemodifyradius ") .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),