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

+1 -1
View File
@@ -18,7 +18,7 @@ dependencies {
compileOnlyApi(libs.checkerQual)
api(libs.kyoriEventApi)
api(libs.event)
api(libs.kyoriRegistry) {
exclude("com.google.guava")
}
@@ -22,7 +22,7 @@ package net.draycia.carbon.api;
import java.nio.file.Path;
import java.util.UUID;
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.api.users.UserManager;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
@@ -21,7 +21,6 @@ package net.draycia.carbon.api;
import java.util.List;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.kyori.adventure.audience.Audience;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -50,14 +49,4 @@ public interface CarbonServer extends Audience {
*/
List<? extends CarbonPlayer> players();
/**
* Manager used to load/obtain and save {@link CarbonPlayer CarbonPlayers}.
*
* @deprecated Use {@link CarbonChat#userManager} (internal code: inject the UserManager)
* @return the user manager
* @since 2.1.0
*/
@Deprecated(forRemoval = true)
UserManager<? extends CarbonPlayer> userManager();
}
@@ -17,7 +17,7 @@
* 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.api.events;
package net.draycia.carbon.api.event;
/**
* Interface to represent that an event belongs to carbon.
@@ -0,0 +1,52 @@
package net.draycia.carbon.api.event;
import com.seiama.event.EventSubscriber;
import com.seiama.event.EventSubscription;
import java.util.function.Consumer;
public interface CarbonEventHandler {
/**
* Registers a subscriber for the given event class.
*
* @param eventClass the class to listen for
* @param subscriber the subscriber that's executed when the event is emitted
* @param <T> the class to listen for
* @return the subscription, so that it may be unregistered
* @since 2.0.0
*/
<T extends CarbonEvent> EventSubscription<T> subscribe(
final Class<T> eventClass,
final EventSubscriber<T> subscriber
);
/**
* Registers a subscriber for the given event class.<br>
* Includes extra values to control when the consumer is executed.
*
* @param eventClass the class to listen for
* @param priority the priority of the consumer
* @param acceptsCancelled if the consumer should be executed if the event is cancelled early
* @param consumer the consumer that's executed when the event is emitted
* @param <T> the class to listen for
* @return the subscription, so that it may be unregistered
* @since 2.0.0
*/
<T extends CarbonEvent> EventSubscription<T> subscribe(
final Class<T> eventClass,
final int priority,
final boolean acceptsCancelled,
final Consumer<T> consumer
);
/**
* Emits the supplied event.<br>
* Events are modified in place, so care should be taken to keep a reference to
* the event while it's being emitted.
*
* @param event the event to be emitted
* @since 2.0.0
*/
void emit(final CarbonEvent event);
}
@@ -17,9 +17,10 @@
* 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.api.events;
package net.draycia.carbon.api.event.events;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEvent;
import net.kyori.adventure.key.Key;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -17,10 +17,12 @@
* 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.api.events;
package net.draycia.carbon.api.event.events;
import com.seiama.event.Cancellable;
import java.util.List;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.CarbonEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.KeyedRenderer;
import net.kyori.adventure.audience.Audience;
@@ -31,15 +33,13 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
import static net.kyori.adventure.text.Component.empty;
/**
* {@link ResultedCarbonEvent} that's called when chat components are rendered for online players.
* Event that's called when chat components are rendered for online players.
*
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Result> {
public class CarbonChatEvent implements CarbonEvent, Cancellable {
private final List<KeyedRenderer> renderers;
private final CarbonPlayer sender;
@@ -48,10 +48,10 @@ public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Resu
private final @MonotonicNonNull ChatChannel chatChannel;
private final @MonotonicNonNull SignedMessage signedMessage;
private Component message;
private Result result = Result.ALLOWED;
private boolean cancelled = false;
/**
* {@link ResultedCarbonEvent} that's called when players send messages in chat.
* Event that's called when players send messages in chat.
*
* @param sender the sender of the message
* @param originalMessage the original message that was sent
@@ -161,45 +161,13 @@ public class CarbonChatEvent implements ResultedCarbonEvent<CarbonChatEvent.Resu
}
@Override
public Result result() {
return this.result;
public boolean cancelled() {
return this.cancelled;
}
@Override
public void result(final Result result) {
this.result = result;
}
/**
* The result of this event.
*
* @since 2.0.0
*/
public record Result(boolean cancelled, Component reason) implements ResultedCarbonEvent.Result {
private static final Result ALLOWED = new Result(false, empty());
/**
* Returns a Result that denotes the event was allowed and not cancelled.
*
* @return an allowed result
* @since 2.0.0
*/
public static Result allowed() {
return ALLOWED;
}
/**
* Returns a Result that denotes the event was denied and cancelled.
*
* @param reason the reason the event was denied
* @return a denied result
* @since 2.0.0
*/
public static Result denied(final Component reason) {
return new Result(true, reason);
}
public void cancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
}
@@ -17,10 +17,12 @@
* 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.api.events;
package net.draycia.carbon.api.event.events;
// TODO: emit event on server shutdown
import net.draycia.carbon.api.event.CarbonEvent;
/**
* An event that's called when the server shuts down.
*
@@ -1,96 +0,0 @@
/*
* 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.api.events;
import java.util.function.Consumer;
import net.kyori.event.EventBus;
import net.kyori.event.EventSubscriber;
import net.kyori.event.EventSubscription;
import net.kyori.event.PostResult;
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 CarbonEventHandler {
private final EventBus<CarbonEvent> eventBus = EventBus.create(CarbonEvent.class, (type, event, subscriber) -> {
if (event instanceof ResultedCarbonEvent<@NonNull ?> rce) {
return !rce.result().cancelled();
}
return true;
});
/**
* Registers a subscriber for the given event class.
*
* @param eventClass the class to listen for
* @param subscriber the subscriber that's executed when the event is emitted
* @param <T> the class to listen for
* @return the subscription, so that it may be unregistered
* @since 2.0.0
*/
public <T extends CarbonEvent> EventSubscription subscribe(
final Class<T> eventClass,
final EventSubscriber<T> subscriber
) {
return this.eventBus.subscribe(eventClass, subscriber);
}
/**
* Registers a subscriber for the given event class.<br>
* Includes extra values to control when the consumer is executed.
*
* @param eventClass the class to listen for
* @param priority the priority of the consumer
* @param acceptsCancelled if the consumer should be executed if the event is cancelled early
* @param consumer the consumer that's executed when the event is emitted
* @param <T> the class to listen for
* @return the subscription, so that it may be unregistered
* @since 2.0.0
*/
public <T extends CarbonEvent> EventSubscription subscribe(
final Class<T> eventClass,
final int priority,
final boolean acceptsCancelled,
final Consumer<T> consumer
) {
return this.eventBus.subscribe(eventClass, new EventSubscriberImpl<>(consumer, priority, acceptsCancelled));
}
/**
* Emits the supplied event and returns its result.<br>
* Events are modified in place, so care should be taken to keep a reference to
* the event while it's being emitted.
*
* @param event the event to be emitted
* @return the result
* @since 2.0.0
*/
public PostResult emit(final CarbonEvent event) {
return this.eventBus.post(event);
}
}
@@ -1,76 +0,0 @@
/*
* 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.api.events;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* Represents a {@link CarbonEvent} that has a result.
*
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public interface ResultedCarbonEvent<R extends ResultedCarbonEvent.Result> extends CarbonEvent {
/**
* The result of the event.
*
* @return the event's result
* @since 2.0.0
*/
R result();
/**
* Sets the result of the event.
*
* @param result the result
* @since 2.0.0
*/
void result(final R result);
/**
* Represents the result of the event.
*
* @since 2.0.0
*/
interface Result {
/**
* If the event is cancelled to continue execution.<br>
*
* @return if listeners will continue executing
* @since 2.0.0
*/
boolean cancelled();
/**
* The reason of the result.<br>
* Typically empty unless allowed is false.
*
* @return the reason of the result
* @since 2.0.0
*/
Component reason();
}
}
@@ -1,37 +0,0 @@
/*
* 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.api.users;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.jetbrains.annotations.ApiStatus;
/**
* The result of a player data operation.
*
* @param player the {@link CarbonPlayer}, or null if unsuccessful
* @param reason the reason of the result, typically empty unless {@link #player} is null
* @since 2.0.0
*/
@Deprecated(forRemoval = true)
@ApiStatus.Internal
public record ComponentPlayerResult<C extends CarbonPlayer>(@MonotonicNonNull C player, Component reason) {
}
@@ -21,8 +21,6 @@ package net.draycia.carbon.api.users;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.util.ComponentMessageThrowable;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -34,21 +32,6 @@ import org.checkerframework.framework.qual.DefaultQualifier;
@DefaultQualifier(NonNull.class)
public interface UserManager<C extends CarbonPlayer> {
/**
* Loads and returns a {@link CarbonPlayer} with the given {@link UUID}.
*
* @deprecated use {@link #user(UUID)} instead
* @param uuid the player's uuid
* @return the result
* @since 2.0.0
*/
@Deprecated(forRemoval = true)
default CompletableFuture<ComponentPlayerResult<C>> carbonPlayer(final UUID uuid) {
return this.user(uuid)
.thenApply(user -> new ComponentPlayerResult<>(user, Component.empty()))
.exceptionally(thr -> new ComponentPlayerResult<>(null, ComponentMessageThrowable.getOrConvertMessage(thr)));
}
/**
* Gets the {@link CarbonPlayer} for the provided player {@link UUID}, whether they are online or not.
*
@@ -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);
}
}
@@ -17,13 +17,14 @@
* 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.api.events;
package net.draycia.carbon.common.event;
import com.seiama.event.EventSubscriber;
import java.util.function.Consumer;
import net.kyori.event.EventSubscriber;
import net.draycia.carbon.api.event.CarbonEvent;
import org.checkerframework.checker.nullness.qual.NonNull;
record EventSubscriberImpl<T extends CarbonEvent>(Consumer<T> consumer, int postOrder, boolean acceptsCancelled) implements EventSubscriber<T> {
public record EventSubscriberImpl<T extends CarbonEvent>(Consumer<T> consumer, int postOrder, boolean acceptsCancelled) implements EventSubscriber<T> {
@Override
public void on(final @NonNull T 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);
}
}
}
@@ -26,12 +26,12 @@ import com.google.inject.Singleton;
import java.nio.file.Path;
import java.util.concurrent.ScheduledExecutorService;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.common.CarbonChatInternal;
import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PeriodicTasks;
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.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.ProfileCache;
@@ -73,7 +73,7 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
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,
@@ -96,12 +96,14 @@ public final class CarbonChatFabricModule extends AbstractModule {
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<Audience, String, Component, Component> messageRenderer(final Injector injector) {
return injector.getInstance(FabricMessageRenderer.class);
}
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<SourcedAudience, String, Component, Component> sourcedRenderer(final Injector injector) {
return injector.getInstance(FabricMessageRenderer.class);
}
@@ -25,8 +25,6 @@ import java.util.List;
import java.util.Objects;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
@@ -65,9 +63,4 @@ public final class CarbonServerFabric implements CarbonServer, ForwardingAudienc
.toList();
}
@Override
public UserManager<CarbonPlayerFabric> userManager() {
return this.userManager;
}
}
@@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.Map;
import java.util.regex.Pattern;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonChatEvent;
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;
@@ -48,7 +48,6 @@ import org.jetbrains.annotations.Nullable;
import static java.util.Objects.requireNonNullElse;
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.empty;
public class FabricChatHandler implements ServerMessageEvents.AllowChatMessage {
@@ -115,22 +114,9 @@ public class FabricChatHandler implements ServerMessageEvents.AllowChatMessage {
final var recipients = channel.recipients(sender);
final var chatEvent = new CarbonChatEvent(sender, message, recipients, renderers, channel, null);
final var result = 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);
}
this.carbonChat.eventHandler().emit(chatEvent);
if (chatEvent.cancelled()) {
return false;
}
@@ -50,7 +50,7 @@ abstract class RegistryDataLoaderMixin {
),
locals = LocalCapture.CAPTURE_FAILEXCEPTION
)
@SuppressWarnings("unchecked")
@SuppressWarnings("unchecked,rawtypes")
private static void carbon$injectMessageTypes(
final ResourceManager resourceManager,
final RegistryAccess registryAccess,
+5 -4
View File
@@ -27,7 +27,7 @@ versions:
paperApi: 1.19.4-R0.1-SNAPSHOT
paperTrail: 0.0.1-SNAPSHOT
foliaApi: 1.19.4-R0.1-SNAPSHOT
kyoriEventApi: 5.0.0-SNAPSHOT
event: 1.0.0-SNAPSHOT
kyoriRegistry: 1.0.0-SNAPSHOT
kyoriMoonshine: 2.0.4
log4j: 2.17.2
@@ -101,10 +101,11 @@ dependencies:
group: org.apache.logging.log4j
name: log4j-api
kyoriEventApi:
group: net.kyori
event:
group: com.seiama
name: event-api
version: { ref: kyoriEventApi }
version: { ref: event }
kyoriRegistry:
group: net.kyori
name: registry
@@ -28,12 +28,12 @@ import java.nio.file.Path;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.common.CarbonChatInternal;
import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PeriodicTasks;
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.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.ProfileCache;
@@ -71,7 +71,7 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
final Injector injector,
final JavaPlugin plugin,
final CarbonMessages carbonMessages,
final CarbonEventHandler eventHandler,
final CarbonEventHandlerImpl eventHandler,
final CarbonChannelRegistry channelRegistry,
final Provider<MessagingManager> messagingManager,
final CarbonServer carbonServer,
@@ -71,6 +71,7 @@ public final class CarbonChatPaperModule extends AbstractModule {
@Provides
@Singleton
@SuppressWarnings("unused")
public CommandManager<Commander> commandManager(final UserManager<?> userManager, final CarbonMessages messages, final ExecutionCoordinatorHolder executionCoordinatorHolder) {
final PaperCommandManager<Commander> commandManager;
@@ -107,12 +108,14 @@ public final class CarbonChatPaperModule extends AbstractModule {
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<Audience, String, Component, Component> messageRenderer(final Injector injector) {
return injector.getInstance(PaperMessageRenderer.class);
}
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<SourcedAudience, String, Component, Component> sourcedRenderer(final Injector injector) {
return injector.getInstance(PaperMessageRenderer.class);
}
@@ -25,8 +25,6 @@ import java.util.List;
import java.util.Objects;
import net.draycia.carbon.api.CarbonServer;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import org.bukkit.Server;
@@ -64,11 +62,6 @@ public final class CarbonServerPaper implements CarbonServer, ForwardingAudience
.toList();
}
@Override
public UserManager<CarbonPlayerPaper> userManager() {
return this.userManager;
}
public static boolean isFolia() {
try {
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
@@ -27,7 +27,7 @@ import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.inject.Inject;
import java.util.UUID;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings;
@@ -31,7 +31,7 @@ import github.scarsz.discordsrv.util.PluginUtil;
import java.time.Duration;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.CarbonChatEvent;
import net.draycia.carbon.api.event.events.CarbonChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.channels.ConfigChatChannel;
import net.draycia.carbon.common.util.ChannelUtils;
@@ -95,7 +95,7 @@ public class DSRVChatHook implements ChatHook {
final String message = PlainTextComponentSerializer.plainText().serialize(eventMessage);
if (player != null) {
DiscordSRV.getPlugin().processChatMessage(player, message, chatChannel.commandName(), event.result().cancelled());
DiscordSRV.getPlugin().processChatMessage(player, message, chatChannel.commandName(), event.cancelled());
}
});
@@ -24,7 +24,7 @@ import io.papermc.paper.event.player.AsyncChatEvent;
import java.util.ArrayList;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonChatEvent;
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;
@@ -47,7 +47,6 @@ import static java.util.Objects.requireNonNullElse;
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
import static net.draycia.carbon.common.util.Strings.URL_REPLACEMENT_CONFIG;
import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.empty;
@DefaultQualifier(NonNull.class)
public final class PaperChatListener implements Listener {
@@ -97,21 +96,11 @@ public final class PaperChatListener implements Listener {
final var recipients = channel.recipients(sender);
final var chatEvent = new CarbonChatEvent(sender, eventMessage, recipients, renderers, channel, event.signedMessage());
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()) {
event.setCancelled(true);
return;
}
try {
@@ -23,7 +23,7 @@ import com.google.inject.Inject;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
import net.draycia.carbon.common.config.ConfigFactory;
import net.draycia.carbon.common.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.CarbonReloadEvent;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.lifecycle.RefreshGameEvent;
@@ -30,11 +30,11 @@ import java.nio.file.Path;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.events.CarbonEventHandler;
import net.draycia.carbon.common.CarbonChatInternal;
import net.draycia.carbon.common.PeriodicTasks;
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.messages.CarbonMessages;
import net.draycia.carbon.common.messaging.MessagingManager;
import net.draycia.carbon.common.users.ProfileCache;
@@ -74,7 +74,7 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
final VelocityUserManager userManager,
final CarbonServerVelocity carbonServer,
final CarbonMessages carbonMessages,
final CarbonEventHandler eventHandler,
final CarbonEventHandlerImpl eventHandler,
final CarbonChannelRegistry channelRegistry,
final Provider<MessagingManager> messagingManager
) {
@@ -97,12 +97,14 @@ public final class CarbonChatVelocityModule extends AbstractModule {
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<Audience, String, Component, Component> messageRenderer(final Injector injector) {
return injector.getInstance(VelocityMessageRenderer.class);
}
@Provides
@Singleton
@SuppressWarnings("unchecked,unused")
public IMessageRenderer<SourcedAudience, String, Component, Component> sourcedRenderer(final Injector injector) {
return injector.getInstance(VelocityMessageRenderer.class);
}
@@ -63,9 +63,4 @@ public final class CarbonServerVelocity implements CarbonServer, ForwardingAudie
.toList();
}
@Override
public UserManager<? extends CarbonPlayer> userManager() {
return this.userManager;
}
}
@@ -29,7 +29,7 @@ import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicInteger;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.events.CarbonChatEvent;
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;
@@ -44,7 +44,6 @@ import static java.util.Objects.requireNonNullElse;
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
import static net.draycia.carbon.common.util.Strings.URL_REPLACEMENT_CONFIG;
import static net.kyori.adventure.key.Key.key;
import static net.kyori.adventure.text.Component.empty;
import static net.kyori.adventure.text.Component.text;
@DefaultQualifier(NonNull.class)
@@ -132,21 +131,11 @@ public final class VelocityChatListener {
renderers.add(keyedRenderer(key("carbon", "default"), channel));
final var chatEvent = new CarbonChatEvent(sender, eventMessage, 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()) {
event.setResult(PlayerChatEvent.ChatResult.denied());
return;
}
for (final var recipient : chatEvent.recipients()) {