Fix rainbow nicknames. Legacy sucks.

This commit is contained in:
Draycia committed 2020-08-24 01:15:02 -07:00
1 parent 9abdc0df4c
commit 45f2915980
8 files changed
+29 -24

No files matched your search

@@ -43,7 +43,12 @@ public final class CarbonChat extends JavaPlugin {
private YamlConfiguration languageConfig;
public static final LegacyComponentSerializer LEGACY =
LegacyComponentSerializer.builder().extractUrls().character('§').build();
LegacyComponentSerializer.builder()
.extractUrls()
.hexColors()
.character('§')
.useUnusualXRepeatedCharacterHexFormat()
.build();
@Override
public void onEnable() {
@@ -105,10 +105,16 @@ public class CarbonChatChannel extends ChatChannel {
String displayName;
if (user.isOnline()) {
displayName = user.asPlayer().getDisplayName();
if (user.getNickname() != null) {
System.out.println("one");
displayName = user.getNickname();
} else {
displayName = user.asOfflinePlayer().getName();
System.out.println("null????");
if (user.isOnline()) {
displayName = user.asPlayer().getDisplayName();
} else {
displayName = user.asOfflinePlayer().getName();
}
}
// Iterate through players who should receive messages in this channel
@@ -7,7 +7,6 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -43,7 +42,7 @@ public class AliasedChannelCommand extends BaseCommand {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
Component component = getChatChannel().sendMessage(user, String.join(" ", args), false);
carbonChat.getLogger().info(LegacyComponentSerializer.legacySection().serialize(component)
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
});
}
@@ -6,7 +6,6 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -35,7 +34,7 @@ public class ChannelCommand extends BaseCommand {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
Component component = channel.sendMessage(user, String.join(" ", args), false);
carbonChat.getLogger().info(LegacyComponentSerializer.legacySection().serialize(component)
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
});
}
@@ -4,7 +4,6 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -71,13 +70,13 @@ public class BukkitChatListener implements Listener {
if (event.isAsynchronous()) {
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
event.setFormat(LegacyComponentSerializer.legacySection().serialize(component)
event.setFormat(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
} else {
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
carbonChat.getLogger().info(LegacyComponentSerializer.legacySection().serialize(component)
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
if (carbonChat.getConfig().getBoolean("show-tips")) {
@@ -1,8 +1,8 @@
package net.draycia.carbon.listeners;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.events.PreChatFormatEvent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -23,8 +23,7 @@ public class UserFormattingListener implements Listener {
suppressFormatting(event);
} else {
// Swap the &-style codes for minimessage-compatible strings
event.setMessage(MiniMessage.get().serialize(
LegacyComponentSerializer.legacyAmpersand().deserialize(event.getMessage())));
event.setMessage(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.getMessage())));
}
}
@@ -10,7 +10,6 @@ import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import java.util.UUID;
import java.util.function.Consumer;
@@ -130,7 +129,7 @@ public class MessageManager {
channel.sendComponent(user, component);
carbonChat.getLogger().info(LegacyComponentSerializer.legacySection().serialize(component)
carbonChat.getLogger().info(CarbonChat.LEGACY.serialize(component)
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
}
});
@@ -76,16 +76,15 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
}
@Override
public void setNickname(String nickname, boolean fromRemote) {
if (nickname != null) {
Component component = carbonChat.getAdventureManager().processMessage(nickname);
nickname = CarbonChat.LEGACY.serialize(component);
}
final String newNickname = nickname;
public void setNickname(String newNickname, boolean fromRemote) {
this.nickname = newNickname;
if (isOnline()) {
if (newNickname != null) {
Component component = carbonChat.getAdventureManager().processMessage(nickname);
newNickname = CarbonChat.LEGACY.serialize(component);
}
this.asPlayer().setDisplayName(newNickname);
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
@@ -98,7 +97,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
carbonChat.getMessageManager().sendMessage("nickname-reset", this.getUUID(), (byteArray) -> {});
} else {
carbonChat.getMessageManager().sendMessage("nickname", this.getUUID(), (byteArray) -> {
byteArray.writeUTF(newNickname);
byteArray.writeUTF(this.nickname);
});
}
}