mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Fix custom placeholders not being used on Velocity and Paper
This commit is contained in:
1 parent
9ab930afce
commit
e4adb0752a
2 files changed
+32
-6
No files matched your search
@@ -22,12 +22,14 @@ package net.draycia.carbon.paper.listeners;
|
||||
import com.google.inject.Inject;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.channels.ConfigChatChannel;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
|
||||
import net.draycia.carbon.paper.CarbonChatPaper;
|
||||
@@ -54,12 +56,19 @@ public final class PaperChatListener implements Listener {
|
||||
private final CarbonChatPaper carbonChat;
|
||||
private final ChannelRegistry registry;
|
||||
private final CarbonMessages carbonMessages;
|
||||
final ConfigFactory configFactory;
|
||||
|
||||
@Inject
|
||||
public PaperChatListener(final CarbonChat carbonChat, final ChannelRegistry registry, final CarbonMessages carbonMessages) {
|
||||
public PaperChatListener(
|
||||
final CarbonChat carbonChat,
|
||||
final ChannelRegistry registry,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ConfigFactory configFactory
|
||||
) {
|
||||
this.carbonChat = (CarbonChatPaper) carbonChat;
|
||||
this.registry = registry;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.configFactory = configFactory;
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
@@ -71,8 +80,14 @@ public final class PaperChatListener implements Listener {
|
||||
}
|
||||
|
||||
var channel = requireNonNullElse(sender.selectedChannel(), this.registry.defaultValue());
|
||||
final var messageContents = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||
Component eventMessage = ConfigChatChannel.parseMessageTags(sender, messageContents);
|
||||
|
||||
String content = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||
|
||||
for (final Map.Entry<String, String> placeholder : this.configFactory.primaryConfig().chatPlaceholders().entrySet()) {
|
||||
content = content.replace(placeholder.getKey(), placeholder.getValue());
|
||||
}
|
||||
|
||||
Component eventMessage = ConfigChatChannel.parseMessageTags(sender, content);
|
||||
|
||||
if (sender.hasPermission("carbon.chatlinks")) {
|
||||
eventMessage = eventMessage.replaceText(URL_REPLACEMENT_CONFIG.get());
|
||||
|
||||
+14
-3
@@ -27,6 +27,7 @@ import com.velocitypowered.api.network.ProtocolVersion;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
@@ -34,6 +35,7 @@ import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.velocity.CarbonChatVelocity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -57,6 +59,7 @@ public final class VelocityChatListener {
|
||||
private final AtomicInteger timesWarned = new AtomicInteger(0);
|
||||
private final PluginManager pluginManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
final ConfigFactory configFactory;
|
||||
|
||||
@Inject
|
||||
private VelocityChatListener(
|
||||
@@ -65,7 +68,8 @@ public final class VelocityChatListener {
|
||||
final UserManager<?> userManager,
|
||||
final Logger logger,
|
||||
final PluginManager pluginManager,
|
||||
final CarbonMessages carbonMessages
|
||||
final CarbonMessages carbonMessages,
|
||||
final ConfigFactory configFactory
|
||||
) {
|
||||
this.carbonChat = (CarbonChatVelocity) carbonChat;
|
||||
this.registry = registry;
|
||||
@@ -73,6 +77,7 @@ public final class VelocityChatListener {
|
||||
this.logger = logger;
|
||||
this.pluginManager = pluginManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.configFactory = configFactory;
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LATE)
|
||||
@@ -106,8 +111,14 @@ public final class VelocityChatListener {
|
||||
|
||||
final CarbonPlayer sender = this.userManager.user(event.getPlayer().getUniqueId()).join();
|
||||
var channel = requireNonNullElse(sender.selectedChannel(), this.registry.defaultValue());
|
||||
final var originalMessage = event.getResult().getMessage().orElse(event.getMessage());
|
||||
Component eventMessage = text(originalMessage);
|
||||
|
||||
String content = event.getResult().getMessage().orElse(event.getMessage());
|
||||
|
||||
for (final Map.Entry<String, String> placeholder : this.configFactory.primaryConfig().chatPlaceholders().entrySet()) {
|
||||
content = content.replace(placeholder.getKey(), placeholder.getValue());
|
||||
}
|
||||
|
||||
Component eventMessage = text(content);
|
||||
|
||||
if (sender.hasPermission("carbon.chatlinks")) {
|
||||
eventMessage = eventMessage.replaceText(URL_REPLACEMENT_CONFIG.get());
|
||||
|
||||
Reference in new issue
Block a user