Let custom disguises retain their disguise name

This commit is contained in:
libraryaddict 2020-04-21 15:00:36 +12:00
parent 884f9471ca
commit 3a2c121f0f
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
4 changed files with 31 additions and 7 deletions

View File

@ -89,6 +89,12 @@ public abstract class Disguise {
@Getter
@Setter
private String disguiseName;
/**
* Is the name allowed to be changed by Lib's Disguises if they do some option?
*/
@Getter
@Setter
private boolean customName = true;
public Disguise(DisguiseType disguiseType) {
this.disguiseType = disguiseType;
@ -112,6 +118,7 @@ public abstract class Disguise {
protected void clone(Disguise disguise) {
disguise.setDisguiseName(getDisguiseName());
disguise.setCustomName(isCustomName());
disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible());

View File

@ -22,8 +22,10 @@ public class DroppedItemWatcher extends FlagWatcher {
setData(MetaIndex.DROPPED_ITEM, item);
sendData(MetaIndex.DROPPED_ITEM);
getDisguise().setDisguiseName(TranslateType.DISGUISES.get(DisguiseType.DROPPED_ITEM.toReadable()) + " " +
TranslateType.DISGUISE_OPTIONS_PARAMETERS
.get(ReflectionManager.toReadable((item == null ? Material.AIR : item.getType()).name())));
if (!getDisguise().isCustomName()) {
getDisguise().setDisguiseName(TranslateType.DISGUISES.get(DisguiseType.DROPPED_ITEM.toReadable()) + " " +
TranslateType.DISGUISE_OPTIONS_PARAMETERS
.get(ReflectionManager.toReadable((item == null ? Material.AIR : item.getType()).name())));
}
}
}

View File

@ -87,8 +87,11 @@ public class FallingBlockWatcher extends FlagWatcher {
this.block = block;
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(ReflectionManager.toReadable(block.getType().name())));
if (!getDisguise().isCustomName()) {
getDisguise().setDisguiseName(TranslateType.DISGUISE_OPTIONS_PARAMETERS.get("Block") + " " +
TranslateType.DISGUISE_OPTIONS_PARAMETERS
.get(ReflectionManager.toReadable(block.getType().name())));
}
if (DisguiseAPI.isDisguiseInUse(getDisguise()) && getDisguise().getWatcher() == this) {
DisguiseUtilities.refreshTrackers(getDisguise());

View File

@ -611,6 +611,7 @@ public class DisguiseParser {
Disguise disguise = null;
DisguisePerm disguisePerm;
String name;
boolean customName = false;
if (args[0].startsWith("@")) {
if (sender.hasPermission("libsdisguises.disguise.disguiseclone")) {
@ -625,6 +626,7 @@ public class DisguiseParser {
disguisePerm = new DisguisePerm(disguise.getType());
name = disguise.getDisguiseName();
customName = disguise.isCustomName();
if (disguisePerm.isUnknown()) {
throw new DisguiseParseException(LibsMsg.PARSE_CANT_DISG_UNKNOWN);
@ -654,6 +656,7 @@ public class DisguiseParser {
}
disguise = new ModdedDisguise(ent);
customName = true;
}
Entry<DisguisePerm, String> customDisguise = DisguiseConfig.getRawCustomDisguise(args[0]);
@ -661,6 +664,7 @@ public class DisguiseParser {
if (customDisguise != null) {
args = DisguiseUtilities.split(customDisguise.getValue());
name = customDisguise.getKey().toReadable();
customName = true;
}
args = parsePlaceholders(args, sender, target);
@ -696,7 +700,11 @@ public class DisguiseParser {
// Construct the player disguise
disguise = new PlayerDisguise(ChatColor.translateAlternateColorCodes('&', args[1]));
name = ((PlayerDisguise) disguise).getName();
if (!customName) {
name = ((PlayerDisguise) disguise).getName();
}
toSkip++;
}
} else if (disguisePerm.isMob()) { // Its a mob, use the mob constructor
@ -792,7 +800,10 @@ public class DisguiseParser {
if (disguisePerm.getType() == DisguiseType.DROPPED_ITEM ||
disguisePerm.getType() == DisguiseType.FALLING_BLOCK) {
disguise = new MiscDisguise(disguisePerm.getType(), itemStack);
name = disguise.getDisguiseName();
if (!customName) {
name = disguise.getDisguiseName();
}
} else {
disguise = new MiscDisguise(disguisePerm.getType(), miscId);
}
@ -801,6 +812,7 @@ public class DisguiseParser {
}
disguise.setDisguiseName(name);
disguise.setCustomName(customName);
// Copy strings to their new range
String[] newArgs = new String[args.length - toSkip];