mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Merge pull request #272 from Hexaoxide/api-cleanup
This commit is contained in:
97 files changed
+780
-1336
No files matched your search
@@ -7,7 +7,6 @@ description = "API for interfacing with the CarbonChat Minecraft mod/plugin"
|
||||
dependencies {
|
||||
// Doesn't add any dependencies, only version constraints
|
||||
api(platform(libs.adventureBom))
|
||||
api(platform(libs.log4jBom))
|
||||
|
||||
// Provided by platform
|
||||
compileOnlyApi(libs.adventureApi)
|
||||
@@ -22,5 +21,4 @@ dependencies {
|
||||
|
||||
// Provided by Minecraft
|
||||
compileOnlyApi(libs.gson)
|
||||
compileOnlyApi(libs.log4jApi)
|
||||
}
|
||||
@@ -19,17 +19,15 @@
|
||||
*/
|
||||
package net.draycia.carbon.api;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.event.CarbonEvent;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
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>On most platforms, you should use the provided load order mechanism to ensure your addon loads after
|
||||
@@ -43,33 +41,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
public interface CarbonChat {
|
||||
|
||||
/**
|
||||
* The server's ID, used for cross-server message handling.
|
||||
*
|
||||
* @return the server id
|
||||
* @since 2.1.0
|
||||
*/
|
||||
UUID serverId();
|
||||
|
||||
/**
|
||||
* The plugin's logger.<br>
|
||||
* All messages will be logged through this.
|
||||
*
|
||||
* @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.
|
||||
* The {@link CarbonEventHandler event handler}, used for listening to
|
||||
* and emitting {@link CarbonEvent events}.
|
||||
*
|
||||
* @return the event handler
|
||||
* @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.Nullable;
|
||||
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
|
||||
*/
|
||||
@@ -43,6 +44,7 @@ public final class CarbonChatProvider {
|
||||
* @param carbonChat the carbon implementation
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void register(final CarbonChat carbonChat) {
|
||||
CarbonChatProvider.instance = carbonChat;
|
||||
}
|
||||
@@ -55,7 +57,7 @@ public final class CarbonChatProvider {
|
||||
*/
|
||||
public static CarbonChat carbonChat() {
|
||||
if (CarbonChatProvider.instance == null) {
|
||||
throw new IllegalStateException("CarbonChat not initialized!"); // LuckPerms design go brrrr
|
||||
throw new IllegalStateException("CarbonChat not initialized!");
|
||||
}
|
||||
|
||||
return CarbonChatProvider.instance;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import net.kyori.adventure.key.Key;
|
||||
@@ -26,7 +27,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Registry for chat channels.
|
||||
* Registry for {@link ChatChannel chat channels}.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@@ -40,19 +41,20 @@ public interface ChannelRegistry {
|
||||
* @param channel the channel to register
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void register(final ChatChannel channel);
|
||||
void register(ChatChannel channel);
|
||||
|
||||
/**
|
||||
* Gets the channel with the matching key.
|
||||
* Retrieve a channel by its key. If there is no matching channel,
|
||||
* returns {@code null}.
|
||||
*
|
||||
* @param key the channel's key
|
||||
* @return the channel
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Nullable ChatChannel channel(final Key key);
|
||||
@Nullable ChatChannel channel(Key key);
|
||||
|
||||
/**
|
||||
* Gets the default key.
|
||||
* Gets the key for the default channel.
|
||||
*
|
||||
* @return the default key
|
||||
* @since 2.1.0
|
||||
@@ -60,7 +62,7 @@ public interface ChannelRegistry {
|
||||
@NonNull Key defaultKey();
|
||||
|
||||
/**
|
||||
* Gets the default value.
|
||||
* Gets the default channel.
|
||||
*
|
||||
* @return the default value
|
||||
* @since 2.1.0
|
||||
@@ -76,13 +78,25 @@ public interface ChannelRegistry {
|
||||
@NonNull Set<Key> keys();
|
||||
|
||||
/**
|
||||
* Gets the channel with the matching key, otherwise the default channel.
|
||||
* Retrieve a channel by its key. If there is no matching channel,
|
||||
* returns {@link #defaultChannel() the default channel}.
|
||||
*
|
||||
* @param key the channel key
|
||||
* @return the channel, or the default one
|
||||
* @since 2.1.0
|
||||
*/
|
||||
ChatChannel keyOrDefault(final Key key);
|
||||
ChatChannel channelOrDefault(Key key);
|
||||
|
||||
/**
|
||||
* Retrieve a channel by its key. If there is no matching channel,
|
||||
* throws {@link NoSuchElementException}.
|
||||
*
|
||||
* @param key channel key
|
||||
* @return channel
|
||||
* @throws NoSuchElementException when no matching channel is found
|
||||
* @since 2.1.0
|
||||
*/
|
||||
ChatChannel channelOrThrow(Key key);
|
||||
|
||||
/**
|
||||
* The provided action will be executed immediately for all currently registered
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
||||
@@ -50,7 +49,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||
* @return if the player may speak
|
||||
* @since 2.0.0
|
||||
*/
|
||||
ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer);
|
||||
ChannelPermissionResult speechPermitted(CarbonPlayer carbonPlayer);
|
||||
|
||||
/**
|
||||
* Checks if the player may receive messages from this channel.
|
||||
@@ -59,7 +58,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||
* @return if the player may receive messages
|
||||
* @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.
|
||||
@@ -68,17 +67,7 @@ public interface ChatChannel extends Keyed, ChatComponentRenderer {
|
||||
* @return the recipients
|
||||
* @since 2.0.0
|
||||
*/
|
||||
List<Audience> recipients(final CarbonPlayer sender);
|
||||
|
||||
/**
|
||||
* Filters the given recipients and removes entries that may not see messages in this channel.
|
||||
*
|
||||
* @param sender the sender of messages
|
||||
* @param recipients the recipients
|
||||
* @return the recipients that may receive messages
|
||||
* @since 2.0.0
|
||||
*/
|
||||
Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients);
|
||||
List<Audience> recipients(CarbonPlayer sender);
|
||||
|
||||
/**
|
||||
* Messages will be sent in this channel if they start with this prefix.
|
||||
|
||||
@@ -37,9 +37,9 @@ public interface Cancellable {
|
||||
/**
|
||||
* Sets the cancelled state.
|
||||
*
|
||||
* @param cancelled sets the cancelled state
|
||||
* @param cancelled new cancelled state
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void cancelled(final boolean cancelled);
|
||||
void cancelled(boolean cancelled);
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
package net.draycia.carbon.api.event;
|
||||
|
||||
/**
|
||||
* Interface to represent that an event belongs to carbon.
|
||||
* Marker interface for events.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,8 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
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
|
||||
*/
|
||||
@@ -40,8 +41,8 @@ public interface CarbonEventHandler {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
||||
final Class<T> eventClass,
|
||||
final CarbonEventSubscriber<T> subscriber
|
||||
Class<T> eventClass,
|
||||
CarbonEventSubscriber<T> subscriber
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -57,21 +58,22 @@ public interface CarbonEventHandler {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
<T extends CarbonEvent> CarbonEventSubscription<T> subscribe(
|
||||
final Class<T> eventClass,
|
||||
final int order,
|
||||
final boolean acceptsCancelled,
|
||||
final CarbonEventSubscriber<T> subscriber
|
||||
Class<T> eventClass,
|
||||
int order,
|
||||
boolean acceptsCancelled,
|
||||
CarbonEventSubscriber<T> subscriber
|
||||
);
|
||||
|
||||
/**
|
||||
* Emits the supplied event.<br>
|
||||
* Events are modified in place, so care should be taken to keep a reference to
|
||||
* the event while it's being emitted.
|
||||
* Emits the supplied event.
|
||||
*
|
||||
* <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 <T> the class to emit
|
||||
* @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.framework.qual.DefaultQualifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* An EventSubscriber.
|
||||
@@ -39,6 +38,6 @@ public interface CarbonEventSubscriber<T extends CarbonEvent> {
|
||||
* @throws Throwable if an exception is thrown
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* An EventSubscription.
|
||||
* A subscription to a specific event type.
|
||||
*
|
||||
* @param <T> CarbonEvent implementations
|
||||
* @param <T> event type
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@@ -40,11 +40,20 @@ public interface CarbonEventSubscription<T extends CarbonEvent> {
|
||||
Class<T> event();
|
||||
|
||||
/**
|
||||
* Gets the subscriber.
|
||||
* Gets the {@link CarbonEventSubscriber subscriber}.
|
||||
*
|
||||
* @return the subscriber
|
||||
* @since 2.1.0
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <p>Note that some invocations of this event may be too early for
|
||||
* API consumers to be notified. Prefer using {@link ChannelRegistry#allKeys(Consumer)}
|
||||
* when knowledge of all registered channels is needed.</p>
|
||||
* API consumers to be notified. {@link ChannelRegistry#allKeys(Consumer)}
|
||||
* is provided as a helper for when knowledge of all registered channels
|
||||
* is needed.</p>
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
|
||||
@@ -41,9 +41,10 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
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
|
||||
*/
|
||||
List<KeyedRenderer> renderers();
|
||||
|
||||
@@ -41,7 +41,7 @@ public interface CarbonPrivateChatEvent extends CarbonEvent, Cancellable {
|
||||
* @throws NullPointerException if message is null
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void message(final Component message);
|
||||
void message(Component message);
|
||||
|
||||
/**
|
||||
* The message that will be sent.
|
||||
|
||||
@@ -21,13 +21,11 @@ package net.draycia.carbon.api.users;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
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;
|
||||
@@ -42,23 +40,6 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface CarbonPlayer extends Audience, Identified {
|
||||
|
||||
CarbonPlayer EMPTY = new EmptyCarbonPlayer();
|
||||
|
||||
/**
|
||||
* Returns the appropriate {@link Component} to represent the player's name.
|
||||
*
|
||||
* @param player the player
|
||||
* @return the player's name
|
||||
* @since 2.0.0
|
||||
*/
|
||||
static Component renderName(final CarbonPlayer player) {
|
||||
if (player.hasCustomDisplayName()) {
|
||||
return Objects.requireNonNull(player.displayName());
|
||||
} else {
|
||||
return player.get(Identity.DISPLAY_NAME).orElseGet(() -> Component.text(player.username()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the distance from the other {@link CarbonPlayer}, or -1 if the players are not in the same world.
|
||||
*
|
||||
@@ -66,7 +47,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return the distance from the other player, or -1
|
||||
* @since 2.1.0
|
||||
*/
|
||||
double distanceSquaredFrom(final CarbonPlayer other);
|
||||
double distanceSquaredFrom(CarbonPlayer other);
|
||||
|
||||
/**
|
||||
* Returns if both players are in the same world or server.
|
||||
@@ -75,7 +56,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return if both players are in the same world/server
|
||||
* @since 2.1.0
|
||||
*/
|
||||
boolean sameWorldAs(final CarbonPlayer other);
|
||||
boolean sameWorldAs(CarbonPlayer other);
|
||||
|
||||
/**
|
||||
* Gets the player's username.
|
||||
@@ -86,41 +67,56 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
String username();
|
||||
|
||||
/**
|
||||
* Checks if the player has a display name set.
|
||||
* Returns the player's display name.
|
||||
*
|
||||
* <p>The display name is the effective or displayed name of a player.
|
||||
* When the player has a nickname set, either through Carbon or the platform,
|
||||
* it will be reflected here. Else, a plain text component representing
|
||||
* the player's name may be returned.</p>
|
||||
*
|
||||
* @return the player's display name
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Component displayName();
|
||||
|
||||
/**
|
||||
* Checks if the player has a nickname set.
|
||||
*
|
||||
* <p>Will always return {@code false} when Carbon's nickname management is disabled.</p>
|
||||
*
|
||||
* @return if the player has a custom display name set
|
||||
* @see #displayName()
|
||||
* @see #displayName(Component)
|
||||
* @since 2.0.0
|
||||
* @return if the player has a nickname set
|
||||
* @see #nickname()
|
||||
* @see #nickname(Component)
|
||||
* @since 2.1.0
|
||||
*/
|
||||
boolean hasCustomDisplayName();
|
||||
boolean hasNickname();
|
||||
|
||||
/**
|
||||
* Gets the player's display name, shown in places like chat and tab menu.
|
||||
* Gets the player's nickname, shown in places like chat and tab menu.
|
||||
*
|
||||
* <p>Will always return {@code null} when Carbon's nickname management is disabled.</p>
|
||||
*
|
||||
* @return the player's display name
|
||||
* @see #hasCustomDisplayName()
|
||||
* @see #displayName(Component)
|
||||
* @since 2.0.0
|
||||
* @return the player's nickname
|
||||
* @see #hasNickname()
|
||||
* @see #nickname(Component)
|
||||
* @see #displayName()
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@Nullable Component displayName();
|
||||
@Nullable Component nickname();
|
||||
|
||||
/**
|
||||
* Sets the player's display name.
|
||||
* Sets the player's nickname.
|
||||
*
|
||||
* <p>Setting {@code null} is equivalent to setting the display name to the username.</p>
|
||||
* <p>Setting {@code null} will remove any current nickname.</p>
|
||||
* <p>Won't have any visible effect when Carbon's nickname management is disabled.</p>
|
||||
*
|
||||
* @param displayName the new display name
|
||||
* @param nickname the new nickname
|
||||
* @see #hasNickname()
|
||||
* @see #nickname()
|
||||
* @see #displayName()
|
||||
* @see #hasCustomDisplayName()
|
||||
* @since 2.0.0
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void displayName(final @Nullable Component displayName);
|
||||
void nickname(@Nullable Component nickname);
|
||||
|
||||
/**
|
||||
* The player's UUID, often used for identification purposes.
|
||||
@@ -137,7 +133,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return the chat component for the item in the slot, or null if the slot is empty
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Nullable Component createItemHoverComponent(final InventorySlot slot);
|
||||
@Nullable Component createItemHoverComponent(InventorySlot slot);
|
||||
|
||||
/**
|
||||
* The player's locale.
|
||||
@@ -161,7 +157,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param chatChannel the channel
|
||||
* @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.
|
||||
@@ -170,7 +166,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return the channel and message
|
||||
* @since 2.1.0
|
||||
*/
|
||||
ChannelMessage channelForMessage(final Component message);
|
||||
ChannelMessage channelForMessage(Component message);
|
||||
|
||||
/**
|
||||
* A message and which channel it should be sent in.
|
||||
@@ -188,7 +184,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return if the player has the permission
|
||||
* @since 2.0.0
|
||||
*/
|
||||
boolean hasPermission(final String permission);
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
/**
|
||||
* Returns the player's primary group.
|
||||
@@ -229,7 +225,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return if this player is ignoring the sender
|
||||
* @since 2.0.5
|
||||
*/
|
||||
boolean ignoring(final UUID player);
|
||||
boolean ignoring(UUID player);
|
||||
|
||||
/**
|
||||
* Checks if the other player is being ignored by this player.
|
||||
@@ -238,7 +234,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return if this player is ignoring the sender
|
||||
* @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.
|
||||
@@ -247,7 +243,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param nowIgnoring if the player should be ignored
|
||||
* @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.
|
||||
@@ -256,7 +252,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param nowIgnoring if the player should be ignored
|
||||
* @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.
|
||||
@@ -271,7 +267,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*
|
||||
* @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.
|
||||
@@ -286,7 +282,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void spying(final boolean spying);
|
||||
void spying(boolean spying);
|
||||
|
||||
/**
|
||||
* Sends the message as the player.
|
||||
@@ -294,7 +290,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param message the message to be sent
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void sendMessageAsPlayer(final String message);
|
||||
void sendMessageAsPlayer(String message);
|
||||
|
||||
/**
|
||||
* Returns whether the player is online.
|
||||
@@ -318,7 +314,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param uuid the uuid of the reply target
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void whisperReplyTarget(final @Nullable UUID uuid);
|
||||
void whisperReplyTarget(@Nullable UUID uuid);
|
||||
|
||||
/**
|
||||
* The last player this player has whispered.
|
||||
@@ -334,7 +330,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param uuid the uuid of the whisper target
|
||||
* @since 2.0.0
|
||||
*/
|
||||
void lastWhisperTarget(final @Nullable UUID uuid);
|
||||
void lastWhisperTarget(@Nullable UUID uuid);
|
||||
|
||||
/**
|
||||
* If this player is vanished in another supported plugin.
|
||||
@@ -353,7 +349,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @return if this player is aware of the other player
|
||||
* @since 2.0.0
|
||||
*/
|
||||
boolean awareOf(final CarbonPlayer other);
|
||||
boolean awareOf(CarbonPlayer other);
|
||||
|
||||
/**
|
||||
* A list of all the channels the player has left
|
||||
@@ -373,7 +369,7 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param channel the channel to join.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void joinChannel(final ChatChannel channel);
|
||||
void joinChannel(ChatChannel channel);
|
||||
|
||||
/**
|
||||
* Leave a channel for this player.
|
||||
@@ -381,6 +377,6 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
* @param channel the channel to leave.
|
||||
* @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 org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@NotNull
|
||||
Component render(final CarbonPlayer sender,
|
||||
final Audience recipient,
|
||||
final Component message,
|
||||
final Component originalMessage);
|
||||
Component render(CarbonPlayer sender,
|
||||
Audience recipient,
|
||||
Component message,
|
||||
Component originalMessage);
|
||||
|
||||
}
|
||||
@@ -39,11 +39,7 @@ public final class InventorySlot {
|
||||
return new InventorySlot(placeholders);
|
||||
}
|
||||
|
||||
private List<String> placeholders;
|
||||
|
||||
private InventorySlot() {
|
||||
|
||||
}
|
||||
private final List<String> placeholders;
|
||||
|
||||
private InventorySlot(final String... placeholders) {
|
||||
this.placeholders = List.of(placeholders);
|
||||
|
||||
@@ -19,17 +19,13 @@
|
||||
*/
|
||||
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.Keyed;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
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
|
||||
*/
|
||||
@@ -45,26 +41,7 @@ public interface KeyedRenderer extends Keyed, ChatComponentRenderer {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
static KeyedRenderer keyedRenderer(final Key key, final ChatComponentRenderer renderer) {
|
||||
return new Impl(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);
|
||||
}
|
||||
|
||||
return new KeyedRendererImpl(key, renderer);
|
||||
}
|
||||
|
||||
}
|
||||
+14
-22
@@ -19,32 +19,24 @@
|
||||
*/
|
||||
package net.draycia.carbon.api.util;
|
||||
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
/**
|
||||
* An audience, where messages are sent from another Audience.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
@DefaultQualifier(NonNull.class)
|
||||
record KeyedRendererImpl(Key key, ChatComponentRenderer renderer) implements KeyedRenderer {
|
||||
|
||||
@Override
|
||||
public @NotNull Audience audience() {
|
||||
return this.recipient;
|
||||
public Component render(
|
||||
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 {
|
||||
id("carbon.base-conventions")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.carbonchatApi)
|
||||
compileOnlyApi(platform(libs.log4jBom))
|
||||
compileOnlyApi(libs.log4jApi)
|
||||
|
||||
// Configs
|
||||
api(libs.configurateHocon)
|
||||
|
||||
@@ -23,17 +23,15 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.listeners.Listener;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
@@ -44,9 +42,6 @@ import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
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 org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -54,44 +49,37 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public abstract class CarbonChatInternal<C extends CarbonPlayer> implements CarbonChat {
|
||||
public abstract class CarbonChatInternal implements CarbonChat {
|
||||
|
||||
private final UUID serverId;
|
||||
private final Injector injector;
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final ScheduledExecutorService periodicTasks;
|
||||
private final ProfileCache profileCache;
|
||||
private final ProfileResolver profileResolver;
|
||||
private final UserManagerInternal<C> userManager;
|
||||
private final UserManagerInternal<?> userManager;
|
||||
private final ExecutionCoordinatorHolder commandExecutor;
|
||||
private final CarbonServer carbonServer;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final CarbonEventHandler eventHandler;
|
||||
private final CarbonChannelRegistry channelRegistry;
|
||||
private final IMessageRenderer<Audience, String, Component, Component> renderer;
|
||||
private final Provider<MessagingManager> messagingManager;
|
||||
|
||||
protected CarbonChatInternal(
|
||||
final Injector injector,
|
||||
final Logger logger,
|
||||
final Path dataDirectory,
|
||||
final ScheduledExecutorService periodicTasks,
|
||||
final ProfileCache profileCache,
|
||||
final ProfileResolver profileResolver,
|
||||
final UserManagerInternal<C> userManager,
|
||||
final UserManagerInternal<?> userManager,
|
||||
final ExecutionCoordinatorHolder commandExecutor,
|
||||
final CarbonServer carbonServer,
|
||||
final CarbonMessages carbonMessages,
|
||||
final CarbonEventHandler eventHandler,
|
||||
final CarbonChannelRegistry channelRegistry,
|
||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
||||
final Provider<MessagingManager> messagingManagerProvider
|
||||
) {
|
||||
this.serverId = UUID.randomUUID();
|
||||
this.injector = injector;
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
this.periodicTasks = periodicTasks;
|
||||
this.profileCache = profileCache;
|
||||
this.profileResolver = profileResolver;
|
||||
@@ -101,7 +89,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.eventHandler = eventHandler;
|
||||
this.channelRegistry = channelRegistry;
|
||||
this.renderer = renderer;
|
||||
this.messagingManager = messagingManagerProvider;
|
||||
}
|
||||
|
||||
@@ -150,17 +137,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
||||
this.commandExecutor.shutdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID serverId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path dataDirectory() {
|
||||
return this.dataDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Logger logger() {
|
||||
return this.logger;
|
||||
}
|
||||
@@ -171,7 +147,7 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserManagerInternal<C> userManager() {
|
||||
public UserManager<?> userManager() {
|
||||
return this.userManager;
|
||||
}
|
||||
|
||||
@@ -185,11 +161,6 @@ public abstract class CarbonChatInternal<C extends CarbonPlayer> implements Carb
|
||||
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() {
|
||||
return this.messagingManager.get().packetService();
|
||||
}
|
||||
|
||||
@@ -36,10 +36,11 @@ import java.util.UUID;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.event.CarbonEventHandlerImpl;
|
||||
import net.draycia.carbon.common.listeners.DeafenHandler;
|
||||
@@ -51,6 +52,7 @@ import net.draycia.carbon.common.listeners.MessagePacketHandler;
|
||||
import net.draycia.carbon.common.listeners.MuteHandler;
|
||||
import net.draycia.carbon.common.listeners.PingHandler;
|
||||
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.CarbonMessageSource;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
@@ -61,10 +63,12 @@ import net.draycia.carbon.common.messages.placeholders.ComponentPlaceholderResol
|
||||
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import net.draycia.carbon.common.messaging.packets.PacketFactory;
|
||||
import net.draycia.carbon.common.users.Backing;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.NetworkUsers;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.common.users.db.mysql.MySQLUserManager;
|
||||
import net.draycia.carbon.common.users.db.postgresql.PostgreSQLUserManager;
|
||||
@@ -76,7 +80,6 @@ import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.Moonshine;
|
||||
import net.kyori.moonshine.exception.scan.UnscannableMethodException;
|
||||
import net.kyori.moonshine.message.IMessageRenderer;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -113,7 +116,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
final BooleanPlaceholderResolver<Audience> booleanPlaceholderResolver,
|
||||
final CarbonMessageSource carbonMessageSource,
|
||||
final CarbonMessageSender carbonMessageSender,
|
||||
final IMessageRenderer<Audience, String, Component, Component> messageRenderer
|
||||
final CarbonMessageRenderer messageRenderer
|
||||
) throws UnscannableMethodException {
|
||||
return Moonshine.<CarbonMessages, Audience>builder(new TypeToken<>() {})
|
||||
.receiverLocatorResolver(receiverResolver, 0)
|
||||
@@ -139,9 +142,12 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
protected void configure() {
|
||||
this.install(new FactoryModuleBuilder().build(ArgumentFactory.class));
|
||||
this.install(factoryModule(PacketFactory.class));
|
||||
this.bind(ServerId.KEY).toInstance(UUID.randomUUID());
|
||||
this.bind(ChannelRegistry.class).to(CarbonChannelRegistry.class);
|
||||
this.bind(CarbonEventHandler.class).to(CarbonEventHandlerImpl.class);
|
||||
this.bind(PlayerSuggestions.class).to(NetworkUsers.class);
|
||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PlatformUserManager.class);
|
||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PlatformUserManager.class);
|
||||
|
||||
final Multibinder<Listener> listeners = Multibinder.newSetBinder(this.binder(), Listener.class);
|
||||
listeners.addBinding().to(DeafenHandler.class);
|
||||
|
||||
@@ -1,178 +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.common.channels;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
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;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class BasicChatChannel implements ChatChannel {
|
||||
|
||||
private final Key key = Key.key("carbon", "basic");
|
||||
|
||||
private final CarbonMessages service;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@Inject
|
||||
private BasicChatChannel(
|
||||
final CarbonMessages service,
|
||||
final CarbonChat carbonChat
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component render(
|
||||
final CarbonPlayer sender,
|
||||
final Audience recipient,
|
||||
final Component message,
|
||||
final Component originalMessage
|
||||
) {
|
||||
return this.service.basicChatFormat(
|
||||
recipient,
|
||||
sender.uuid(),
|
||||
CarbonPlayer.renderName(sender),
|
||||
sender.username(),
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String quickPrefix() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRegisterCommands() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String commandName() {
|
||||
return "basic";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> commandAliases() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String permission() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double radius() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emptyRadiusRecipientsMessage() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return ChannelPermissionResult.allowedIf(Component.empty(), () -> !player.leftChannels().contains(this.key));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Audience> recipients(final CarbonPlayer sender) {
|
||||
final List<Audience> recipients = new ArrayList<>();
|
||||
|
||||
for (final CarbonPlayer player : this.carbonChat.server().players()) {
|
||||
if (this.hearingPermitted(player).permitted()) {
|
||||
recipients.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
// console too!
|
||||
recipients.add(this.carbonChat.server().console());
|
||||
|
||||
return recipients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients) {
|
||||
recipients.removeIf(it -> !this.hearingPermitted(it).permitted());
|
||||
|
||||
return recipients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Key key() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (!(other instanceof BasicChatChannel otherChannel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(otherChannel.commandName().equals(this.commandName()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(Objects.equals(otherChannel.quickPrefix(), this.quickPrefix()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(Objects.equals(otherChannel.permission(), this.permission()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (otherChannel.radius() != this.radius()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return otherChannel.key().equals(this.key());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.commandName(), this.quickPrefix(), this.permission(), this.radius(), this.key());
|
||||
}
|
||||
|
||||
}
|
||||
+18
-15
@@ -26,7 +26,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.seiama.event.EventConfig;
|
||||
import com.seiama.registry.Holder;
|
||||
import com.seiama.registry.Registry;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -34,6 +34,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -44,13 +45,12 @@ import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
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.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||
import net.draycia.carbon.common.event.events.CarbonReloadEvent;
|
||||
import net.draycia.carbon.common.event.events.ChannelRegisterEventImpl;
|
||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||
@@ -60,7 +60,6 @@ import net.draycia.carbon.common.util.Exceptions;
|
||||
import net.draycia.carbon.common.util.FileUtil;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -118,7 +117,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
this.carbonMessages = carbonMessages;
|
||||
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() {
|
||||
@@ -309,20 +308,14 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
final List<Audience> recipients,
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Audience recipient : recipients) {
|
||||
Component renderedMessage = chatEvent.message();
|
||||
|
||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
||||
}
|
||||
|
||||
recipient.sendMessage(renderedMessage);
|
||||
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,7 +408,8 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel channel(final Key key) {
|
||||
return this.channelRegistry.getOrCreateHolder(key).value();
|
||||
final @Nullable Holder<ChatChannel> holder = this.channelRegistry.getHolder(key);
|
||||
return holder == null ? null : holder.value();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel channelByValue(final String value) {
|
||||
@@ -448,7 +442,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel keyOrDefault(final Key key) {
|
||||
public ChatChannel channelOrDefault(final Key key) {
|
||||
final @Nullable ChatChannel channel = this.channel(key);
|
||||
|
||||
if (channel != null) {
|
||||
@@ -458,6 +452,15 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
|
||||
return this.defaultChannel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatChannel channelOrThrow(final Key key) {
|
||||
final @Nullable ChatChannel channel = this.channel(key);
|
||||
if (channel != null) {
|
||||
return channel;
|
||||
}
|
||||
throw new NoSuchElementException("No channel registered with key '" + key.asString() + "'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void allKeys(final Consumer<Key> action) {
|
||||
for (final Key key : this.channelRegistry.keys()) {
|
||||
|
||||
@@ -25,15 +25,14 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
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.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.draycia.carbon.common.CarbonChatInternal;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessages;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||
import net.draycia.carbon.common.messages.SourcedMessageSender;
|
||||
import net.draycia.carbon.common.messages.SourcedReceiverResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
|
||||
@@ -41,6 +40,7 @@ import net.draycia.carbon.common.messages.placeholders.ComponentPlaceholderResol
|
||||
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
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.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -65,7 +65,8 @@ import static net.kyori.adventure.text.Component.text;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
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("""
|
||||
The channel's key, used to track the channel.
|
||||
@@ -144,10 +145,10 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
final Component originalMessage
|
||||
) {
|
||||
return this.carbonMessages().chatFormat(
|
||||
new SourcedAudience(sender, recipient),
|
||||
SourcedAudience.of(sender, recipient),
|
||||
sender.uuid(),
|
||||
this.key(),
|
||||
Objects.requireNonNull(CarbonPlayer.renderName(sender)),
|
||||
sender.displayName(),
|
||||
sender.username(),
|
||||
message
|
||||
);
|
||||
@@ -168,25 +169,14 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
public List<Audience> recipients(final CarbonPlayer sender) {
|
||||
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()) {
|
||||
recipients.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
// console too!
|
||||
recipients.add(this.carbonChat.server().console());
|
||||
|
||||
return recipients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CarbonPlayer> filterRecipients(final CarbonPlayer sender, final Set<CarbonPlayer> recipients) {
|
||||
try {
|
||||
recipients.removeIf(it -> !this.hearingPermitted(it).permitted());
|
||||
} catch (final UnsupportedOperationException ignored) {
|
||||
|
||||
}
|
||||
recipients.add(this.server.console());
|
||||
|
||||
return recipients;
|
||||
}
|
||||
@@ -197,10 +187,10 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
}
|
||||
|
||||
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 ComponentPlaceholderResolver<SourcedAudience> componentPlaceholderResolver = new ComponentPlaceholderResolver<>();
|
||||
final UUIDPlaceholderResolver<SourcedAudience> uuidPlaceholderResolver = new UUIDPlaceholderResolver<>();
|
||||
@@ -213,7 +203,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
return Moonshine.<ConfigChannelMessages, SourcedAudience>builder(new TypeToken<ConfigChannelMessages>() {})
|
||||
.receiverLocatorResolver(serverReceiverResolver, 0)
|
||||
.sourced(this.messageSource)
|
||||
.rendered(((CarbonChatInternal<?>) this.carbonChat).messageRenderer())
|
||||
.rendered(this.renderer.asSourced())
|
||||
.sent(carbonMessageSender)
|
||||
.resolvingWithStrategy(new StandardPlaceholderResolverStrategy<>(new StandardSupertypeThenInterfaceSupertypeStrategy(false)))
|
||||
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
|
||||
@@ -223,10 +213,8 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||
.create(this.getClass().getClassLoader());
|
||||
} catch (final UnscannableMethodException e) {
|
||||
e.printStackTrace();
|
||||
throw Exceptions.rethrow(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private ConfigChannelMessages carbonMessages() {
|
||||
@@ -258,32 +246,15 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object other) {
|
||||
if (!(other instanceof BasicChatChannel otherChannel)) {
|
||||
if (!(other instanceof ConfigChatChannel otherChannel)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(otherChannel.commandName().equals(this.commandName()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(Objects.equals(otherChannel.quickPrefix(), this.quickPrefix()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(Objects.equals(otherChannel.permission(), this.permission()))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (otherChannel.radius() != this.radius()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return otherChannel.key().equals(this.key());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.commandName(), this.quickPrefix(), this.permission(), this.radius(), this.key());
|
||||
return Objects.hash(this.key());
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -23,7 +23,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
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.kyori.adventure.audience.Audience;
|
||||
import net.kyori.moonshine.message.IMessageSource;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
package net.draycia.carbon.common.channels.messages;
|
||||
|
||||
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.text.Component;
|
||||
import net.kyori.moonshine.annotation.Message;
|
||||
|
||||
+1
-2
@@ -17,7 +17,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.draycia.carbon.common.command.commands;
|
||||
package net.draycia.carbon.common.command;
|
||||
|
||||
import cloud.commandframework.CommandTree;
|
||||
import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator;
|
||||
@@ -26,7 +26,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.util.ConcurrentUtil;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+11
-12
@@ -22,8 +22,7 @@ package net.draycia.carbon.common.command.commands;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
@@ -36,21 +35,21 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ClearChatCommand extends CarbonCommand {
|
||||
public final class ClearChatCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final ConfigFactory configFactory;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CarbonServer server;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final ConfigFactory configFactory;
|
||||
private final CarbonMessages carbonMessages;
|
||||
|
||||
@Inject
|
||||
public ClearChatCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final CarbonServer server,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final ConfigFactory configFactory,
|
||||
final CarbonMessages carbonMessages
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.server = server;
|
||||
this.commandManager = commandManager;
|
||||
this.configFactory = configFactory;
|
||||
this.carbonMessages = carbonMessages;
|
||||
@@ -76,7 +75,7 @@ public class ClearChatCommand extends CarbonCommand {
|
||||
// Not fond of having to send 50 messages to each player
|
||||
// Are we not able to just paste in 50 newlines and call it a day?
|
||||
for (int i = 0; i < this.configFactory.primaryConfig().clearChatSettings().iterations(); i++) {
|
||||
for (final var player : this.carbonChat.server().players()) {
|
||||
for (final var player : this.server.players()) {
|
||||
if (!player.hasPermission("carbon.clearchat.exempt")) {
|
||||
player.sendMessage(this.configFactory.primaryConfig().clearChatSettings().message());
|
||||
}
|
||||
@@ -87,14 +86,14 @@ public class ClearChatCommand extends CarbonCommand {
|
||||
final String username;
|
||||
|
||||
if (handler.getSender() instanceof PlayerCommander player) {
|
||||
senderName = CarbonPlayer.renderName(player.carbonPlayer());
|
||||
senderName = player.carbonPlayer().displayName();
|
||||
username = player.carbonPlayer().username();
|
||||
} else {
|
||||
senderName = Component.text("Console");
|
||||
username = "Console";
|
||||
}
|
||||
|
||||
this.carbonChat.server().sendMessage(this.configFactory.primaryConfig().clearChatSettings()
|
||||
this.server.sendMessage(this.configFactory.primaryConfig().clearChatSettings()
|
||||
.broadcast(senderName, username));
|
||||
})
|
||||
.build();
|
||||
|
||||
+11
-15
@@ -25,40 +25,37 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ContinueCommand extends CarbonCommand {
|
||||
public final class ContinueCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
final ConfigFactory configFactory;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final WhisperCommand.WhisperHandler whisper;
|
||||
|
||||
@Inject
|
||||
public ContinueCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ConfigFactory configFactory,
|
||||
final WhisperCommand.WhisperHandler whisper
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.configFactory = configFactory;
|
||||
this.whisper = whisper;
|
||||
}
|
||||
|
||||
@@ -89,15 +86,14 @@ public class ContinueCommand extends CarbonCommand {
|
||||
}
|
||||
|
||||
final String message = ctx.get("message");
|
||||
final UUID whisperTarget = sender.lastWhisperTarget();
|
||||
final @Nullable UUID whisperTarget = sender.lastWhisperTarget();
|
||||
|
||||
if (whisperTarget == null) {
|
||||
this.carbonMessages.whisperTargetNotSet(sender, CarbonPlayer.renderName(sender));
|
||||
this.carbonMessages.whisperTargetNotSet(sender, sender.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
final @MonotonicNonNull CarbonPlayer recipient = this.carbonChat
|
||||
.userManager().user(whisperTarget).join();
|
||||
final @MonotonicNonNull CarbonPlayer recipient = this.users.user(whisperTarget).join();
|
||||
|
||||
this.whisper.whisper(sender, recipient, message);
|
||||
})
|
||||
|
||||
@@ -39,10 +39,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class DebugCommand extends CarbonCommand {
|
||||
public final class DebugCommand extends CarbonCommand {
|
||||
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
|
||||
@@ -49,9 +49,9 @@ import static net.kyori.adventure.text.format.TextColor.color;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class HelpCommand extends CarbonCommand {
|
||||
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
final MinecraftHelp<Commander> minecraftHelp;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final MinecraftHelp<Commander> minecraftHelp;
|
||||
|
||||
@Inject
|
||||
public HelpCommand(
|
||||
|
||||
+11
-11
@@ -24,8 +24,8 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
@@ -37,21 +37,21 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class IgnoreCommand extends CarbonCommand {
|
||||
public final class IgnoreCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
public IgnoreCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
@@ -87,24 +87,24 @@ public class IgnoreCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
target = this.carbonChat.userManager().user(handler.get("uuid")).join();
|
||||
target = this.users.user(handler.get("uuid")).join();
|
||||
} else {
|
||||
this.carbonMessages.ignoreTargetInvalid(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.hasPermission("carbon.ignore.exempt")) {
|
||||
this.carbonMessages.ignoreExempt(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.ignoreExempt(sender, target.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.ignoring(target)) {
|
||||
this.carbonMessages.alreadyIgnored(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.alreadyIgnored(sender, target.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
sender.ignoring(target, true);
|
||||
this.carbonMessages.nowIgnoring(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.nowIgnoring(sender, target.displayName());
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
@@ -38,11 +38,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class JoinCommand extends CarbonCommand {
|
||||
public final class JoinCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChannelRegistry channelRegistry;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CarbonChannelRegistry channelRegistry;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
|
||||
@Inject
|
||||
public JoinCommand(
|
||||
|
||||
@@ -38,11 +38,11 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class LeaveCommand extends CarbonCommand {
|
||||
public final class LeaveCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChannelRegistry channelRegistry;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CarbonChannelRegistry channelRegistry;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
|
||||
@Inject
|
||||
public LeaveCommand(
|
||||
|
||||
@@ -24,8 +24,9 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
@@ -37,21 +38,24 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class MuteCommand extends CarbonCommand {
|
||||
public final class MuteCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CarbonServer server;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
public MuteCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CarbonServer server,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.server = server;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
@@ -87,7 +91,7 @@ public class MuteCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
target = this.carbonChat.userManager().user(handler.get("uuid")).join();
|
||||
target = this.users.user(handler.get("uuid")).join();
|
||||
} else {
|
||||
this.carbonMessages.muteNoTarget(sender);
|
||||
// TODO: send command syntax
|
||||
@@ -102,15 +106,15 @@ public class MuteCommand extends CarbonCommand {
|
||||
this.carbonMessages.muteAlertRecipient(target);
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
this.carbonMessages.muteAlertPlayers(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.muteAlertPlayers(sender, target.displayName());
|
||||
}
|
||||
|
||||
for (final var player : this.carbonChat.server().players()) {
|
||||
for (final var player : this.server.players()) {
|
||||
if (player.equals(target) || player.equals(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.carbonMessages.muteAlertPlayers(player, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.muteAlertPlayers(player, target.displayName());
|
||||
}
|
||||
|
||||
target.muted(true);
|
||||
|
||||
+10
-10
@@ -24,8 +24,8 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
@@ -37,21 +37,21 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class MuteInfoCommand extends CarbonCommand {
|
||||
public final class MuteInfoCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
public MuteInfoCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
@@ -87,7 +87,7 @@ public class MuteInfoCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
target = this.carbonChat.userManager().user(handler.get("uuid")).join();
|
||||
target = this.users.user(handler.get("uuid")).join();
|
||||
} else {
|
||||
target = sender;
|
||||
}
|
||||
@@ -96,13 +96,13 @@ public class MuteInfoCommand extends CarbonCommand {
|
||||
if (sender.equals(target)) {
|
||||
this.carbonMessages.muteInfoSelfNotMuted(sender);
|
||||
} else {
|
||||
this.carbonMessages.muteInfoNotMuted(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.muteInfoNotMuted(sender, target.displayName());
|
||||
}
|
||||
} else {
|
||||
if (sender.equals(target)) {
|
||||
this.carbonMessages.muteInfoSelfMuted(sender);
|
||||
} else {
|
||||
this.carbonMessages.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
|
||||
this.carbonMessages.muteInfoMuted(sender, target.displayName(), target.muted());
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
+9
-9
@@ -43,10 +43,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class NicknameCommand extends CarbonCommand {
|
||||
public final class NicknameCommand extends CarbonCommand {
|
||||
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ConfigFactory config;
|
||||
|
||||
@@ -114,7 +114,7 @@ public class NicknameCommand extends CarbonCommand {
|
||||
}
|
||||
|
||||
private void resetNickname(final Commander sender, final CarbonPlayer target) {
|
||||
target.displayName(null);
|
||||
target.nickname(null);
|
||||
|
||||
if (sender instanceof PlayerCommander playerCommander
|
||||
&& playerCommander.carbonPlayer().uuid().equals(target.uuid())) {
|
||||
@@ -127,7 +127,7 @@ public class NicknameCommand extends CarbonCommand {
|
||||
private void applyNickname(final Commander sender, final CarbonPlayer target, final String nick) {
|
||||
// Lazy since the sender might not have permission to set the nickname
|
||||
final Supplier<Component> parsedNick = Suppliers.memoize(() -> parseNickname(sender, nick));
|
||||
target.displayName(parsedNick.get());
|
||||
target.nickname(parsedNick.get());
|
||||
|
||||
if (sender instanceof PlayerCommander playerCommander
|
||||
&& playerCommander.carbonPlayer().uuid().equals(target.uuid())) {
|
||||
@@ -141,16 +141,16 @@ public class NicknameCommand extends CarbonCommand {
|
||||
}
|
||||
|
||||
private void checkOwnNickname(final CarbonPlayer sender) {
|
||||
if (sender.displayName() != null) {
|
||||
this.carbonMessages.nicknameShow(sender, sender.username(), sender.displayName());
|
||||
if (sender.nickname() != null) {
|
||||
this.carbonMessages.nicknameShow(sender, sender.username(), sender.nickname());
|
||||
} else {
|
||||
this.carbonMessages.nicknameShowUnset(sender, sender.username());
|
||||
}
|
||||
}
|
||||
|
||||
private void checkOthersNickname(final Audience sender, final CarbonPlayer target) {
|
||||
if (target.displayName() != null) {
|
||||
this.carbonMessages.nicknameShowOthers(sender, target.username(), target.displayName());
|
||||
if (target.nickname() != null) {
|
||||
this.carbonMessages.nicknameShowOthers(sender, target.username(), target.nickname());
|
||||
} else {
|
||||
this.carbonMessages.nicknameShowOthersUnset(sender, target.username());
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.draycia.carbon.common.command.commands;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
@@ -33,19 +33,19 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ReloadCommand extends CarbonCommand {
|
||||
public final class ReloadCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final CarbonEventHandler events;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
|
||||
@Inject
|
||||
public ReloadCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final CarbonEventHandler eventHandler,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.events = eventHandler;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class ReloadCommand extends CarbonCommand {
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandReloadDescription())
|
||||
.handler(handler -> {
|
||||
// TODO: Check if all listeners succeeded
|
||||
this.carbonChat.eventHandler().emit(new CarbonReloadEvent());
|
||||
this.events.emit(new CarbonReloadEvent());
|
||||
this.carbonMessages.configReloaded(handler.getSender());
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -25,13 +25,12 @@ import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@@ -40,26 +39,23 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class ReplyCommand extends CarbonCommand {
|
||||
public final class ReplyCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
final ConfigFactory configFactory;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final WhisperCommand.WhisperHandler whisper;
|
||||
|
||||
@Inject
|
||||
public ReplyCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ConfigFactory configFactory,
|
||||
final WhisperCommand.WhisperHandler whisper
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.configFactory = configFactory;
|
||||
this.whisper = whisper;
|
||||
}
|
||||
|
||||
@@ -93,11 +89,11 @@ public class ReplyCommand extends CarbonCommand {
|
||||
final @Nullable UUID replyTarget = sender.whisperReplyTarget();
|
||||
|
||||
if (replyTarget == null) {
|
||||
this.carbonMessages.replyTargetNotSet(sender, CarbonPlayer.renderName(sender));
|
||||
this.carbonMessages.replyTargetNotSet(sender, sender.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
final @MonotonicNonNull CarbonPlayer recipient = this.carbonChat.userManager().user(replyTarget).join();
|
||||
final @MonotonicNonNull CarbonPlayer recipient = this.users.user(replyTarget).join();
|
||||
|
||||
this.whisper.whisper(sender, recipient, message);
|
||||
})
|
||||
|
||||
+9
-9
@@ -24,8 +24,8 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
@@ -37,21 +37,21 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class UnignoreCommand extends CarbonCommand {
|
||||
public final class UnignoreCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
public UnignoreCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
@@ -88,14 +88,14 @@ public class UnignoreCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
target = this.carbonChat.userManager().user(handler.get("uuid")).join();
|
||||
target = this.users.user(handler.get("uuid")).join();
|
||||
} else {
|
||||
this.carbonMessages.ignoreTargetInvalid(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
sender.ignoring(target, false);
|
||||
this.carbonMessages.noLongerIgnoring(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.noLongerIgnoring(sender, target.displayName());
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
+15
-11
@@ -24,8 +24,9 @@ import cloud.commandframework.arguments.standard.UUIDArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.command.ArgumentFactory;
|
||||
import net.draycia.carbon.common.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
@@ -37,21 +38,24 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class UnmuteCommand extends CarbonCommand {
|
||||
public final class UnmuteCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
private final UserManager<?> users;
|
||||
private final CarbonServer server;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
|
||||
@Inject
|
||||
public UnmuteCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final UserManager<?> userManager,
|
||||
final CarbonServer server,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final ArgumentFactory argumentFactory
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.users = userManager;
|
||||
this.server = server;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.argumentFactory = argumentFactory;
|
||||
@@ -87,7 +91,7 @@ public class UnmuteCommand extends CarbonCommand {
|
||||
if (handler.contains("player")) {
|
||||
target = handler.get("player");
|
||||
} else if (handler.flags().contains("uuid")) {
|
||||
target = this.carbonChat.userManager().user(handler.get("uuid")).join();
|
||||
target = this.users.user(handler.get("uuid")).join();
|
||||
} else {
|
||||
this.carbonMessages.unmuteNoTarget(sender);
|
||||
// TODO: send command syntax
|
||||
@@ -97,10 +101,10 @@ public class UnmuteCommand extends CarbonCommand {
|
||||
this.carbonMessages.unmuteAlertRecipient(target);
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
this.carbonMessages.unmuteAlertPlayers(sender, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.unmuteAlertPlayers(sender, target.displayName());
|
||||
}
|
||||
|
||||
for (final var player : this.carbonChat.server().players()) {
|
||||
for (final var player : this.server.players()) {
|
||||
if (player.equals(target) || player.equals(sender)) {
|
||||
continue;
|
||||
}
|
||||
@@ -109,7 +113,7 @@ public class UnmuteCommand extends CarbonCommand {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.carbonMessages.unmuteAlertPlayers(player, CarbonPlayer.renderName(target));
|
||||
this.carbonMessages.unmuteAlertPlayers(player, target.displayName());
|
||||
}
|
||||
|
||||
target.muted(false);
|
||||
|
||||
+3
-3
@@ -41,11 +41,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class UpdateUsernameCommand extends CarbonCommand {
|
||||
public final class UpdateUsernameCommand extends CarbonCommand {
|
||||
|
||||
private final UserManager<?> userManager;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages messageService;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages messageService;
|
||||
private final ArgumentFactory argumentFactory;
|
||||
private final ProfileResolver profileResolver;
|
||||
|
||||
|
||||
+13
-13
@@ -30,7 +30,6 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
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.CarbonCommand;
|
||||
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.event.events.CarbonPrivateChatEventImpl;
|
||||
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.packets.PacketFactory;
|
||||
import net.draycia.carbon.common.messaging.packets.WhisperPacket;
|
||||
@@ -54,7 +54,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class WhisperCommand extends CarbonCommand {
|
||||
public final class WhisperCommand extends CarbonCommand {
|
||||
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages carbonMessages;
|
||||
@@ -162,7 +162,7 @@ public class WhisperCommand extends CarbonCommand {
|
||||
final @Nullable String recipientInputString
|
||||
) {
|
||||
if (sender.equals(recipient)) {
|
||||
this.messages.whisperSelfError(sender, CarbonPlayer.renderName(sender));
|
||||
this.messages.whisperSelfError(sender, sender.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -178,29 +178,29 @@ public class WhisperCommand extends CarbonCommand {
|
||||
final boolean localRecipient = recipient.online();
|
||||
|
||||
if (sender.ignoring(recipient)) {
|
||||
this.messages.whisperIgnoringTarget(sender, CarbonPlayer.renderName(recipient));
|
||||
this.messages.whisperIgnoringTarget(sender, recipient.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
if (recipient.ignoring(sender)) {
|
||||
this.messages.whisperTargetIgnoring(sender, CarbonPlayer.renderName(recipient));
|
||||
this.messages.whisperTargetIgnoring(sender, recipient.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
final Component senderName = CarbonPlayer.renderName(sender);
|
||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||
final Component senderName = sender.displayName();
|
||||
final Component recipientName = recipient.displayName();
|
||||
|
||||
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message));
|
||||
this.events.emit(privateChatEvent);
|
||||
|
||||
if (privateChatEvent.cancelled()) {
|
||||
this.messages.whisperError(sender, CarbonPlayer.renderName(sender), CarbonPlayer.renderName(recipient));
|
||||
this.messages.whisperError(sender, sender.displayName(), recipient.displayName());
|
||||
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) {
|
||||
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());
|
||||
|
||||
@@ -229,11 +229,11 @@ public class WhisperCommand extends CarbonCommand {
|
||||
return;
|
||||
}
|
||||
this.userManager.user(packet.from()).thenAccept(sender -> {
|
||||
final Component senderName = CarbonPlayer.renderName(sender);
|
||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||
final Component senderName = sender.displayName();
|
||||
final Component recipientName = recipient.displayName();
|
||||
|
||||
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());
|
||||
final @Nullable Sound messageSound = this.configFactory.primaryConfig().messageSound();
|
||||
if (messageSound != null) {
|
||||
|
||||
@@ -21,7 +21,6 @@ package net.draycia.carbon.common.config;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.seiama.event.EventConfig;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -57,7 +56,7 @@ public class ConfigFactory {
|
||||
this.dataDirectory = dataDirectory;
|
||||
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() {
|
||||
|
||||
@@ -22,15 +22,18 @@ package net.draycia.carbon.common.event;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.seiama.event.EventConfig;
|
||||
import com.seiama.event.EventSubscriber;
|
||||
import com.seiama.event.EventSubscription;
|
||||
import com.seiama.event.bus.EventBus;
|
||||
import com.seiama.event.bus.SimpleEventBus;
|
||||
import com.seiama.event.registry.EventRegistry;
|
||||
import com.seiama.event.registry.SimpleEventRegistry;
|
||||
import net.draycia.carbon.api.event.Cancellable;
|
||||
import net.draycia.carbon.api.event.CarbonEvent;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
||||
import net.draycia.carbon.api.event.CarbonEventSubscription;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@@ -43,16 +46,21 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@Singleton
|
||||
public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
||||
|
||||
@Inject
|
||||
private CarbonEventHandlerImpl() {
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
private CarbonEventHandlerImpl(final Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
private final EventRegistry<CarbonEvent> eventRegistry = new SimpleEventRegistry<>(CarbonEvent.class);
|
||||
private final EventBus<CarbonEvent> eventBus = new SimpleEventBus<>(this.eventRegistry, this::onException);
|
||||
|
||||
private <E> void onException(final EventSubscription<E> subscription, final E event, final Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
final Object subscriber = subscription.subscriber() instanceof SubscriberWrapper<?> wrapped
|
||||
? wrapped.carbon
|
||||
: subscription.subscriber();
|
||||
this.logger.warn("Exception posting event '{}' to subscriber '{}'", event, subscriber, throwable);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,8 +68,11 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
||||
final Class<T> eventClass,
|
||||
final CarbonEventSubscriber<T> subscriber
|
||||
) {
|
||||
this.eventRegistry.subscribe(eventClass, subscriber::on);
|
||||
return new CarbonEventSubscriptionImpl<>(eventClass, subscriber);
|
||||
return new CarbonEventSubscriptionImpl<>(
|
||||
eventClass,
|
||||
subscriber,
|
||||
this.eventRegistry.subscribe(eventClass, new SubscriberWrapper<>(subscriber, true))
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: support EventConfig#exact()
|
||||
@@ -73,8 +84,11 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
||||
final CarbonEventSubscriber<T> subscriber
|
||||
) {
|
||||
final EventConfig eventConfig = EventConfig.defaults().order(order).acceptsCancelled(acceptsCancelled);
|
||||
this.eventRegistry.subscribe(eventClass, eventConfig, subscriber::on);
|
||||
return new CarbonEventSubscriptionImpl<>(eventClass, subscriber);
|
||||
return new CarbonEventSubscriptionImpl<>(
|
||||
eventClass,
|
||||
subscriber,
|
||||
this.eventRegistry.subscribe(eventClass, eventConfig, new SubscriberWrapper<>(subscriber, acceptsCancelled))
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,4 +96,20 @@ public final class CarbonEventHandlerImpl implements CarbonEventHandler {
|
||||
this.eventBus.post(event);
|
||||
}
|
||||
|
||||
private record SubscriberWrapper<T extends CarbonEvent>(
|
||||
CarbonEventSubscriber<T> carbon,
|
||||
boolean acceptsCancelled
|
||||
) implements EventSubscriber<T> {
|
||||
|
||||
@Override
|
||||
public void on(final T event) throws Throwable {
|
||||
// Our events implement seiama Cancellable; but API consumers won't be able to do that
|
||||
if (!this.acceptsCancelled && event instanceof Cancellable cancellable && cancellable.cancelled()) {
|
||||
return;
|
||||
}
|
||||
this.carbon.on(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+11
-1
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.event;
|
||||
|
||||
import com.seiama.event.EventSubscription;
|
||||
import net.draycia.carbon.api.event.CarbonEvent;
|
||||
import net.draycia.carbon.api.event.CarbonEventSubscriber;
|
||||
import net.draycia.carbon.api.event.CarbonEventSubscription;
|
||||
@@ -26,6 +27,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KeyedRenderer> renderers() {
|
||||
return this.renderers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @MonotonicNonNull SignedMessage signedMessage() {
|
||||
return this.signedMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CarbonPlayer sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component originalMessage() {
|
||||
return this.originalMessage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component message() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void message(final Component message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @MonotonicNonNull ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Audience> 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 net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
@@ -60,7 +59,7 @@ public abstract class ChatListenerInternal {
|
||||
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 ChatChannel channel = channelMessage.channel();
|
||||
final String message = PlainTextComponentSerializer.plainText().serialize(channelMessage.message());
|
||||
@@ -68,7 +67,7 @@ public abstract class ChatListenerInternal {
|
||||
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);
|
||||
content = this.configFactory.primaryConfig().applyChatFilters(content);
|
||||
|
||||
@@ -98,7 +97,7 @@ public abstract class ChatListenerInternal {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -40,15 +40,11 @@ public class ItemLinkHandler implements Listener {
|
||||
event.message()
|
||||
.replaceText(TextReplacementConfig.builder()
|
||||
.matchLiteral("<" + placeholder + ">")
|
||||
.once()
|
||||
// .once()
|
||||
.replacement(builder -> {
|
||||
final var itemComponent = event.sender().createItemHoverComponent(slot);
|
||||
|
||||
if (itemComponent == null) {
|
||||
return builder;
|
||||
}
|
||||
|
||||
return event.sender().createItemHoverComponent(slot);
|
||||
return itemComponent == null ? builder : itemComponent;
|
||||
})
|
||||
.build())
|
||||
);
|
||||
|
||||
@@ -21,12 +21,13 @@ package net.draycia.carbon.common.listeners;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import net.draycia.carbon.common.messaging.packets.ChatMessagePacket;
|
||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -39,7 +40,7 @@ public class MessagePacketHandler implements Listener {
|
||||
@Inject
|
||||
public MessagePacketHandler(
|
||||
final CarbonEventHandler events,
|
||||
final CarbonChat carbonChat,
|
||||
final @ServerId UUID serverId,
|
||||
final Provider<MessagingManager> messaging
|
||||
) {
|
||||
events.subscribe(CarbonChatEvent.class, 100, false, event -> {
|
||||
@@ -52,13 +53,9 @@ public class MessagePacketHandler implements Listener {
|
||||
|
||||
messaging.get().withPacketService(packetService -> {
|
||||
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(serverId, sender.uuid(),
|
||||
event.chatChannel().permission(), event.chatChannel().key(), sender.username(), networkMessage));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,22 +21,18 @@ package net.draycia.carbon.common.listeners;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
import java.util.regex.Pattern;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
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;
|
||||
|
||||
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
|
||||
import static net.kyori.adventure.key.Key.key;
|
||||
@@ -67,18 +63,7 @@ public class PingHandler implements Listener {
|
||||
|
||||
public Component convertPings(final CarbonPlayer recipient, final Component message) {
|
||||
final String prefix = this.configFactory.primaryConfig().pings().prefix();
|
||||
final @Nullable Component displayComponent = recipient.displayName();
|
||||
final String displayName;
|
||||
|
||||
if (displayComponent != null) {
|
||||
displayName = PlainTextComponentSerializer.plainText().serialize(displayComponent);
|
||||
} else {
|
||||
final @NotNull Optional<Component> audienceNickname = recipient.get(Identity.DISPLAY_NAME);
|
||||
|
||||
displayName = audienceNickname
|
||||
.map(component -> PlainTextComponentSerializer.plainText().serialize(component))
|
||||
.orElse(recipient.username()); // Hacky workaround
|
||||
}
|
||||
final String plainDisplayName = PlainTextComponentSerializer.plainText().serialize(recipient.displayName());
|
||||
|
||||
return message.replaceText(TextReplacementConfig.builder()
|
||||
// \B(@Username|@Displayname)\b
|
||||
@@ -87,7 +72,7 @@ public class PingHandler implements Listener {
|
||||
"\\B%1$s(%2$s|%3$s)\\b",
|
||||
Pattern.quote(prefix),
|
||||
Pattern.quote(recipient.username()),
|
||||
Pattern.quote(displayName)),
|
||||
Pattern.quote(plainDisplayName)),
|
||||
Pattern.CASE_INSENSITIVE))
|
||||
.replacement(matchedText -> {
|
||||
if (this.configFactory.primaryConfig().pings().playSound()) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.Singleton;
|
||||
import com.seiama.event.EventConfig;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -87,7 +86,7 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
||||
|
||||
this.reloadTranslations();
|
||||
|
||||
events.subscribe(CarbonReloadEvent.class, -99, EventConfig.DEFAULT_ACCEPTS_CANCELLED, event -> {
|
||||
events.subscribe(CarbonReloadEvent.class, -99, true, event -> {
|
||||
this.reloadTranslations();
|
||||
});
|
||||
}
|
||||
@@ -194,6 +193,10 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
||||
public String messageOf(final Audience receiver, final String messageKey) {
|
||||
Audience audience = receiver;
|
||||
|
||||
if (audience instanceof SourcedAudience sourced) {
|
||||
audience = sourced.recipient();
|
||||
}
|
||||
|
||||
// Unwrap PlayerCommanders
|
||||
if (audience instanceof PlayerCommander playerCommander) {
|
||||
audience = playerCommander.carbonPlayer();
|
||||
@@ -202,7 +205,7 @@ public final class CarbonMessageSource implements IMessageSource<Audience, Strin
|
||||
if (audience instanceof CarbonPlayer player) {
|
||||
return this.forPlayer(messageKey, player);
|
||||
} 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);
|
||||
|
||||
if (defaultProperties != null) {
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.messages;
|
||||
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.annotation.Message;
|
||||
@@ -34,15 +32,6 @@ public interface CarbonMessages {
|
||||
* =============================================================
|
||||
*/
|
||||
|
||||
@Message("channel.format.basic")
|
||||
Component basicChatFormat(
|
||||
final Audience audience,
|
||||
final UUID uuid,
|
||||
@Placeholder("display_name") final Component displayName,
|
||||
final String username,
|
||||
final Component message
|
||||
);
|
||||
|
||||
@Message("channel.change")
|
||||
void changedChannels(final Audience audience, final String channel);
|
||||
|
||||
|
||||
@@ -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
|
||||
* 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;
|
||||
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.message.IMessageSender;
|
||||
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.Type;
|
||||
import javax.inject.Singleton;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.moonshine.receiver.IReceiverLocator;
|
||||
import net.kyori.moonshine.receiver.IReceiverLocatorResolver;
|
||||
@@ -71,7 +70,7 @@ public final class SourcedReceiverResolver implements IReceiverLocatorResolver<S
|
||||
if (parameter instanceof SourcedAudience sourcedAudience) {
|
||||
return sourcedAudience;
|
||||
} else if (parameter instanceof Audience audience) {
|
||||
return new SourcedAudience(audience, audience);
|
||||
return SourcedAudience.of(audience, audience);
|
||||
}
|
||||
|
||||
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.ChatChannel;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.command.commands.WhisperCommand;
|
||||
@@ -106,7 +105,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
||||
final List<KeyedRenderer> renderers = new ArrayList<>();
|
||||
|
||||
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);
|
||||
|
||||
for (final Audience recipient : recipients) {
|
||||
@@ -115,13 +114,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
||||
continue;
|
||||
}
|
||||
|
||||
Component renderedMessage = chatEvent.message();
|
||||
|
||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, messagePacket.message());
|
||||
}
|
||||
|
||||
recipient.sendMessage(renderedMessage);
|
||||
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||
}
|
||||
|
||||
this.server.console().sendMessage(Component.text("[Cross-Server] ").append(chatEvent.message()));
|
||||
|
||||
@@ -78,7 +78,8 @@ public class MessagingManager {
|
||||
|
||||
private static final byte protocolVersion = 0;
|
||||
|
||||
private final CarbonChat carbonChat;
|
||||
private final Logger logger;
|
||||
private final UUID serverId;
|
||||
private final @MonotonicNonNull ScheduledExecutorService scheduledExecutor;
|
||||
private final @MonotonicNonNull PacketService packetService;
|
||||
private @MonotonicNonNull MessagingService messagingService;
|
||||
@@ -87,6 +88,7 @@ public class MessagingManager {
|
||||
public MessagingManager(
|
||||
final ConfigFactory configFactory,
|
||||
final CarbonChat carbonChat,
|
||||
final @ServerId UUID serverId,
|
||||
final CarbonServer server,
|
||||
final Logger logger,
|
||||
final UserManagerInternal<?> userManager,
|
||||
@@ -94,13 +96,14 @@ public class MessagingManager {
|
||||
final WhisperCommand.WhisperHandler whisper,
|
||||
final PacketFactory packetFactory
|
||||
) {
|
||||
this.serverId = serverId;
|
||||
this.logger = logger;
|
||||
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!");
|
||||
}
|
||||
this.messagingService = EMPTY_MESSAGING_SERVICE;
|
||||
this.packetService = null;
|
||||
this.carbonChat = carbonChat;
|
||||
this.scheduledExecutor = null;
|
||||
return;
|
||||
}
|
||||
@@ -126,11 +129,10 @@ public class MessagingManager {
|
||||
}
|
||||
};
|
||||
this.scheduledExecutor = new ExceptionLoggingScheduledThreadPoolExecutor(4,
|
||||
ConcurrentUtil.carbonThreadFactory(carbonChat.logger(), "MessagingManager"), carbonChat.logger());
|
||||
this.carbonChat = carbonChat;
|
||||
ConcurrentUtil.carbonThreadFactory(logger, "MessagingManager"), logger);
|
||||
|
||||
final MessagingHandlerImpl handlerImpl = new MessagingHandlerImpl(this.packetService);
|
||||
handlerImpl.addHandler(new CarbonServerHandler(server, carbonChat.serverId(), this.packetService, handlerImpl, packetFactory));
|
||||
handlerImpl.addHandler(new CarbonServerHandler(server, serverId, this.packetService, handlerImpl, packetFactory));
|
||||
handlerImpl.addHandler(new CarbonChatPacketHandler(carbonChat, this, userManager, networkUsers, whisper));
|
||||
|
||||
try {
|
||||
@@ -143,12 +145,12 @@ public class MessagingManager {
|
||||
|
||||
this.packetService.addMessenger(this.messagingService);
|
||||
|
||||
this.packetService.queuePacket(new InitializationPacket(carbonChat.serverId(), protocolVersion));
|
||||
this.packetService.queuePacket(new InitializationPacket(serverId, protocolVersion));
|
||||
this.packetService.flushQueue();
|
||||
|
||||
// Broadcast keepalive packets
|
||||
this.scheduledExecutor.scheduleAtFixedRate(() -> {
|
||||
this.packetService.queuePacket(new KeepAlivePacket(carbonChat.serverId()));
|
||||
this.packetService.queuePacket(new KeepAlivePacket(serverId));
|
||||
this.packetService.flushQueue();
|
||||
}, 5, 5, TimeUnit.SECONDS);
|
||||
|
||||
@@ -197,9 +199,9 @@ public class MessagingManager {
|
||||
|
||||
switch (messagingSettings.brokerType()) {
|
||||
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.serverId, handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port(), messagingSettings.vhost())
|
||||
.timeout(5000);
|
||||
|
||||
@@ -210,9 +212,9 @@ public class MessagingManager {
|
||||
this.messagingService = builder.build();
|
||||
}
|
||||
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.serverId, handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port())
|
||||
.life(5000);
|
||||
|
||||
@@ -223,9 +225,9 @@ public class MessagingManager {
|
||||
this.messagingService = builder.build();
|
||||
}
|
||||
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.serverId, handlerImpl, 0L, false, packetDir)
|
||||
.url(messagingSettings.url(), messagingSettings.port());
|
||||
|
||||
if (messagingSettings.password() != null && !messagingSettings.password().isBlank()) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.messaging;
|
||||
|
||||
import com.google.inject.BindingAnnotation;
|
||||
import com.google.inject.Key;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Injection binding annotation for the {@link UUID} identifier of
|
||||
* the currently running Carbon instance for cross-server packet
|
||||
* communications.
|
||||
*/
|
||||
@BindingAnnotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD})
|
||||
public @interface ServerId {
|
||||
Key<UUID> KEY = Key.get(UUID.class, ServerId.class);
|
||||
}
|
||||
+3
-3
@@ -23,7 +23,7 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -38,12 +38,12 @@ public final class LocalPlayerChangePacket extends CarbonPacket {
|
||||
|
||||
@AssistedInject
|
||||
public LocalPlayerChangePacket(
|
||||
final CarbonChat carbonChat,
|
||||
final @ServerId UUID serverId,
|
||||
final @Assisted UUID playerId,
|
||||
final @Assisted @Nullable String playerName,
|
||||
final @Assisted ChangeType changeType
|
||||
) {
|
||||
super(carbonChat.serverId());
|
||||
super(serverId);
|
||||
if (changeType == ChangeType.ADD && playerName == null) {
|
||||
throw new IllegalArgumentException("playerName cannot be null for ChangeType.ADD");
|
||||
}
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -36,10 +36,10 @@ public final class LocalPlayersPacket extends CarbonPacket {
|
||||
|
||||
@AssistedInject
|
||||
public LocalPlayersPacket(
|
||||
final CarbonChat carbonChat,
|
||||
final @ServerId UUID serverId,
|
||||
final @Assisted Map<UUID, String> players
|
||||
) {
|
||||
super(carbonChat.serverId());
|
||||
super(serverId);
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -34,8 +34,8 @@ public final class SaveCompletedPacket extends CarbonPacket {
|
||||
private @MonotonicNonNull UUID player;
|
||||
|
||||
@AssistedInject
|
||||
public SaveCompletedPacket(final CarbonChat carbonChat, final @Assisted UUID player) {
|
||||
super(carbonChat.serverId());
|
||||
public SaveCompletedPacket(final @ServerId UUID serverId, final @Assisted UUID player) {
|
||||
super(serverId);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.messaging.ServerId;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -38,12 +38,12 @@ public final class WhisperPacket extends CarbonPacket {
|
||||
|
||||
@AssistedInject
|
||||
public WhisperPacket(
|
||||
final CarbonChat carbonChat,
|
||||
final @ServerId UUID serverId,
|
||||
final @Assisted("from") UUID from,
|
||||
final @Assisted("to") UUID to,
|
||||
final @Assisted Component message
|
||||
) {
|
||||
super(carbonChat.serverId());
|
||||
super(serverId);
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.message = message;
|
||||
|
||||
@@ -44,7 +44,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||
@@ -154,7 +153,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Audience audience() {
|
||||
public Audience audience() {
|
||||
return Audience.empty();
|
||||
}
|
||||
|
||||
@@ -164,7 +163,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component displayName() {
|
||||
public @Nullable Component nickname() {
|
||||
if (!this.config.primaryConfig().useCarbonNicknames()) {
|
||||
return null;
|
||||
}
|
||||
@@ -176,8 +175,8 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
this.displayName.set(displayName);
|
||||
public void nickname(final @Nullable Component nickname) {
|
||||
this.displayName.set(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -350,11 +349,8 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
|
||||
@Override
|
||||
public @Nullable ChatChannel selectedChannel() {
|
||||
if (!this.selectedChannel.hasValue()) {
|
||||
return this.channelRegistry.defaultChannel();
|
||||
}
|
||||
|
||||
return this.channelRegistry.channel(this.selectedChannel.get());
|
||||
final @Nullable Key selected = this.selectedChannelKey();
|
||||
return selected == null ? null : this.channelRegistry.channel(selected);
|
||||
}
|
||||
|
||||
public ChannelRegistry channelRegistry() {
|
||||
@@ -401,6 +397,11 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component displayName() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void username(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
@@ -418,7 +419,7 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomDisplayName() {
|
||||
public boolean hasNickname() {
|
||||
if (!this.config.primaryConfig().useCarbonNicknames()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,17 +65,22 @@ public class ConsoleCarbonPlayer implements CarbonPlayer, ForwardingAudience.Sin
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomDisplayName() {
|
||||
public Component displayName() {
|
||||
return Component.text(this.username());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNickname() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component displayName() {
|
||||
public @Nullable Component nickname() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
public void nickname(final @Nullable Component nickname) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -19,31 +19,40 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Module;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@Singleton
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> implements UserManagerInternal<C> {
|
||||
public final class PlatformUserManager implements UserManagerInternal<WrappedCarbonPlayer> {
|
||||
|
||||
private final UserManagerInternal<CarbonPlayerCommon> backingManager;
|
||||
private final PlayerFactory playerFactory;
|
||||
|
||||
public PlatformUserManager(final UserManagerInternal<CarbonPlayerCommon> backingManager) {
|
||||
@Inject
|
||||
private PlatformUserManager(
|
||||
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
|
||||
final PlayerFactory playerFactory
|
||||
) {
|
||||
this.backingManager = backingManager;
|
||||
this.playerFactory = playerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<C> user(final UUID uuid) {
|
||||
public CompletableFuture<WrappedCarbonPlayer> user(final UUID uuid) {
|
||||
return this.backingManager.user(uuid).thenApply(common -> {
|
||||
final C wrapped = this.wrap(common);
|
||||
final WrappedCarbonPlayer wrapped = this.playerFactory.wrap(common);
|
||||
common.markTransientLoaded(!wrapped.online());
|
||||
return wrapped;
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract C wrap(final CarbonPlayerCommon common);
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
this.backingManager.shutdown();
|
||||
@@ -55,7 +64,7 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> saveIfNeeded(final C player) {
|
||||
public CompletableFuture<Void> saveIfNeeded(final WrappedCarbonPlayer player) {
|
||||
return this.backingManager.saveIfNeeded(player.carbonPlayerCommon());
|
||||
}
|
||||
|
||||
@@ -69,4 +78,16 @@ public abstract class PlatformUserManager<C extends WrappedCarbonPlayer> impleme
|
||||
this.backingManager.cleanup();
|
||||
}
|
||||
|
||||
public interface PlayerFactory {
|
||||
|
||||
WrappedCarbonPlayer wrap(CarbonPlayerCommon common);
|
||||
|
||||
static Module moduleFor(final Class<? extends WrappedCarbonPlayer> carbonPlayerImpl) {
|
||||
return new FactoryModuleBuilder()
|
||||
.implement(WrappedCarbonPlayer.class, carbonPlayerImpl)
|
||||
.build(PlatformUserManager.PlayerFactory.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -41,7 +42,6 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.util.Tristate;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -206,19 +206,33 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
return this.carbonPlayerCommon.username();
|
||||
}
|
||||
|
||||
// take care not to call get(Identity.DISPLAY_NAME) on a CarbonPlayer
|
||||
// from this method - it would result in a stack overflow when pointers
|
||||
// are retrieved from EmptyAudienceWithPointers
|
||||
@Override
|
||||
public boolean hasCustomDisplayName() {
|
||||
return this.carbonPlayerCommon.hasCustomDisplayName();
|
||||
public Component displayName() {
|
||||
final @Nullable Component nick = this.nickname();
|
||||
if (nick != null) {
|
||||
return nick;
|
||||
}
|
||||
return this.platformDisplayName().orElseGet(() -> Component.text(this.username()));
|
||||
}
|
||||
|
||||
protected abstract Optional<Component> platformDisplayName();
|
||||
|
||||
@Override
|
||||
public boolean hasNickname() {
|
||||
return this.carbonPlayerCommon.hasNickname();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component displayName() {
|
||||
return this.carbonPlayerCommon.displayName();
|
||||
public @Nullable Component nickname() {
|
||||
return this.carbonPlayerCommon.nickname();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
this.carbonPlayerCommon.displayName(displayName);
|
||||
public void nickname(final @Nullable Component nickname) {
|
||||
this.carbonPlayerCommon.nickname(nickname);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -241,11 +255,11 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
||||
Component formattedMessage = message;
|
||||
|
||||
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon().channelRegistry().defaultChannel());
|
||||
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon.channelRegistry().defaultChannel());
|
||||
|
||||
for (final Key channelKey : this.carbonPlayerCommon.channelRegistry().keys()) {
|
||||
final @MonotonicNonNull ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channel(channelKey);
|
||||
final @MonotonicNonNull String prefix = chatChannel.quickPrefix();
|
||||
final ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channelOrThrow(channelKey);
|
||||
final @Nullable String prefix = chatChannel.quickPrefix();
|
||||
|
||||
if (prefix == null) {
|
||||
continue;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
channel.change=<green>You are now messaging </green><channel>
|
||||
channel.format.basic=<display_name>\: <message>
|
||||
command.clearchat.description=Clears the chat window for all players.
|
||||
command.continue.argument.message=The message to send.
|
||||
command.continue.description=Sends a message to the last person you messaged.
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.function.Consumer;
|
||||
@@ -31,26 +30,22 @@ import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.CarbonChatInternal;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
import net.draycia.carbon.common.PeriodicTasks;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileCache;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.fabric.command.DeleteMessageCommand;
|
||||
import net.draycia.carbon.fabric.listeners.FabricChatHandler;
|
||||
import net.draycia.carbon.fabric.listeners.FabricJoinQuitListener;
|
||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
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.network.chat.ChatType;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
@@ -61,7 +56,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabric> {
|
||||
public final class CarbonChatFabric extends CarbonChatInternal {
|
||||
|
||||
public static ResourceKey<ChatType> CHAT_TYPE = ResourceKey.create(Registries.CHAT_TYPE, new ResourceLocation("carbon", "chat"));
|
||||
|
||||
@@ -69,17 +64,15 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
||||
private CarbonChatFabric(
|
||||
final Injector injector,
|
||||
final Logger logger,
|
||||
final @DataDirectory Path dataDirectory,
|
||||
final @PeriodicTasks ScheduledExecutorService periodicTasks,
|
||||
final ProfileCache profileCache,
|
||||
final ProfileResolver profileResolver,
|
||||
final FabricUserManager userManager,
|
||||
final PlatformUserManager userManager,
|
||||
final ExecutionCoordinatorHolder commandExecutor,
|
||||
final CarbonServer carbonServer,
|
||||
final CarbonMessages carbonMessages,
|
||||
final CarbonEventHandler eventHandler,
|
||||
final CarbonChannelRegistry channelRegistry,
|
||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
||||
final Provider<MessagingManager> messagingManagerProvider,
|
||||
@SuppressWarnings("unused") // Make sure it initializes now
|
||||
final MinecraftServerHolder minecraftServerHolder
|
||||
@@ -87,7 +80,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
||||
super(
|
||||
injector,
|
||||
logger,
|
||||
dataDirectory,
|
||||
periodicTasks,
|
||||
profileCache,
|
||||
profileResolver,
|
||||
@@ -97,7 +89,6 @@ public final class CarbonChatFabric extends CarbonChatInternal<CarbonPlayerFabri
|
||||
carbonMessages,
|
||||
eventHandler,
|
||||
channelRegistry,
|
||||
renderer,
|
||||
messagingManagerProvider
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,33 +22,28 @@ package net.draycia.carbon.fabric;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.nio.file.Path;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
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.DataDirectory;
|
||||
import net.draycia.carbon.common.PlatformScheduler;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.fabric.command.FabricCommander;
|
||||
import net.draycia.carbon.fabric.command.FabricPlayerCommander;
|
||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import net.draycia.carbon.fabric.users.FabricProfileResolver;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
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 org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -93,20 +88,6 @@ public final class CarbonChatFabricModule extends AbstractModule {
|
||||
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
|
||||
public void configure() {
|
||||
this.install(new CarbonCommonModule());
|
||||
@@ -118,8 +99,8 @@ public final class CarbonChatFabricModule extends AbstractModule {
|
||||
this.bind(CarbonServer.class).to(CarbonServerFabric.class);
|
||||
this.bind(ProfileResolver.class).to(FabricProfileResolver.class);
|
||||
this.bind(PlatformScheduler.class).to(FabricScheduler.class);
|
||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(FabricUserManager.class);
|
||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(FabricUserManager.class);
|
||||
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerFabric.class));
|
||||
this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.platform.fabric.FabricServerAudiences;
|
||||
@@ -37,10 +38,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
public final class CarbonServerFabric implements CarbonServer, ForwardingAudience.Single {
|
||||
|
||||
private final MinecraftServerHolder serverHolder;
|
||||
private final FabricUserManager userManager;
|
||||
private final UserManager<?> userManager;
|
||||
|
||||
@Inject
|
||||
private CarbonServerFabric(final MinecraftServerHolder serverHolder, final FabricUserManager userManager) {
|
||||
private CarbonServerFabric(final MinecraftServerHolder serverHolder, final UserManager<?> userManager) {
|
||||
this.serverHolder = serverHolder;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
package net.draycia.carbon.fabric;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
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.fabric.users.CarbonPlayerFabric;
|
||||
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.tag.Tag;
|
||||
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.framework.qual.DefaultQualifier;
|
||||
|
||||
@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;
|
||||
|
||||
@@ -50,7 +52,7 @@ public class FabricMessageRenderer<T extends Audience> implements IMessageRender
|
||||
|
||||
@Override
|
||||
public Component render(
|
||||
final T receiver,
|
||||
final Audience receiver,
|
||||
final String intermediateMessage,
|
||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||
final Method method,
|
||||
|
||||
@@ -1,56 +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.fabric;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import net.draycia.carbon.common.users.Backing;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public final class FabricUserManager extends PlatformUserManager<CarbonPlayerFabric> {
|
||||
|
||||
private final MinecraftServerHolder serverHolder;
|
||||
private final Provider<CarbonChatFabric> carbonChat;
|
||||
|
||||
@Inject
|
||||
private FabricUserManager(
|
||||
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
|
||||
final MinecraftServerHolder serverHolder,
|
||||
final Provider<CarbonChatFabric> carbonChat
|
||||
) {
|
||||
super(backingManager);
|
||||
this.serverHolder = serverHolder;
|
||||
this.carbonChat = carbonChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CarbonPlayerFabric wrap(final CarbonPlayerCommon common) {
|
||||
return new CarbonPlayerFabric(common, this.serverHolder, this.carbonChat);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,10 +20,9 @@
|
||||
package net.draycia.carbon.fabric.listeners;
|
||||
|
||||
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.util.KeyedRenderer;
|
||||
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.messages.CarbonMessages;
|
||||
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 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()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (final var recipient : chatEvent.recipients()) {
|
||||
Component renderedMessage = chatEvent.message();
|
||||
|
||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
||||
}
|
||||
|
||||
final Component finishedMessage = renderedMessage;
|
||||
final Component finishedMessage = chatEvent.renderFor(recipient);
|
||||
|
||||
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);
|
||||
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.network.chat.ChatTypeDecoration;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
@@ -50,7 +51,7 @@ abstract class RegistryDataLoaderMixin {
|
||||
),
|
||||
locals = LocalCapture.CAPTURE_FAILEXCEPTION
|
||||
)
|
||||
@SuppressWarnings("unchecked,rawtypes")
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static void carbon$injectMessageTypes(
|
||||
final ResourceManager resourceManager,
|
||||
final RegistryAccess registryAccess,
|
||||
@@ -67,6 +68,7 @@ abstract class RegistryDataLoaderMixin {
|
||||
}
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static ChatType carbonChatType() {
|
||||
return new ChatType(ChatTypeDecoration.withSender("%s"), ChatTypeDecoration.withSender("%s"));
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
package net.draycia.carbon.fabric.users;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import java.util.ArrayList;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
@@ -49,7 +50,8 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
||||
private final MinecraftServerHolder serverHolder;
|
||||
private final Provider<CarbonChatFabric> carbonChatFabric;
|
||||
|
||||
public CarbonPlayerFabric(final CarbonPlayerCommon carbonPlayerCommon, final MinecraftServerHolder serverHolder, final Provider<CarbonChatFabric> carbonChatFabric) {
|
||||
@AssistedInject
|
||||
public CarbonPlayerFabric(final @Assisted CarbonPlayerCommon carbonPlayerCommon, final MinecraftServerHolder serverHolder, final Provider<CarbonChatFabric> carbonChatFabric) {
|
||||
super(carbonPlayerCommon);
|
||||
this.serverHolder = serverHolder;
|
||||
this.carbonChatFabric = carbonChatFabric;
|
||||
@@ -170,7 +172,7 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
||||
return "default";
|
||||
}
|
||||
|
||||
return this.user().getPrimaryGroup();
|
||||
return super.primaryGroup();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,13 +181,12 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
||||
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;
|
||||
@Override
|
||||
protected Optional<Component> platformDisplayName() {
|
||||
return this.player().flatMap(p -> p.get(Identity.DISPLAY_NAME));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,18 +24,17 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import github.scarsz.discordsrv.DiscordSRV;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.CarbonChatInternal;
|
||||
import net.draycia.carbon.common.DataDirectory;
|
||||
import net.draycia.carbon.common.PeriodicTasks;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileCache;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.paper.hooks.CarbonPAPIPlaceholders;
|
||||
@@ -44,10 +43,6 @@ import net.draycia.carbon.paper.hooks.PAPIChatHook;
|
||||
import net.draycia.carbon.paper.listeners.DiscordMessageListener;
|
||||
import net.draycia.carbon.paper.listeners.PaperChatListener;
|
||||
import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
|
||||
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.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -58,7 +53,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper> {
|
||||
public final class CarbonChatPaper extends CarbonChatInternal {
|
||||
|
||||
private static final Set<Class<? extends Listener>> LISTENER_CLASSES = Set.of(
|
||||
PaperChatListener.class,
|
||||
@@ -77,16 +72,15 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
|
||||
final CarbonChannelRegistry channelRegistry,
|
||||
final Provider<MessagingManager> messagingManager,
|
||||
final CarbonServer carbonServer,
|
||||
final PaperUserManager userManager,
|
||||
@DataDirectory final Path dataDirectory,
|
||||
final PlatformUserManager userManager,
|
||||
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
||||
final ProfileCache profileCache,
|
||||
final ProfileResolver profileResolver,
|
||||
final ExecutionCoordinatorHolder commandExecutor,
|
||||
final IMessageRenderer<Audience, String, Component, Component> renderer
|
||||
final ExecutionCoordinatorHolder commandExecutor
|
||||
) {
|
||||
super(
|
||||
injector, LogManager.getLogger("CarbonChat"), dataDirectory,
|
||||
injector,
|
||||
LogManager.getLogger("CarbonChat"),
|
||||
periodicTasks,
|
||||
profileCache,
|
||||
profileResolver,
|
||||
@@ -96,7 +90,6 @@ public final class CarbonChatPaper extends CarbonChatInternal<CarbonPlayerPaper>
|
||||
carbonMessages,
|
||||
eventHandler,
|
||||
channelRegistry,
|
||||
renderer,
|
||||
messagingManager
|
||||
);
|
||||
this.plugin = plugin;
|
||||
|
||||
@@ -23,33 +23,27 @@ import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.paper.PaperCommandManager;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.google.inject.assistedinject.FactoryModuleBuilder;
|
||||
import java.nio.file.Path;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
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.DataDirectory;
|
||||
import net.draycia.carbon.common.PlatformScheduler;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.paper.command.PaperCommander;
|
||||
import net.draycia.carbon.paper.command.PaperPlayerCommander;
|
||||
import net.draycia.carbon.paper.messages.PaperMessageRenderer;
|
||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||
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.Logger;
|
||||
import org.bukkit.Server;
|
||||
@@ -106,20 +100,6 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
||||
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
|
||||
public void configure() {
|
||||
this.install(new CarbonCommonModule());
|
||||
@@ -132,9 +112,8 @@ public final class CarbonChatPaperModule extends AbstractModule {
|
||||
this.bind(CarbonServer.class).to(CarbonServerPaper.class);
|
||||
this.bind(ProfileResolver.class).to(PaperProfileResolver.class);
|
||||
this.bind(PlatformScheduler.class).to(PaperScheduler.class);
|
||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(PaperUserManager.class);
|
||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(PaperUserManager.class);
|
||||
this.install(new FactoryModuleBuilder().build(CarbonPlayerPaper.Factory.class));
|
||||
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerPaper.class));
|
||||
this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.bukkit.Server;
|
||||
@@ -36,10 +37,10 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
public final class CarbonServerPaper implements CarbonServer, ForwardingAudience.Single {
|
||||
|
||||
private final Server server;
|
||||
private final PaperUserManager userManager;
|
||||
private final UserManager<?> userManager;
|
||||
|
||||
@Inject
|
||||
private CarbonServerPaper(final Server server, final PaperUserManager userManager) {
|
||||
private CarbonServerPaper(final Server server, final UserManager<?> userManager) {
|
||||
this.server = server;
|
||||
this.userManager = userManager;
|
||||
}
|
||||
@@ -62,13 +63,4 @@ public final class CarbonServerPaper implements CarbonServer, ForwardingAudience
|
||||
.toList();
|
||||
}
|
||||
|
||||
public static boolean isFolia() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer");
|
||||
return true;
|
||||
} catch (final ClassNotFoundException ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +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.paper;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import net.draycia.carbon.common.users.Backing;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public final class PaperUserManager extends PlatformUserManager<CarbonPlayerPaper> {
|
||||
|
||||
private final CarbonPlayerPaper.Factory playerFactory;
|
||||
|
||||
@Inject
|
||||
private PaperUserManager(
|
||||
final @Backing UserManagerInternal<CarbonPlayerCommon> backingManager,
|
||||
final CarbonPlayerPaper.Factory playerFactory
|
||||
) {
|
||||
super(backingManager);
|
||||
this.playerFactory = playerFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CarbonPlayerPaper wrap(final CarbonPlayerCommon common) {
|
||||
return this.playerFactory.wrap(common);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class CarbonPAPIPlaceholders extends PlaceholderExpansion {
|
||||
public @Nullable String onRequest(final OfflinePlayer player, final String params) {
|
||||
final CarbonPlayer carbonPlayer = this.userManager.user(player.getUniqueId()).join();
|
||||
|
||||
final Component nickname = CarbonPlayer.renderName(carbonPlayer);
|
||||
final Component nickname = carbonPlayer.displayName();
|
||||
|
||||
if (params.endsWith("nickname")) {
|
||||
return MiniMessage.miniMessage().serialize(nickname);
|
||||
|
||||
@@ -22,9 +22,9 @@ package net.draycia.carbon.paper.listeners;
|
||||
import com.google.inject.Inject;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
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.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
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 @Nullable CarbonChatEvent chatEvent = this.prepareAndEmitChatEvent(sender, content, event.signedMessage());
|
||||
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, content, event.signedMessage());
|
||||
|
||||
if (chatEvent == null || chatEvent.cancelled()) {
|
||||
event.setCancelled(true);
|
||||
@@ -78,7 +78,6 @@ public final class PaperChatListener extends ChatListenerInternal implements Lis
|
||||
}
|
||||
|
||||
event.renderer(($, $$, $$$, recipient) -> {
|
||||
var renderedMessage = chatEvent.message();
|
||||
final var recipientUUID = recipient.get(Identity.UUID);
|
||||
final Audience recipientViewer;
|
||||
|
||||
@@ -88,11 +87,7 @@ public final class PaperChatListener extends ChatListenerInternal implements Lis
|
||||
recipientViewer = recipient;
|
||||
}
|
||||
|
||||
for (final var renderer : chatEvent.renderers()) {
|
||||
renderedMessage = renderer.render(sender, recipientViewer, renderedMessage, event.originalMessage());
|
||||
}
|
||||
|
||||
return renderedMessage;
|
||||
return chatEvent.renderFor(recipientViewer);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.messaging.packets.PacketFactory;
|
||||
import net.draycia.carbon.common.users.ProfileCache;
|
||||
import net.draycia.carbon.paper.PaperUserManager;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -47,7 +47,7 @@ public class PaperPlayerJoinListener implements Listener {
|
||||
private final ConfigFactory configFactory;
|
||||
private final Logger logger;
|
||||
private final ProfileCache profileCache;
|
||||
private final PaperUserManager userManager;
|
||||
private final UserManagerInternal<?> userManager;
|
||||
private final Provider<MessagingManager> messaging;
|
||||
private final PacketFactory packetFactory;
|
||||
|
||||
@@ -56,7 +56,7 @@ public class PaperPlayerJoinListener implements Listener {
|
||||
final ConfigFactory configFactory,
|
||||
final Logger logger,
|
||||
final ProfileCache profileCache,
|
||||
final PaperUserManager userManager,
|
||||
final UserManagerInternal<?> userManager,
|
||||
final Provider<MessagingManager> messaging,
|
||||
final PacketFactory packetFactory
|
||||
) {
|
||||
|
||||
@@ -21,14 +21,16 @@ package net.draycia.carbon.paper.messages;
|
||||
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
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.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.SourcedAudience;
|
||||
import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
|
||||
import net.draycia.carbon.paper.CarbonChatPaper;
|
||||
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.tag.Tag;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.moonshine.message.IMessageRenderer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
@@ -47,7 +48,8 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
@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(() -> {
|
||||
if (CarbonChatPaper.papiLoaded()) {
|
||||
@@ -67,7 +69,7 @@ public class PaperMessageRenderer<T extends Audience> implements IMessageRendere
|
||||
|
||||
@Override
|
||||
public Component render(
|
||||
final T receiver,
|
||||
final Audience receiver,
|
||||
final String intermediateMessage,
|
||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||
final Method method,
|
||||
|
||||
@@ -56,7 +56,7 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
super(carbonPlayerCommon);
|
||||
|
||||
if (config.primaryConfig().useCarbonNicknames()) {
|
||||
this.player().ifPresent(this.applyDisplayNameToBukkit(carbonPlayerCommon.displayName()));
|
||||
this.player().ifPresent(this.applyDisplayNameToBukkit(carbonPlayerCommon.nickname()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +64,11 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
return Optional.ofNullable(Bukkit.getPlayer(this.carbonPlayerCommon.uuid()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Component> platformDisplayName() {
|
||||
return this.player().map(Player::displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Audience audience() {
|
||||
return this.player().map(player -> (Audience) player).orElseGet(() -> EmptyAudienceWithPointers.forCarbonPlayer(this));
|
||||
@@ -102,10 +107,10 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayName(final @Nullable Component displayName) {
|
||||
super.displayName(displayName);
|
||||
public void nickname(final @Nullable Component nickname) {
|
||||
super.nickname(nickname);
|
||||
|
||||
this.player().ifPresent(this.applyDisplayNameToBukkit(displayName));
|
||||
this.player().ifPresent(this.applyDisplayNameToBukkit(nickname));
|
||||
}
|
||||
|
||||
private Consumer<Player> applyDisplayNameToBukkit(final @Nullable Component displayName) {
|
||||
@@ -191,8 +196,4 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
return Bukkit.getPlayer(this.uuid());
|
||||
}
|
||||
|
||||
public interface Factory {
|
||||
CarbonPlayerPaper wrap(CarbonPlayerCommon common);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,9 +24,7 @@ import com.google.inject.Injector;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
@@ -34,26 +32,23 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||
import net.draycia.carbon.common.CarbonChatInternal;
|
||||
import net.draycia.carbon.common.PeriodicTasks;
|
||||
import net.draycia.carbon.common.channels.CarbonChannelRegistry;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.messaging.MessagingManager;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileCache;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.velocity.listeners.VelocityChatListener;
|
||||
import net.draycia.carbon.velocity.listeners.VelocityListener;
|
||||
import net.draycia.carbon.velocity.listeners.VelocityPlayerJoinListener;
|
||||
import net.draycia.carbon.velocity.listeners.VelocityPlayerLeaveListener;
|
||||
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.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity> {
|
||||
public class CarbonChatVelocity extends CarbonChatInternal {
|
||||
|
||||
private static final Set<Class<? extends VelocityListener<?>>> LISTENER_CLASSES = Set.of(
|
||||
VelocityChatListener.class,
|
||||
@@ -68,13 +63,11 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
||||
final ProxyServer proxyServer,
|
||||
final Injector injector,
|
||||
final PluginContainer pluginContainer,
|
||||
@DataDirectory final Path dataDirectory,
|
||||
@PeriodicTasks final ScheduledExecutorService periodicTasks,
|
||||
final ProfileCache profileCache,
|
||||
final ProfileResolver profileResolver,
|
||||
final ExecutionCoordinatorHolder commandExecutor,
|
||||
final IMessageRenderer<Audience, String, Component, Component> renderer,
|
||||
final VelocityUserManager userManager,
|
||||
final PlatformUserManager userManager,
|
||||
final CarbonServerVelocity carbonServer,
|
||||
final CarbonMessages carbonMessages,
|
||||
final CarbonEventHandler eventHandler,
|
||||
@@ -82,8 +75,8 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
||||
final Provider<MessagingManager> messagingManager
|
||||
) {
|
||||
super(
|
||||
injector, LogManager.getLogger(pluginContainer.getDescription().getId()),
|
||||
dataDirectory,
|
||||
injector,
|
||||
LogManager.getLogger(pluginContainer.getDescription().getId()),
|
||||
periodicTasks,
|
||||
profileCache,
|
||||
profileResolver,
|
||||
@@ -93,7 +86,6 @@ public class CarbonChatVelocity extends CarbonChatInternal<CarbonPlayerVelocity>
|
||||
carbonMessages,
|
||||
eventHandler,
|
||||
channelRegistry,
|
||||
renderer,
|
||||
messagingManager
|
||||
);
|
||||
this.proxyServer = proxyServer;
|
||||
|
||||
@@ -22,10 +22,8 @@ package net.draycia.carbon.velocity;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.velocity.VelocityCommandManager;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
@@ -33,22 +31,20 @@ import java.nio.file.Path;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
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.DataDirectory;
|
||||
import net.draycia.carbon.common.PlatformScheduler;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.commands.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.ProfileResolver;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.common.util.CloudUtils;
|
||||
import net.draycia.carbon.velocity.command.VelocityCommander;
|
||||
import net.draycia.carbon.velocity.command.VelocityPlayerCommander;
|
||||
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
||||
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.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -100,20 +96,6 @@ public final class CarbonChatVelocityModule extends AbstractModule {
|
||||
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
|
||||
public void configure() {
|
||||
this.install(new CarbonCommonModule());
|
||||
@@ -124,8 +106,8 @@ public final class CarbonChatVelocityModule extends AbstractModule {
|
||||
this.bind(Path.class).annotatedWith(DataDirectory.class).toInstance(this.dataDirectory);
|
||||
this.bind(Logger.class).toInstance(this.logger);
|
||||
this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class);
|
||||
this.bind(new TypeLiteral<UserManager<?>>() {}).to(VelocityUserManager.class);
|
||||
this.bind(new TypeLiteral<UserManagerInternal<?>>() {}).to(VelocityUserManager.class);
|
||||
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerVelocity.class));
|
||||
this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,13 +20,15 @@
|
||||
package net.draycia.carbon.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.velocitypowered.api.plugin.PluginManager;
|
||||
import io.github.miniplaceholders.api.MiniPlaceholders;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
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.velocity.users.CarbonPlayerVelocity;
|
||||
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.tag.Tag;
|
||||
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.framework.qual.DefaultQualifier;
|
||||
|
||||
@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 PluginManager pluginManager;
|
||||
@@ -52,7 +54,7 @@ public class VelocityMessageRenderer<T extends Audience> implements IMessageRend
|
||||
|
||||
@Override
|
||||
public Component render(
|
||||
final T receiver,
|
||||
final Audience receiver,
|
||||
final String intermediateMessage,
|
||||
final Map<String, ? extends Component> resolvedPlaceholders,
|
||||
final Method method,
|
||||
|
||||
@@ -1,50 +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.velocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.draycia.carbon.common.users.Backing;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.PlatformUserManager;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
@Singleton
|
||||
public class VelocityUserManager extends PlatformUserManager<CarbonPlayerVelocity> {
|
||||
|
||||
private final ProxyServer proxyServer;
|
||||
|
||||
@Inject
|
||||
public VelocityUserManager(@Backing final UserManagerInternal<CarbonPlayerCommon> proxiedUserManager, final ProxyServer proxyServer) {
|
||||
super(proxiedUserManager);
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CarbonPlayerVelocity wrap(final CarbonPlayerCommon common) {
|
||||
return new CarbonPlayerVelocity(this.proxyServer, common);
|
||||
}
|
||||
|
||||
}
|
||||
+3
-11
@@ -31,16 +31,14 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Supplier;
|
||||
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.UserManager;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.common.config.ConfigFactory;
|
||||
import net.draycia.carbon.common.event.events.CarbonChatEventImpl;
|
||||
import net.draycia.carbon.common.listeners.ChatListenerInternal;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
|
||||
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.Nullable;
|
||||
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 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()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Audience recipient : chatEvent.recipients()) {
|
||||
Component renderedMessage = chatEvent.message();
|
||||
|
||||
for (final KeyedRenderer renderer : chatEvent.renderers()) {
|
||||
renderedMessage = renderer.render(sender, recipient, renderedMessage, chatEvent.message());
|
||||
}
|
||||
|
||||
recipient.sendMessage(renderedMessage);
|
||||
recipient.sendMessage(chatEvent.renderFor(recipient));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.EventManager;
|
||||
import com.velocitypowered.api.event.EventTask;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
|
||||
import net.draycia.carbon.velocity.VelocityUserManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -34,12 +34,12 @@ import static net.draycia.carbon.common.util.PlayerUtils.joinExceptionHandler;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class VelocityPlayerJoinListener implements VelocityListener<LoginEvent> {
|
||||
|
||||
private final VelocityUserManager userManager;
|
||||
private final UserManagerInternal<?> userManager;
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
public VelocityPlayerJoinListener(
|
||||
final VelocityUserManager userManager,
|
||||
final UserManagerInternal<?> userManager,
|
||||
final Logger logger
|
||||
) {
|
||||
this.userManager = userManager;
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.EventManager;
|
||||
import com.velocitypowered.api.event.EventTask;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import net.draycia.carbon.common.users.UserManagerInternal;
|
||||
import net.draycia.carbon.velocity.CarbonVelocityBootstrap;
|
||||
import net.draycia.carbon.velocity.VelocityUserManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
@@ -34,12 +34,12 @@ import static net.draycia.carbon.common.util.PlayerUtils.saveExceptionHandler;
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class VelocityPlayerLeaveListener implements VelocityListener<DisconnectEvent> {
|
||||
|
||||
private final VelocityUserManager userManager;
|
||||
private final UserManagerInternal<?> userManager;
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
public VelocityPlayerLeaveListener(
|
||||
final VelocityUserManager userManager,
|
||||
final UserManagerInternal<?> userManager,
|
||||
final Logger logger
|
||||
) {
|
||||
this.userManager = userManager;
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
*/
|
||||
package net.draycia.carbon.velocity.users;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.google.inject.assistedinject.AssistedInject;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import java.util.Locale;
|
||||
@@ -30,6 +32,7 @@ import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
import net.draycia.carbon.common.util.EmptyAudienceWithPointers;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -41,7 +44,8 @@ public final class CarbonPlayerVelocity extends WrappedCarbonPlayer implements F
|
||||
|
||||
private final ProxyServer server;
|
||||
|
||||
public CarbonPlayerVelocity(final ProxyServer server, final CarbonPlayerCommon carbonPlayerCommon) {
|
||||
@AssistedInject
|
||||
private CarbonPlayerVelocity(final ProxyServer server, @Assisted final CarbonPlayerCommon carbonPlayerCommon) {
|
||||
super(carbonPlayerCommon);
|
||||
this.server = server;
|
||||
}
|
||||
@@ -86,6 +90,11 @@ public final class CarbonPlayerVelocity extends WrappedCarbonPlayer implements F
|
||||
return playerServer.getServer().equals(otherServer.getServer());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Component> platformDisplayName() {
|
||||
return this.player().flatMap(p -> p.get(Identity.DISPLAY_NAME));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Component createItemHoverComponent(final InventorySlot slot) {
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user