Replace event library, remove deprecated methods

And some cleanup
This commit is contained in:
Draycia committed 2023-06-06 21:04:41 -07:00
1 parent e87cff5330
commit 5668ad21a8
57 files changed
+278 -488

No files matched your search

@@ -27,10 +27,11 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.event.CarbonEventHandlerImpl;
import net.draycia.carbon.common.listeners.RadiusListener;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager;
@@ -80,7 +81,7 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
final ExecutionCoordinatorHolder commandExecutor,
final CarbonServer carbonServer,
final CarbonMessages carbonMessages,
final CarbonEventHandler eventHandler,
final CarbonEventHandlerImpl eventHandler,
final CarbonChannelRegistry channelRegistry,
final IMessageRenderer<Audience, String, Component, Component> renderer,
final Provider<MessagingManager> messagingManagerProvider
@@ -180,6 +181,7 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
}
@Override
@SuppressWarnings("unchecked")
public <T extends Audience> IMessageRenderer<T, String, Component, Component> messageRenderer() {
return (IMessageRenderer<T, String, Component, Component>) this.renderer;
}
@@ -29,11 +29,12 @@ import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.command.ArgumentFactory;
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.event.CarbonEventHandlerImpl;
import net.draycia.carbon.common.messages.CarbonMessageSender;
import net.draycia.carbon.common.messages.CarbonMessageSource;
import net.draycia.carbon.common.messages.CarbonMessages;
@@ -86,7 +87,7 @@ public final class CarbonCommonModule extends AbstractModule {
@Provides
@Singleton
public CarbonEventHandler eventHandler() {
return new CarbonEventHandler();
return new CarbonEventHandlerImpl();
}
@Provides
@@ -44,16 +44,16 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
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.DataDirectory;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.events.CarbonReloadEvent;
import net.draycia.carbon.common.events.ChannelRegisterEvent;
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
import net.kyori.adventure.audience.Audience;
@@ -75,7 +75,6 @@ import org.spongepowered.configurate.serialize.SerializationException;
import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
import static net.kyori.adventure.text.Component.empty;
@Singleton
@DefaultQualifier(NonNull.class)
@@ -246,7 +245,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
exception.printStackTrace();
}
this.carbonChat.eventHandler().emit(new ChannelRegisterEvent(this.channelMap.values(), this));
this.carbonChat.eventHandler().emit(new ChannelRegisterEventImpl(this.channelMap.values(), this));
}
public @Nullable ChatChannel loadChannel(final Path channelFile) {
@@ -312,21 +311,10 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
renderers.add(keyedRenderer(Key.key("carbon", "default"), channel));
final var chatEvent = new CarbonChatEvent(sender, Component.text(plainMessage), recipients, renderers, channel, null);
final var result = this.carbonChat.eventHandler().emit(chatEvent);
this.carbonChat.eventHandler().emit(chatEvent);
if (!result.wasSuccessful() || chatEvent.result().cancelled()) {
if (!result.exceptions().isEmpty()) {
for (final var entry : result.exceptions().entrySet()) {
this.carbonChat.logger().error("Exception in event handler: " + entry.getKey().getClass().getName());
entry.getValue().printStackTrace();
}
}
final var failure = chatEvent.result().reason();
if (!failure.equals(empty())) {
sender.sendMessage(failure);
}
if (chatEvent.cancelled()) {
return;
}
for (final Audience recipient : chatEvent.recipients()) {
@@ -36,7 +36,7 @@ public final class ConfigChannelSettings {
You only need to change the second part of the key. "global" by default.
The value is what's used in commands, this is probably what you want to change.
""")
private @Nullable Key key = Key.key("carbon", "basic");
private final @Nullable Key key = Key.key("carbon", "basic");
@Comment("""
The permission required to use the channel.
@@ -44,19 +44,19 @@ public final class ConfigChannelSettings {
To send messages you must have the permission carbon.channel.basic.speak
If you want to give both, grant carbon.channel.basic or carbon.channel.basic.*
""")
private @Nullable String permission = "carbon.channel.basic";
private final @Nullable String permission = "carbon.channel.basic";
@Setting("format")
@Comment("The chat formats for this channel.")
private @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
private final @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
@Comment("Messages will be sent in this channel if they start with this prefix.")
private @Nullable String quickPrefix = "";
private final @Nullable String quickPrefix = "";
private @Nullable Boolean shouldRegisterCommands = true;
private final @Nullable Boolean shouldRegisterCommands = true;
private @Nullable String commandName = null;
private final @Nullable String commandName = null;
private @Nullable List<String> commandAliases = Collections.emptyList();
private final @Nullable List<String> commandAliases = Collections.emptyList();
}
@@ -75,7 +75,7 @@ public final class ConfigChatChannel implements ChatChannel {
You only need to change the second part of the key. "global" by default.
The value is what's used in commands, this is probably what you want to change.
""")
private @Nullable Key key = Key.key("carbon", "global");
private final @Nullable Key key = Key.key("carbon", "global");
@Comment("""
The permission required to use the /channel <channelname> and /<channelname> commands.
@@ -84,22 +84,22 @@ public final class ConfigChatChannel implements ChatChannel {
To read messages you must have the permission carbon.channel.global.see
To send messages you must have the permission carbon.channel.global.speak
""")
private @Nullable String permission = "carbon.channel.global";
private final @Nullable String permission = "carbon.channel.global";
@Setting("format")
@Comment("The chat formats for this channel.")
private @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
private final @Nullable ConfigChannelMessageSource messageSource = new ConfigChannelMessageSource();
@Comment("Messages will be sent in this channel if they start with this prefix.")
private @Nullable String quickPrefix = "";
private final @Nullable String quickPrefix = "";
private @Nullable
private final @Nullable
Boolean shouldRegisterCommands = true;
private @Nullable
private final @Nullable
String commandName = null;
private @Nullable
private final @Nullable
List<String> commandAliases = Collections.emptyList();
private transient @Nullable ConfigChannelMessages carbonMessages = null;
@@ -109,15 +109,15 @@ public final class ConfigChatChannel implements ChatChannel {
A value of '0' requires that both players are in the same world.
On velocity, '0' requires that both players are in the same server.
""")
private int radius = -1;
private final int radius = -1;
@Comment("""
If true, players will be able to see if they're not sending messages to anyone
because they're out of range from the radius.
""")
private boolean emptyRadiusRecipientsMessage = true;
private final boolean emptyRadiusRecipientsMessage = true;
private transient @Nullable ConfigChannelMessages messageService = null;
private final transient @Nullable ConfigChannelMessages messageService = null;
@Override
public @Nullable String quickPrefix() {
@@ -57,7 +57,7 @@ public class ConfigChannelMessageSource implements IMessageSource<SourcedAudienc
discord="<message>"
}
""")
private Map<String, String> defaults = Map.of(
private final Map<String, String> defaults = Map.of(
"default_format", "<display_name>: <message>",
"console", "[<channel>] <username> - <uuid>: <message>",
"discord", "<message>"
@@ -69,7 +69,7 @@ public class ConfigChannelMessageSource implements IMessageSource<SourcedAudienc
You can safely delete this section if you don't want to use this feature.
Will fall back to the defaults section if no format was found for the player.
""")
private Map<Locale, Map<String, String>> locales = Map.of(
private final Map<Locale, Map<String, String>> locales = Map.of(
Locale.US, Map.of("default_format", "<display_name>: <message>")
);
@@ -26,7 +26,7 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -35,13 +35,13 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
public class ClearChatSettings {
@Comment("The message that will be sent to each player.")
private String message = "";
private final String message = "";
@Comment("The number of times the message will be sent to each player.")
private int iterations = 50;
private final int iterations = 50;
@Comment("The message to be sent after chat is cleared.")
private String broadcast = "<gold>Chat has been cleared by </gold><green><display_name><green><gold>.";
private final String broadcast = "<gold>Chat has been cleared by </gold><green><display_name><green><gold>.";
private @MonotonicNonNull Component messageComponent = null;
@@ -24,9 +24,9 @@ import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
import net.draycia.carbon.common.serialisation.gson.LocaleSerializerConfigurate;
import net.kyori.adventure.serializer.configurate4.ConfigurateComponentSerializer;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -34,13 +34,13 @@ public class DatabaseSettings {
MariaDB: jdbc:mariadb://host:3306/DB
PostgreSQL: jdbc:postgresql://host:5432/database
""")
private String url = "jdbc:mysql://localhost:3306/carbon";
private final String url = "jdbc:mysql://localhost:3306/carbon";
@Comment("The connection username.")
private String username = "username";
private final String username = "username";
@Comment("The connection password.")
private String password = "password";
private final String password = "password";
public String url() {
return this.url;
@@ -30,28 +30,28 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
@ConfigSerializable
public class MessagingSettings {
private boolean enabled = false;
private final boolean enabled = false;
@Comment("Options: RABBITMQ, NATS, REDIS")
private MessagingManager.@NonNull BrokerType brokerType = MessagingManager.BrokerType.NONE;
private final MessagingManager.@NonNull BrokerType brokerType = MessagingManager.BrokerType.NONE;
@Comment("")
private String url = "127.0.0.1";
private final String url = "127.0.0.1";
@Comment("")
private int port = 5672; // RabbitMQ 5672, NATS 4222, Redis 6379
private final int port = 5672; // RabbitMQ 5672, NATS 4222, Redis 6379
@Comment("RabbitMQ VHost")
private String vhost = "/"; // RabbitMQ only
private final String vhost = "/"; // RabbitMQ only
@Comment("NATS credentials file")
private String credentialsFile = ""; // NATS only
private final String credentialsFile = ""; // NATS only
@Comment("RabbitMQ username")
private String username = "username"; // RabbitMQ only
private final String username = "username"; // RabbitMQ only
@Comment("RabbitMQ and Redis password")
private String password = "password"; // RabbitMQ and Redis only
private final String password = "password"; // RabbitMQ and Redis only
public boolean enabled() {
return this.enabled;
@@ -30,15 +30,15 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
public class PingSettings {
@Comment("The color your name will be when another player mentions you.")
private TextColor highlightTextColor = NamedTextColor.YELLOW;
private final TextColor highlightTextColor = NamedTextColor.YELLOW;
private String prefix = "@";
private final String prefix = "@";
private boolean playSound = false;
private Key name = Key.key("block.anvil.use");
private Sound.Source source = Sound.Source.MASTER;
private float volume = 1.0f; // 0.0 -> infinity
private float pitch = 1.0f; // 0.0 -> 2.0
private final boolean playSound = false;
private final Key name = Key.key("block.anvil.use");
private final Sound.Source source = Sound.Source.MASTER;
private final float volume = 1.0f; // 0.0 -> infinity
private final float pitch = 1.0f; // 0.0 -> 2.0
public TextColor highlightTextColor() {
return this.highlightTextColor;
@@ -35,22 +35,22 @@ import org.spongepowered.configurate.objectmapping.meta.Comment;
public class PrimaryConfig {
@Comment("The default locale for plugin messages.")
private Locale defaultLocale = Locale.US;
private final Locale defaultLocale = Locale.US;
@Comment("""
The default channel that new players will be in when they join.
If the channel is not found or the player cannot use the channel, they will speak in basic non-channel chat.
""")
private Key defaultChannel = Key.key("carbon", "global");
private final Key defaultChannel = Key.key("carbon", "global");
@Comment("The service that will be used to store and load player information.")
private StorageType storageType = StorageType.JSON;
private final StorageType storageType = StorageType.JSON;
@Comment("")
private DatabaseSettings databaseSettings = new DatabaseSettings();
private final DatabaseSettings databaseSettings = new DatabaseSettings();
@Comment("Various ClearChat command settings.")
private ClearChatSettings clearChatSettings = new ClearChatSettings();
private final ClearChatSettings clearChatSettings = new ClearChatSettings();
@Comment("""
Plugin-wide custom placeholders.
@@ -59,26 +59,26 @@ public class PrimaryConfig {
Make sure to close your tags so they do not bleed into other formats.
Only a single pass is done so custom placeholders will not work within each other.
""")
private Map<String, String> customPlaceholders = Map.of();
private final Map<String, String> customPlaceholders = Map.of();
@Comment("The suggestions shown when using the TAB key in chat.")
private List<String> customChatSuggestions = List.of();
private final List<String> customChatSuggestions = List.of();
@Comment("The placeholders replaced in chat messages, this WILL work with chat previews.")
private Map<String, String> chatPlaceholders = Map.of();
private final Map<String, String> chatPlaceholders = Map.of();
@Comment("Various settings related to pinging players in channels.")
private PingSettings pingSettings = new PingSettings();
private final PingSettings pingSettings = new PingSettings();
@Comment("Various sound settings for messages.")
private @Nullable Sound messageSound = Sound.sound(
private final @Nullable Sound messageSound = Sound.sound(
Key.key("entity.experience_orb.pickup"),
Sound.Source.MASTER,
1.0F,
1.0F
);
private MessagingSettings messagingSettings = new MessagingSettings();
private final MessagingSettings messagingSettings = new MessagingSettings();
public Locale defaultLocale() {
return this.defaultLocale;
@@ -0,0 +1,72 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.event;
import com.seiama.event.EventSubscriber;
import com.seiama.event.EventSubscription;
import com.seiama.event.bus.EventBus;
import com.seiama.event.bus.SimpleEventBus;
import com.seiama.event.registry.EventRegistry;
import com.seiama.event.registry.SimpleEventRegistry;
import java.util.function.Consumer;
import net.draycia.carbon.api.event.CarbonEvent;
import net.draycia.carbon.api.event.CarbonEventHandler;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* Event handler for listening to and emitting carbon events.
*
* @since 1.0.0
*/
@DefaultQualifier(NonNull.class)
public final class CarbonEventHandlerImpl implements CarbonEventHandler {
private final EventRegistry<CarbonEvent> eventRegistry = new SimpleEventRegistry<>(CarbonEvent.class);
private final EventBus<CarbonEvent> eventBus = new SimpleEventBus<>(this.eventRegistry, this::onException);
private <E> void onException(final EventSubscription<E> subscription, final E event, final Throwable throwable) {
throwable.printStackTrace();
}
@Override
public <T extends CarbonEvent> EventSubscription<T> subscribe(
final Class<T> eventClass,
final EventSubscriber<T> subscriber
) {
return this.eventRegistry.subscribe(eventClass, subscriber);
}
@Override
public <T extends CarbonEvent> EventSubscription<T> subscribe(
final Class<T> eventClass,
final int priority,
final boolean acceptsCancelled,
final Consumer<T> consumer
) {
return this.eventRegistry.subscribe(eventClass, new EventSubscriberImpl<>(consumer, priority, acceptsCancelled));
}
@Override
public void emit(final CarbonEvent event) {
this.eventBus.post(event);
}
}
@@ -0,0 +1,34 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.event;
import com.seiama.event.EventSubscriber;
import java.util.function.Consumer;
import net.draycia.carbon.api.event.CarbonEvent;
import org.checkerframework.checker.nullness.qual.NonNull;
public record EventSubscriberImpl<T extends CarbonEvent>(Consumer<T> consumer, int postOrder, boolean acceptsCancelled) implements EventSubscriber<T> {
@Override
public void on(final @NonNull T event) {
this.consumer.accept(event);
}
}
@@ -17,9 +17,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.events;
package net.draycia.carbon.common.event.events;
import net.draycia.carbon.api.events.CarbonEvent;
import net.draycia.carbon.api.event.CarbonEvent;
public class CarbonReloadEvent implements CarbonEvent {
@@ -17,11 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.common.events;
package net.draycia.carbon.common.event.events;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.CarbonChannelRegisterEvent;
import net.draycia.carbon.api.events.CarbonEvent;
import net.draycia.carbon.api.event.CarbonEvent;
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -33,7 +33,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
* @since 2.1.0
*/
@DefaultQualifier(NonNull.class)
public class ChannelRegisterEvent implements CarbonChannelRegisterEvent {
public class ChannelRegisterEventImpl implements CarbonChannelRegisterEvent {
private final Iterable<ChatChannel> channels;
private final CarbonChannelRegistry registry;
@@ -44,7 +44,7 @@ public class ChannelRegisterEvent implements CarbonChannelRegisterEvent {
* @param channels the channels that were registered
* @since 2.1.0
*/
public ChannelRegisterEvent(final Iterable<ChatChannel> channels, final CarbonChannelRegistry registry) {
public ChannelRegisterEventImpl(final Iterable<ChatChannel> channels, final CarbonChannelRegistry registry) {
this.channels = channels;
this.registry = registry;
}
@@ -20,8 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -20,8 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -20,8 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.util.InventorySlot;
import net.kyori.adventure.text.TextReplacementConfig;
@@ -20,8 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
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.messages.CarbonMessages;
@@ -22,8 +22,8 @@ package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import java.util.Optional;
import java.util.regex.Pattern;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
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.config.ConfigFactory;
@@ -20,8 +20,8 @@
package net.draycia.carbon.common.listeners;
import com.google.inject.Inject;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.messages.CarbonMessages;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -19,10 +19,8 @@
*/
package net.draycia.carbon.common.messages;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.SourcedAudience;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.moonshine.message.IMessageSender;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -34,13 +32,9 @@ public class CarbonMessageSender implements IMessageSender<Audience, Component>
@Override
public void send(final Audience receiver, final Component renderedMessage) {
if (receiver instanceof SourcedAudience sourcedAudience) {
if (sourcedAudience.sender() instanceof CarbonPlayer sender && !sender.hasPermission("carbon.hideidentity")) {
sourcedAudience.recipient().sendMessage(Identity.identity(sender.uuid()), renderedMessage);
} else {
sourcedAudience.recipient().sendMessage(Identity.nil(), renderedMessage);
}
sourcedAudience.recipient().sendMessage(renderedMessage);
} else {
receiver.sendMessage(Identity.nil(), renderedMessage);
receiver.sendMessage(renderedMessage);
}
}
@@ -47,12 +47,12 @@ import java.util.Set;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.translation.Translator;
import net.kyori.moonshine.message.IMessageSource;
@@ -19,9 +19,7 @@
*/
package net.draycia.carbon.common.messages;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.SourcedAudience;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import net.kyori.moonshine.message.IMessageSender;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -32,11 +30,7 @@ public class SourcedMessageSender implements IMessageSender<SourcedAudience, Com
@Override
public void send(final SourcedAudience receiver, final Component renderedMessage) {
if (receiver.sender() instanceof CarbonPlayer sender) {
receiver.recipient().sendMessage(Identity.identity(sender.uuid()), renderedMessage);
} else {
receiver.recipient().sendMessage(Identity.nil(), renderedMessage);
}
receiver.recipient().sendMessage(renderedMessage);
}
}
@@ -31,7 +31,7 @@ import java.util.concurrent.TimeoutException;
import java.util.function.Consumer;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.events.CarbonShutdownEvent;
import net.draycia.carbon.api.event.events.CarbonShutdownEvent;
import net.draycia.carbon.common.CarbonChatInternal;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.config.MessagingSettings;
@@ -22,7 +22,6 @@ package net.draycia.carbon.common.util;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -40,7 +39,7 @@ public final class ChannelUtils {
for (final CarbonPlayer recipient : CarbonChatProvider.carbonChat().server().players()) {
if (channel.hearingPermitted(recipient).permitted()) {
recipient.sendMessage(originalMessage, MessageType.CHAT);
recipient.sendMessage(originalMessage);
}
}
}