Fix Hex-Colored names in parties/admin chat

This commit is contained in:
nossr50 2020-11-06 14:01:07 -08:00
parent b2cdffe965
commit a4fd632d53
23 changed files with 300 additions and 220 deletions

View File

@ -1,3 +1,12 @@
Version 2.1.154
(API) Author class has been reworked
(API) McMMOChatEvent::getSender removed (use getDisplayName() instead)
(API) McMMMOChatEvent::setDisplayName() removed (you can set author names in Author)
(API) Removed Author::setName use Player::SetDisplayName instead
(API) Modified Author::getAuthoredName signature to -> Author::getAuthoredName(ChatChannel)
(API) Added Author::getAuthoredComponentName(ChatChannel)
(API) PartyAuthor and AdminAuthor removed, replaced by PlayerAuthor
Version 2.1.153
Fixed a bug where most sub-skills were not being displayed when using a skills command (for example /taming)
Fixed a bug where some URL links were not being colored

View File

@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.1.153</version>
<version>2.1.154-SNAPSHOT</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
@ -243,7 +243,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>

View File

@ -13,6 +13,7 @@ import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.text.StringUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.ConsoleCommandSender;
import org.jetbrains.annotations.NotNull;
@ -70,10 +71,10 @@ public class ChatManager {
private void processPlayerMessage(@NotNull McMMOPlayer mmoPlayer, @NotNull ChatChannel chatChannel, @NotNull String rawMessage, boolean isAsync) {
switch (chatChannel) {
case ADMIN:
adminChatMailer.processChatMessage(mmoPlayer.getAdminAuthor(), rawMessage, isAsync, Permissions.colorChat(mmoPlayer.getPlayer()));
adminChatMailer.processChatMessage(mmoPlayer.getPlayerAuthor(), rawMessage, isAsync, Permissions.colorChat(mmoPlayer.getPlayer()));
break;
case PARTY:
partyChatMailer.processChatMessage(mmoPlayer.getPartyAuthor(), rawMessage, mmoPlayer.getParty(), isAsync, Permissions.colorChat(mmoPlayer.getPlayer()), isPartyLeader(mmoPlayer));
partyChatMailer.processChatMessage(mmoPlayer.getPlayerAuthor(), rawMessage, mmoPlayer.getParty(), isAsync, Permissions.colorChat(mmoPlayer.getPlayer()), isPartyLeader(mmoPlayer));
break;
case PARTY_OFFICER:
case NONE:

View File

@ -0,0 +1,95 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.util.text.TextUtils;
import com.google.common.base.Objects;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public abstract class AbstractPlayerAuthor implements Author {
private final @NotNull Player player;
private @NotNull String displayName;
private @Nullable TextComponent componentDisplayName;
private @Nullable TextComponent componentUserName;
public AbstractPlayerAuthor(@NotNull Player player) {
this.player = player;
this.displayName = player.getDisplayName();
}
/**
* Grabs the {@link TextComponent} version of a players display name
* Cached and only processed as needed
* Always checks if the player display name has changed, if it has it regenerates the output
*
* @return the {@link TextComponent} version of a players display name
*/
public @NotNull TextComponent getComponentDisplayName() {
//Not sure if this is expensive but it ensures always up to date names
if(!player.getDisplayName().equals(displayName)) {
displayName = player.getDisplayName();
componentDisplayName = null;
}
if(componentDisplayName != null) {
return componentDisplayName;
} else {
//convert to adventure component
componentDisplayName = TextUtils.ofBungeeRawStrings(displayName);
}
return componentDisplayName;
}
/**
* Grabs the {@link TextComponent} version of a players current minecraft nickname
* Cached and only processed as needed
*
* @return the {@link TextComponent} version of a players current minecraft nickname
*/
public @NotNull TextComponent getComponentUserName() {
//Not sure if this is expensive but it ensures always up to date names
if(componentUserName != null) {
return componentUserName;
} else {
//convert to adventure component
componentUserName = TextUtils.ofBungeeRawStrings(player.getName());
}
return componentUserName;
}
@Override
public boolean isConsole() {
return false;
}
@Override
public boolean isPlayer() {
return true;
}
public @NotNull Player getPlayer() {
return player;
}
@Override
public @NonNull UUID uuid() {
return player.getUniqueId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AbstractPlayerAuthor that = (AbstractPlayerAuthor) o;
return Objects.equal(player, that.player);
}
@Override
public int hashCode() {
return Objects.hashCode(player);
}
}

View File

@ -1,79 +0,0 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class AdminAuthor implements Author {
private final @NotNull Player player;
private @Nullable String overrideName;
public AdminAuthor(@NotNull Player player) {
this.player = player;
}
@Override
public @NotNull String getAuthoredName() {
if(overrideName != null) {
return overrideName;
} else {
if(ChatConfig.getInstance().useDisplayNames(ChatChannel.ADMIN)) {
return player.getDisplayName();
} else {
return player.getName();
}
}
}
public @NotNull Player getPlayer() {
return player;
}
public @Nullable String getOverrideName() {
return overrideName;
}
/**
* Set the name of this author
* @param newName value of the new name
*/
public void setName(@NotNull String newName) {
overrideName = newName;
}
@Override
public boolean isConsole() {
return false;
}
@Override
public boolean isPlayer() {
return true;
}
@Override
public @NonNull UUID uuid() {
return player.getUniqueId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
AdminAuthor that = (AdminAuthor) o;
return Objects.equal(player, that.player) &&
Objects.equal(overrideName, that.overrideName);
}
@Override
public int hashCode() {
return Objects.hashCode(player, overrideName);
}
}

View File

@ -1,15 +1,35 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.TextComponent;
import org.jetbrains.annotations.NotNull;
public interface Author extends Identity {
/**
* The name of this author
* @return the name of this author
* The name of this author as used in mcMMO chat
* This is the {@link TextComponent} representation of the users current chat username
* This can either be the player's display name or the player's official registered nickname with Mojang it depends on the servers chat settings for mcMMO
*
* NOTE:
* mcMMO doesn't use this method currently because we convert the whole chat message from raw Bungee-compatible strings to Bungee components before converting it to adventure components (hacky and will be changed later)
* So this method is provided for future use or if plugins want to make use of it
*
* @param chatChannel which chat channel this is going to
* @return The name of this author as used in mcMMO chat
*/
@NotNull String getAuthoredName();
@NotNull TextComponent getAuthoredComponentName(@NotNull ChatChannel chatChannel);
/**
* The name of this author as used in mcMMO chat
* This is the {@link String} representation of the users current chat username
* This can either be the player's display name or the player's official registered nickname with Mojang it depends on the servers chat settings for mcMMO
*
* @param chatChannel which chat channel this is going to
* @return The name of this author as used in mcMMO chat
*/
@NotNull String getAuthoredName(@NotNull ChatChannel chatChannel);
/**
* Whether or not this author is a {@link org.bukkit.command.ConsoleCommandSender}

View File

@ -1,5 +1,8 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.util.text.TextUtils;
import net.kyori.adventure.text.TextComponent;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
@ -8,14 +11,22 @@ import java.util.UUID;
public class ConsoleAuthor implements Author {
private final UUID uuid;
private final @NotNull String name;
private final @NotNull TextComponent componentName;
public ConsoleAuthor(@NotNull String name) {
this.name = name;
this.uuid = new UUID(0, 0);
this.name = name;
this.componentName = TextUtils.ofBungeeRawStrings(name);
}
//TODO: Think of a better solution later
@Override
public @NotNull TextComponent getAuthoredComponentName(@NotNull ChatChannel chatChannel) {
return componentName;
}
@Override
public @NotNull String getAuthoredName() {
public @NotNull String getAuthoredName(@NotNull ChatChannel chatChannel) {
return name;
}

View File

@ -1,75 +0,0 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.google.common.base.Objects;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;
public class PartyAuthor implements Author {
private final @NotNull Player player;
private @Nullable String overrideName;
public PartyAuthor(@NotNull Player player) {
this.player = player;
}
@Override
public @NotNull String getAuthoredName() {
if(overrideName != null) {
return overrideName;
} else {
if(ChatConfig.getInstance().useDisplayNames(ChatChannel.PARTY)) {
return player.getDisplayName();
} else {
return player.getName();
}
}
}
/**
* Set the name of this author
* @param newName value of the new name
*/
public void setName(@NotNull String newName) {
overrideName = newName;
}
@Override
public boolean isConsole() {
return false;
}
@Override
public boolean isPlayer() {
return true;
}
public Player getPlayer() {
return player;
}
@Override
public @NonNull UUID uuid() {
return player.getUniqueId();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PartyAuthor that = (PartyAuthor) o;
return Objects.equal(player, that.player) &&
Objects.equal(overrideName, that.overrideName);
}
@Override
public int hashCode() {
return Objects.hashCode(player, overrideName);
}
}

View File

@ -0,0 +1,33 @@
package com.gmail.nossr50.chat.author;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
public class PlayerAuthor extends AbstractPlayerAuthor {
public PlayerAuthor(@NotNull Player player) {
super(player);
}
@Override
public @NotNull TextComponent getAuthoredComponentName(@NotNull ChatChannel chatChannel) {
if(ChatConfig.getInstance().useDisplayNames(chatChannel)) {
return getComponentDisplayName();
} else {
return getComponentUserName();
}
}
@Override
public @NotNull String getAuthoredName(@NotNull ChatChannel chatChannel) {
if(ChatConfig.getInstance().useDisplayNames(chatChannel)) {
return getPlayer().getDisplayName();
} else {
return getPlayer().getName();
}
}
}

View File

@ -3,12 +3,13 @@ package com.gmail.nossr50.chat.mailer;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.chat.message.AdminChatMessage;
import com.gmail.nossr50.chat.message.ChatMessage;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.events.chat.McMMOAdminChatEvent;
import com.gmail.nossr50.events.chat.McMMOChatEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.TextUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -53,9 +54,9 @@ public class AdminChatMailer extends AbstractChatMailer {
*/
public @NotNull TextComponent addStyle(@NotNull Author author, @NotNull String message, boolean canColor) {
if(canColor) {
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), LocaleLoader.addColors(message)));
return TextUtils.ofBungeeRawStrings(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(ChatChannel.ADMIN), LocaleLoader.addColors(message)));
} else {
return Component.text(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(), message));
return TextUtils.ofBungeeRawStrings(LocaleLoader.getString("Chat.Style.Admin", author.getAuthoredName(ChatChannel.ADMIN), message));
}
}

View File

@ -3,13 +3,14 @@ package com.gmail.nossr50.chat.mailer;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.chat.message.ChatMessage;
import com.gmail.nossr50.chat.message.PartyChatMessage;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.events.chat.McMMOChatEvent;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.text.TextUtils;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
@ -49,9 +50,9 @@ public class PartyChatMailer extends AbstractChatMailer {
}
if(isLeader) {
return Component.text(LocaleLoader.getString("Chat.Style.Party.Leader", author.getAuthoredName(), message));
return TextUtils.ofBungeeRawStrings(LocaleLoader.getString("Chat.Style.Party.Leader", author.getAuthoredName(ChatChannel.PARTY), message));
} else {
return Component.text(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(), message));
return TextUtils.ofBungeeRawStrings(LocaleLoader.getString("Chat.Style.Party", author.getAuthoredName(ChatChannel.PARTY), message));
}
}

View File

@ -1,8 +1,10 @@
package com.gmail.nossr50.chat.message;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.google.common.base.Objects;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
@ -33,11 +35,6 @@ public abstract class AbstractChatMessage implements ChatMessage {
return author;
}
@Override
public @NotNull String getAuthorDisplayName() {
return author.getAuthoredName();
}
@Override
public @NotNull Audience getAudience() {
return audience;

View File

@ -1,6 +1,7 @@
package com.gmail.nossr50.chat.message;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.plugin.Plugin;
@ -15,4 +16,9 @@ public class AdminChatMessage extends AbstractChatMessage {
public void sendMessage() {
audience.sendMessage(author, componentMessage);
}
@Override
public @NotNull String getAuthorDisplayName() {
return author.getAuthoredName(ChatChannel.ADMIN);
}
}

View File

@ -1,7 +1,9 @@
package com.gmail.nossr50.chat.message;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.jetbrains.annotations.NotNull;

View File

@ -1,14 +1,15 @@
package com.gmail.nossr50.chat.message;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import com.gmail.nossr50.datatypes.party.Party;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.text.TextUtils;
import com.google.common.base.Objects;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@ -31,6 +32,11 @@ public class PartyChatMessage extends AbstractChatMessage {
return party;
}
@Override
public @NotNull String getAuthorDisplayName() {
return author.getAuthoredName(ChatChannel.PARTY);
}
@Override
public void sendMessage() {
/*
@ -40,7 +46,7 @@ public class PartyChatMessage extends AbstractChatMessage {
//Sends to everyone but console
audience.sendMessage(author, componentMessage);
TextComponent spyMessage = Component.text(LocaleLoader.getString("Chat.Spy.Party", author.getAuthoredName(), rawMessage, party.getName()));
TextComponent spyMessage = TextUtils.ofBungeeRawStrings(LocaleLoader.getString("Chat.Spy.Party", author.getAuthoredName(ChatChannel.PARTY), rawMessage, party.getName()));
//Relay to spies
messagePartyChatSpies(spyMessage);

View File

@ -1,7 +1,6 @@
package com.gmail.nossr50.datatypes.player;
import com.gmail.nossr50.chat.author.AdminAuthor;
import com.gmail.nossr50.chat.author.PartyAuthor;
import com.gmail.nossr50.chat.author.PlayerAuthor;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.ChatConfig;
import com.gmail.nossr50.config.Config;
@ -74,8 +73,7 @@ public class McMMOPlayer implements Identified {
private final @NotNull Identity identity;
//Hacky fix for now, redesign later
private final @NotNull PartyAuthor partyAuthor;
private final @NotNull AdminAuthor adminAuthor;
private final @NotNull PlayerAuthor playerAuthor;
private final Player player;
private final PlayerProfile profile;
@ -158,8 +156,7 @@ public class McMMOPlayer implements Identified {
debugMode = false; //Debug mode helps solve support issues, players can toggle it on or off
attackStrength = 1.0D;
this.adminAuthor = new AdminAuthor(player);
this.partyAuthor = new PartyAuthor(player);
this.playerAuthor = new PlayerAuthor(player);
this.chatChannel = ChatChannel.NONE;
@ -176,9 +173,9 @@ public class McMMOPlayer implements Identified {
return attackStrength;
}
public void setAttackStrength(double attackStrength) {
this.attackStrength = attackStrength;
}
// public void setAttackStrength(double attackStrength) {
// this.attackStrength = attackStrength;
// }
/*public void hideXpBar(PrimarySkillType primarySkillType)
{
@ -1049,22 +1046,25 @@ public class McMMOPlayer implements Identified {
return identity;
}
//TODO: Replace this hacky crap
public @NotNull PartyAuthor getPartyAuthor() {
return partyAuthor;
}
//TODO: Replace this hacky crap
public @NotNull AdminAuthor getAdminAuthor() {
return adminAuthor;
/**
* The {@link com.gmail.nossr50.chat.author.Author} for this player, used by mcMMO chat
* @return the {@link com.gmail.nossr50.chat.author.Author} for this player
*/
public @NotNull PlayerAuthor getPlayerAuthor() {
return playerAuthor;
}
public @NotNull ChatChannel getChatChannel() {
return chatChannel;
}
public void setChatMode(ChatChannel chatChannel) {
//TODO: Code in the "you turned off blah, you turned on blah" messages.
/**
* Change the chat channel for a player
* This does not inform the player
* @param chatChannel new chat channel
*/
public void setChatMode(@NotNull ChatChannel chatChannel) {
this.chatChannel = chatChannel;
}
}

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.events.chat;
import com.gmail.nossr50.chat.author.Author;
import com.gmail.nossr50.chat.message.AbstractChatMessage;
import com.gmail.nossr50.chat.message.ChatMessage;
import com.gmail.nossr50.datatypes.chat.ChatChannel;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@ -57,23 +58,13 @@ public abstract class McMMOChatEvent extends Event implements Cancellable {
return plugin;
}
/**
* The display name of the author
*
* @return the display name of the author
* @deprecated Use {@link #getDisplayName()} instead
*/
@Deprecated
public @NotNull String getSender() {
return getAuthor().getAuthoredName();
}
/**
* The name of the author
* Will return the display name if mcMMO chat config is set to, otherwise returns the players Mojang registered nickname
* @return the author's name
*/
public @NotNull String getDisplayName() {
return getAuthor().getAuthoredName();
public @NotNull String getDisplayName(ChatChannel chatChannel) {
return getAuthor().getAuthoredName(chatChannel);
}
/**
@ -115,14 +106,6 @@ public abstract class McMMOChatEvent extends Event implements Cancellable {
this.chatMessage.setChatMessage(chatMessage);
}
/**
* Does not function anymore
*/
@Deprecated
public void setDisplayName(@NotNull String displayName) {
return;
}
/**
* @param message Adjusts the final message sent to players in the party
*

View File

@ -2,7 +2,9 @@ package com.gmail.nossr50.util.compat;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.compat.layers.attackcooldown.PlayerAttackCooldownExploitPreventionLayer;
import com.gmail.nossr50.util.compat.layers.bungee.AbstractBungeeSerializerCompatibilityLayer;
import com.gmail.nossr50.util.compat.layers.bungee.BungeeLegacySerializerCompatibilityLayer;
import com.gmail.nossr50.util.compat.layers.bungee.BungeeModernSerializerCompatibilityLayer;
import com.gmail.nossr50.util.compat.layers.persistentdata.AbstractPersistentDataLayer;
import com.gmail.nossr50.util.compat.layers.persistentdata.SpigotPersistentDataLayer_1_13;
import com.gmail.nossr50.util.compat.layers.persistentdata.SpigotPersistentDataLayer_1_14;
@ -26,8 +28,9 @@ public class CompatibilityManager {
private final NMSVersion nmsVersion;
/* Compatibility Layers */
private PlayerAttackCooldownExploitPreventionLayer playerAttackCooldownExploitPreventionLayer;
// private PlayerAttackCooldownExploitPreventionLayer playerAttackCooldownExploitPreventionLayer;
private AbstractPersistentDataLayer persistentDataLayer;
private AbstractBungeeSerializerCompatibilityLayer bungeeSerializerCompatibilityLayer;
public CompatibilityManager(MinecraftGameVersion minecraftGameVersion) {
mcMMO.p.getLogger().info("Loading compatibility layers...");
@ -60,10 +63,19 @@ public class CompatibilityManager {
*/
private void initCompatibilityLayers() {
initPersistentDataLayer();
initBungeeSerializerLayer();
isFullyCompatibleServerSoftware = true;
}
private void initBungeeSerializerLayer() {
if(minecraftGameVersion.getMinorVersion().asInt() >= 16) {
bungeeSerializerCompatibilityLayer = new BungeeModernSerializerCompatibilityLayer();
} else {
bungeeSerializerCompatibilityLayer = new BungeeLegacySerializerCompatibilityLayer();
}
}
private void initPersistentDataLayer() {
if(minecraftGameVersion.getMinorVersion().asInt() >= 14 || minecraftGameVersion.getMajorVersion().asInt() >= 2) {
@ -133,8 +145,13 @@ public class CompatibilityManager {
return NMSVersion.UNSUPPORTED;
}
public PlayerAttackCooldownExploitPreventionLayer getPlayerAttackCooldownExploitPreventionLayer() {
return playerAttackCooldownExploitPreventionLayer;
// public PlayerAttackCooldownExploitPreventionLayer getPlayerAttackCooldownExploitPreventionLayer() {
// return playerAttackCooldownExploitPreventionLayer;
// }
public AbstractBungeeSerializerCompatibilityLayer getBungeeSerializerCompatibilityLayer() {
return bungeeSerializerCompatibilityLayer;
}
public AbstractPersistentDataLayer getPersistentDataLayer() {

View File

@ -2,5 +2,6 @@ package com.gmail.nossr50.util.compat;
public enum CompatibilityType {
PLAYER_ATTACK_COOLDOWN_EXPLOIT_PREVENTION,
PERSISTENT_DATA
PERSISTENT_DATA,
BUNGEE_SERIALIZER
}

View File

@ -0,0 +1,11 @@
package com.gmail.nossr50.util.compat.layers.bungee;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.chat.BaseComponent;
import org.checkerframework.checker.nullness.qual.NonNull;
public abstract class AbstractBungeeSerializerCompatibilityLayer {
public abstract @NonNull Component deserialize(final @NonNull BaseComponent @NonNull[] input);
}

View File

@ -0,0 +1,13 @@
package com.gmail.nossr50.util.compat.layers.bungee;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import org.checkerframework.checker.nullness.qual.NonNull;
public class BungeeLegacySerializerCompatibilityLayer extends AbstractBungeeSerializerCompatibilityLayer {
@Override
public @NonNull Component deserialize(@NonNull BaseComponent @NonNull [] input) {
return BungeeComponentSerializer.legacy().deserialize(input);
}
}

View File

@ -0,0 +1,13 @@
package com.gmail.nossr50.util.compat.layers.bungee;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
import net.md_5.bungee.api.chat.BaseComponent;
import org.checkerframework.checker.nullness.qual.NonNull;
public class BungeeModernSerializerCompatibilityLayer extends AbstractBungeeSerializerCompatibilityLayer {
@Override
public @NonNull Component deserialize(@NonNull BaseComponent @NonNull [] input) {
return BungeeComponentSerializer.get().deserialize(input);
}
}

View File

@ -1,10 +1,12 @@
package com.gmail.nossr50.util.text;
import com.gmail.nossr50.mcMMO;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentBuilder;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.md_5.bungee.api.chat.BaseComponent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -84,4 +86,16 @@ public class TextUtils {
static void addNewHoverComponentToTextComponent(@NotNull TextComponent.Builder textComponent, @NotNull Component baseComponent) {
textComponent.hoverEvent(HoverEvent.showText(baseComponent));
}
public static BaseComponent[] convertToBungeeComponent(@NotNull String displayName) {
return net.md_5.bungee.api.chat.TextComponent.fromLegacyText(displayName);
}
public static @NotNull TextComponent ofBungeeComponents(@NotNull BaseComponent[] bungeeName) {
return TextComponent.ofChildren(mcMMO.getCompatibilityManager().getBungeeSerializerCompatibilityLayer().deserialize(bungeeName));
}
public static @NotNull TextComponent ofBungeeRawStrings(@NotNull String bungeeRawString) {
return ofBungeeComponents(convertToBungeeComponent(bungeeRawString));
}
}