Add better updating, add %user-displayname% and target

This commit is contained in:
libraryaddict 2020-08-11 08:28:43 +12:00
parent 9ffbd9e272
commit e5304f19e2
4 changed files with 50 additions and 19 deletions

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.commands.modify.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand; import me.libraryaddict.disguise.commands.modify.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.params.ParamInfo; import me.libraryaddict.disguise.utilities.params.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
@ -210,17 +211,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
} }
protected String getDisplayName(CommandSender player) { protected String getDisplayName(CommandSender player) {
Team team = ((Player) player).getScoreboard().getEntryTeam(player.getName()); return DisguiseUtilities.getDisplayName(player);
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();
} }
protected ArrayList<String> getAllowedDisguises(DisguisePermissions permissions) { protected ArrayList<String> getAllowedDisguises(DisguisePermissions permissions) {

View File

@ -40,10 +40,12 @@ public class LDUpdate implements LDCommand {
} }
boolean releaseBuilds = checker.isUsingReleaseBuilds(); boolean releaseBuilds = checker.isUsingReleaseBuilds();
boolean forceUpdate = args[0].endsWith("!"); boolean wantsDownload = args[0].endsWith("!");
boolean forceCheck = args[0].endsWith("?") || args.length > 1 || forceUpdate; boolean wantsCheck = args[0].endsWith("?");
if (args.length > 1) { if (args.length > 1) {
boolean previous = releaseBuilds;
if (args[1].equalsIgnoreCase("dev")) { if (args[1].equalsIgnoreCase("dev")) {
releaseBuilds = false; releaseBuilds = false;
} else if (args[1].equalsIgnoreCase("release")) { } else if (args[1].equalsIgnoreCase("release")) {
@ -53,11 +55,16 @@ public class LDUpdate implements LDCommand {
return; return;
} }
if (previous != releaseBuilds && !wantsCheck) {
wantsDownload = true;
}
wantsCheck = true;
DisguiseConfig.setUsingReleaseBuilds(releaseBuilds); DisguiseConfig.setUsingReleaseBuilds(releaseBuilds);
} }
if (checker.getUpdate() != null && checker.getUpdate().isReleaseBuild() == releaseBuilds && args.length <= 1 && if (checker.getUpdate() != null && checker.getUpdate().isReleaseBuild() == releaseBuilds && !wantsCheck) {
!forceCheck) {
if (checker.isServerLatestVersion()) { if (checker.isServerLatestVersion()) {
LibsMsg.UPDATE_ON_LATEST.send(sender); LibsMsg.UPDATE_ON_LATEST.send(sender);
return; return;
@ -69,12 +76,15 @@ public class LDUpdate implements LDCommand {
} }
} }
boolean finalWantsCheck = wantsCheck;
boolean finalWantsDownload = wantsDownload;
new BukkitRunnable() { new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
LibsMsg updateResult = null; 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(); updateResult = checker.doUpdateCheck();
} }
@ -83,7 +93,7 @@ public class LDUpdate implements LDCommand {
return; return;
} }
if (checker.isOnLatestUpdate(true)) { if (checker.isOnLatestUpdate(true) && !finalWantsDownload) {
if (checker.getLastDownload() != null) { if (checker.getLastDownload() != null) {
LibsMsg.UPDATE_ALREADY_DOWNLOADED.send(sender); LibsMsg.UPDATE_ALREADY_DOWNLOADED.send(sender);
} else { } else {
@ -93,7 +103,7 @@ public class LDUpdate implements LDCommand {
return; return;
} }
if (!forceUpdate) { if (!finalWantsDownload) {
if (updateResult != null) { if (updateResult != null) {
updateResult.send(sender); updateResult.send(sender);
} else { } else {

View File

@ -197,6 +197,26 @@ public class DisguiseUtilities {
return viewSelf; 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() { public static void saveViewPreferances() {
if (!DisguiseConfig.isSaveUserPreferences()) { if (!DisguiseConfig.isSaveUserPreferences()) {
return; return;

View File

@ -436,7 +436,8 @@ public class DisguiseParser {
} }
public static String[] parsePlaceholders(String[] args, CommandSender user, CommandSender target) { 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)); getEntityEquipment(user), getEntityEquipment(target));
} }
@ -446,13 +447,22 @@ public class DisguiseParser {
public static String[] parsePlaceholders(String[] args, String userName, String userSkin, String targetName, public static String[] parsePlaceholders(String[] args, String userName, String userSkin, String targetName,
String targetSkin, EntityEquipment equip, EntityEquipment targetEquip) { 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++) { for (int i = 0; i < args.length; i++) {
String arg = args[i]; String arg = args[i];
arg = replace(arg, "%user-name%", userName); arg = replace(arg, "%user-name%", userName);
arg = replace(arg, "%user-displayname%", userDisplayname);
arg = replace(arg, "%user-skin%", userSkin); arg = replace(arg, "%user-skin%", userSkin);
arg = replace(arg, "%target-name%", targetName); arg = replace(arg, "%target-name%", targetName);
arg = replace(arg, "%target-displayname%", targetDisplayname);
arg = replace(arg, "%target-skin%", targetSkin); arg = replace(arg, "%target-skin%", targetSkin);
arg = replace(arg, "%held-item%", equip == null ? null : equip.getItemInMainHand()); arg = replace(arg, "%held-item%", equip == null ? null : equip.getItemInMainHand());
arg = replace(arg, "%offhand-item%", equip == null ? null : equip.getItemInOffHand()); arg = replace(arg, "%offhand-item%", equip == null ? null : equip.getItemInOffHand());