From 2de723af8a0879573f160ca09ef721c26e9ef032 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Fri, 8 May 2020 03:20:58 +1200 Subject: [PATCH] Add the workings of custom names for all, I should make it check permissions... --- .../disguise/DisguiseConfig.java | 8 ++++-- .../disguise/disguisetypes/FlagWatcher.java | 26 +++++++++++++++++++ src/main/resources/config.yml | 2 ++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 1283bf48..e316b51a 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -243,6 +243,9 @@ public class DisguiseConfig { @Getter @Setter private static PlayerNameType playerNameType = PlayerNameType.TEAMS; + @Getter + @Setter + private static boolean overrideCustomNames; public static boolean isArmorstandsName() { return getPlayerNameType() == PlayerNameType.ARMORSTANDS; @@ -644,6 +647,7 @@ public class DisguiseConfig { setTablistRemoveDelay(config.getInt("TablistRemoveDelay")); setAutoUpdate(config.getBoolean("AutoUpdate")); setHideTallSelfDisguises(config.getBoolean("HideTallSelfDisguises")); + setOverrideCustomNames(config.getBoolean("OverrideCustomNames")); if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) { DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!"); @@ -653,8 +657,8 @@ public class DisguiseConfig { setPlayerNameType(PlayerNameType.valueOf(config.getString("PlayerNames").toUpperCase())); } catch (Exception ex) { - DisguiseUtilities.getLogger() - .warning("Cannot parse '" + config.getString("PlayerNames") + "' to a valid option for PlayerNames"); + DisguiseUtilities.getLogger().warning( + "Cannot parse '" + config.getString("PlayerNames") + "' to a valid option for PlayerNames"); } try { diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java index 4e8e791d..65ca9de6 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/FlagWatcher.java @@ -21,6 +21,7 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.TextComponent; +import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -255,6 +256,10 @@ public class FlagWatcher { } public String getCustomName() { + if (DisguiseConfig.isOverrideCustomNames() && DisguiseConfig.isArmorstandsName()) { + return StringUtils.join(getDisguise().getMultiName(), "\n"); + } + if (!NmsVersion.v1_13.isSupported()) { return getData(MetaIndex.ENTITY_CUSTOM_NAME_OLD); } @@ -271,6 +276,26 @@ public class FlagWatcher { } public void setCustomName(String name) { + if (DisguiseConfig.isArmorstandsName() && DisguiseConfig.isOverrideCustomNames()) { + if (NmsVersion.v1_13.isSupported()) { + if (!hasValue(MetaIndex.ENTITY_CUSTOM_NAME)) { + setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); + sendData(MetaIndex.ENTITY_CUSTOM_NAME); + } + } else { + if (!hasValue(MetaIndex.ENTITY_CUSTOM_NAME_OLD)) { + setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, ""); + sendData(MetaIndex.ENTITY_CUSTOM_NAME_OLD); + } + } + + if (name == null) { + getDisguise().setMultiName(); + } else { + getDisguise().setMultiName(DisguiseUtilities.splitNewLine(name)); + } + } + if (Strings.isNullOrEmpty(name)) { if (NmsVersion.v1_13.isSupported()) { setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); @@ -288,6 +313,7 @@ public class FlagWatcher { setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); } } + if (NmsVersion.v1_13.isSupported()) { sendData(MetaIndex.ENTITY_CUSTOM_NAME); } else { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 082dd4b3..51d63e2f 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -73,6 +73,8 @@ SaveDisguises: # ARMORSTANDS - Names are limited to 256 chars, uses a mix of armorstands and teams to do this. Slightly hacky. # Downside of armorstand names is that there's a chance of it becoming desynced from the player disguise PlayerNames: TEAMS +# If doing armorstands, should CustomNames be overridden to use armorstands too? +OverrideCustomNames: true # How many ticks before tab packet is sent to remove from tablist. This shouldn't need to be touched TablistRemoveDelay: 2