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 @Getter
@Setter @Setter
private String disguiseName; 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) { public Disguise(DisguiseType disguiseType) {
this.disguiseType = disguiseType; this.disguiseType = disguiseType;
@ -112,6 +118,7 @@ public abstract class Disguise {
protected void clone(Disguise disguise) { protected void clone(Disguise disguise) {
disguise.setDisguiseName(getDisguiseName()); disguise.setDisguiseName(getDisguiseName());
disguise.setCustomName(isCustomName());
disguise.setReplaceSounds(isSoundsReplaced()); disguise.setReplaceSounds(isSoundsReplaced());
disguise.setViewSelfDisguise(isSelfDisguiseVisible()); disguise.setViewSelfDisguise(isSelfDisguiseVisible());

View File

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

View File

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

View File

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