Use translatablecomponents

This commit is contained in:
Draycia committed 2020-09-06 01:40:47 -07:00
1 parent 5565871807
commit 5585452fdc
2 files changed
+13 -11

No files matched your search

@@ -8,6 +8,7 @@ import net.draycia.carbon.events.PreChatFormatEvent;
import net.draycia.carbon.storage.ChatUser;
import net.draycia.carbon.util.CarbonUtils;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.Component;
@@ -130,6 +131,7 @@ public class CarbonChatChannel extends ChatChannel {
"phase", Long.toString(System.currentTimeMillis() % 25),
"server", carbonChat.getConfig().getString("server-name", "Server"));
if (isUserSpying(user, target)) {
String prefix = processPlaceholders(user, carbonChat.getConfig().getString("spy-prefix"));
@@ -137,6 +139,8 @@ public class CarbonChatChannel extends ChatChannel {
targetColor.asHexString()).append(formatComponent);
}
TranslatableComponent translation = TranslatableComponent.of("<message>", formatComponent);
TextComponent messageComponent;
if (user.isOnline() && user.asPlayer().hasPermission("carbonchat.formatting")) {
@@ -150,9 +154,7 @@ public class CarbonChatChannel extends ChatChannel {
messageComponent = TextComponent.of(formatEvent.getMessage());
}
TextComponent processedComponent = (TextComponent)formatComponent.replaceFirstText(MESSAGE_PATTERN, (input) -> {
return messageComponent.toBuilder();
});
TranslatableComponent processedComponent = translation.args(messageComponent);
ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, processedComponent,
formatEvent.getMessage());
@@ -178,11 +180,10 @@ public class CarbonChatChannel extends ChatChannel {
TextComponent consoleMessage = TextComponent.of(consoleFormatEvent.getMessage());
TextComponent consoleComponent = (TextComponent)consoleFormat.replaceFirstText(MESSAGE_PATTERN, (input) -> {
return consoleMessage.toBuilder();
});
TranslatableComponent consoleTranslation = TranslatableComponent.of("<message>", consoleFormat)
.args(consoleMessage);
ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleComponent,
ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleTranslation,
consoleFormatEvent.getMessage());
Bukkit.getPluginManager().callEvent(consoleEvent);
@@ -2,6 +2,7 @@ package net.draycia.carbon.events;
import net.draycia.carbon.channels.ChatChannel;
import net.draycia.carbon.storage.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable;
@@ -18,10 +19,10 @@ public class ChatComponentEvent extends Event implements Cancellable {
private @NotNull final ChatUser sender;
private @Nullable final ChatUser target;
private ChatChannel chatChannel;
private TextComponent component;
private Component component;
private final String originalMessage;
public ChatComponentEvent(@NotNull ChatUser sender, @Nullable ChatUser target, ChatChannel chatChannel, TextComponent component, String originalMessage) {
public ChatComponentEvent(@NotNull ChatUser sender, @Nullable ChatUser target, ChatChannel chatChannel, Component component, String originalMessage) {
super(!Bukkit.isPrimaryThread());
this.sender = sender;
@@ -69,11 +70,11 @@ public class ChatComponentEvent extends Event implements Cancellable {
this.chatChannel = chatChannel;
}
public TextComponent getComponent() {
public Component getComponent() {
return component;
}
public void setComponent(TextComponent component) {
public void setComponent(Component component) {
this.component = component;
}