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

@ -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 {

@ -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 {

@ -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