From e5304f19e2730451e1c1ae454371aa108579c32c Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 11 Aug 2020 08:28:43 +1200 Subject: [PATCH] Add better updating, add %user-displayname% and target --- .../commands/DisguiseBaseCommand.java | 13 ++-------- .../commands/libsdisguises/LDUpdate.java | 24 +++++++++++++------ .../disguise/utilities/DisguiseUtilities.java | 20 ++++++++++++++++ .../utilities/parser/DisguiseParser.java | 12 +++++++++- 4 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java index d3476e39..01127cc0 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java +++ b/src/main/java/me/libraryaddict/disguise/commands/DisguiseBaseCommand.java @@ -9,6 +9,7 @@ import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand; import me.libraryaddict.disguise.disguisetypes.DisguiseType; +import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; @@ -210,17 +211,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { } protected String getDisplayName(CommandSender player) { - Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName()); - - if (team == null) { - team = ((Player) player).getScoreboard().getEntryTeam(((Player) player).getUniqueId().toString()); - } - - if (team == null || (StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) { - return ((Player) player).getDisplayName(); - } - - return team.getPrefix() + team.getColor() + player.getName() + team.getSuffix(); + return DisguiseUtilities.getDisplayName(player); } protected ArrayList getAllowedDisguises(DisguisePermissions permissions) { diff --git a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java index fcbe202b..b77251a7 100644 --- a/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java +++ b/src/main/java/me/libraryaddict/disguise/commands/libsdisguises/LDUpdate.java @@ -40,10 +40,12 @@ public class LDUpdate implements LDCommand { } boolean releaseBuilds = checker.isUsingReleaseBuilds(); - boolean forceUpdate = args[0].endsWith("!"); - boolean forceCheck = args[0].endsWith("?") || args.length > 1 || forceUpdate; + boolean wantsDownload = args[0].endsWith("!"); + boolean wantsCheck = args[0].endsWith("?"); if (args.length > 1) { + boolean previous = releaseBuilds; + if (args[1].equalsIgnoreCase("dev")) { releaseBuilds = false; } else if (args[1].equalsIgnoreCase("release")) { @@ -53,11 +55,16 @@ public class LDUpdate implements LDCommand { return; } + if (previous != releaseBuilds && !wantsCheck) { + wantsDownload = true; + } + + wantsCheck = true; + DisguiseConfig.setUsingReleaseBuilds(releaseBuilds); } - if (checker.getUpdate() != null && checker.getUpdate().isReleaseBuild() == releaseBuilds && args.length <= 1 && - !forceCheck) { + if (checker.getUpdate() != null && checker.getUpdate().isReleaseBuild() == releaseBuilds && !wantsCheck) { if (checker.isServerLatestVersion()) { LibsMsg.UPDATE_ON_LATEST.send(sender); return; @@ -69,12 +76,15 @@ public class LDUpdate implements LDCommand { } } + boolean finalWantsCheck = wantsCheck; + boolean finalWantsDownload = wantsDownload; + new BukkitRunnable() { @Override public void run() { LibsMsg updateResult = null; - if (checker.getUpdate() == null || args.length > 1 || checker.isOldUpdate() || forceCheck) { + if (checker.getUpdate() == null || args.length > 1 || checker.isOldUpdate() || finalWantsCheck) { updateResult = checker.doUpdateCheck(); } @@ -83,7 +93,7 @@ public class LDUpdate implements LDCommand { return; } - if (checker.isOnLatestUpdate(true)) { + if (checker.isOnLatestUpdate(true) && !finalWantsDownload) { if (checker.getLastDownload() != null) { LibsMsg.UPDATE_ALREADY_DOWNLOADED.send(sender); } else { @@ -93,7 +103,7 @@ public class LDUpdate implements LDCommand { return; } - if (!forceUpdate) { + if (!finalWantsDownload) { if (updateResult != null) { updateResult.send(sender); } else { diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index b0e74b95..9950a2c2 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -197,6 +197,26 @@ public class DisguiseUtilities { return viewSelf; } + public static String getDisplayName(CommandSender player) { + Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName()); + + if (team == null) { + team = ((Player) player).getScoreboard().getEntryTeam(((Player) player).getUniqueId().toString()); + } + + if (team == null || (StringUtils.isEmpty(team.getPrefix()) && StringUtils.isEmpty(team.getSuffix()))) { + String name = ((Player) player).getDisplayName(); + + if (name.equals(player.getName())) { + return ((Player) player).getPlayerListName(); + } + + return name; + } + + return team.getPrefix() + team.getColor() + player.getName() + team.getSuffix(); + } + public static void saveViewPreferances() { if (!DisguiseConfig.isSaveUserPreferences()) { return; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java index 7cdc5385..062a68e5 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -436,7 +436,8 @@ public class DisguiseParser { } public static String[] parsePlaceholders(String[] args, CommandSender user, CommandSender target) { - return parsePlaceholders(args, getName(user), getSkin(user), getName(target), DisguiseParser.getSkin(target), + return parsePlaceholders(args, getName(user), DisguiseUtilities.getDisplayName(user), getSkin(user), + getName(target), DisguiseUtilities.getDisplayName(target), DisguiseParser.getSkin(target), getEntityEquipment(user), getEntityEquipment(target)); } @@ -446,13 +447,22 @@ public class DisguiseParser { public static String[] parsePlaceholders(String[] args, String userName, String userSkin, String targetName, String targetSkin, EntityEquipment equip, EntityEquipment targetEquip) { + return parsePlaceholders(args, userName, userName, userSkin, targetName, targetName, targetSkin, equip, + targetEquip); + } + + public static String[] parsePlaceholders(String[] args, String userName, String userDisplayname, String userSkin, + String targetName, String targetDisplayname, String targetSkin, EntityEquipment equip, + EntityEquipment targetEquip) { for (int i = 0; i < args.length; i++) { String arg = args[i]; arg = replace(arg, "%user-name%", userName); + arg = replace(arg, "%user-displayname%", userDisplayname); arg = replace(arg, "%user-skin%", userSkin); arg = replace(arg, "%target-name%", targetName); + arg = replace(arg, "%target-displayname%", targetDisplayname); arg = replace(arg, "%target-skin%", targetSkin); arg = replace(arg, "%held-item%", equip == null ? null : equip.getItemInMainHand()); arg = replace(arg, "%offhand-item%", equip == null ? null : equip.getItemInOffHand());