mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
API cleanup & other various refactoring
This commit is contained in:
58 files changed
+340
-614
No files matched your search
@@ -7,7 +7,6 @@ description = "API for interfacing with the CarbonChat Minecraft mod/plugin"
|
|||||||
dependencies {
|
dependencies {
|
||||||
// Doesn't add any dependencies, only version constraints
|
// Doesn't add any dependencies, only version constraints
|
||||||
api(platform(libs.adventureBom))
|
api(platform(libs.adventureBom))
|
||||||
api(platform(libs.log4jBom))
|
|
||||||
|
|
||||||
// Provided by platform
|
// Provided by platform
|
||||||
compileOnlyApi(libs.adventureApi)
|
compileOnlyApi(libs.adventureApi)
|
||||||
@@ -22,5 +21,4 @@ dependencies {
|
|||||||
|
|
||||||
// Provided by Minecraft
|
// Provided by Minecraft
|
||||||
compileOnlyApi(libs.gson)
|
compileOnlyApi(libs.gson)
|
||||||
compileOnlyApi(libs.log4jApi)
|
|
||||||
}
|
}
|
||||||
@@ -19,17 +19,16 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api;
|
package net.draycia.carbon.api;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||||
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main plugin interface.
|
* The {@link CarbonChat} interface is the gateway to interacting with the majority of the CarbonChat API.
|
||||||
*
|
*
|
||||||
* <p>Instances may be obtained through {@link CarbonChatProvider#carbonChat()} once Carbon is loaded.</p>
|
* <p>Instances may be obtained through {@link CarbonChatProvider#carbonChat()} once Carbon is loaded.</p>
|
||||||
* <p>On most platforms, you should use the provided load order mechanism to ensure your addon loads after
|
* <p>On most platforms, you should use the provided load order mechanism to ensure your addon loads after
|
||||||
@@ -51,25 +50,8 @@ public interface CarbonChat {
|
|||||||
UUID serverId();
|
UUID serverId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The plugin's logger.<br>
|
* The {@link CarbonEventHandler event handler}, used for listening to
|
||||||
* All messages will be logged through this.
|
* and emitting {@link CarbonEvent events}.
|
||||||
*
|
|
||||||
* @return the plugin's logger
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
Logger logger();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The plugin's data storage directory.<br>
|
|
||||||
* This is where configs and misc files will be stored.
|
|
||||||
*
|
|
||||||
* @return the plugin's data directory
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
Path dataDirectory();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The event handler, used for listening to and emitting events.
|
|
||||||
*
|
*
|
||||||
* @return the event handler
|
* @return the event handler
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
|
|||||||
@@ -22,9 +22,10 @@ package net.draycia.carbon.api;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static accessor for the {@link CarbonChat} class.
|
* Static accessor for the {@link CarbonChat} instance.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@@ -43,6 +44,7 @@ public final class CarbonChatProvider {
|
|||||||
* @param carbonChat the carbon implementation
|
* @param carbonChat the carbon implementation
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@ApiStatus.Internal
|
||||||
public static void register(final CarbonChat carbonChat) {
|
public static void register(final CarbonChat carbonChat) {
|
||||||
CarbonChatProvider.instance = carbonChat;
|
CarbonChatProvider.instance = carbonChat;
|
||||||
}
|
}
|
||||||
@@ -55,7 +57,7 @@ public final class CarbonChatProvider {
|
|||||||
*/
|
*/
|
||||||
public static CarbonChat carbonChat() {
|
public static CarbonChat carbonChat() {
|
||||||
if (CarbonChatProvider.instance == null) {
|
if (CarbonChatProvider.instance == null) {
|
||||||
throw new IllegalStateException("CarbonChat not initialized!"); // LuckPerms design go brrrr
|
throw new IllegalStateException("CarbonChat not initialized!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return CarbonChatProvider.instance;
|
return CarbonChatProvider.instance;
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public interface ChannelRegistry {
|
|||||||
* @param channel the channel to register
|
* @param channel the channel to register
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
void register(final ChatChannel channel);
|
void register(ChatChannel channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the channel with the matching key.
|
* Gets the channel with the matching key.
|
||||||
@@ -49,7 +49,7 @@ public interface ChannelRegistry {
|
|||||||
* @return the channel
|
* @return the channel
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@Nullable ChatChannel channel(final Key key);
|
@Nullable ChatChannel channel(Key key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the default key.
|
* Gets the default key.
|
||||||
@@ -82,7 +82,7 @@ public interface ChannelRegistry {
|
|||||||
* @return the channel, or the default one
|
* @return the channel, or the default one
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
ChatChannel keyOrDefault(final Key key);
|
ChatChannel keyOrDefault(Key key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The provided action will be executed immediately for all currently registered
|
* The provided action will be executed immediately for all currently registered
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
* @return if the player may speak
|
* @return if the player may speak
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer);
|
ChannelPermissionResult speechPermitted(CarbonPlayer carbonPlayer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the player may receive messages from this channel.
|
* Checks if the player may receive messages from this channel.
|
||||||
@@ -59,7 +59,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
* @return if the player may receive messages
|
* @return if the player may receive messages
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
ChannelPermissionResult hearingPermitted(final CarbonPlayer player);
|
ChannelPermissionResult hearingPermitted(CarbonPlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all recipients that will receive messages from the sender.
|
* Returns a list of all recipients that will receive messages from the sender.
|
||||||
@@ -68,7 +68,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
* @return the recipients
|
* @return the recipients
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
List<Audience> recipients(final CarbonPlayer sender);
|
List<Audience> recipients(CarbonPlayer sender);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the given recipients and removes entries that may not see messages in this channel.
|
* Filters the given recipients and removes entries that may not see messages in this channel.
|
||||||
@@ -78,7 +78,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
|||||||
* @return the recipients that may receive messages
|
* @return the recipients that may receive messages
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients);
|
Set<CarbonPlayer> filterRecipients(CarbonPlayer sender, Set<CarbonPlayer> recipients);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Messages will be sent in this channel if they start with this prefix.
|
* Messages will be sent in this channel if they start with this prefix.
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ public interface Cancellable {
|
|||||||
/**
|
/**
|
||||||
* Sets the cancelled state.
|
* Sets the cancelled state.
|
||||||
*
|
*
|
||||||
* @param cancelled sets the cancelled state
|
* @param cancelled new cancelled state
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
void cancelled(final boolean cancelled);
|
void cancelled(boolean cancelled);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
package net.draycia.carbon.api.event;
|
package net.draycia.carbon.api.event;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to represent that an event belongs to carbon.
|
* Marker interface for events.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Carbon event dispatcher.
|
* The {@link CarbonEventHandler} is responsible for managing {@link CarbonEventSubscription event subscriptions}
|
||||||
|
* and emitting {@link CarbonEvent events}.
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@@ -40,8 +41,8 @@ public interface CarbonEventHandler {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
||||||
final Class<T> eventClass,
|
Class<T> eventClass,
|
||||||
final CarbonEventSubscriber<T> subscriber
|
CarbonEventSubscriber<T> subscriber
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,21 +58,22 @@ public interface CarbonEventHandler {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
||||||
final Class<T> eventClass,
|
Class<T> eventClass,
|
||||||
final int order,
|
int order,
|
||||||
final boolean acceptsCancelled,
|
boolean acceptsCancelled,
|
||||||
final CarbonEventSubscriber<T> subscriber
|
CarbonEventSubscriber<T> subscriber
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emits the supplied event.<br>
|
* Emits the supplied event.
|
||||||
* Events are modified in place, so care should be taken to keep a reference to
|
*
|
||||||
* the event while it's being emitted.
|
* <p>Events are modified in place, meaning you must keep a reference to the event
|
||||||
|
* yourself if you wish to inspect it's state after this call.</p>
|
||||||
*
|
*
|
||||||
* @param event the event to be emitted
|
* @param event the event to be emitted
|
||||||
* @param <T> the class to emit
|
* @param <T> the class to emit
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
<T extends CarbonEvent> void emit(final T event);
|
<T extends CarbonEvent> void emit(T event);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,7 +21,6 @@ package net.draycia.carbon.api.event;
|
|||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An EventSubscriber.
|
* An EventSubscriber.
|
||||||
@@ -39,6 +38,6 @@ public interface CarbonEventSubscriber<T extends CarbonEvent> {
|
|||||||
* @throws Throwable if an exception is thrown
|
* @throws Throwable if an exception is thrown
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
void on(final @NotNull T event) throws Throwable;
|
void on(T event) throws Throwable;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,9 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An EventSubscription.
|
* A subscription to a specific event type.
|
||||||
*
|
*
|
||||||
* @param <T> CarbonEvent implementations
|
* @param <T> event type
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
@@ -40,11 +40,20 @@ public interface CarbonEventSubscription<T extends CarbonEvent> {
|
|||||||
Class<T> event();
|
Class<T> event();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the subscriber.
|
* Gets the {@link CarbonEventSubscriber subscriber}.
|
||||||
*
|
*
|
||||||
* @return the subscriber
|
* @return the subscriber
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
CarbonEventSubscriber<T> subscriber();
|
CarbonEventSubscriber<T> subscriber();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes this subscription.
|
||||||
|
*
|
||||||
|
* <p>The subscriber held by this subscription will no longer receive events.</p>
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
void dispose();
|
||||||
|
|
||||||
}
|
}
|
||||||
+3
-2
@@ -31,8 +31,9 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
* {@link CarbonEvent} that's called after new channels are registered.
|
* {@link CarbonEvent} that's called after new channels are registered.
|
||||||
*
|
*
|
||||||
* <p>Note that some invocations of this event may be too early for
|
* <p>Note that some invocations of this event may be too early for
|
||||||
* API consumers to be notified. Prefer using {@link ChannelRegistry#allKeys(Consumer)}
|
* API consumers to be notified. {@link ChannelRegistry#allKeys(Consumer)}
|
||||||
* when knowledge of all registered channels is needed.</p>
|
* is provided as a helper for when knowledge of all registered channels
|
||||||
|
* is needed.</p>
|
||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -41,9 +41,10 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
public interface CarbonChatEvent extends CarbonEvent, Cancellable {
|
public interface CarbonChatEvent extends CarbonEvent, Cancellable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the renderers used to construct components for each of the recipients.
|
* Get the renderers used to construct components for each of the recipients. The returned list
|
||||||
|
* is mutable.
|
||||||
*
|
*
|
||||||
* @return The per-recipient component renderers.
|
* @return renderers
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
List<KeyedRenderer> renderers();
|
List<KeyedRenderer> renderers();
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public interface CarbonPrivateChatEvent extends CarbonEvent, Cancellable {
|
|||||||
* @throws NullPointerException if message is null
|
* @throws NullPointerException if message is null
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
void message(final Component message);
|
void message(Component message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message that will be sent.
|
* The message that will be sent.
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface CarbonPlayer extends Audience, Identified {
|
public interface CarbonPlayer extends Audience, Identified {
|
||||||
|
|
||||||
CarbonPlayer EMPTY = new EmptyCarbonPlayer();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the appropriate {@link Component} to represent the player's name.
|
* Returns the appropriate {@link Component} to represent the player's name.
|
||||||
*
|
*
|
||||||
@@ -66,7 +64,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return the distance from the other player, or -1
|
* @return the distance from the other player, or -1
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
double distanceSquaredFrom(final CarbonPlayer other);
|
double distanceSquaredFrom(CarbonPlayer other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if both players are in the same world or server.
|
* Returns if both players are in the same world or server.
|
||||||
@@ -75,7 +73,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return if both players are in the same world/server
|
* @return if both players are in the same world/server
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
boolean sameWorldAs(final CarbonPlayer other);
|
boolean sameWorldAs(CarbonPlayer other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player's username.
|
* Gets the player's username.
|
||||||
@@ -112,7 +110,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
/**
|
/**
|
||||||
* Sets the player's display name.
|
* Sets the player's display name.
|
||||||
*
|
*
|
||||||
* <p>Setting {@code null} is equivalent to setting the display name to the username.</p>
|
* <p>Setting {@code null} will remove the current display name.</p>
|
||||||
* <p>Won't have any visible effect when Carbon's nickname management is disabled.</p>
|
* <p>Won't have any visible effect when Carbon's nickname management is disabled.</p>
|
||||||
*
|
*
|
||||||
* @param displayName the new display name
|
* @param displayName the new display name
|
||||||
@@ -120,7 +118,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @see #hasCustomDisplayName()
|
* @see #hasCustomDisplayName()
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void displayName(final @Nullable Component displayName);
|
void displayName(@Nullable Component displayName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player's UUID, often used for identification purposes.
|
* The player's UUID, often used for identification purposes.
|
||||||
@@ -137,7 +135,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return the chat component for the item in the slot, or null if the slot is empty
|
* @return the chat component for the item in the slot, or null if the slot is empty
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Nullable Component createItemHoverComponent(final InventorySlot slot);
|
@Nullable Component createItemHoverComponent(InventorySlot slot);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The player's locale.
|
* The player's locale.
|
||||||
@@ -161,7 +159,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param chatChannel the channel
|
* @param chatChannel the channel
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void selectedChannel(final @Nullable ChatChannel chatChannel);
|
void selectedChannel(@Nullable ChatChannel chatChannel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines which channel the message should go to, and removes any channel prefixes from the message.
|
* Determines which channel the message should go to, and removes any channel prefixes from the message.
|
||||||
@@ -170,7 +168,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return the channel and message
|
* @return the channel and message
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
ChannelMessage channelForMessage(final Component message);
|
ChannelMessage channelForMessage(Component message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message and which channel it should be sent in.
|
* A message and which channel it should be sent in.
|
||||||
@@ -188,7 +186,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return if the player has the permission
|
* @return if the player has the permission
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
boolean hasPermission(final String permission);
|
boolean hasPermission(String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the player's primary group.
|
* Returns the player's primary group.
|
||||||
@@ -229,7 +227,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return if this player is ignoring the sender
|
* @return if this player is ignoring the sender
|
||||||
* @since 2.0.5
|
* @since 2.0.5
|
||||||
*/
|
*/
|
||||||
boolean ignoring(final UUID player);
|
boolean ignoring(UUID player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the other player is being ignored by this player.
|
* Checks if the other player is being ignored by this player.
|
||||||
@@ -238,7 +236,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return if this player is ignoring the sender
|
* @return if this player is ignoring the sender
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
boolean ignoring(final CarbonPlayer player);
|
boolean ignoring(CarbonPlayer player);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the player to and removes the player from the ignore list.
|
* Adds the player to and removes the player from the ignore list.
|
||||||
@@ -247,7 +245,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param nowIgnoring if the player should be ignored
|
* @param nowIgnoring if the player should be ignored
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void ignoring(final UUID player, final boolean nowIgnoring);
|
void ignoring(UUID player, boolean nowIgnoring);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the player to and removes the player from the ignore list.
|
* Adds the player to and removes the player from the ignore list.
|
||||||
@@ -256,7 +254,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param nowIgnoring if the player should be ignored
|
* @param nowIgnoring if the player should be ignored
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void ignoring(final CarbonPlayer player, boolean nowIgnoring);
|
void ignoring(CarbonPlayer player, boolean nowIgnoring);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the player is deafened and unable to read messages.
|
* Returns if the player is deafened and unable to read messages.
|
||||||
@@ -271,7 +269,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void deafened(final boolean deafened);
|
void deafened(boolean deafened);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the player is spying on messages and able to read muted/private messages.
|
* Returns if the player is spying on messages and able to read muted/private messages.
|
||||||
@@ -286,7 +284,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void spying(final boolean spying);
|
void spying(boolean spying);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the message as the player.
|
* Sends the message as the player.
|
||||||
@@ -294,7 +292,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param message the message to be sent
|
* @param message the message to be sent
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void sendMessageAsPlayer(final String message);
|
void sendMessageAsPlayer(String message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the player is online.
|
* Returns whether the player is online.
|
||||||
@@ -318,7 +316,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param uuid the uuid of the reply target
|
* @param uuid the uuid of the reply target
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void whisperReplyTarget(final @Nullable UUID uuid);
|
void whisperReplyTarget(@Nullable UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last player this player has whispered.
|
* The last player this player has whispered.
|
||||||
@@ -334,7 +332,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param uuid the uuid of the whisper target
|
* @param uuid the uuid of the whisper target
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void lastWhisperTarget(final @Nullable UUID uuid);
|
void lastWhisperTarget(@Nullable UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this player is vanished in another supported plugin.
|
* If this player is vanished in another supported plugin.
|
||||||
@@ -353,7 +351,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @return if this player is aware of the other player
|
* @return if this player is aware of the other player
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
boolean awareOf(final CarbonPlayer other);
|
boolean awareOf(CarbonPlayer other);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A list of all the channels the player has left
|
* A list of all the channels the player has left
|
||||||
@@ -373,7 +371,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param channel the channel to join.
|
* @param channel the channel to join.
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
void joinChannel(final ChatChannel channel);
|
void joinChannel(ChatChannel channel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Leave a channel for this player.
|
* Leave a channel for this player.
|
||||||
@@ -381,6 +379,6 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* @param channel the channel to leave.
|
* @param channel the channel to leave.
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
void leaveChannel(final ChatChannel channel);
|
void leaveChannel(ChatChannel channel);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,223 +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 java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.UUID;
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
|
||||||
import net.draycia.carbon.api.util.InventorySlot;
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
|
||||||
import net.kyori.adventure.key.Key;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
|
||||||
class EmptyCarbonPlayer implements CarbonPlayer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double distanceSquaredFrom(final CarbonPlayer other) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean sameWorldAs(final CarbonPlayer other) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String username() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasCustomDisplayName() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Component displayName() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayName(final @Nullable Component displayName) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UUID uuid() {
|
|
||||||
return new UUID(0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Component createItemHoverComponent(final InventorySlot slot) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable Locale locale() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable ChatChannel selectedChannel() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void selectedChannel(final @Nullable ChatChannel chatChannel) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelMessage channelForMessage(final Component message) {
|
|
||||||
return new ChannelMessage(message, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPermission(final String permission) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String primaryGroup() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> groups() {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean muted() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void muted(final boolean muted) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ignoring(final UUID player) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ignoring(final CarbonPlayer sender) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ignoring(final UUID player, final boolean nowIgnoring) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void ignoring(final CarbonPlayer player, final boolean nowIgnoring) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean deafened() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deafened(final boolean deafened) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean spying() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void spying(final boolean spying) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void sendMessageAsPlayer(final String message) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean online() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable UUID whisperReplyTarget() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void whisperReplyTarget(final @Nullable UUID uuid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @Nullable UUID lastWhisperTarget() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void lastWhisperTarget(final @Nullable UUID uuid) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean vanished() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean awareOf(final CarbonPlayer other) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<Key> leftChannels() {
|
|
||||||
return List.of();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void joinChannel(final ChatChannel channel) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void leaveChannel(final ChatChannel channel) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Identity identity() {
|
|
||||||
return Identity.nil();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -24,7 +24,6 @@ import net.kyori.adventure.audience.Audience;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderer used to construct chat components on a per-player basis.
|
* Renderer used to construct chat components on a per-player basis.
|
||||||
@@ -47,10 +46,9 @@ public interface ChatComponentRenderer {
|
|||||||
* or empty if the recipient should not receive the message
|
* or empty if the recipient should not receive the message
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NotNull
|
Component render(CarbonPlayer sender,
|
||||||
Component render(final CarbonPlayer sender,
|
Audience recipient,
|
||||||
final Audience recipient,
|
Component message,
|
||||||
final Component message,
|
Component originalMessage);
|
||||||
final Component originalMessage);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -39,11 +39,7 @@ public final class InventorySlot {
|
|||||||
return new InventorySlot(placeholders);
|
return new InventorySlot(placeholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> placeholders;
|
private final List<String> placeholders;
|
||||||
|
|
||||||
private InventorySlot() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private InventorySlot(final String... placeholders) {
|
private InventorySlot(final String... placeholders) {
|
||||||
this.placeholders = List.of(placeholders);
|
this.placeholders = List.of(placeholders);
|
||||||
|
|||||||
@@ -19,17 +19,13 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.util;
|
package net.draycia.carbon.api.util;
|
||||||
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.key.Keyed;
|
import net.kyori.adventure.key.Keyed;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A chat renderer that's identifiable by key.
|
* A {@link ChatComponentRenderer chat renderer} that's identifiable by key.
|
||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@@ -45,26 +41,7 @@ public interface KeyedRenderer extends Keyed, ChatComponentRenderer {
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
static KeyedRenderer keyedRenderer(final Key key, final ChatComponentRenderer renderer) {
|
static KeyedRenderer keyedRenderer(final Key key, final ChatComponentRenderer renderer) {
|
||||||
return new Impl(key, renderer);
|
return new KeyedRendererImpl(key, renderer);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of the keyed renderer.
|
|
||||||
*
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
record Impl(Key key, ChatComponentRenderer renderer) implements KeyedRenderer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull Component render(
|
|
||||||
final CarbonPlayer sender,
|
|
||||||
final Audience recipient,
|
|
||||||
final Component message,
|
|
||||||
final Component originalMessage
|
|
||||||
) {
|
|
||||||
return this.renderer.render(sender, recipient, message, originalMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+14
-22
@@ -19,32 +19,24 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.util;
|
package net.draycia.carbon.api.util;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.audience.ForwardingAudience;
|
import net.kyori.adventure.key.Key;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
@DefaultQualifier(NonNull.class)
|
||||||
* An audience, where messages are sent from another Audience.
|
record KeyedRendererImpl(Key key, ChatComponentRenderer renderer) implements KeyedRenderer {
|
||||||
*
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public record SourcedAudience(Audience sender, Audience recipient) implements ForwardingAudience.Single {
|
|
||||||
|
|
||||||
public static final SourcedAudience EMPTY = new SourcedAudience(Audience.empty(), Audience.empty());
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An empty {@link SourcedAudience}, with an empty sender and recipient.
|
|
||||||
*
|
|
||||||
* @return an empty sourced audience
|
|
||||||
* @since 2.0.0
|
|
||||||
*/
|
|
||||||
public static SourcedAudience empty() {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Audience audience() {
|
public Component render(
|
||||||
return this.recipient;
|
final CarbonPlayer sender,
|
||||||
|
final Audience recipient,
|
||||||
|
final Component message,
|
||||||
|
final Component originalMessage
|
||||||
|
) {
|
||||||
|
return this.renderer.render(sender, recipient, message, originalMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.exclude
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("carbon.base-conventions")
|
id("carbon.base-conventions")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api(projects.carbonchatApi)
|
api(projects.carbonchatApi)
|
||||||
|
compileOnlyApi(platform(libs.log4jBom))
|
||||||
|
compileOnlyApi(libs.log4jApi)
|
||||||
|
|
||||||
// Configs
|
// Configs
|
||||||
api(libs.configurateHocon)
|
api(libs.configurateHocon)
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.inject.Injector;
|
|||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
@@ -44,9 +43,6 @@ import net.draycia.carbon.common.users.UserManagerInternal;
|
|||||||
import net.draycia.carbon.common.util.CloudUtils;
|
import net.draycia.carbon.common.util.CloudUtils;
|
||||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||||
import net.draycia.carbon.common.util.PlayerUtils;
|
import net.draycia.carbon.common.util.PlayerUtils;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import ninja.egg82.messenger.services.PacketService;
|
import ninja.egg82.messenger.services.PacketService;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -59,7 +55,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
private final UUID serverId;
|
private final UUID serverId;
|
||||||
private final Injector injector;
|
private final Injector injector;
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Path dataDirectory;
|
|
||||||
private final ScheduledExecutorService periodicTasks;
|
private final ScheduledExecutorService periodicTasks;
|
||||||
private final ProfileCache profileCache;
|
private final ProfileCache profileCache;
|
||||||
private final ProfileResolver profileResolver;
|
private final ProfileResolver profileResolver;
|
||||||
@@ -69,13 +64,11 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
private final CarbonMessages carbonMessages;
|
private final CarbonMessages carbonMessages;
|
||||||
private final CarbonEventHandler eventHandler;
|
private final CarbonEventHandler eventHandler;
|
||||||
private final CarbonChannelRegistry channelRegistry;
|
private final CarbonChannelRegistry channelRegistry;
|
||||||
private final IMessageRenderer<Audience, String, Component, Component> renderer;
|
|
||||||
private final Provider<MessagingManager> messagingManager;
|
private final Provider<MessagingManager> messagingManager;
|
||||||
|
|
||||||
protected CarbonChatInternal(
|
protected CarbonChatInternal(
|
||||||
final Injector injector,
|
final Injector injector,
|
||||||
final Logger logger,
|
final Logger logger,
|
||||||
final Path dataDirectory,
|
|
||||||
final ScheduledExecutorService periodicTasks,
|
final ScheduledExecutorService periodicTasks,
|
||||||
final ProfileCache profileCache,
|
final ProfileCache profileCache,
|
||||||
final ProfileResolver profileResolver,
|
final ProfileResolver profileResolver,
|
||||||
@@ -85,13 +78,11 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
final CarbonMessages carbonMessages,
|
final CarbonMessages carbonMessages,
|
||||||
final CarbonEventHandler eventHandler,
|
final CarbonEventHandler eventHandler,
|
||||||
final CarbonChannelRegistry channelRegistry,
|
final CarbonChannelRegistry channelRegistry,
|
||||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
|
||||||
final Provider<MessagingManager> messagingManagerProvider
|
final Provider<MessagingManager> messagingManagerProvider
|
||||||
) {
|
) {
|
||||||
this.serverId = UUID.randomUUID();
|
this.serverId = UUID.randomUUID();
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.dataDirectory = dataDirectory;
|
|
||||||
this.periodicTasks = periodicTasks;
|
this.periodicTasks = periodicTasks;
|
||||||
this.profileCache = profileCache;
|
this.profileCache = profileCache;
|
||||||
this.profileResolver = profileResolver;
|
this.profileResolver = profileResolver;
|
||||||
@@ -101,7 +92,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
this.carbonMessages = carbonMessages;
|
this.carbonMessages = carbonMessages;
|
||||||
this.eventHandler = eventHandler;
|
this.eventHandler = eventHandler;
|
||||||
this.channelRegistry = channelRegistry;
|
this.channelRegistry = channelRegistry;
|
||||||
this.renderer = renderer;
|
|
||||||
this.messagingManager = messagingManagerProvider;
|
this.messagingManager = messagingManagerProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,12 +145,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
return this.serverId;
|
return this.serverId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Path dataDirectory() {
|
|
||||||
return this.dataDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Logger logger() {
|
public Logger logger() {
|
||||||
return this.logger;
|
return this.logger;
|
||||||
}
|
}
|
||||||
@@ -185,11 +169,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
|||||||
return this.channelRegistry;
|
return this.channelRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T extends Audience> IMessageRenderer<T, String, Component, Component> messageRenderer() {
|
|
||||||
return (IMessageRenderer<T, String, Component, Component>) this.renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable PacketService packetService() {
|
public @Nullable PacketService packetService() {
|
||||||
return this.messagingManager.get().packetService();
|
return this.messagingManager.get().packetService();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import net.draycia.carbon.common.listeners.MessagePacketHandler;
|
|||||||
import net.draycia.carbon.common.listeners.MuteHandler;
|
import net.draycia.carbon.common.listeners.MuteHandler;
|
||||||
import net.draycia.carbon.common.listeners.PingHandler;
|
import net.draycia.carbon.common.listeners.PingHandler;
|
||||||
import net.draycia.carbon.common.listeners.RadiusListener;
|
import net.draycia.carbon.common.listeners.RadiusListener;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessageSender;
|
import net.draycia.carbon.common.messages.CarbonMessageSender;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessageSource;
|
import net.draycia.carbon.common.messages.CarbonMessageSource;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
@@ -76,7 +77,6 @@ import net.kyori.adventure.key.Key;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.moonshine.Moonshine;
|
import net.kyori.moonshine.Moonshine;
|
||||||
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
@@ -113,7 +113,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
|||||||
final BooleanPlaceholderResolver<Audience> booleanPlaceholderResolver,
|
final BooleanPlaceholderResolver<Audience> booleanPlaceholderResolver,
|
||||||
final CarbonMessageSource carbonMessageSource,
|
final CarbonMessageSource carbonMessageSource,
|
||||||
final CarbonMessageSender carbonMessageSender,
|
final CarbonMessageSender carbonMessageSender,
|
||||||
final IMessageRenderer<Audience, String, Component, Component> messageRenderer
|
final CarbonMessageRenderer messageRenderer
|
||||||
) throws UnscannableMethodException {
|
) throws UnscannableMethodException {
|
||||||
return Moonshine.<CarbonMessages, Audience>builder(new TypeToken<>() {})
|
return Moonshine.<CarbonMessages, Audience>builder(new TypeToken<>() {})
|
||||||
.receiverLocatorResolver(receiverResolver, 0)
|
.receiverLocatorResolver(receiverResolver, 0)
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
import com.seiama.event.EventConfig;
|
|
||||||
import com.seiama.registry.Registry;
|
import com.seiama.registry.Registry;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -44,13 +43,12 @@ import net.draycia.carbon.api.channels.ChannelRegistry;
|
|||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.DataDirectory;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
import net.draycia.carbon.common.command.PlayerCommander;
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
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.CarbonReloadEvent;
|
||||||
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
|
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
|
||||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||||
@@ -60,7 +58,6 @@ import net.draycia.carbon.common.util.Exceptions;
|
|||||||
import net.draycia.carbon.common.util.FileUtil;
|
import net.draycia.carbon.common.util.FileUtil;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -118,7 +115,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
this.carbonMessages = carbonMessages;
|
this.carbonMessages = carbonMessages;
|
||||||
this.eventHandler = events;
|
this.eventHandler = events;
|
||||||
|
|
||||||
events.subscribe(CarbonReloadEvent.class, -99, EventConfig.DEFAULT_ACCEPTS_CANCELLED, event -> this.reloadConfigChannels());
|
events.subscribe(CarbonReloadEvent.class, -99, true, event -> this.reloadConfigChannels());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurationTransformation.Versioned versioned() {
|
public static ConfigurationTransformation.Versioned versioned() {
|
||||||
@@ -309,20 +306,14 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
|||||||
final List<Audience> recipients,
|
final List<Audience> recipients,
|
||||||
final String plainMessage
|
final String plainMessage
|
||||||
) {
|
) {
|
||||||
final @Nullable CarbonChatEvent chatEvent = this.prepareAndEmitChatEvent(sender, plainMessage, null, channel);
|
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, plainMessage, null, channel);
|
||||||
|
|
||||||
if (chatEvent == null || chatEvent.cancelled()) {
|
if (chatEvent == null || chatEvent.cancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Audience recipient : recipients) {
|
for (final Audience recipient : recipients) {
|
||||||
Component renderedMessage = chatEvent.message();
|
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||||
|
|
||||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
|
||||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
recipient.sendMessage(renderedMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.ConfigChannelMessageSource;
|
||||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessages;
|
import net.draycia.carbon.common.channels.messages.ConfigChannelMessages;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.messages.SourcedMessageSender;
|
import net.draycia.carbon.common.messages.SourcedMessageSender;
|
||||||
import net.draycia.carbon.common.messages.SourcedReceiverResolver;
|
import net.draycia.carbon.common.messages.SourcedReceiverResolver;
|
||||||
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
|
||||||
@@ -41,6 +41,7 @@ import net.draycia.carbon.common.messages.placeholders.ComponentPlaceholderResol
|
|||||||
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||||
|
import net.draycia.carbon.common.util.Exceptions;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -65,7 +66,8 @@ import static net.kyori.adventure.text.Component.text;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class ConfigChatChannel implements ChatChannel {
|
public final class ConfigChatChannel implements ChatChannel {
|
||||||
|
|
||||||
private transient @MonotonicNonNull @Inject CarbonChat carbonChat;
|
private transient @MonotonicNonNull @Inject CarbonServer server;
|
||||||
|
private transient @MonotonicNonNull @Inject CarbonMessageRenderer renderer;
|
||||||
|
|
||||||
@Comment("""
|
@Comment("""
|
||||||
The channel's key, used to track the channel.
|
The channel's key, used to track the channel.
|
||||||
@@ -144,7 +146,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
|||||||
final Component originalMessage
|
final Component originalMessage
|
||||||
) {
|
) {
|
||||||
return this.carbonMessages().chatFormat(
|
return this.carbonMessages().chatFormat(
|
||||||
new SourcedAudience(sender, recipient),
|
SourcedAudience.of(sender, recipient),
|
||||||
sender.uuid(),
|
sender.uuid(),
|
||||||
this.key(),
|
this.key(),
|
||||||
Objects.requireNonNull(CarbonPlayer.renderName(sender)),
|
Objects.requireNonNull(CarbonPlayer.renderName(sender)),
|
||||||
@@ -168,14 +170,14 @@ public final class ConfigChatChannel implements ChatChannel {
|
|||||||
public List<Audience> recipients(final CarbonPlayer sender) {
|
public List<Audience> recipients(final CarbonPlayer sender) {
|
||||||
final List<Audience> recipients = new ArrayList<>();
|
final List<Audience> recipients = new ArrayList<>();
|
||||||
|
|
||||||
for (final CarbonPlayer player : this.carbonChat.server().players()) {
|
for (final CarbonPlayer player : this.server.players()) {
|
||||||
if (this.hearingPermitted(player).permitted()) {
|
if (this.hearingPermitted(player).permitted()) {
|
||||||
recipients.add(player);
|
recipients.add(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// console too!
|
// console too!
|
||||||
recipients.add(this.carbonChat.server().console());
|
recipients.add(this.server.console());
|
||||||
|
|
||||||
return recipients;
|
return recipients;
|
||||||
}
|
}
|
||||||
@@ -197,10 +199,10 @@ public final class ConfigChatChannel implements ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String messageFormat(final CarbonPlayer sender) {
|
public String messageFormat(final CarbonPlayer sender) {
|
||||||
return this.messageSource.messageOf(new SourcedAudience(sender, sender), "");
|
return this.messageSource.messageOf(SourcedAudience.of(sender, sender), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
private @Nullable ConfigChannelMessages loadMessages() {
|
private ConfigChannelMessages loadMessages() {
|
||||||
final SourcedReceiverResolver serverReceiverResolver = new SourcedReceiverResolver();
|
final SourcedReceiverResolver serverReceiverResolver = new SourcedReceiverResolver();
|
||||||
final ComponentPlaceholderResolver<SourcedAudience> componentPlaceholderResolver = new ComponentPlaceholderResolver<>();
|
final ComponentPlaceholderResolver<SourcedAudience> componentPlaceholderResolver = new ComponentPlaceholderResolver<>();
|
||||||
final UUIDPlaceholderResolver<SourcedAudience> uuidPlaceholderResolver = new UUIDPlaceholderResolver<>();
|
final UUIDPlaceholderResolver<SourcedAudience> uuidPlaceholderResolver = new UUIDPlaceholderResolver<>();
|
||||||
@@ -213,7 +215,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
|||||||
return Moonshine.<ConfigChannelMessages, SourcedAudience>builder(new TypeToken<ConfigChannelMessages>() {})
|
return Moonshine.<ConfigChannelMessages, SourcedAudience>builder(new TypeToken<ConfigChannelMessages>() {})
|
||||||
.receiverLocatorResolver(serverReceiverResolver, 0)
|
.receiverLocatorResolver(serverReceiverResolver, 0)
|
||||||
.sourced(this.messageSource)
|
.sourced(this.messageSource)
|
||||||
.rendered(((CarbonChatInternal<?>) this.carbonChat).messageRenderer())
|
.rendered(this.renderer.asSourced())
|
||||||
.sent(carbonMessageSender)
|
.sent(carbonMessageSender)
|
||||||
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
|
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
|
||||||
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
|
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
|
||||||
@@ -223,10 +225,8 @@ public final class ConfigChatChannel implements ChatChannel {
|
|||||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||||
.create(this.getClass().getClassLoader());
|
.create(this.getClass().getClassLoader());
|
||||||
} catch (final UnscannableMethodException e) {
|
} catch (final UnscannableMethodException e) {
|
||||||
e.printStackTrace();
|
throw Exceptions.rethrow(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConfigChannelMessages carbonMessages() {
|
private ConfigChannelMessages carbonMessages() {
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.util.DiscordRecipient;
|
import net.draycia.carbon.common.util.DiscordRecipient;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.moonshine.message.IMessageSource;
|
import net.kyori.moonshine.message.IMessageSource;
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
package net.draycia.carbon.common.channels.messages;
|
package net.draycia.carbon.common.channels.messages;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.moonshine.annotation.Message;
|
import net.kyori.moonshine.annotation.Message;
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
|
|||||||
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
|
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||||
import net.draycia.carbon.common.command.CarbonCommand;
|
import net.draycia.carbon.common.command.CarbonCommand;
|
||||||
import net.draycia.carbon.common.command.CommandSettings;
|
import net.draycia.carbon.common.command.CommandSettings;
|
||||||
@@ -40,6 +39,7 @@ import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
|||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||||
import net.draycia.carbon.common.messaging.packets.PacketFactory;
|
import net.draycia.carbon.common.messaging.packets.PacketFactory;
|
||||||
import net.draycia.carbon.common.messaging.packets.WhisperPacket;
|
import net.draycia.carbon.common.messaging.packets.WhisperPacket;
|
||||||
@@ -198,9 +198,9 @@ public class WhisperCommand extends CarbonCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.messages.whisperSender(new SourcedAudience(sender, sender), senderName, recipientName, privateChatEvent.message());
|
this.messages.whisperSender(SourcedAudience.of(sender, sender), senderName, recipientName, privateChatEvent.message());
|
||||||
if (localRecipient) {
|
if (localRecipient) {
|
||||||
this.messages.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, privateChatEvent.message());
|
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderName, recipientName, privateChatEvent.message());
|
||||||
}
|
}
|
||||||
this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, privateChatEvent.message());
|
this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, privateChatEvent.message());
|
||||||
|
|
||||||
@@ -233,7 +233,7 @@ public class WhisperCommand extends CarbonCommand {
|
|||||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||||
|
|
||||||
recipient.whisperReplyTarget(sender.uuid());
|
recipient.whisperReplyTarget(sender.uuid());
|
||||||
this.messages.whisperRecipient(new SourcedAudience(sender, recipient), senderName, recipientName, packet.message());
|
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderName, recipientName, packet.message());
|
||||||
this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, packet.message());
|
this.messages.whisperConsoleLog(this.server.console(), senderName, recipientName, packet.message());
|
||||||
final @Nullable Sound messageSound = this.configFactory.primaryConfig().messageSound();
|
final @Nullable Sound messageSound = this.configFactory.primaryConfig().messageSound();
|
||||||
if (messageSound != null) {
|
if (messageSound != null) {
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package net.draycia.carbon.common.config;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.seiama.event.EventConfig;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -57,7 +56,7 @@ public class ConfigFactory {
|
|||||||
this.dataDirectory = dataDirectory;
|
this.dataDirectory = dataDirectory;
|
||||||
this.locale = locale;
|
this.locale = locale;
|
||||||
|
|
||||||
events.subscribe(CarbonReloadEvent.class, -100, EventConfig.DEFAULT_ACCEPTS_CANCELLED, event -> this.reloadPrimaryConfig());
|
events.subscribe(CarbonReloadEvent.class, -100, true, event -> this.reloadPrimaryConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable PrimaryConfig reloadPrimaryConfig() {
|
public @Nullable PrimaryConfig reloadPrimaryConfig() {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import com.seiama.event.bus.EventBus;
|
|||||||
import com.seiama.event.bus.SimpleEventBus;
|
import com.seiama.event.bus.SimpleEventBus;
|
||||||
import com.seiama.event.registry.EventRegistry;
|
import com.seiama.event.registry.EventRegistry;
|
||||||
import com.seiama.event.registry.SimpleEventRegistry;
|
import com.seiama.event.registry.SimpleEventRegistry;
|
||||||
|
import net.draycia.carbon.api.event.Cancellable;
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
||||||
@@ -60,8 +61,11 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
|||||||
final Class<T> eventClass,
|
final Class<T> eventClass,
|
||||||
final CarbonEventSubscriber<T> subscriber
|
final CarbonEventSubscriber<T> subscriber
|
||||||
) {
|
) {
|
||||||
this.eventRegistry.subscribe(eventClass, subscriber::on);
|
return new CarbonEventSubscriptionImpl<>(
|
||||||
return new CarbonEventSubscriptionImpl<>(eventClass, subscriber);
|
eventClass,
|
||||||
|
subscriber,
|
||||||
|
this.eventRegistry.subscribe(eventClass, subscriber::on)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: support EventConfig#exact()
|
// TODO: support EventConfig#exact()
|
||||||
@@ -73,8 +77,17 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
|||||||
final CarbonEventSubscriber<T> subscriber
|
final CarbonEventSubscriber<T> subscriber
|
||||||
) {
|
) {
|
||||||
final EventConfig eventConfig = EventConfig.defaults().order(order).acceptsCancelled(acceptsCancelled);
|
final EventConfig eventConfig = EventConfig.defaults().order(order).acceptsCancelled(acceptsCancelled);
|
||||||
this.eventRegistry.subscribe(eventClass, eventConfig, subscriber::on);
|
return new CarbonEventSubscriptionImpl<>(
|
||||||
return new CarbonEventSubscriptionImpl<>(eventClass, subscriber);
|
eventClass,
|
||||||
|
subscriber,
|
||||||
|
this.eventRegistry.subscribe(eventClass, eventConfig, event -> {
|
||||||
|
// Our events implement seiama Cancellable; but API consumers won't be able to do that
|
||||||
|
if (!acceptsCancelled && event instanceof Cancellable cancellable && cancellable.cancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
subscriber.on(event);
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
+11
-1
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.common.event;
|
package net.draycia.carbon.common.event;
|
||||||
|
|
||||||
|
import com.seiama.event.EventSubscription;
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
||||||
import net.draycia.carbon.api.event.CarbonEventSubscription;
|
import net.draycia.carbon.api.event.CarbonEventSubscription;
|
||||||
@@ -26,6 +27,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
record CarbonEventSubscriptionImpl<T extends CarbonEvent>(Class<T> event, CarbonEventSubscriber<T> subscriber) implements CarbonEventSubscription<T> {
|
record CarbonEventSubscriptionImpl<T extends CarbonEvent>(
|
||||||
|
Class<T> event,
|
||||||
|
CarbonEventSubscriber<T> subscriber,
|
||||||
|
EventSubscription<T> backingSubscription
|
||||||
|
) implements CarbonEventSubscription<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
this.backingSubscription.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -80,36 +80,52 @@ public class CarbonChatEventImpl extends CancellableImpl implements CarbonChatEv
|
|||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<KeyedRenderer> renderers() {
|
public List<KeyedRenderer> renderers() {
|
||||||
return this.renderers;
|
return this.renderers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public @MonotonicNonNull SignedMessage signedMessage() {
|
public @MonotonicNonNull SignedMessage signedMessage() {
|
||||||
return this.signedMessage;
|
return this.signedMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public CarbonPlayer sender() {
|
public CarbonPlayer sender() {
|
||||||
return this.sender;
|
return this.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Component originalMessage() {
|
public Component originalMessage() {
|
||||||
return this.originalMessage;
|
return this.originalMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Component message() {
|
public Component message() {
|
||||||
return this.message;
|
return this.message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void message(final Component message) {
|
public void message(final Component message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public @MonotonicNonNull ChatChannel chatChannel() {
|
public @MonotonicNonNull ChatChannel chatChannel() {
|
||||||
return this.chatChannel;
|
return this.chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<? extends Audience> recipients() {
|
public List<? extends Audience> recipients() {
|
||||||
return this.recipients;
|
return this.recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Component renderFor(final Audience viewer) {
|
||||||
|
Component renderedMessage = this.message();
|
||||||
|
for (final var renderer : this.renderers()) {
|
||||||
|
renderedMessage = renderer.render(this.sender, viewer, renderedMessage, this.message());
|
||||||
|
}
|
||||||
|
return renderedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,6 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.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.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
@@ -60,7 +59,7 @@ public abstract class ChatListenerInternal {
|
|||||||
this.carbonEventHandler = carbonEventHandler;
|
this.carbonEventHandler = carbonEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @Nullable CarbonChatEvent prepareAndEmitChatEvent(final CarbonPlayer sender, final String messageContent, final SignedMessage signedMessage) {
|
protected @Nullable CarbonChatEventImpl prepareAndEmitChatEvent(final CarbonPlayer sender, final String messageContent, final @Nullable SignedMessage signedMessage) {
|
||||||
final CarbonPlayer.ChannelMessage channelMessage = sender.channelForMessage(Component.text(messageContent));
|
final CarbonPlayer.ChannelMessage channelMessage = sender.channelForMessage(Component.text(messageContent));
|
||||||
final ChatChannel channel = channelMessage.channel();
|
final ChatChannel channel = channelMessage.channel();
|
||||||
final String message = PlainTextComponentSerializer.plainText().serialize(channelMessage.message());
|
final String message = PlainTextComponentSerializer.plainText().serialize(channelMessage.message());
|
||||||
@@ -68,7 +67,7 @@ public abstract class ChatListenerInternal {
|
|||||||
return this.prepareAndEmitChatEvent(sender, message, signedMessage, channel);
|
return this.prepareAndEmitChatEvent(sender, message, signedMessage, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected @Nullable CarbonChatEvent prepareAndEmitChatEvent(final CarbonPlayer sender, final String messageContent, final SignedMessage signedMessage, final ChatChannel channel) {
|
protected @Nullable CarbonChatEventImpl prepareAndEmitChatEvent(final CarbonPlayer sender, final String messageContent, final @Nullable SignedMessage signedMessage, final ChatChannel channel) {
|
||||||
String content = this.configFactory.primaryConfig().applyChatPlaceholders(messageContent);
|
String content = this.configFactory.primaryConfig().applyChatPlaceholders(messageContent);
|
||||||
content = this.configFactory.primaryConfig().applyChatFilters(content);
|
content = this.configFactory.primaryConfig().applyChatFilters(content);
|
||||||
|
|
||||||
@@ -98,7 +97,7 @@ public abstract class ChatListenerInternal {
|
|||||||
|
|
||||||
final List<Audience> recipients = channel.recipients(sender);
|
final List<Audience> recipients = channel.recipients(sender);
|
||||||
|
|
||||||
final CarbonChatEvent chatEvent = new CarbonChatEventImpl(sender, message, recipients, renderers, channel, signedMessage);
|
final var chatEvent = new CarbonChatEventImpl(sender, message, recipients, renderers, channel, signedMessage);
|
||||||
|
|
||||||
this.carbonEventHandler.emit(chatEvent);
|
this.carbonEventHandler.emit(chatEvent);
|
||||||
|
|
||||||
|
|||||||
@@ -40,15 +40,11 @@ public class ItemLinkHandler implements Listener {
|
|||||||
event.message()
|
event.message()
|
||||||
.replaceText(TextReplacementConfig.builder()
|
.replaceText(TextReplacementConfig.builder()
|
||||||
.matchLiteral("<" + placeholder + ">")
|
.matchLiteral("<" + placeholder + ">")
|
||||||
.once()
|
// .once()
|
||||||
.replacement(builder -> {
|
.replacement(builder -> {
|
||||||
final var itemComponent = event.sender().createItemHoverComponent(slot);
|
final var itemComponent = event.sender().createItemHoverComponent(slot);
|
||||||
|
|
||||||
if (itemComponent == null) {
|
return itemComponent == null ? builder : itemComponent;
|
||||||
return builder;
|
|
||||||
}
|
|
||||||
|
|
||||||
return event.sender().createItemHoverComponent(slot);
|
|
||||||
})
|
})
|
||||||
.build())
|
.build())
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -52,11 +52,7 @@ public class MessagePacketHandler implements Listener {
|
|||||||
|
|
||||||
messaging.get().withPacketService(packetService -> {
|
messaging.get().withPacketService(packetService -> {
|
||||||
final CarbonPlayer sender = event.sender();
|
final CarbonPlayer sender = event.sender();
|
||||||
Component networkMessage = event.message();
|
final Component networkMessage = e.renderFor(sender);
|
||||||
|
|
||||||
for (final var renderer : event.renderers()) {
|
|
||||||
networkMessage = renderer.render(sender, sender, networkMessage, event.originalMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
packetService.queuePacket(new ChatMessagePacket(carbonChat.serverId(), sender.uuid(),
|
packetService.queuePacket(new ChatMessagePacket(carbonChat.serverId(), sender.uuid(),
|
||||||
event.chatChannel().permission(), event.chatChannel().key(), sender.username(), networkMessage));
|
event.chatChannel().permission(), event.chatChannel().key(), sender.username(), networkMessage));
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.messages;
|
||||||
|
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.moonshine.message.IMessageRenderer;
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface CarbonMessageRenderer extends IMessageRenderer<Audience, String, Component, Component> {
|
||||||
|
|
||||||
|
default IMessageRenderer<SourcedAudience, String, Component, Component> asSourced() {
|
||||||
|
return this::render;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.common.messages;
|
package net.draycia.carbon.common.messages;
|
||||||
|
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.moonshine.message.IMessageSender;
|
import net.kyori.moonshine.message.IMessageSender;
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ package net.draycia.carbon.common.messages;
|
|||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.seiama.event.EventConfig;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -87,7 +86,7 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
|||||||
|
|
||||||
this.reloadTranslations();
|
this.reloadTranslations();
|
||||||
|
|
||||||
events.subscribe(CarbonReloadEvent.class, -99, EventConfig.DEFAULT_ACCEPTS_CANCELLED, event -> {
|
events.subscribe(CarbonReloadEvent.class, -99, true, event -> {
|
||||||
this.reloadTranslations();
|
this.reloadTranslations();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -194,6 +193,10 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
|||||||
public String messageOf(final Audience receiver, final String messageKey) {
|
public String messageOf(final Audience receiver, final String messageKey) {
|
||||||
Audience audience = receiver;
|
Audience audience = receiver;
|
||||||
|
|
||||||
|
if (audience instanceof SourcedAudience sourced) {
|
||||||
|
audience = sourced.recipient();
|
||||||
|
}
|
||||||
|
|
||||||
// Unwrap PlayerCommanders
|
// Unwrap PlayerCommanders
|
||||||
if (audience instanceof PlayerCommander playerCommander) {
|
if (audience instanceof PlayerCommander playerCommander) {
|
||||||
audience = playerCommander.carbonPlayer();
|
audience = playerCommander.carbonPlayer();
|
||||||
@@ -202,7 +205,7 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
|||||||
if (audience instanceof CarbonPlayer player) {
|
if (audience instanceof CarbonPlayer player) {
|
||||||
return this.forPlayer(messageKey, player);
|
return this.forPlayer(messageKey, player);
|
||||||
} else {
|
} else {
|
||||||
return this.forAudience(messageKey, audience);
|
return this.fromDefaultLocale(messageKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,10 +222,10 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.forAudience(key, player);
|
return this.fromDefaultLocale(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String forAudience(final String key, final Audience audience) {
|
private String fromDefaultLocale(final String key) {
|
||||||
final Properties defaultProperties = this.locales.get(this.defaultLocale);
|
final Properties defaultProperties = this.locales.get(this.defaultLocale);
|
||||||
|
|
||||||
if (defaultProperties != null) {
|
if (defaultProperties != null) {
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package net.draycia.carbon.common.messages;
|
package net.draycia.carbon.common.messages;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.moonshine.annotation.Message;
|
import net.kyori.moonshine.annotation.Message;
|
||||||
|
|||||||
@@ -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.messages;
|
||||||
|
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An audience, where messages are sent from another Audience.
|
||||||
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public interface SourcedAudience extends ForwardingAudience.Single {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The source audience.
|
||||||
|
*
|
||||||
|
* @return source
|
||||||
|
*/
|
||||||
|
Audience sender();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The recipient audience. The audience that this sourced audience forwards to.
|
||||||
|
*
|
||||||
|
* @return recipient
|
||||||
|
*/
|
||||||
|
Audience recipient();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default Audience audience() {
|
||||||
|
return this.recipient();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link SourcedAudience} instance.
|
||||||
|
*
|
||||||
|
* @param sender sender
|
||||||
|
* @param recipient recipient
|
||||||
|
* @return sourced audience
|
||||||
|
*/
|
||||||
|
static SourcedAudience of(final Audience sender, final Audience recipient) {
|
||||||
|
return new SourcedAudienceImpl(sender, recipient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The empty {@link SourcedAudience}, with an empty sender and recipient.
|
||||||
|
*
|
||||||
|
* @return the empty sourced audience
|
||||||
|
*/
|
||||||
|
static SourcedAudience empty() {
|
||||||
|
return SourcedAudienceImpl.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+5
-9
@@ -17,16 +17,12 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.event.events;
|
package net.draycia.carbon.common.messages;
|
||||||
|
|
||||||
// TODO: emit event on server shutdown
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
record SourcedAudienceImpl(Audience sender, Audience recipient) implements SourcedAudience {
|
||||||
|
|
||||||
|
static final SourcedAudience EMPTY = new SourcedAudienceImpl(Audience.empty(), Audience.empty());
|
||||||
|
|
||||||
/**
|
|
||||||
* An event that's called when the server shuts down.
|
|
||||||
*
|
|
||||||
* @since 2.1.0
|
|
||||||
*/
|
|
||||||
public class CarbonShutdownEvent implements CarbonEvent {
|
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.common.messages;
|
package net.draycia.carbon.common.messages;
|
||||||
|
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.moonshine.message.IMessageSender;
|
import net.kyori.moonshine.message.IMessageSender;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|||||||
+1
-2
@@ -42,7 +42,6 @@ package net.draycia.carbon.common.messages;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.moonshine.receiver.IReceiverLocator;
|
import net.kyori.moonshine.receiver.IReceiverLocator;
|
||||||
import net.kyori.moonshine.receiver.IReceiverLocatorResolver;
|
import net.kyori.moonshine.receiver.IReceiverLocatorResolver;
|
||||||
@@ -71,7 +70,7 @@ public final class SourcedReceiverResolver implements IReceiverLocatorResolver<S
|
|||||||
if (parameter instanceof SourcedAudience sourcedAudience) {
|
if (parameter instanceof SourcedAudience sourcedAudience) {
|
||||||
return sourcedAudience;
|
return sourcedAudience;
|
||||||
} else if (parameter instanceof Audience audience) {
|
} else if (parameter instanceof Audience audience) {
|
||||||
return new SourcedAudience(audience, audience);
|
return SourcedAudience.of(audience, audience);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SourcedAudience.empty();
|
return SourcedAudience.empty();
|
||||||
|
|||||||
+2
-9
@@ -26,7 +26,6 @@ import net.draycia.carbon.api.CarbonServer;
|
|||||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.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.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||||
import net.draycia.carbon.common.command.commands.WhisperCommand;
|
import net.draycia.carbon.common.command.commands.WhisperCommand;
|
||||||
@@ -106,7 +105,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
|||||||
final List<KeyedRenderer> renderers = new ArrayList<>();
|
final List<KeyedRenderer> renderers = new ArrayList<>();
|
||||||
|
|
||||||
final List<Audience> recipients = channel.recipients(sender);
|
final List<Audience> recipients = channel.recipients(sender);
|
||||||
final CarbonChatEvent chatEvent = new CarbonChatEventImpl(sender, messagePacket.message(), recipients, renderers, channel, null, false);
|
final CarbonChatEventImpl chatEvent = new CarbonChatEventImpl(sender, messagePacket.message(), recipients, renderers, channel, null, false);
|
||||||
this.events.emit(chatEvent);
|
this.events.emit(chatEvent);
|
||||||
|
|
||||||
for (final Audience recipient : recipients) {
|
for (final Audience recipient : recipients) {
|
||||||
@@ -115,13 +114,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component renderedMessage = chatEvent.message();
|
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||||
|
|
||||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
|
||||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, messagePacket.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
recipient.sendMessage(renderedMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.server.console().sendMessage(Component.text("[Cross-Server] ").append(chatEvent.message()));
|
this.server.console().sendMessage(Component.text("[Cross-Server] ").append(chatEvent.message()));
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public class MessagingManager {
|
|||||||
private static final byte protocolVersion = 0;
|
private static final byte protocolVersion = 0;
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
private final Logger logger;
|
||||||
private final @MonotonicNonNull ScheduledExecutorService scheduledExecutor;
|
private final @MonotonicNonNull ScheduledExecutorService scheduledExecutor;
|
||||||
private final @MonotonicNonNull PacketService packetService;
|
private final @MonotonicNonNull PacketService packetService;
|
||||||
private @MonotonicNonNull MessagingService messagingService;
|
private @MonotonicNonNull MessagingService messagingService;
|
||||||
@@ -94,13 +95,14 @@ public class MessagingManager {
|
|||||||
final WhisperCommand.WhisperHandler whisper,
|
final WhisperCommand.WhisperHandler whisper,
|
||||||
final PacketFactory packetFactory
|
final PacketFactory packetFactory
|
||||||
) {
|
) {
|
||||||
|
this.carbonChat = carbonChat;
|
||||||
|
this.logger = logger;
|
||||||
if (!configFactory.primaryConfig().messagingSettings().enabled()) {
|
if (!configFactory.primaryConfig().messagingSettings().enabled()) {
|
||||||
if (!((CarbonChatInternal<?>) carbonChat).isProxy()) {
|
if (!((CarbonChatInternal<?>) carbonChat).isProxy()) {
|
||||||
logger.info("Messaging services disabled in config. Cross-server will not work without this!");
|
logger.info("Messaging services disabled in config. Cross-server will not work without this!");
|
||||||
}
|
}
|
||||||
this.messagingService = EMPTY_MESSAGING_SERVICE;
|
this.messagingService = EMPTY_MESSAGING_SERVICE;
|
||||||
this.packetService = null;
|
this.packetService = null;
|
||||||
this.carbonChat = carbonChat;
|
|
||||||
this.scheduledExecutor = null;
|
this.scheduledExecutor = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -126,8 +128,7 @@ public class MessagingManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.scheduledExecutor = new ExceptionLoggingScheduledThreadPoolExecutor(4,
|
this.scheduledExecutor = new ExceptionLoggingScheduledThreadPoolExecutor(4,
|
||||||
ConcurrentUtil.carbonThreadFactory(carbonChat.logger(), "MessagingManager"), carbonChat.logger());
|
ConcurrentUtil.carbonThreadFactory(logger, "MessagingManager"), logger);
|
||||||
this.carbonChat = carbonChat;
|
|
||||||
|
|
||||||
final MessagingHandlerImpl handlerImpl = new MessagingHandlerImpl(this.packetService);
|
final MessagingHandlerImpl handlerImpl = new MessagingHandlerImpl(this.packetService);
|
||||||
handlerImpl.addHandler(new CarbonServerHandler(server, carbonChat.serverId(), this.packetService, handlerImpl, packetFactory));
|
handlerImpl.addHandler(new CarbonServerHandler(server, carbonChat.serverId(), this.packetService, handlerImpl, packetFactory));
|
||||||
@@ -197,7 +198,7 @@ public class MessagingManager {
|
|||||||
|
|
||||||
switch (messagingSettings.brokerType()) {
|
switch (messagingSettings.brokerType()) {
|
||||||
case RABBITMQ -> {
|
case RABBITMQ -> {
|
||||||
this.carbonChat.logger().info("Initializing RabbitMQ Messaging services...");
|
this.logger.info("Initializing RabbitMQ Messaging services...");
|
||||||
|
|
||||||
final RabbitMQMessagingService.Builder builder = RabbitMQMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
final RabbitMQMessagingService.Builder builder = RabbitMQMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||||
.url(messagingSettings.url(), messagingSettings.port(), messagingSettings.vhost())
|
.url(messagingSettings.url(), messagingSettings.port(), messagingSettings.vhost())
|
||||||
@@ -210,7 +211,7 @@ public class MessagingManager {
|
|||||||
this.messagingService = builder.build();
|
this.messagingService = builder.build();
|
||||||
}
|
}
|
||||||
case NATS -> {
|
case NATS -> {
|
||||||
this.carbonChat.logger().info("Initializing NATS Messaging services...");
|
this.logger.info("Initializing NATS Messaging services...");
|
||||||
|
|
||||||
final NATSMessagingService.Builder builder = NATSMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
final NATSMessagingService.Builder builder = NATSMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||||
.url(messagingSettings.url(), messagingSettings.port())
|
.url(messagingSettings.url(), messagingSettings.port())
|
||||||
@@ -223,7 +224,7 @@ public class MessagingManager {
|
|||||||
this.messagingService = builder.build();
|
this.messagingService = builder.build();
|
||||||
}
|
}
|
||||||
case REDIS -> {
|
case REDIS -> {
|
||||||
this.carbonChat.logger().info("Initializing Redis Messaging services...");
|
this.logger.info("Initializing Redis Messaging services...");
|
||||||
|
|
||||||
final RedisMessagingService.Builder builder = RedisMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
final RedisMessagingService.Builder builder = RedisMessagingService.builder(packetService, name, channelName, this.carbonChat.serverId(), handlerImpl, 0L, false, packetDir)
|
||||||
.url(messagingSettings.url(), messagingSettings.port());
|
.url(messagingSettings.url(), messagingSettings.port());
|
||||||
|
|||||||
@@ -350,11 +350,8 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ChatChannel selectedChannel() {
|
public @Nullable ChatChannel selectedChannel() {
|
||||||
if (!this.selectedChannel.hasValue()) {
|
final @Nullable Key selected = this.selectedChannelKey();
|
||||||
return this.channelRegistry.defaultChannel();
|
return selected == null ? null : this.channelRegistry.channel(selected);
|
||||||
}
|
|
||||||
|
|
||||||
return this.channelRegistry.channel(this.selectedChannel.get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelRegistry channelRegistry() {
|
public ChannelRegistry channelRegistry() {
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.google.inject.Inject;
|
|||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@@ -31,7 +30,6 @@ import net.draycia.carbon.api.CarbonChat;
|
|||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.common.CarbonChatInternal;
|
import net.draycia.carbon.common.CarbonChatInternal;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
|
||||||
import net.draycia.carbon.common.PeriodicTasks;
|
import net.draycia.carbon.common.PeriodicTasks;
|
||||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||||
@@ -48,9 +46,6 @@ import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
|||||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
|
import net.fabricmc.loader.api.entrypoint.EntrypointContainer;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import net.minecraft.core.registries.Registries;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.network.chat.ChatType;
|
import net.minecraft.network.chat.ChatType;
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
@@ -69,7 +64,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
|||||||
private CarbonChatFabric(
|
private CarbonChatFabric(
|
||||||
final Injector injector,
|
final Injector injector,
|
||||||
final Logger logger,
|
final Logger logger,
|
||||||
final @DataDirectory Path dataDirectory,
|
|
||||||
final @PeriodicTasks ScheduledExecutorService periodicTasks,
|
final @PeriodicTasks ScheduledExecutorService periodicTasks,
|
||||||
final ProfileCache profileCache,
|
final ProfileCache profileCache,
|
||||||
final ProfileResolver profileResolver,
|
final ProfileResolver profileResolver,
|
||||||
@@ -79,7 +73,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
|||||||
final CarbonMessages carbonMessages,
|
final CarbonMessages carbonMessages,
|
||||||
final CarbonEventHandler eventHandler,
|
final CarbonEventHandler eventHandler,
|
||||||
final CarbonChannelRegistry channelRegistry,
|
final CarbonChannelRegistry channelRegistry,
|
||||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
|
||||||
final Provider<MessagingManager> messagingManagerProvider,
|
final Provider<MessagingManager> messagingManagerProvider,
|
||||||
@SuppressWarnings("unused") // Make sure it initializes now
|
@SuppressWarnings("unused") // Make sure it initializes now
|
||||||
final MinecraftServerHolder minecraftServerHolder
|
final MinecraftServerHolder minecraftServerHolder
|
||||||
@@ -87,7 +80,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
|||||||
super(
|
super(
|
||||||
injector,
|
injector,
|
||||||
logger,
|
logger,
|
||||||
dataDirectory,
|
|
||||||
periodicTasks,
|
periodicTasks,
|
||||||
profileCache,
|
profileCache,
|
||||||
profileResolver,
|
profileResolver,
|
||||||
@@ -97,7 +89,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
|||||||
carbonMessages,
|
carbonMessages,
|
||||||
eventHandler,
|
eventHandler,
|
||||||
channelRegistry,
|
channelRegistry,
|
||||||
renderer,
|
|
||||||
messagingManagerProvider
|
messagingManagerProvider
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package net.draycia.carbon.fabric;
|
|||||||
import cloud.commandframework.CommandManager;
|
import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
@@ -31,12 +30,12 @@ import java.nio.file.Path;
|
|||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.CarbonCommonModule;
|
import net.draycia.carbon.common.CarbonCommonModule;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
import net.draycia.carbon.common.DataDirectory;
|
||||||
import net.draycia.carbon.common.PlatformScheduler;
|
import net.draycia.carbon.common.PlatformScheduler;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||||
@@ -46,9 +45,6 @@ import net.draycia.carbon.fabric.command.FabricPlayerCommander;
|
|||||||
import net.draycia.carbon.fabric.users.FabricProfileResolver;
|
import net.draycia.carbon.fabric.users.FabricProfileResolver;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -93,20 +89,6 @@ public final class CarbonChatFabricModule extends AbstractModule {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
this.install(new CarbonCommonModule());
|
this.install(new CarbonCommonModule());
|
||||||
@@ -120,6 +102,7 @@ public final class CarbonChatFabricModule extends AbstractModule {
|
|||||||
this.bind(PlatformScheduler.class).to(FabricScheduler.class);
|
this.bind(PlatformScheduler.class).to(FabricScheduler.class);
|
||||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(FabricUserManager.class);
|
this.bind(new TypeLiteral<UserManager<?>>() {}).to(FabricUserManager.class);
|
||||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(FabricUserManager.class);
|
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(FabricUserManager.class);
|
||||||
|
this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,12 +20,14 @@
|
|||||||
package net.draycia.carbon.fabric;
|
package net.draycia.carbon.fabric;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
@@ -34,12 +36,12 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class FabricMessageRenderer<T extends Audience> implements IMessageRenderer<T, String, Component, Component> {
|
@Singleton
|
||||||
|
public class FabricMessageRenderer implements CarbonMessageRenderer {
|
||||||
|
|
||||||
private final ConfigFactory configFactory;
|
private final ConfigFactory configFactory;
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ public class FabricMessageRenderer<T extends Audience> implements IMessageRender
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component render(
|
public Component render(
|
||||||
final T receiver,
|
final Audience receiver,
|
||||||
final String intermediateMessage,
|
final String intermediateMessage,
|
||||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||||
final Method method,
|
final Method method,
|
||||||
|
|||||||
@@ -20,10 +20,9 @@
|
|||||||
package net.draycia.carbon.fabric.listeners;
|
package net.draycia.carbon.fabric.listeners;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
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.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.fabric.CarbonChatFabric;
|
import net.draycia.carbon.fabric.CarbonChatFabric;
|
||||||
@@ -62,20 +61,14 @@ public class FabricChatHandler extends ChatListenerInternal implements ServerMes
|
|||||||
final @Nullable CarbonPlayer sender = this.carbonChat.userManager().user(serverPlayer.getUUID()).join();
|
final @Nullable CarbonPlayer sender = this.carbonChat.userManager().user(serverPlayer.getUUID()).join();
|
||||||
|
|
||||||
final String content = chatMessage.decoratedContent().getString();
|
final String content = chatMessage.decoratedContent().getString();
|
||||||
final @Nullable CarbonChatEvent chatEvent = this.prepareAndEmitChatEvent(sender, content, null);
|
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, content, null);
|
||||||
|
|
||||||
if (chatEvent == null || chatEvent.cancelled()) {
|
if (chatEvent == null || chatEvent.cancelled()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final var recipient : chatEvent.recipients()) {
|
for (final var recipient : chatEvent.recipients()) {
|
||||||
Component renderedMessage = chatEvent.message();
|
final Component finishedMessage = chatEvent.renderFor(recipient);
|
||||||
|
|
||||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
|
||||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Component finishedMessage = renderedMessage;
|
|
||||||
|
|
||||||
final net.minecraft.network.chat.Component nativeMessage = FabricAudiences.nonWrappingSerializer().serialize(finishedMessage);
|
final net.minecraft.network.chat.Component nativeMessage = FabricAudiences.nonWrappingSerializer().serialize(finishedMessage);
|
||||||
final PlayerChatMessage customChatMessage = new PlayerChatMessage(chatMessage.link(), chatMessage.signature(), chatMessage.signedBody(), nativeMessage, FilterMask.FULLY_FILTERED);
|
final PlayerChatMessage customChatMessage = new PlayerChatMessage(chatMessage.link(), chatMessage.signature(), chatMessage.signedBody(), nativeMessage, FilterMask.FULLY_FILTERED);
|
||||||
|
|||||||
@@ -20,7 +20,6 @@
|
|||||||
package net.draycia.carbon.fabric.users;
|
package net.draycia.carbon.fabric.users;
|
||||||
|
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -170,7 +169,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.user().getPrimaryGroup();
|
return super.primaryGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -179,13 +178,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
|||||||
return List.of("default");
|
return List.of("default");
|
||||||
}
|
}
|
||||||
|
|
||||||
final var groups = new ArrayList<String>();
|
return super.groups();
|
||||||
|
|
||||||
for (final var group : this.user().getInheritedGroups(this.user().getQueryOptions())) {
|
|
||||||
groups.add(group.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
return groups;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,13 +24,11 @@ import com.google.inject.Injector;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import github.scarsz.discordsrv.DiscordSRV;
|
import github.scarsz.discordsrv.DiscordSRV;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.common.CarbonChatInternal;
|
import net.draycia.carbon.common.CarbonChatInternal;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
|
||||||
import net.draycia.carbon.common.PeriodicTasks;
|
import net.draycia.carbon.common.PeriodicTasks;
|
||||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||||
@@ -45,9 +43,6 @@ import net.draycia.carbon.paper.listeners.DiscordMessageListener;
|
|||||||
import net.draycia.carbon.paper.listeners.PaperChatListener;
|
import net.draycia.carbon.paper.listeners.PaperChatListener;
|
||||||
import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
|
import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
|
||||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -78,15 +73,14 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
|
|||||||
final Provider<MessagingManager> messagingManager,
|
final Provider<MessagingManager> messagingManager,
|
||||||
final CarbonServer carbonServer,
|
final CarbonServer carbonServer,
|
||||||
final PaperUserManager userManager,
|
final PaperUserManager userManager,
|
||||||
@DataDirectory final Path dataDirectory,
|
|
||||||
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
||||||
final ProfileCache profileCache,
|
final ProfileCache profileCache,
|
||||||
final ProfileResolver profileResolver,
|
final ProfileResolver profileResolver,
|
||||||
final ExecutionCoordinatorHolder commandExecutor,
|
final ExecutionCoordinatorHolder commandExecutor
|
||||||
final IMessageRenderer<Audience, String, Component, Component> renderer
|
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
injector, LogManager.getLogger("CarbonChat"), dataDirectory,
|
injector,
|
||||||
|
LogManager.getLogger("CarbonChat"),
|
||||||
periodicTasks,
|
periodicTasks,
|
||||||
profileCache,
|
profileCache,
|
||||||
profileResolver,
|
profileResolver,
|
||||||
@@ -96,7 +90,6 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
|
|||||||
carbonMessages,
|
carbonMessages,
|
||||||
eventHandler,
|
eventHandler,
|
||||||
channelRegistry,
|
channelRegistry,
|
||||||
renderer,
|
|
||||||
messagingManager
|
messagingManager
|
||||||
);
|
);
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import cloud.commandframework.CommandManager;
|
|||||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||||
import cloud.commandframework.paper.PaperCommandManager;
|
import cloud.commandframework.paper.PaperCommandManager;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
@@ -32,12 +31,12 @@ import java.nio.file.Path;
|
|||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.CarbonCommonModule;
|
import net.draycia.carbon.common.CarbonCommonModule;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
import net.draycia.carbon.common.DataDirectory;
|
||||||
import net.draycia.carbon.common.PlatformScheduler;
|
import net.draycia.carbon.common.PlatformScheduler;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||||
@@ -47,9 +46,6 @@ import net.draycia.carbon.paper.command.PaperPlayerCommander;
|
|||||||
import net.draycia.carbon.paper.messages.PaperMessageRenderer;
|
import net.draycia.carbon.paper.messages.PaperMessageRenderer;
|
||||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||||
import net.draycia.carbon.paper.users.PaperProfileResolver;
|
import net.draycia.carbon.paper.users.PaperProfileResolver;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@@ -106,20 +102,6 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
this.install(new CarbonCommonModule());
|
this.install(new CarbonCommonModule());
|
||||||
@@ -134,6 +116,7 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
|||||||
this.bind(PlatformScheduler.class).to(PaperScheduler.class);
|
this.bind(PlatformScheduler.class).to(PaperScheduler.class);
|
||||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PaperUserManager.class);
|
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PaperUserManager.class);
|
||||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PaperUserManager.class);
|
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PaperUserManager.class);
|
||||||
|
this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class);
|
||||||
this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class));
|
this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ package net.draycia.carbon.paper.listeners;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
@@ -63,7 +63,7 @@ public final class PaperChatListener extends ChatListenerInternal implements Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String content = PlainTextComponentSerializer.plainText().serialize(event.message());
|
final String content = PlainTextComponentSerializer.plainText().serialize(event.message());
|
||||||
final @Nullable CarbonChatEvent chatEvent = this.prepareAndEmitChatEvent(sender, content, event.signedMessage());
|
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, content, event.signedMessage());
|
||||||
|
|
||||||
if (chatEvent == null || chatEvent.cancelled()) {
|
if (chatEvent == null || chatEvent.cancelled()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
@@ -78,7 +78,6 @@ public final class PaperChatListener extends ChatListenerInternal implements Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
event.renderer(($, $$, $$$, recipient) -> {
|
event.renderer(($, $$, $$$, recipient) -> {
|
||||||
var renderedMessage = chatEvent.message();
|
|
||||||
final var recipientUUID = recipient.get(Identity.UUID);
|
final var recipientUUID = recipient.get(Identity.UUID);
|
||||||
final Audience recipientViewer;
|
final Audience recipientViewer;
|
||||||
|
|
||||||
@@ -88,11 +87,7 @@ public final class PaperChatListener extends ChatListenerInternal implements Lis
|
|||||||
recipientViewer = recipient;
|
recipientViewer = recipient;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final var renderer : chatEvent.renderers()) {
|
return chatEvent.renderFor(recipientViewer);
|
||||||
renderedMessage = renderer.render(sender, recipientViewer, renderedMessage, event.originalMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return renderedMessage;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,14 +21,16 @@ package net.draycia.carbon.paper.messages;
|
|||||||
|
|
||||||
import com.google.common.base.Suppliers;
|
import com.google.common.base.Suppliers;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||||
import net.draycia.carbon.paper.CarbonChatPaper;
|
import net.draycia.carbon.paper.CarbonChatPaper;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
@@ -36,7 +38,6 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
@@ -47,7 +48,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
import static java.util.Objects.requireNonNull;
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class PaperMessageRenderer<T extends Audience> implements IMessageRenderer<T, String, Component, Component> {
|
@Singleton
|
||||||
|
public class PaperMessageRenderer implements CarbonMessageRenderer {
|
||||||
|
|
||||||
private final Supplier<@MonotonicNonNull PlaceholderAPIMiniMessageParser> placeholderApiProcessor = Suppliers.memoize(() -> {
|
private final Supplier<@MonotonicNonNull PlaceholderAPIMiniMessageParser> placeholderApiProcessor = Suppliers.memoize(() -> {
|
||||||
if (CarbonChatPaper.papiLoaded()) {
|
if (CarbonChatPaper.papiLoaded()) {
|
||||||
@@ -67,7 +69,7 @@ public class PaperMessageRenderer<T extends Audience> implements IMessageRendere
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component render(
|
public Component render(
|
||||||
final T receiver,
|
final Audience receiver,
|
||||||
final String intermediateMessage,
|
final String intermediateMessage,
|
||||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||||
final Method method,
|
final Method method,
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ import com.google.inject.Injector;
|
|||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.velocitypowered.api.plugin.PluginContainer;
|
import com.velocitypowered.api.plugin.PluginContainer;
|
||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import net.draycia.carbon.api.CarbonChatProvider;
|
import net.draycia.carbon.api.CarbonChatProvider;
|
||||||
@@ -44,9 +42,6 @@ import net.draycia.carbon.velocity.listeners.VelocityListener;
|
|||||||
import net.draycia.carbon.velocity.listeners.VelocityPlayerJoinListener;
|
import net.draycia.carbon.velocity.listeners.VelocityPlayerJoinListener;
|
||||||
import net.draycia.carbon.velocity.listeners.VelocityPlayerLeaveListener;
|
import net.draycia.carbon.velocity.listeners.VelocityPlayerLeaveListener;
|
||||||
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
@@ -68,12 +63,10 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
|||||||
final ProxyServer proxyServer,
|
final ProxyServer proxyServer,
|
||||||
final Injector injector,
|
final Injector injector,
|
||||||
final PluginContainer pluginContainer,
|
final PluginContainer pluginContainer,
|
||||||
@DataDirectory final Path dataDirectory,
|
|
||||||
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
||||||
final ProfileCache profileCache,
|
final ProfileCache profileCache,
|
||||||
final ProfileResolver profileResolver,
|
final ProfileResolver profileResolver,
|
||||||
final ExecutionCoordinatorHolder commandExecutor,
|
final ExecutionCoordinatorHolder commandExecutor,
|
||||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
|
||||||
final VelocityUserManager userManager,
|
final VelocityUserManager userManager,
|
||||||
final CarbonServerVelocity carbonServer,
|
final CarbonServerVelocity carbonServer,
|
||||||
final CarbonMessages carbonMessages,
|
final CarbonMessages carbonMessages,
|
||||||
@@ -82,8 +75,8 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
|||||||
final Provider<MessagingManager> messagingManager
|
final Provider<MessagingManager> messagingManager
|
||||||
) {
|
) {
|
||||||
super(
|
super(
|
||||||
injector, LogManager.getLogger(pluginContainer.getDescription().getId()),
|
injector,
|
||||||
dataDirectory,
|
LogManager.getLogger(pluginContainer.getDescription().getId()),
|
||||||
periodicTasks,
|
periodicTasks,
|
||||||
profileCache,
|
profileCache,
|
||||||
profileResolver,
|
profileResolver,
|
||||||
@@ -93,7 +86,6 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
|||||||
carbonMessages,
|
carbonMessages,
|
||||||
eventHandler,
|
eventHandler,
|
||||||
channelRegistry,
|
channelRegistry,
|
||||||
renderer,
|
|
||||||
messagingManager
|
messagingManager
|
||||||
);
|
);
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ package net.draycia.carbon.velocity;
|
|||||||
import cloud.commandframework.CommandManager;
|
import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.velocity.VelocityCommandManager;
|
import cloud.commandframework.velocity.VelocityCommandManager;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Injector;
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
@@ -33,12 +32,12 @@ import java.nio.file.Path;
|
|||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.CarbonServer;
|
import net.draycia.carbon.api.CarbonServer;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.CarbonCommonModule;
|
import net.draycia.carbon.common.CarbonCommonModule;
|
||||||
import net.draycia.carbon.common.DataDirectory;
|
import net.draycia.carbon.common.DataDirectory;
|
||||||
import net.draycia.carbon.common.PlatformScheduler;
|
import net.draycia.carbon.common.PlatformScheduler;
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.users.ProfileResolver;
|
import net.draycia.carbon.common.users.ProfileResolver;
|
||||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||||
@@ -46,9 +45,6 @@ import net.draycia.carbon.common.util.CloudUtils;
|
|||||||
import net.draycia.carbon.velocity.command.VelocityCommander;
|
import net.draycia.carbon.velocity.command.VelocityCommander;
|
||||||
import net.draycia.carbon.velocity.command.VelocityPlayerCommander;
|
import net.draycia.carbon.velocity.command.VelocityPlayerCommander;
|
||||||
import net.draycia.carbon.velocity.users.VelocityProfileResolver;
|
import net.draycia.carbon.velocity.users.VelocityProfileResolver;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -100,20 +96,6 @@ public final class CarbonChatVelocityModule extends AbstractModule {
|
|||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configure() {
|
public void configure() {
|
||||||
this.install(new CarbonCommonModule());
|
this.install(new CarbonCommonModule());
|
||||||
@@ -126,6 +108,7 @@ public final class CarbonChatVelocityModule extends AbstractModule {
|
|||||||
this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class);
|
this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class);
|
||||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(VelocityUserManager.class);
|
this.bind(new TypeLiteral<UserManager<?>>() {}).to(VelocityUserManager.class);
|
||||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(VelocityUserManager.class);
|
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(VelocityUserManager.class);
|
||||||
|
this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -20,13 +20,15 @@
|
|||||||
package net.draycia.carbon.velocity;
|
package net.draycia.carbon.velocity;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
import com.google.inject.Singleton;
|
||||||
import com.velocitypowered.api.plugin.PluginManager;
|
import com.velocitypowered.api.plugin.PluginManager;
|
||||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.draycia.carbon.api.util.SourcedAudience;
|
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
|
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||||
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
@@ -34,12 +36,12 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.moonshine.message.IMessageRenderer;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class VelocityMessageRenderer<T extends Audience> implements IMessageRenderer<T, String, Component, Component> {
|
@Singleton
|
||||||
|
public class VelocityMessageRenderer implements CarbonMessageRenderer {
|
||||||
|
|
||||||
private final ConfigFactory configFactory;
|
private final ConfigFactory configFactory;
|
||||||
private final PluginManager pluginManager;
|
private final PluginManager pluginManager;
|
||||||
@@ -52,7 +54,7 @@ public class VelocityMessageRenderer<T extends Audience> implements IMessageRend
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component render(
|
public Component render(
|
||||||
final T receiver,
|
final Audience receiver,
|
||||||
final String intermediateMessage,
|
final String intermediateMessage,
|
||||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||||
final Method method,
|
final Method method,
|
||||||
|
|||||||
+3
-11
@@ -31,16 +31,14 @@ import com.velocitypowered.api.proxy.Player;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
|
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
@@ -115,20 +113,14 @@ public final class VelocityChatListener extends ChatListenerInternal implements
|
|||||||
final CarbonPlayer sender = this.userManager.user(event.getPlayer().getUniqueId()).join();
|
final CarbonPlayer sender = this.userManager.user(event.getPlayer().getUniqueId()).join();
|
||||||
|
|
||||||
final String content = event.getResult().getMessage().orElse(event.getMessage());
|
final String content = event.getResult().getMessage().orElse(event.getMessage());
|
||||||
final @Nullable CarbonChatEvent chatEvent = this.prepareAndEmitChatEvent(sender, content, null);
|
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, content, null);
|
||||||
|
|
||||||
if (chatEvent == null || chatEvent.cancelled()) {
|
if (chatEvent == null || chatEvent.cancelled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Audience recipient : chatEvent.recipients()) {
|
for (final Audience recipient : chatEvent.recipients()) {
|
||||||
Component renderedMessage = chatEvent.message();
|
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||||
|
|
||||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
|
||||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
recipient.sendMessage(renderedMessage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user