From 3a2c121f0f13cf6d6309606b43f61a3617e9cb12 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 21 Apr 2020 15:00:36 +1200 Subject: [PATCH] Let custom disguises retain their disguise name --- .../disguise/disguisetypes/Disguise.java | 7 +++++++ .../watchers/DroppedItemWatcher.java | 8 +++++--- .../watchers/FallingBlockWatcher.java | 7 +++++-- .../utilities/parser/DisguiseParser.java | 16 ++++++++++++++-- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index f0425352..f095224d 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -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()); diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java index 91a5744b..e75e0fcf 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/DroppedItemWatcher.java @@ -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()))); + } } } diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java index cad8bab9..2a809053 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/watchers/FallingBlockWatcher.java @@ -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()); 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 9ad8f382..764c1e10 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/DisguiseParser.java @@ -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 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];