Add the workings of custom names for all, I should make it check permissions...

This commit is contained in:
libraryaddict 2020-05-08 03:20:58 +12:00
parent 944dd7243b
commit 2de723af8a
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
3 changed files with 34 additions and 2 deletions

View File

@ -243,6 +243,9 @@ public class DisguiseConfig {
@Getter @Getter
@Setter @Setter
private static PlayerNameType playerNameType = PlayerNameType.TEAMS; private static PlayerNameType playerNameType = PlayerNameType.TEAMS;
@Getter
@Setter
private static boolean overrideCustomNames;
public static boolean isArmorstandsName() { public static boolean isArmorstandsName() {
return getPlayerNameType() == PlayerNameType.ARMORSTANDS; return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
@ -644,6 +647,7 @@ public class DisguiseConfig {
setTablistRemoveDelay(config.getInt("TablistRemoveDelay")); setTablistRemoveDelay(config.getInt("TablistRemoveDelay"));
setAutoUpdate(config.getBoolean("AutoUpdate")); setAutoUpdate(config.getBoolean("AutoUpdate"));
setHideTallSelfDisguises(config.getBoolean("HideTallSelfDisguises")); setHideTallSelfDisguises(config.getBoolean("HideTallSelfDisguises"));
setOverrideCustomNames(config.getBoolean("OverrideCustomNames"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) { if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!"); 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())); setPlayerNameType(PlayerNameType.valueOf(config.getString("PlayerNames").toUpperCase()));
} }
catch (Exception ex) { catch (Exception ex) {
DisguiseUtilities.getLogger() DisguiseUtilities.getLogger().warning(
.warning("Cannot parse '" + config.getString("PlayerNames") + "' to a valid option for PlayerNames"); "Cannot parse '" + config.getString("PlayerNames") + "' to a valid option for PlayerNames");
} }
try { try {

View File

@ -21,6 +21,7 @@ import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import net.md_5.bungee.api.chat.BaseComponent; import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -255,6 +256,10 @@ public class FlagWatcher {
} }
public String getCustomName() { public String getCustomName() {
if (DisguiseConfig.isOverrideCustomNames() && DisguiseConfig.isArmorstandsName()) {
return StringUtils.join(getDisguise().getMultiName(), "\n");
}
if (!NmsVersion.v1_13.isSupported()) { if (!NmsVersion.v1_13.isSupported()) {
return getData(MetaIndex.ENTITY_CUSTOM_NAME_OLD); return getData(MetaIndex.ENTITY_CUSTOM_NAME_OLD);
} }
@ -271,6 +276,26 @@ public class FlagWatcher {
} }
public void setCustomName(String name) { 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 (Strings.isNullOrEmpty(name)) {
if (NmsVersion.v1_13.isSupported()) { if (NmsVersion.v1_13.isSupported()) {
setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty()); setData(MetaIndex.ENTITY_CUSTOM_NAME, Optional.empty());
@ -288,6 +313,7 @@ public class FlagWatcher {
setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, name); setData(MetaIndex.ENTITY_CUSTOM_NAME_OLD, name);
} }
} }
if (NmsVersion.v1_13.isSupported()) { if (NmsVersion.v1_13.isSupported()) {
sendData(MetaIndex.ENTITY_CUSTOM_NAME); sendData(MetaIndex.ENTITY_CUSTOM_NAME);
} else { } else {

View File

@ -73,6 +73,8 @@ SaveDisguises:
# ARMORSTANDS - Names are limited to 256 chars, uses a mix of armorstands and teams to do this. Slightly hacky. # 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 # Downside of armorstand names is that there's a chance of it becoming desynced from the player disguise
PlayerNames: TEAMS 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 # How many ticks before tab packet is sent to remove from tablist. This shouldn't need to be touched
TablistRemoveDelay: 2 TablistRemoveDelay: 2