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.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<String> getAllowedDisguises(DisguisePermissions permissions) {

View File

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

View File

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

View File

@ -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());