diff --git a/src/me/libraryaddict/disguise/DisguiseAPI.java b/src/me/libraryaddict/disguise/DisguiseAPI.java index 77633b41..842d8a1b 100644 --- a/src/me/libraryaddict/disguise/DisguiseAPI.java +++ b/src/me/libraryaddict/disguise/DisguiseAPI.java @@ -163,10 +163,6 @@ public class DisguiseAPI { return; } - if (entity instanceof Player) { - disguise.setViewSelfDisguise(DisguiseAPI.isViewSelfToggled(entity)); - } - // The event wasn't cancelled. // If the disguise entity isn't the same as the one we are disguising if (disguise.getEntity() != entity) { @@ -179,8 +175,9 @@ public class DisguiseAPI { disguise.setEntity(entity); } - disguise.setViewSelfDisguise(Disguise.getViewSelf().contains(disguise.getEntity().getUniqueId()) != - DisguiseConfig.isViewDisguises()); + // They prefer to have the opposite of whatever the view disguises option is + if (hasSelfDisguisePreference(entity) && disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); disguise.startDisguise(); } @@ -382,8 +379,11 @@ public class DisguiseAPI { * @return */ public static boolean isViewSelfToggled(Entity entity) { - return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() : - !Disguise.getViewSelf().contains(entity.getUniqueId()) == DisguiseConfig.isViewDisguises(); + return hasSelfDisguisePreference(entity) != DisguiseConfig.isViewDisguises(); + } + + public static boolean hasSelfDisguisePreference(Entity entity) { + return Disguise.getViewSelf().contains(entity.getUniqueId()); } /** @@ -417,7 +417,7 @@ public class DisguiseAPI { } if (!canSeeSelfDisguises == DisguiseConfig.isViewDisguises()) { - if (!Disguise.getViewSelf().contains(entity.getUniqueId())) { + if (!hasSelfDisguisePreference(entity)) { Disguise.getViewSelf().add(entity.getUniqueId()); } } else { diff --git a/src/me/libraryaddict/disguise/DisguiseListener.java b/src/me/libraryaddict/disguise/DisguiseListener.java index 2efc9ee0..7c94b42d 100644 --- a/src/me/libraryaddict/disguise/DisguiseListener.java +++ b/src/me/libraryaddict/disguise/DisguiseListener.java @@ -465,7 +465,7 @@ public class DisguiseListener implements Listener { } } - DisguiseAPI.disguiseToAll(entity, disguise); + DisguiseAPI.disguiseEntity(entity, disguise); String disguiseName; diff --git a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java index f1263980..e1774132 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseCommand.java @@ -1,11 +1,9 @@ package me.libraryaddict.disguise.commands; -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.DisguiseType; -import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException; @@ -13,7 +11,6 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.LibsMsg; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; -import me.libraryaddict.disguise.utilities.TranslateType; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -45,7 +42,9 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter Disguise disguise; try { - disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(args, " ")), getPermissions(sender)); + disguise = DisguiseParser + .parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(args, " ")), + getPermissions(sender)); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -69,7 +68,16 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter } } - DisguiseAPI.disguiseToAll((Player) sender, disguise); + disguise.setEntity((Player) sender); + + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); if (disguise.isDisguiseInUse()) { sender.sendMessage(LibsMsg.DISGUISED.get(disguise.getType().toReadable())); @@ -80,6 +88,17 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter return true; } + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setViewSelfDisguise")) + continue; + + return true; + } + + return false; + } + @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { ArrayList tabs = new ArrayList<>(); diff --git a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java index db591bc2..48172408 100644 --- a/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguisePlayerCommand.java @@ -72,7 +72,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom Disguise disguise; try { - disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs, " ")), map); + disguise = DisguiseParser + .parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs, " ")), map); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -100,8 +101,16 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom } } } + disguise.setEntity(player); - DisguiseAPI.disguiseToAll(player, disguise); + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); if (disguise.isDisguiseInUse()) { sender.sendMessage(LibsMsg.DISG_PLAYER_AS_DISG @@ -116,6 +125,17 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom return true; } + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setViewSelfDisguise")) + continue; + + return true; + } + + return false; + } + @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { ArrayList tabs = new ArrayList<>(); diff --git a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java index 4c2f2851..a519e5e5 100644 --- a/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java +++ b/src/me/libraryaddict/disguise/commands/DisguiseRadiusCommand.java @@ -57,8 +57,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom return true; } - if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) || args[0] - .equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) { + if (args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType")) || + args[0].equalsIgnoreCase(TranslateType.DISGUISES.get("EntityType") + "s")) { ArrayList classes = new ArrayList<>(); for (Class c : validClasses) { @@ -130,7 +130,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } try { - disguise = DisguiseParser.parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs, " ")), map); + disguise = DisguiseParser + .parseDisguise(sender, getPermNode(), DisguiseParser.split(StringUtils.join(newArgs, " ")), map); } catch (DisguiseParseException ex) { if (ex.getMessage() != null) { @@ -162,8 +163,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } if (type != null ? entity.getType() == type : entityClass.isAssignableFrom(entity.getClass())) { - if (disguise.isMiscDisguise() && !DisguiseConfig - .isMiscDisguisesForLivingEnabled() && entity instanceof LivingEntity) { + if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled() && + entity instanceof LivingEntity) { miscDisguises++; continue; } @@ -179,7 +180,17 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom } } - DisguiseAPI.disguiseToAll(entity, disguise); + disguise.setEntity(entity); + + if (!setViewDisguise(args)) { + // They prefer to have the opposite of whatever the view disguises option is + if (DisguiseAPI.hasSelfDisguisePreference(disguise.getEntity()) && + disguise.isSelfDisguiseVisible() == DisguiseConfig.isViewDisguises()) + disguise.setViewSelfDisguise(!disguise.isSelfDisguiseVisible()); + } + + disguise.startDisguise(); + DisguiseAPI.disguiseEntity(entity, disguise); if (disguise.isDisguiseInUse()) { disguisedEntitys++; @@ -200,6 +211,17 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom return true; } + private boolean setViewDisguise(String[] strings) { + for (String string : strings) { + if (!string.equalsIgnoreCase("setViewSelfDisguise")) + continue; + + return true; + } + + return false; + } + @Override public List onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { ArrayList tabs = new ArrayList<>(); @@ -248,8 +270,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom ArrayList usedOptions = new ArrayList<>(); for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { - for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 : - starting + 1; i < args.length; i++) { + for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 : starting + 1; + i < args.length; i++) { String arg = args[i]; if (!method.getName().equalsIgnoreCase(arg))