Improved self disguises toggling to allow commandline to override player preferences, still ignores the commandline users if its a custom or right click disguise.

This commit is contained in:
libraryaddict 2018-02-14 18:49:10 +13:00
parent 758f24108b
commit 206207a374
5 changed files with 86 additions and 25 deletions

View File

@ -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 {

View File

@ -465,7 +465,7 @@ public class DisguiseListener implements Listener {
}
}
DisguiseAPI.disguiseToAll(entity, disguise);
DisguiseAPI.disguiseEntity(entity, disguise);
String disguiseName;

View File

@ -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<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();

View File

@ -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<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();

View File

@ -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<String> 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<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<>();
@ -248,8 +270,8 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
ArrayList<String> 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))