mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Change indentation and improve event
This commit is contained in:
1 parent
73c7f3f78f
commit
591a6606cc
18 files changed
+236
-138
No files matched your search
@@ -109,12 +109,12 @@
|
|||||||
|
|
||||||
<!-- https://checkstyle.org/config_misc.html#Indentation -->
|
<!-- https://checkstyle.org/config_misc.html#Indentation -->
|
||||||
<module name="Indentation">
|
<module name="Indentation">
|
||||||
<property name="arrayInitIndent" value="2"/>
|
<property name="arrayInitIndent" value="4"/>
|
||||||
<property name="basicOffset" value="2"/>
|
<property name="basicOffset" value="4"/>
|
||||||
<property name="braceAdjustment" value="0"/>
|
<property name="braceAdjustment" value="0"/>
|
||||||
<property name="caseIndent" value="2"/>
|
<property name="caseIndent" value="4"/>
|
||||||
<property name="lineWrappingIndentation" value="0"/>
|
<property name="lineWrappingIndentation" value="0"/>
|
||||||
<property name="throwsIndent" value="2"/>
|
<property name="throwsIndent" value="4"/>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
<!-- https://checkstyle.org/config_javadoc.html#InvalidJavadocPosition -->
|
<!-- https://checkstyle.org/config_javadoc.html#InvalidJavadocPosition -->
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ root = true
|
|||||||
|
|
||||||
[*]
|
[*]
|
||||||
charset = utf-8
|
charset = utf-8
|
||||||
indent_size = 2
|
indent_size = 4
|
||||||
indent_style = space
|
indent_style = space
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
max_line_length = off
|
max_line_length = off
|
||||||
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.users.CarbonPlayer;
|
|||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main plugin interface.<br>
|
* The main plugin interface.<br>
|
||||||
@@ -12,6 +13,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface CarbonChat {
|
public interface CarbonChat {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,27 +21,24 @@ public interface CarbonChat {
|
|||||||
* All messages will be logged through this.
|
* All messages will be logged through this.
|
||||||
*
|
*
|
||||||
* @return the plugin's logger
|
* @return the plugin's logger
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull Logger logger();
|
Logger logger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The event handler, used for listening to and emitting events.
|
* The event handler, used for listening to and emitting events.
|
||||||
*
|
*
|
||||||
* @return the event handler
|
* @return the event handler
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull CarbonEventHandler eventHandler();
|
CarbonEventHandler eventHandler();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user manager, used for loading and obtaining {@link CarbonPlayer CarbonPlayers}.
|
* The user manager, used for loading and obtaining {@link CarbonPlayer CarbonPlayers}.
|
||||||
*
|
*
|
||||||
* @return the user manager
|
* @return the user manager
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull UserManager userManager();
|
UserManager userManager();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,14 @@ package net.draycia.carbon.api;
|
|||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Static accessor for the {@link CarbonChat} class.
|
* Static accessor for the {@link CarbonChat} class.
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class CarbonChatProvider {
|
public final class CarbonChatProvider {
|
||||||
|
|
||||||
private CarbonChatProvider() {
|
private CarbonChatProvider() {
|
||||||
@@ -20,10 +22,9 @@ public final class CarbonChatProvider {
|
|||||||
* Registers the {@link CarbonChat} implementation.
|
* Registers the {@link CarbonChat} implementation.
|
||||||
*
|
*
|
||||||
* @param carbonChat the carbon implementation
|
* @param carbonChat the carbon implementation
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static void register(final @NonNull CarbonChat carbonChat) {
|
public static void register(final CarbonChat carbonChat) {
|
||||||
CarbonChatProvider.instance = carbonChat;
|
CarbonChatProvider.instance = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +32,9 @@ public final class CarbonChatProvider {
|
|||||||
* Gets the currently registered {@link CarbonChat} implementation.
|
* Gets the currently registered {@link CarbonChat} implementation.
|
||||||
*
|
*
|
||||||
* @return the registered carbon implementation
|
* @return the registered carbon implementation
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static @NonNull CarbonChat carbonChat() {
|
public static CarbonChat carbonChat() {
|
||||||
if (CarbonChatProvider.instance == null) {
|
if (CarbonChatProvider.instance == null) {
|
||||||
throw new IllegalStateException("CarbonChat not initialized!"); // LuckPerms design go brrrr
|
throw new IllegalStateException("CarbonChat not initialized!"); // LuckPerms design go brrrr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.draycia.carbon.api.channels;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ChatChannel interface, supplies a formatter and filters recipients.
|
||||||
|
*
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public interface ChatChannel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player may receive messages from this channel.
|
||||||
|
*
|
||||||
|
* @param player the player
|
||||||
|
* @return if the player may receive this channel's messages
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
boolean mayReceiveMessages(final CarbonPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the player may send messages in this channel.
|
||||||
|
*
|
||||||
|
* @param player the player
|
||||||
|
* @return if the player may send messages in this channel
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
boolean maySendMessages(final CarbonPlayer player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This channel's renderer.
|
||||||
|
*
|
||||||
|
* @return the renderer
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
ChatComponentRenderer renderer();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import net.kyori.adventure.audience.Audience;
|
|||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -15,17 +16,18 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public class CarbonChatEvent extends CancellableCarbonEvent {
|
public class CarbonChatEvent extends CancellableCarbonEvent {
|
||||||
|
|
||||||
private final @NonNull Map<Key, ChatComponentRenderer> renderers;
|
private final Map<Key, ChatComponentRenderer> renderers;
|
||||||
|
|
||||||
private final @NonNull CarbonPlayer sender;
|
private final CarbonPlayer sender;
|
||||||
|
|
||||||
private final @NonNull Component originalMessage;
|
private final Component originalMessage;
|
||||||
|
|
||||||
private @NonNull Component message;
|
private Component message;
|
||||||
|
|
||||||
private final @NonNull List<@NonNull ? extends Audience> recipients;
|
private final List<? extends Audience> recipients;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CancellableCarbonEvent} that's called when players send messages in chat.
|
* {@link CancellableCarbonEvent} that's called when players send messages in chat.
|
||||||
@@ -34,14 +36,13 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* @param originalMessage the original message that was sent
|
* @param originalMessage the original message that was sent
|
||||||
* @param recipients the recipients of the message
|
* @param recipients the recipients of the message
|
||||||
* @param renderers the renderers of the message
|
* @param renderers the renderers of the message
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public CarbonChatEvent(
|
public CarbonChatEvent(
|
||||||
final @NonNull CarbonPlayer sender,
|
final CarbonPlayer sender,
|
||||||
final @NonNull Component originalMessage,
|
final Component originalMessage,
|
||||||
final @NonNull List<@NonNull ? extends Audience> recipients,
|
final List<? extends Audience> recipients,
|
||||||
final @NonNull Map<Key, ChatComponentRenderer> renderers
|
final Map<Key, ChatComponentRenderer> renderers
|
||||||
) {
|
) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.originalMessage = originalMessage;
|
this.originalMessage = originalMessage;
|
||||||
@@ -54,10 +55,9 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* Get the renderers used to construct components for each of the recipients.
|
* Get the renderers used to construct components for each of the recipients.
|
||||||
*
|
*
|
||||||
* @return The per-recipient component renderers.
|
* @return The per-recipient component renderers.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public @NonNull Map<Key, ChatComponentRenderer> renderers() {
|
public Map<Key, ChatComponentRenderer> renderers() {
|
||||||
return this.renderers;
|
return this.renderers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +65,6 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* Get the sender of the message.
|
* Get the sender of the message.
|
||||||
*
|
*
|
||||||
* @return The message sender.
|
* @return The message sender.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public CarbonPlayer sender() {
|
public CarbonPlayer sender() {
|
||||||
@@ -76,7 +75,6 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* Get the original message that was sent.
|
* Get the original message that was sent.
|
||||||
*
|
*
|
||||||
* @return The original message.
|
* @return The original message.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public Component originalMessage() {
|
public Component originalMessage() {
|
||||||
@@ -87,7 +85,6 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* Get the chat message that will be sent.
|
* Get the chat message that will be sent.
|
||||||
*
|
*
|
||||||
* @return The chat message.
|
* @return The chat message.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public Component message() {
|
public Component message() {
|
||||||
@@ -98,10 +95,9 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
* Set the chat message that will be sent.
|
* Set the chat message that will be sent.
|
||||||
*
|
*
|
||||||
* @param message new message
|
* @param message new message
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public void message(final @NonNull Component message) {
|
public void message(final Component message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,10 +107,9 @@ public class CarbonChatEvent extends CancellableCarbonEvent {
|
|||||||
*
|
*
|
||||||
* @return the recipients of the message.
|
* @return the recipients of the message.
|
||||||
* entries may be players, console, or other audience implementations
|
* entries may be players, console, or other audience implementations
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public @NonNull List<@NonNull ? extends Audience> recipients() {
|
public List<? extends Audience> recipients() {
|
||||||
return this.recipients;
|
return this.recipients;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.kyori.event.EventSubscriber;
|
|||||||
import net.kyori.event.PostResult;
|
import net.kyori.event.PostResult;
|
||||||
import net.kyori.event.SimpleEventBus;
|
import net.kyori.event.SimpleEventBus;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@@ -12,6 +13,7 @@ import java.util.function.Consumer;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class CarbonEventHandler {
|
public final class CarbonEventHandler {
|
||||||
|
|
||||||
private final SimpleEventBus<CarbonEvent> eventBus = new SimpleEventBus<>(CarbonEvent.class);
|
private final SimpleEventBus<CarbonEvent> eventBus = new SimpleEventBus<>(CarbonEvent.class);
|
||||||
@@ -22,10 +24,9 @@ public final class CarbonEventHandler {
|
|||||||
* @param eventClass the class to listen for
|
* @param eventClass the class to listen for
|
||||||
* @param subscriber the subscriber that's executed when the event is emitted
|
* @param subscriber the subscriber that's executed when the event is emitted
|
||||||
* @param <T> the class to listen for
|
* @param <T> the class to listen for
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public <T extends CarbonEvent> void register(final @NonNull Class<T> eventClass, final @NonNull EventSubscriber<T> subscriber) {
|
public <T extends CarbonEvent> void register(final Class<T> eventClass, final EventSubscriber<T> subscriber) {
|
||||||
this.eventBus.register(eventClass, subscriber);
|
this.eventBus.register(eventClass, subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,12 +39,14 @@ public final class CarbonEventHandler {
|
|||||||
* @param consumeCancelled if the consumer should be executed if the event is cancelled early
|
* @param consumeCancelled if the consumer should be executed if the event is cancelled early
|
||||||
* @param consumer the consumer that's executed when the event is emitted
|
* @param consumer the consumer that's executed when the event is emitted
|
||||||
* @param <T> the class to listen for
|
* @param <T> the class to listen for
|
||||||
*
|
|
||||||
* @return the subscriber, so that it may be unregistered
|
* @return the subscriber, so that it may be unregistered
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public <T extends CarbonEvent> EventSubscriber<T> register(final @NonNull Class<T> eventClass, final int priority, final boolean consumeCancelled, final @NonNull Consumer<T> consumer) {
|
public <T extends CarbonEvent> EventSubscriber<T> register(
|
||||||
|
final Class<T> eventClass, final int priority,
|
||||||
|
final boolean consumeCancelled,
|
||||||
|
final Consumer<T> consumer) {
|
||||||
|
|
||||||
final var subscriber = new EventSubscriber<T>() {
|
final var subscriber = new EventSubscriber<T>() {
|
||||||
@Override
|
@Override
|
||||||
public int postOrder() {
|
public int postOrder() {
|
||||||
@@ -56,7 +59,7 @@ public final class CarbonEventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(final @NonNull T event) {
|
public void invoke(final T event) {
|
||||||
consumer.accept(event);
|
consumer.accept(event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -70,10 +73,9 @@ public final class CarbonEventHandler {
|
|||||||
* Unregisters the subscriber and prevents it from being executed.
|
* Unregisters the subscriber and prevents it from being executed.
|
||||||
*
|
*
|
||||||
* @param subscriber the subscriber
|
* @param subscriber the subscriber
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public void unregister(final @NonNull EventSubscriber<? super CarbonEvent> subscriber) {
|
public void unregister(final EventSubscriber<? super CarbonEvent> subscriber) {
|
||||||
this.eventBus.unregister(subscriber);
|
this.eventBus.unregister(subscriber);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,12 +85,10 @@ public final class CarbonEventHandler {
|
|||||||
* the event while it's being emitted.
|
* the event while it's being emitted.
|
||||||
*
|
*
|
||||||
* @param event the event to be emitted
|
* @param event the event to be emitted
|
||||||
*
|
|
||||||
* @return the result
|
* @return the result
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public PostResult emit(final @NonNull CarbonEvent event) {
|
public PostResult emit(final CarbonEvent event) {
|
||||||
return this.eventBus.post(event);
|
return this.eventBus.post(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package net.draycia.carbon.api.users;
|
package net.draycia.carbon.api.users;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.identity.Identified;
|
import net.kyori.adventure.identity.Identified;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -13,32 +15,30 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface CarbonPlayer extends Audience, Identified {
|
public interface CarbonPlayer extends Audience, Identified {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player's username.
|
* Gets the player's username.
|
||||||
*
|
*
|
||||||
* @return the player's username
|
* @return the player's username
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull String username();
|
String username();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the player's display name, shown in places like chat and tab menu.
|
* Gets the player's display name, shown in places like chat and tab menu.
|
||||||
*
|
*
|
||||||
* @return the player's display name
|
* @return the player's display name
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull Component displayName();
|
Component displayName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the player's display name.<br>
|
* Sets the player's display name.<br>
|
||||||
* Setting null is equivalent to setting the display name to the username.
|
* Setting null is equivalent to setting the display name to the username.
|
||||||
*
|
*
|
||||||
* @param displayName the new display name
|
* @param displayName the new display name
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
void displayName(final @Nullable Component displayName);
|
void displayName(final @Nullable Component displayName);
|
||||||
@@ -47,18 +47,32 @@ public interface CarbonPlayer extends Audience, Identified {
|
|||||||
* The player's UUID, often used for identification purposes.
|
* The player's UUID, often used for identification purposes.
|
||||||
*
|
*
|
||||||
* @return the player's UUID
|
* @return the player's UUID
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull UUID uuid();
|
UUID uuid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Component} with a content and item hover given the player's actively held item.
|
* Creates a {@link Component} with a content and item hover given the player's actively held item.
|
||||||
*
|
*
|
||||||
* @return the player's held item as an item hover component
|
* @return the player's held item as an item hover component
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull Component createItemHoverComponent();
|
Component createItemHoverComponent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The player's selected channel. If none has been set, returns the server default.
|
||||||
|
*
|
||||||
|
* @return the player's selected channel
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
ChatChannel selectedChannel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the player's selected channel.
|
||||||
|
*
|
||||||
|
* @param chatChannel the channel
|
||||||
|
* @since 2.0.0
|
||||||
|
*/
|
||||||
|
void selectedChannel(final ChatChannel chatChannel);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package net.draycia.carbon.api.users;
|
|||||||
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -10,28 +11,25 @@ import java.util.UUID;
|
|||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface UserManager {
|
public interface UserManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and returns a {@link CarbonPlayer} with the given {@link UUID}.
|
* Loads and returns a {@link CarbonPlayer} with the given {@link UUID}.
|
||||||
*
|
*
|
||||||
* @param uuid The player's UUID.
|
* @param uuid The player's UUID.
|
||||||
*
|
|
||||||
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
|
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Nullable CarbonPlayer carbonPlayer(final @NonNull UUID uuid);
|
@Nullable CarbonPlayer carbonPlayer(final UUID uuid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads and returns a {@link CarbonPlayer} with the given username.
|
* Loads and returns a {@link CarbonPlayer} with the given username.
|
||||||
*
|
*
|
||||||
* @param username The player's username.
|
* @param username The player's username.
|
||||||
*
|
|
||||||
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
|
* @return The {@link CarbonPlayer}, or null if the player doesn't exist.
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Nullable CarbonPlayer carbonPlayer(final @NonNull String username);
|
@Nullable CarbonPlayer carbonPlayer(final String username);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ import net.kyori.adventure.audience.Audience;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renderer used to construct chat components on a per-player basis.
|
* Renderer used to construct chat components on a per-player basis.
|
||||||
@@ -12,6 +13,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface ChatComponentRenderer {
|
public interface ChatComponentRenderer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,16 +24,14 @@ public interface ChatComponentRenderer {
|
|||||||
* may be a player, console, or other Audience implementations
|
* may be a player, console, or other Audience implementations
|
||||||
* @param message the message being sent
|
* @param message the message being sent
|
||||||
* @param originalMessage the original message that was sent
|
* @param originalMessage the original message that was sent
|
||||||
*
|
|
||||||
* @return the component to be shown to the recipient,
|
* @return the component to be shown to the recipient,
|
||||||
* or null if the recipient should not receive the message
|
* or null if the recipient should not receive the message
|
||||||
*
|
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
Component render(final @NonNull CarbonPlayer sender,
|
Component render(final CarbonPlayer sender,
|
||||||
final @NonNull Audience recipient,
|
final Audience recipient,
|
||||||
final @NonNull Component message,
|
final Component message,
|
||||||
final @NonNull Component originalMessage);
|
final Component originalMessage);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|||||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ import java.util.regex.Pattern;
|
|||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public final class ColorUtils {
|
public final class ColorUtils {
|
||||||
|
|
||||||
private ColorUtils() {
|
private ColorUtils() {
|
||||||
@@ -26,12 +28,10 @@ public final class ColorUtils {
|
|||||||
* Supports named colors, legacy, and hex inputs.
|
* Supports named colors, legacy, and hex inputs.
|
||||||
*
|
*
|
||||||
* @param input the color input
|
* @param input the color input
|
||||||
*
|
|
||||||
* @return the color
|
* @return the color
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static @Nullable TextColor parseColor(@NonNull String input) {
|
public static @Nullable TextColor parseColor(String input) {
|
||||||
if (input.isEmpty()) {
|
if (input.isEmpty()) {
|
||||||
return NamedTextColor.WHITE;
|
return NamedTextColor.WHITE;
|
||||||
}
|
}
|
||||||
@@ -51,24 +51,22 @@ public final class ColorUtils {
|
|||||||
return TextColor.fromCSSHexString(input);
|
return TextColor.fromCSSHexString(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final @NonNull Pattern spigotLegacyRGB =
|
private static final Pattern spigotLegacyRGB =
|
||||||
Pattern.compile("[§&]x[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])");
|
Pattern.compile("[§&]x[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])[§&]([0-9a-fA-F])");
|
||||||
|
|
||||||
private static final @NonNull Pattern pluginRGB =
|
private static final Pattern pluginRGB =
|
||||||
Pattern.compile("[§&]#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
|
Pattern.compile("[§&]#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
|
||||||
|
|
||||||
private static final @NonNull String hexReplacement = "<#$1$2$3$4$5$6>";
|
private static final String hexReplacement = "<#$1$2$3$4$5$6>";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the input legacy, legacy rgb, and alternate color formats to MiniMessage color tags.
|
* Converts the input legacy, legacy rgb, and alternate color formats to MiniMessage color tags.
|
||||||
*
|
*
|
||||||
* @param input the message to convert
|
* @param input the message to convert
|
||||||
*
|
|
||||||
* @return the converted message
|
* @return the converted message
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public static @NonNull String legacyToMiniMessage(final @NonNull String input) {
|
public static String legacyToMiniMessage(final String input) {
|
||||||
String output = input;
|
String output = input;
|
||||||
|
|
||||||
// Legacy RGB
|
// Legacy RGB
|
||||||
@@ -79,10 +77,10 @@ public final class ColorUtils {
|
|||||||
|
|
||||||
// Legacy Colors
|
// Legacy Colors
|
||||||
for (final char c : "0123456789abcdefABCDEF".toCharArray()) {
|
for (final char c : "0123456789abcdefABCDEF".toCharArray()) {
|
||||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
|
final @Nullable LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
|
||||||
|
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
final TextColor color = format.color();
|
final @Nullable TextColor color = format.color();
|
||||||
|
|
||||||
if (color != null) {
|
if (color != null) {
|
||||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
||||||
@@ -92,10 +90,10 @@ public final class ColorUtils {
|
|||||||
|
|
||||||
// Legacy Formatting
|
// Legacy Formatting
|
||||||
for (final char c : "klmnoKLMNO".toCharArray()) {
|
for (final char c : "klmnoKLMNO".toCharArray()) {
|
||||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
|
final @Nullable LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
|
||||||
|
|
||||||
if (format != null) {
|
if (format != null) {
|
||||||
final TextDecoration decoration = format.decoration();
|
final @Nullable TextDecoration decoration = format.decoration();
|
||||||
|
|
||||||
if (decoration != null) {
|
if (decoration != null) {
|
||||||
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
*
|
*
|
||||||
* @param <K> the key type
|
* @param <K> the key type
|
||||||
* @param <V> the value type
|
* @param <V> the value type
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter<K, V> {
|
public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter<K, V> {
|
||||||
@@ -17,7 +16,6 @@ public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter
|
|||||||
* Gets the default value.
|
* Gets the default value.
|
||||||
*
|
*
|
||||||
* @return the default value
|
* @return the default value
|
||||||
*
|
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
@NonNull V defaultValue();
|
@NonNull V defaultValue();
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ package net.draycia.carbon.bukkit.listeners;
|
|||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@@ -24,24 +25,30 @@ public final class BukkitChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerChat(final @NonNull AsyncChatEvent event) {
|
public void onPlayerChat(final @NonNull AsyncChatEvent event) {
|
||||||
final var player = this.userManager.carbonPlayer(event.getPlayer().getUniqueId());
|
final var sender = this.userManager.carbonPlayer(event.getPlayer().getUniqueId());
|
||||||
|
|
||||||
if (player == null) {
|
if (sender == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final var recipients = new ArrayList<CarbonPlayer>();
|
final var recipients = new ArrayList<Audience>();
|
||||||
|
final var channel = sender.selectedChannel();
|
||||||
|
|
||||||
for (final Player recipient : event.recipients()) {
|
for (final Player bukkitRecipient : event.recipients()) {
|
||||||
final var bukkitRecipient = this.userManager.carbonPlayer(recipient.getUniqueId());
|
final var recipient = this.userManager.carbonPlayer(bukkitRecipient.getUniqueId());
|
||||||
|
|
||||||
if (bukkitRecipient != null) {
|
// The naming is a little backwards, ChatChannel#mayReceiveMessages
|
||||||
recipients.add(bukkitRecipient);
|
// TODO: Change it at some point
|
||||||
|
if (recipient != null && channel.mayReceiveMessages(recipient)) {
|
||||||
|
recipients.add(recipient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final var chatEvent = new CarbonChatEvent(player, event.message(), recipients,
|
// console too!
|
||||||
Map.of(key("carbon", "default"), this.carbonChat.vanillaChatRenderer));
|
recipients.add(Bukkit.getConsoleSender());
|
||||||
|
|
||||||
|
final var chatEvent = new CarbonChatEvent(sender, event.message(), recipients,
|
||||||
|
Map.of(key("carbon", "default"), channel.renderer()));
|
||||||
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
||||||
|
|
||||||
if (result.wasSuccessful()) {
|
if (result.wasSuccessful()) {
|
||||||
@@ -51,7 +58,7 @@ public final class BukkitChatListener implements Listener {
|
|||||||
var component = chatEvent.message();
|
var component = chatEvent.message();
|
||||||
|
|
||||||
for (final var entry : chatEvent.renderers().entrySet()) {
|
for (final var entry : chatEvent.renderers().entrySet()) {
|
||||||
component = entry.getValue().render(player,
|
component = entry.getValue().render(sender,
|
||||||
recipient, chatEvent.message(), chatEvent.originalMessage());
|
recipient, chatEvent.message(), chatEvent.originalMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public final class CarbonPlayerBukkit extends CarbonPlayerCommon {
|
|||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
player.displayName(displayName);
|
player.displayName(displayName);
|
||||||
|
player.playerListName(displayName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,41 +3,19 @@ package net.draycia.carbon.common;
|
|||||||
import cloud.commandframework.CommandManager;
|
import cloud.commandframework.CommandManager;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||||
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
|
||||||
import net.draycia.carbon.common.command.Commander;
|
import net.draycia.carbon.common.command.Commander;
|
||||||
import net.draycia.carbon.common.command.PlayerCommander;
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.kyori.adventure.key.Key;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.event.ClickEvent;
|
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import static net.kyori.adventure.text.Component.empty;
|
import static net.kyori.adventure.text.Component.empty;
|
||||||
import static net.kyori.adventure.text.Component.text;
|
import static net.kyori.adventure.text.Component.text;
|
||||||
import static net.kyori.adventure.text.Component.translatable;
|
|
||||||
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY;
|
import static net.kyori.adventure.text.format.NamedTextColor.DARK_GRAY;
|
||||||
import static net.kyori.adventure.text.format.TextDecoration.BOLD;
|
import static net.kyori.adventure.text.format.TextDecoration.BOLD;
|
||||||
|
|
||||||
public abstract class CarbonChatCommon implements CarbonChat {
|
public abstract class CarbonChatCommon implements CarbonChat {
|
||||||
|
|
||||||
// Mimics vanilla chat, should be *visually* identical but without the hover stuff.
|
|
||||||
// Temporary: This will be removed in the future.
|
|
||||||
@Deprecated(forRemoval = true)
|
|
||||||
public final @NonNull ChatComponentRenderer vanillaChatRenderer =
|
|
||||||
(sender, recipient, message, originalMessage) -> {
|
|
||||||
final var clickEvent = ClickEvent.suggestCommand("/msg " + sender.username());
|
|
||||||
final var hoverEvent = HoverEvent.showEntity(Key.key("player"),
|
|
||||||
sender.uuid(), text(sender.username()));
|
|
||||||
|
|
||||||
final var name = sender.displayName()
|
|
||||||
.clickEvent(clickEvent)
|
|
||||||
.hoverEvent(hoverEvent)
|
|
||||||
.insertion(sender.username());
|
|
||||||
|
|
||||||
return translatable("chat.type.text", name, message);
|
|
||||||
};
|
|
||||||
|
|
||||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||||
|
|
||||||
public final void initialize() {
|
public final void initialize() {
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.draycia.carbon.common.channels;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.api.util.ChatComponentRenderer;
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
import static net.kyori.adventure.text.Component.translatable;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public class VanillaChatChannel implements ChatChannel {
|
||||||
|
|
||||||
|
private final @NonNull ChatComponentRenderer renderer =
|
||||||
|
(sender, recipient, message, originalMessage) -> {
|
||||||
|
final var clickEvent = ClickEvent.suggestCommand("/msg " + sender.username());
|
||||||
|
final var hoverEvent = HoverEvent.showEntity(Key.key("player"),
|
||||||
|
sender.uuid(), text(sender.username()));
|
||||||
|
|
||||||
|
final var name = sender.displayName()
|
||||||
|
.clickEvent(clickEvent)
|
||||||
|
.hoverEvent(hoverEvent)
|
||||||
|
.insertion(sender.username());
|
||||||
|
|
||||||
|
return translatable("chat.type.text", name.color(TextColor.color(0xff0000)), message);
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mayReceiveMessages(final CarbonPlayer player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean maySendMessages(final CarbonPlayer player) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatComponentRenderer renderer() {
|
||||||
|
return this.renderer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,43 +1,49 @@
|
|||||||
package net.draycia.carbon.common.users;
|
package net.draycia.carbon.common.users;
|
||||||
|
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.common.channels.VanillaChatChannel;
|
||||||
import net.kyori.adventure.audience.ForwardingAudience;
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNullElseGet;
|
import static java.util.Objects.requireNonNullElseGet;
|
||||||
import static net.kyori.adventure.text.Component.text;
|
import static net.kyori.adventure.text.Component.text;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Single {
|
||||||
|
|
||||||
protected final @NonNull String username;
|
protected final String username;
|
||||||
protected @NonNull Component displayName;
|
protected Component displayName;
|
||||||
protected final @NonNull UUID uuid;
|
protected final UUID uuid;
|
||||||
protected final @NonNull Identity identity;
|
protected final Identity identity;
|
||||||
|
protected ChatChannel selectedChannel;
|
||||||
|
|
||||||
protected CarbonPlayerCommon(
|
protected CarbonPlayerCommon(
|
||||||
final @NonNull String username,
|
final String username,
|
||||||
final @NonNull Component displayName,
|
final Component displayName,
|
||||||
final @NonNull UUID uuid,
|
final UUID uuid,
|
||||||
final @NonNull Identity identity
|
final Identity identity
|
||||||
) {
|
) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.identity = identity;
|
this.identity = identity;
|
||||||
|
this.selectedChannel = new VanillaChatChannel(); // TODO: replace, persist and use global instance
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull String username() {
|
public String username() {
|
||||||
return this.username;
|
return this.username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Component displayName() {
|
public Component displayName() {
|
||||||
return this.displayName;
|
return this.displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,13 +53,23 @@ public abstract class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Identity identity() {
|
public Identity identity() {
|
||||||
return this.identity;
|
return this.identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull UUID uuid() {
|
public UUID uuid() {
|
||||||
return this.uuid;
|
return this.uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ChatChannel selectedChannel() {
|
||||||
|
return this.selectedChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void selectedChannel(final ChatChannel chatChannel) {
|
||||||
|
this.selectedChannel = chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,9 @@ package net.draycia.carbon.sponge.listeners;
|
|||||||
|
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
|
||||||
import net.draycia.carbon.api.users.UserManager;
|
import net.draycia.carbon.api.users.UserManager;
|
||||||
import net.draycia.carbon.sponge.CarbonChatSponge;
|
import net.draycia.carbon.sponge.CarbonChatSponge;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.spongepowered.api.Sponge;
|
import org.spongepowered.api.Sponge;
|
||||||
import org.spongepowered.api.entity.living.player.Player;
|
import org.spongepowered.api.entity.living.player.Player;
|
||||||
@@ -25,31 +25,36 @@ public final class SpongeChatListener {
|
|||||||
private final UserManager userManager = this.carbonChat.userManager();
|
private final UserManager userManager = this.carbonChat.userManager();
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void onPlayerChat(final @NonNull PlayerChatEvent event, final @First Player sender) {
|
public void onPlayerChat(final @NonNull PlayerChatEvent event, final @First Player messageSender) {
|
||||||
// https://github.com/SpongePowered/SpongeAPI/pull/2340
|
// https://github.com/SpongePowered/SpongeAPI/pull/2340
|
||||||
// this event currently doesn't have a concept of recipients, it seems?
|
// this event currently doesn't have a concept of recipients, it seems?
|
||||||
// or they're in the stack?
|
// or they're in the stack?
|
||||||
// idk, let's just do our own thing in the meantime
|
// idk, let's just do our own thing in the meantime
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
final var player = this.userManager.carbonPlayer(sender.uniqueId());
|
final var sender = this.userManager.carbonPlayer(messageSender.uniqueId());
|
||||||
|
|
||||||
if (player == null) {
|
if (sender == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final var recipients = new ArrayList<CarbonPlayer>();
|
final var recipients = new ArrayList<Audience>();
|
||||||
|
final var channel = sender.selectedChannel();
|
||||||
|
|
||||||
for (final ServerPlayer recipient : Sponge.server().onlinePlayers()) {
|
for (final ServerPlayer spongeRecipient : Sponge.server().onlinePlayers()) {
|
||||||
final var bukkitRecipient = this.userManager.carbonPlayer(recipient.uniqueId());
|
final var recipient = this.userManager.carbonPlayer(spongeRecipient.uniqueId());
|
||||||
|
|
||||||
if (bukkitRecipient != null) {
|
if (recipient != null && channel.mayReceiveMessages(recipient)) {
|
||||||
recipients.add(bukkitRecipient);
|
recipients.add(recipient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final var chatEvent = new CarbonChatEvent(player, event.message(), recipients,
|
// console too!
|
||||||
Map.of(key("carbon", "default"), this.carbonChat.vanillaChatRenderer));
|
// i'm not 100% sure this is "console" but I literally cannot find anything that explicitly says console
|
||||||
|
recipients.add(Sponge.systemSubject());
|
||||||
|
|
||||||
|
final var chatEvent = new CarbonChatEvent(sender, event.message(), recipients,
|
||||||
|
Map.of(key("carbon", "default"), channel.renderer()));
|
||||||
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
final var result = this.carbonChat.eventHandler().emit(chatEvent);
|
||||||
|
|
||||||
if (result.wasSuccessful()) {
|
if (result.wasSuccessful()) {
|
||||||
@@ -59,7 +64,7 @@ public final class SpongeChatListener {
|
|||||||
var component = chatEvent.message();
|
var component = chatEvent.message();
|
||||||
|
|
||||||
for (final var entry : chatEvent.renderers().entrySet()) {
|
for (final var entry : chatEvent.renderers().entrySet()) {
|
||||||
component = entry.getValue().render(player,
|
component = entry.getValue().render(sender,
|
||||||
recipient, chatEvent.message(), chatEvent.originalMessage());
|
recipient, chatEvent.message(), chatEvent.originalMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user