Hide Event lib from API

This commit is contained in:
Draycia committed 2023-07-08 15:55:17 -07:00
1 parent 43d2754018
commit 09054b7332
15 files changed
+213 -114

No files matched your search

-8
View File
@@ -20,14 +20,6 @@ dependencies {
compileOnlyApi(libs.checkerQual)
compileOnlyApi(libs.event)
compileOnlyApi(libs.kyoriRegistry) {
exclude("com.google.guava")
}
compileOnlyApi(libs.kyoriMoonshine)
compileOnlyApi(libs.kyoriMoonshineCore)
compileOnlyApi(libs.kyoriMoonshineStandard)
// Provided by Minecraft
compileOnlyApi(libs.gson)
compileOnlyApi(libs.log4jApi)
@@ -24,9 +24,6 @@ import java.util.UUID;
import net.draycia.carbon.api.channels.ChannelRegistry;
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;
import net.kyori.moonshine.message.IMessageRenderer;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -98,12 +95,4 @@ public interface CarbonChat {
*/
ChannelRegistry channelRegistry();
/**
* The message renderer, tailored for the current platform.
*
* @return the message renderer
* @since 2.0.0
*/
<T extends Audience> IMessageRenderer<T, String, Component, Component> messageRenderer();
}
@@ -0,0 +1,28 @@
/*
* 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.event;
public interface Cancellable {
boolean cancelled();
void cancelled(final boolean cancelled);
}
@@ -19,9 +19,9 @@
*/
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.Cancellable;
import net.draycia.carbon.api.event.CarbonEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.KeyedRenderer;
@@ -30,7 +30,6 @@ import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
@@ -39,44 +38,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public class CarbonChatEvent implements CarbonEvent, Cancellable {
private final List<KeyedRenderer> renderers;
private final CarbonPlayer sender;
private final Component originalMessage;
private final List<? extends Audience> recipients;
private final @MonotonicNonNull ChatChannel chatChannel;
private final @MonotonicNonNull SignedMessage signedMessage;
private Component message;
private boolean cancelled = false;
/**
* 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
* @param recipients the recipients of the message
* @param renderers the renderers of the message
* @param chatChannel the channel the message was sent in
* @param signedMessage the signature information for the message, if present
* @since 2.0.0
*/
public CarbonChatEvent(
final CarbonPlayer sender,
final Component originalMessage,
final List<? extends Audience> recipients,
final List<KeyedRenderer> renderers,
final @Nullable ChatChannel chatChannel,
final @Nullable SignedMessage signedMessage
) {
this.sender = sender;
this.originalMessage = originalMessage;
this.message = originalMessage;
this.recipients = recipients;
this.renderers = renderers;
this.chatChannel = chatChannel;
this.signedMessage = signedMessage;
}
public interface CarbonChatEvent extends CarbonEvent, Cancellable {
/**
* Get the renderers used to construct components for each of the recipients.
@@ -84,9 +46,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The per-recipient component renderers.
* @since 2.0.0
*/
public List<KeyedRenderer> renderers() {
return this.renderers;
}
List<KeyedRenderer> renderers();
/**
* If the message is being previewed by the player.
@@ -94,9 +54,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return if the message is being previewed
* @since 2.1.0
*/
public @MonotonicNonNull SignedMessage signedMessage() {
return this.signedMessage;
}
@MonotonicNonNull SignedMessage signedMessage();
/**
* Get the sender of the message.
@@ -104,9 +62,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The message sender.
* @since 2.0.0
*/
public CarbonPlayer sender() {
return this.sender;
}
CarbonPlayer sender();
/**
* Get the original message that was sent.
@@ -114,9 +70,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The original message.
* @since 2.0.0
*/
public Component originalMessage() {
return this.originalMessage;
}
Component originalMessage();
/**
* Get the chat message that will be sent.
@@ -124,9 +78,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The chat message.
* @since 2.0.0
*/
public Component message() {
return this.message;
}
Component message();
/**
* Set the chat message that will be sent.
@@ -134,9 +86,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @param message new message
* @since 2.0.0
*/
public void message(final Component message) {
this.message = message;
}
void message(final Component message);
/**
* The chat channel the message was sent in.
@@ -144,9 +94,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return the chat channel
* @since 2.0.0
*/
public @MonotonicNonNull ChatChannel chatChannel() {
return this.chatChannel;
}
@MonotonicNonNull ChatChannel chatChannel();
/**
* The recipients of the message.
@@ -156,18 +104,6 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* entries may be players, console, or other audience implementations
* @since 2.0.0
*/
public List<? extends Audience> recipients() {
return this.recipients;
}
@Override
public boolean cancelled() {
return this.cancelled;
}
@Override
public void cancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
List<? extends Audience> recipients();
}
+8
View File
@@ -44,6 +44,14 @@ dependencies {
api(libs.messengerRedis)
compileOnlyApi(libs.netty)
implementation(libs.event)
implementation(libs.kyoriRegistry) {
exclude("com.google.guava")
}
implementation(libs.kyoriMoonshine)
implementation(libs.kyoriMoonshineCore)
implementation(libs.kyoriMoonshineStandard)
compileOnlyApi(libs.jarRelocator)
compileOnlyApi(libs.caffeine)
@@ -180,7 +180,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
return this.channelRegistry;
}
@Override
@SuppressWarnings("unchecked")
public <T extends Audience> IMessageRenderer<T, String, Component, Component> messageRenderer() {
return (IMessageRenderer<T, String, Component, Component>) this.renderer;
@@ -19,6 +19,7 @@
*/
package net.draycia.carbon.common.channels;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import com.google.common.collect.BiMap;
@@ -39,7 +40,9 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Stream;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChannelRegistry;
@@ -53,6 +56,7 @@ 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.event.events.CarbonChatEventImpl;
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
import net.draycia.carbon.common.messages.CarbonMessages;
@@ -257,7 +261,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final ConfigurationLoader<?> loader = this.configFactory.configurationLoader(channelFile);
try {
final var loaded = updateNode(loader.load());
final ConfigurationNode loaded = updateNode(loader.load());
loader.save(loaded);
return MAPPER.load(loaded);
} catch (final ConfigurateException exception) {
@@ -273,10 +277,10 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final Path configFile = this.configChannelDir.resolve("global.conf");
final var loader = this.configFactory.configurationLoader(configFile);
final var node = loader.load();
final ConfigurationLoader<?> loader = this.configFactory.configurationLoader(configFile);
final ConfigurationNode node = loader.load();
final var configChannel = this.injector.getInstance(ConfigChatChannel.class);
final ConfigChatChannel configChannel = this.injector.getInstance(ConfigChatChannel.class);
node.set(ConfigChatChannel.class, configChannel);
loader.save(node);
@@ -310,9 +314,9 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final ChatChannel channel,
final String plainMessage
) {
final var recipients = channel.recipients(sender);
final List<Audience> recipients = channel.recipients(sender);
final var renderers = new ArrayList<KeyedRenderer>();
final List<KeyedRenderer> renderers = new ArrayList<>();
renderers.add(keyedRenderer(Key.key("carbon", "default"), channel));
final Component eventMessage;
@@ -323,7 +327,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
eventMessage = WrappedCarbonPlayer.parseMessageTags(plainMessage, sender::hasPermission);
}
final var chatEvent = new CarbonChatEvent(sender, eventMessage, recipients, renderers, channel, null);
final CarbonChatEvent chatEvent = new CarbonChatEventImpl(sender, eventMessage, recipients, renderers, channel, null);
this.eventHandler.emit(chatEvent);
if (chatEvent.cancelled()) {
@@ -333,10 +337,10 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final CarbonChatInternal<?> carbonChat = (CarbonChatInternal<?>) this.carbonChatProvider.get();
for (final Audience recipient : chatEvent.recipients()) {
final var recipientUUID = recipient.get(Identity.UUID);
final Optional<UUID> recipientUUID = recipient.get(Identity.UUID);
final Audience recipientViewer;
var renderedMessage = chatEvent.message();
Component renderedMessage = chatEvent.message();
if (recipientUUID.isPresent()) {
recipientViewer = carbonChat.userManager().user(recipient.get(Identity.UUID).orElseThrow()).join();
@@ -344,7 +348,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
recipientViewer = recipient;
}
for (final var renderer : chatEvent.renderers()) {
for (final KeyedRenderer renderer : chatEvent.renderers()) {
renderedMessage = renderer.render(sender, recipientViewer, renderedMessage, chatEvent.originalMessage());
}
recipient.sendMessage(renderedMessage);
@@ -366,7 +370,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final CommandManager<Commander> commandManager =
this.injector.getInstance(com.google.inject.Key.get(new TypeLiteral<CommandManager<Commander>>() {}));
var builder = commandManager.commandBuilder(channel.commandName(),
Command.Builder<Commander> builder = commandManager.commandBuilder(channel.commandName(),
channel.commandAliases(), commandManager.createDefaultCommandMeta())
.argument(StringArgument.<Commander>builder("message").greedy().asOptional().build());
@@ -383,9 +387,9 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
final Key channelKey = channel.key();
final var command = builder.senderType(PlayerCommander.class)
final Command<Commander> command = builder.senderType(PlayerCommander.class)
.handler(handler -> {
final var sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
final @Nullable ChatChannel chatChannel = this.get(channelKey);
if (sender.muted()) {
@@ -410,7 +414,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
commandManager.command(command);
final var channelCommand = commandManager.commandBuilder("channel", "ch")
final Command<Commander> channelCommand = commandManager.commandBuilder("channel", "ch")
.literal(channelKey.value())
.proxies(command)
.build();
@@ -31,6 +31,7 @@ import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.SourcedAudience;
import net.draycia.carbon.common.CarbonChatInternal;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
import net.draycia.carbon.common.channels.messages.ConfigChannelMessages;
import net.draycia.carbon.common.messages.SourcedMessageSender;
@@ -212,7 +213,7 @@ public final class ConfigChatChannel implements ChatChannel {
return Moonshine.<ConfigChannelMessages, SourcedAudience>builder(new TypeToken<ConfigChannelMessages>() {})
.receiverLocatorResolver(serverReceiverResolver, 0)
.sourced(this.messageSource)
.rendered(this.carbonChat.messageRenderer())
.rendered(((CarbonChatInternal<?>) this.carbonChat).messageRenderer())
.sent(carbonMessageSender)
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
@@ -0,0 +1,39 @@
/*
* 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 net.draycia.carbon.api.event.Cancellable;
public class CancellableImpl implements Cancellable, com.seiama.event.Cancellable {
private boolean cancelled = false;
@Override
public boolean cancelled() {
return this.cancelled;
}
@Override
public void cancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
}
@@ -56,7 +56,7 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
}
@Override
public <T extends CarbonEvent> CarbonEventSubscription subscribe(
public <T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
final Class<T> eventClass,
final CarbonEventSubscriber<T> subscriber
) {
@@ -0,0 +1,101 @@
/*
* 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.events;
import java.util.List;
import net.draycia.carbon.api.channels.ChatChannel;
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.event.CancellableImpl;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
* Event that's called when chat components are rendered for online players.
*
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public class CarbonChatEventImpl extends CancellableImpl implements CarbonChatEvent {
private final List<KeyedRenderer> renderers;
private final CarbonPlayer sender;
private final Component originalMessage;
private final List<? extends Audience> recipients;
private final @MonotonicNonNull ChatChannel chatChannel;
private final @MonotonicNonNull SignedMessage signedMessage;
private Component message;
public CarbonChatEventImpl(
final CarbonPlayer sender,
final Component originalMessage,
final List<? extends Audience> recipients,
final List<KeyedRenderer> renderers,
final @Nullable ChatChannel chatChannel,
final @Nullable SignedMessage signedMessage
) {
this.sender = sender;
this.originalMessage = originalMessage;
this.message = originalMessage;
this.recipients = recipients;
this.renderers = renderers;
this.chatChannel = chatChannel;
this.signedMessage = signedMessage;
}
public List<KeyedRenderer> renderers() {
return this.renderers;
}
public @MonotonicNonNull SignedMessage signedMessage() {
return this.signedMessage;
}
public CarbonPlayer sender() {
return this.sender;
}
public Component originalMessage() {
return this.originalMessage;
}
public Component message() {
return this.message;
}
public void message(final Component message) {
this.message = message;
}
public @MonotonicNonNull ChatChannel chatChannel() {
return this.chatChannel;
}
public List<? extends Audience> recipients() {
return this.recipients;
}
}
@@ -27,6 +27,7 @@ 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;
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
import net.draycia.carbon.common.event.events.CarbonEarlyChatEvent;
import net.draycia.carbon.common.messages.CarbonMessages;
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
@@ -82,7 +83,7 @@ public abstract class ChatListenerInternal {
final List<Audience> recipients = channel.recipients(sender);
final CarbonChatEvent chatEvent = new CarbonChatEvent(sender, message, recipients, renderers, channel, signedMessage);
final CarbonChatEvent chatEvent = new CarbonChatEventImpl(sender, message, recipients, renderers, channel, signedMessage);
this.carbonChat.eventHandler().emit(chatEvent);
@@ -26,6 +26,7 @@ import net.draycia.carbon.api.channels.ChatChannel;
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.event.events.CarbonChatEventImpl;
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
import net.draycia.carbon.common.messaging.packets.SaveCompletedPacket;
import net.draycia.carbon.common.users.UserManagerInternal;
@@ -76,7 +77,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
final List<KeyedRenderer> renderers = new ArrayList<>();
final List<Audience> recipients = channel.recipients(sender);
final CarbonChatEvent chatEvent = new CarbonChatEvent(sender, messagePacket.message(), recipients, renderers, channel, null);
final CarbonChatEvent chatEvent = new CarbonChatEventImpl(sender, messagePacket.message(), recipients, renderers, channel, null);
this.carbonChat.eventHandler().emit(chatEvent);
for (final Audience recipient : recipients) {
@@ -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.util;
package net.draycia.carbon.common.util;
import java.util.regex.Pattern;
import net.kyori.adventure.text.format.NamedTextColor;
@@ -22,7 +22,7 @@ package net.draycia.carbon.paper.hooks;
import com.google.inject.Inject;
import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.util.ColorUtils;
import net.draycia.carbon.common.util.ColorUtils;
import net.draycia.carbon.common.event.events.CarbonEarlyChatEvent;
import net.draycia.carbon.common.listeners.Listener;
import net.draycia.carbon.paper.CarbonChatPaper;