mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Fix messaging services, misc fixes
This commit is contained in:
1 parent
b1f7c8f6c3
commit
6a49ae1767
9 files changed
+81
-10
No files matched your search
@@ -58,7 +58,6 @@ import net.draycia.carbon.common.events.ChannelRegisterEvent;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.registry.DefaultedRegistryGetter;
|
||||
@@ -318,7 +317,6 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
final var renderers = new ArrayList<KeyedRenderer>();
|
||||
renderers.add(keyedRenderer(Key.key("carbon", "default"), channel));
|
||||
|
||||
// TODO: add previewing when cloud/adventure support it
|
||||
final var chatEvent = new CarbonChatEvent(sender, Component.text(plainMessage), recipients, renderers, channel, false);
|
||||
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
||||
|
||||
@@ -338,10 +336,8 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
renderedMessage = renderer.render(sender, sender, renderedMessage, chatEvent.message());
|
||||
}
|
||||
|
||||
final Identity identity = sender.hasPermission("carbon.hideidentity") ? Identity.nil() : sender.identity();
|
||||
|
||||
for (final Audience recipient : chatEvent.recipients()) {
|
||||
recipient.sendMessage(identity, renderedMessage);
|
||||
recipient.sendMessage(renderedMessage);
|
||||
}
|
||||
|
||||
final @Nullable PacketService packetService = this.carbonChat.packetService();
|
||||
@@ -353,7 +349,6 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
packetService.queuePacket(new ChatMessagePacket(this.carbonChat.serverId(), sender.uuid(),
|
||||
configChatChannel.permission(), channel.key(), sender.username(), format,
|
||||
Map.of("username", sender.username(), "message", plainMessage)));
|
||||
packetService.flushQueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.draycia.carbon.common.listeners;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.channels.ConfigChatChannel;
|
||||
import net.draycia.carbon.common.messaging.CarbonChatPacketHandler;
|
||||
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import ninja.egg82.messenger.services.PacketService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class MessagingHandler {
|
||||
|
||||
@Inject
|
||||
public MessagingHandler(final CarbonChat carbonChat, final CarbonEventHandler events) {
|
||||
events.subscribe(CarbonChatEvent.class, 1000, false, event -> {
|
||||
final @Nullable PacketService packetService = carbonChat.packetService();
|
||||
|
||||
if (packetService != null) {
|
||||
if (event.chatChannel() instanceof ConfigChatChannel configChatChannel) {
|
||||
final @Nullable String format = configChatChannel.messageFormat(event.sender());
|
||||
|
||||
packetService.queuePacket(new ChatMessagePacket(carbonChat.serverId(), event.sender().uuid(),
|
||||
configChatChannel.permission(), event.chatChannel().key(), event.sender().username(), format,
|
||||
Map.of("username", event.sender().username(), "message", MiniMessage.miniMessage().serialize(event.message()))));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+4
-1
@@ -49,9 +49,12 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
||||
@Override
|
||||
protected boolean handlePacket(final @NotNull Packet packet) {
|
||||
if (!(packet instanceof ChatMessagePacket messagePacket)) {
|
||||
this.logger.info("Messaging packet received - Not a ChatMessagePacket.");
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logger.info("Messaging packet received");
|
||||
|
||||
final TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
|
||||
for (final var entry : messagePacket.placeholders().entrySet()) {
|
||||
@@ -64,7 +67,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
||||
for (final var recipient : CarbonChatProvider.carbonChat().server().players()) {
|
||||
if (recipient.hasPermission(messagePacket.channelPermission() + ".see")) {
|
||||
if (recipient.hasPermission("carbon.crossserver")) {
|
||||
recipient.sendMessage(Identity.identity(messagePacket.userId()), component);
|
||||
recipient.sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,12 +146,15 @@ public class MessagingManager {
|
||||
final String channelName = "carbon-data";
|
||||
|
||||
if (!messagingSettings.enabled()) {
|
||||
this.carbonChat.logger().info("Messaging services disabled in config. Cross-server will not work without this!");
|
||||
this.messagingService = EMPTY_MESSAGING_SERVICE;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (messagingSettings.brokerType()) {
|
||||
case RABBITMQ -> {
|
||||
this.carbonChat.logger().info("Initializing RabbitMQ Messaging services...");
|
||||
|
||||
final RabbitMQMessagingService.Builder builder = RabbitMQMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port(), messagingSettings.vhost())
|
||||
.timeout(5000);
|
||||
@@ -163,6 +166,8 @@ public class MessagingManager {
|
||||
this.messagingService = builder.build();
|
||||
}
|
||||
case NATS -> {
|
||||
this.carbonChat.logger().info("Initializing NATS Messaging services...");
|
||||
|
||||
final NATSMessagingService.Builder builder = NATSMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port())
|
||||
.life(5000);
|
||||
@@ -174,6 +179,8 @@ public class MessagingManager {
|
||||
this.messagingService = builder.build();
|
||||
}
|
||||
case REDIS -> {
|
||||
this.carbonChat.logger().info("Initializing Redis Messaging services...");
|
||||
|
||||
final RedisMessagingService.Builder builder = RedisMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port());
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.draycia.carbon.common.users.db;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.intellij.lang.annotations.Subst;
|
||||
import org.jdbi.v3.core.mapper.ColumnMapper;
|
||||
import org.jdbi.v3.core.statement.StatementContext;
|
||||
|
||||
public class KeyColumnMapper implements ColumnMapper<Key> {
|
||||
|
||||
@Override
|
||||
public Key map(final ResultSet rs, final int columnNumber, final StatementContext ctx) throws SQLException {
|
||||
final @Subst("key:value") String keyValue = rs.getString(columnNumber);
|
||||
|
||||
if (keyValue != null) {
|
||||
return Key.key(keyValue);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -38,6 +38,7 @@ import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.DBType;
|
||||
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
||||
import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
@@ -171,10 +172,11 @@ public final class MySQLUserManager extends DatabaseUserManager {
|
||||
flyway.migrate();
|
||||
|
||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
||||
.registerArrayType(UUID.class, "uuid")
|
||||
.registerArgument(new ComponentArgumentFactory())
|
||||
.registerArgument(new KeyArgumentFactory())
|
||||
.registerArgument(new MySQLUUIDArgumentFactory())
|
||||
.registerArrayType(UUID.class, "uuid")
|
||||
.registerColumnMapper(new KeyColumnMapper())
|
||||
.registerRowMapper(new MySQLPlayerRowMapper())
|
||||
.installPlugin(new SqlObjectPlugin());
|
||||
|
||||
|
||||
+2
@@ -37,6 +37,7 @@ import net.draycia.carbon.common.users.db.ComponentArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.DBType;
|
||||
import net.draycia.carbon.common.users.db.DatabaseUserManager;
|
||||
import net.draycia.carbon.common.users.db.KeyArgumentFactory;
|
||||
import net.draycia.carbon.common.users.db.KeyColumnMapper;
|
||||
import net.draycia.carbon.common.users.db.QueriesLocator;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import net.kyori.adventure.key.Key;
|
||||
@@ -175,6 +176,7 @@ public final class PostgreSQLUserManager extends DatabaseUserManager {
|
||||
final Jdbi jdbi = Jdbi.create(dataSource)
|
||||
.registerArgument(new ComponentArgumentFactory())
|
||||
.registerArgument(new KeyArgumentFactory())
|
||||
.registerColumnMapper(new KeyColumnMapper())
|
||||
.registerRowMapper(new PostgreSQLPlayerRowMapper())
|
||||
.installPlugin(new SqlObjectPlugin())
|
||||
.installPlugin(new PostgresPlugin());
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import net.draycia.carbon.common.listeners.DeafenHandler;
|
||||
import net.draycia.carbon.common.listeners.IgnoreHandler;
|
||||
import net.draycia.carbon.common.listeners.ItemLinkHandler;
|
||||
import net.draycia.carbon.common.listeners.MessagingHandler;
|
||||
import net.draycia.carbon.common.listeners.MuteHandler;
|
||||
import net.draycia.carbon.common.listeners.PingHandler;
|
||||
|
||||
@@ -34,7 +35,7 @@ public final class ListenerUtils {
|
||||
}
|
||||
|
||||
public static final List<Class<?>> LISTENER_CLASSES = List.of(DeafenHandler.class, IgnoreHandler.class,
|
||||
ItemLinkHandler.class, MuteHandler.class, PingHandler.class);
|
||||
ItemLinkHandler.class, MessagingHandler.class, MuteHandler.class, PingHandler.class);
|
||||
|
||||
public static void registerCommonListeners(final Injector injector) {
|
||||
for (final var listenerClass : LISTENER_CLASSES) {
|
||||
|
||||
Reference in new issue
Block a user