Support signing messages from command arguments (#434)

* Initial signed command argument impl

* Implement on Paper and map to greedy string (unsigned) on velocity

* Use cloud signed arguments

* add relocations

* fabric: include instead of shade cloud-signed-arguments

* Make whispers between players on the same server signed

* Update cloud & loom

---------

Co-authored-by: Draycia <[email protected]>
This commit is contained in:
Jason PenillaandDraycia authored and GitHub committed 2024-05-14 16:13:57 -07:00
1 parent a53d2e3d84
commit a816dcd738
17 files changed
+147 -36

No files matched your search

+1
View File
@@ -21,6 +21,7 @@ dependencies {
api(libs.cloudMinecraftExtras) { api(libs.cloudMinecraftExtras) {
isTransitive = false isTransitive = false
} }
api(libs.cloudSigned)
// Other // Other
compileOnlyApi(libs.guice) { compileOnlyApi(libs.guice) {
@@ -0,0 +1,35 @@
/*
* CarbonChat
*
* Copyright (c) 2024 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;
import com.google.inject.BindingAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Injection binding annotation for the raw chat type key.
*/
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD})
public @interface RawChat {
}
@@ -48,6 +48,7 @@ import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
import net.draycia.carbon.api.event.events.ChannelSwitchEvent; import net.draycia.carbon.api.event.events.ChannelSwitchEvent;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.common.DataDirectory; import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.RawChat;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.PlayerCommander; import net.draycia.carbon.common.command.PlayerCommander;
import net.draycia.carbon.common.config.ConfigManager; import net.draycia.carbon.common.config.ConfigManager;
@@ -61,6 +62,7 @@ import net.draycia.carbon.common.users.ConsoleCarbonPlayer;
import net.draycia.carbon.common.util.Exceptions; import net.draycia.carbon.common.util.Exceptions;
import net.draycia.carbon.common.util.FileUtil; import net.draycia.carbon.common.util.FileUtil;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.chat.ChatType;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@@ -69,12 +71,13 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.Command; import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager; import org.incendo.cloud.CommandManager;
import org.incendo.cloud.minecraft.signed.SignedString;
import org.spongepowered.configurate.ConfigurateException; import org.spongepowered.configurate.ConfigurateException;
import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.loader.ConfigurationLoader; import org.spongepowered.configurate.loader.ConfigurationLoader;
import org.spongepowered.configurate.transformation.ConfigurationTransformation; import org.spongepowered.configurate.transformation.ConfigurationTransformation;
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser; import static org.incendo.cloud.minecraft.signed.SignedGreedyStringParser.signedGreedyStringParser;
@Singleton @Singleton
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
@@ -87,6 +90,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
private @MonotonicNonNull Key defaultKey; private @MonotonicNonNull Key defaultKey;
private final CarbonMessages carbonMessages; private final CarbonMessages carbonMessages;
private final CarbonEventHandler eventHandler; private final CarbonEventHandler eventHandler;
private final Key rawChatKey;
private final Map<String, SpecialHandler<?>> handlers = new HashMap<>(); private final Map<String, SpecialHandler<?>> handlers = new HashMap<>();
private record SpecialHandler<T extends ConfigChatChannel>(Class<T> cls, Supplier<T> defaultSupplier) {} private record SpecialHandler<T extends ConfigChatChannel>(Class<T> cls, Supplier<T> defaultSupplier) {}
@@ -111,7 +115,8 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
final Logger logger, final Logger logger,
final ConfigManager config, final ConfigManager config,
final CarbonMessages carbonMessages, final CarbonMessages carbonMessages,
final CarbonEventHandler events final CarbonEventHandler events,
@RawChat final Key rawChatKey
) { ) {
super(events, carbonMessages, config); super(events, carbonMessages, config);
this.configChannelDir = dataDirectory.resolve("channels"); this.configChannelDir = dataDirectory.resolve("channels");
@@ -120,6 +125,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
this.config = config; this.config = config;
this.carbonMessages = carbonMessages; this.carbonMessages = carbonMessages;
this.eventHandler = events; this.eventHandler = events;
this.rawChatKey = rawChatKey;
if (config.primaryConfig().partyChat().enabled) { if (config.primaryConfig().partyChat().enabled) {
this.registerSpecialConfigChannel(PartyChatChannel.FILE_NAME, PartyChatChannel.class); this.registerSpecialConfigChannel(PartyChatChannel.FILE_NAME, PartyChatChannel.class);
@@ -327,22 +333,22 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
final ChatChannel channel, final ChatChannel channel,
final String plainMessage final String plainMessage
) { ) {
this.sendMessageInChannel(new ConsoleCarbonPlayer(sender), channel, plainMessage); this.sendMessageInChannel(new ConsoleCarbonPlayer(sender), channel, SignedString.unsigned(plainMessage));
} }
private void sendMessageInChannel( private void sendMessageInChannel(
final CarbonPlayer sender, final CarbonPlayer sender,
final ChatChannel channel, final ChatChannel channel,
final String plainMessage final SignedString message
) { ) {
final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, plainMessage, null, channel); final @Nullable CarbonChatEventImpl chatEvent = this.prepareAndEmitChatEvent(sender, message.string(), message.signedMessage(), channel);
if (chatEvent == null || chatEvent.cancelled()) { if (chatEvent == null || chatEvent.cancelled()) {
return; return;
} }
for (final Audience recipient : chatEvent.recipients()) { for (final Audience recipient : chatEvent.recipients()) {
recipient.sendMessage(chatEvent.renderFor(recipient)); message.sendMessage(recipient, ChatType.chatType(this.rawChatKey), chatEvent.renderFor(recipient));
} }
} }
@@ -355,7 +361,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
Command.Builder<Commander> builder = commandManager.commandBuilder(channel.commandName(), Command.Builder<Commander> builder = commandManager.commandBuilder(channel.commandName(),
channel.commandAliases(), commandManager.createDefaultCommandMeta()) channel.commandAliases(), commandManager.createDefaultCommandMeta())
.optional("message", greedyStringParser()); .optional("message", signedGreedyStringParser());
if (channel.permission() != null) { if (channel.permission() != null) {
builder = builder.permission(channel.permission()); builder = builder.permission(channel.permission());
@@ -377,10 +383,10 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
if (!(commander instanceof PlayerCommander playerCommander)) { if (!(commander instanceof PlayerCommander playerCommander)) {
if (chatChannel != null && handler.contains("message")) { if (chatChannel != null && handler.contains("message")) {
final String message = handler.get("message"); final SignedString message = handler.get("message");
// TODO: trigger platform events related to chat // TODO: trigger platform events related to chat
this.sendMessageInChannelAsConsole(commander, chatChannel, message); this.sendMessageInChannelAsConsole(commander, chatChannel, message.string());
} }
return; return;
@@ -397,7 +403,7 @@ public class CarbonChannelRegistry extends ChatListenerInternal implements Chann
this.carbonMessages.channelJoined(player); this.carbonMessages.channelJoined(player);
} }
if (handler.contains("message")) { if (handler.contains("message")) {
final String message = handler.get("message"); final SignedString message = handler.get("message");
// TODO: trigger platform events related to chat // TODO: trigger platform events related to chat
this.sendMessageInChannel(player, chatChannel, message); this.sendMessageInChannel(player, chatChannel, message);
@@ -102,4 +102,5 @@ public final class CarbonPlayerParser implements ArgumentParser.FutureArgumentPa
} }
} }
} }
@@ -34,9 +34,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager; import org.incendo.cloud.CommandManager;
import org.incendo.cloud.minecraft.signed.SignedString;
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription; import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser; import static org.incendo.cloud.minecraft.signed.SignedGreedyStringParser.signedGreedyStringParser;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public final class ContinueCommand extends CarbonCommand { public final class ContinueCommand extends CarbonCommand {
@@ -72,7 +73,7 @@ public final class ContinueCommand extends CarbonCommand {
@Override @Override
public void init() { public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases()) final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.required("message", greedyStringParser(), richDescription(this.messages.commandContinueArgumentMessage())) .required("message", signedGreedyStringParser(), richDescription(this.messages.commandContinueArgumentMessage()))
.permission("carbon.whisper.continue") .permission("carbon.whisper.continue")
.senderType(PlayerCommander.class) .senderType(PlayerCommander.class)
.commandDescription(richDescription(this.messages.commandContinueDescription())) .commandDescription(richDescription(this.messages.commandContinueDescription()))
@@ -84,7 +85,7 @@ public final class ContinueCommand extends CarbonCommand {
return; return;
} }
final String message = ctx.get("message"); final SignedString message = ctx.get("message");
final @Nullable UUID whisperTarget = sender.lastWhisperTarget(); final @Nullable UUID whisperTarget = sender.lastWhisperTarget();
if (whisperTarget == null) { if (whisperTarget == null) {
@@ -34,9 +34,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager; import org.incendo.cloud.CommandManager;
import org.incendo.cloud.minecraft.signed.SignedString;
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription; import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser; import static org.incendo.cloud.minecraft.signed.SignedGreedyStringParser.signedGreedyStringParser;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public final class ReplyCommand extends CarbonCommand { public final class ReplyCommand extends CarbonCommand {
@@ -72,7 +73,7 @@ public final class ReplyCommand extends CarbonCommand {
@Override @Override
public void init() { public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases()) final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.required("message", greedyStringParser(), richDescription(this.messages.commandReplyArgumentMessage())) .required("message", signedGreedyStringParser(), richDescription(this.messages.commandReplyArgumentMessage()))
.permission("carbon.whisper.reply") .permission("carbon.whisper.reply")
.senderType(PlayerCommander.class) .senderType(PlayerCommander.class)
.commandDescription(richDescription(this.messages.commandReplyDescription())) .commandDescription(richDescription(this.messages.commandReplyDescription()))
@@ -84,7 +85,7 @@ public final class ReplyCommand extends CarbonCommand {
return; return;
} }
final String message = ctx.get("message"); final SignedString message = ctx.get("message");
final @Nullable UUID replyTarget = sender.whisperReplyTarget(); final @Nullable UUID replyTarget = sender.whisperReplyTarget();
if (replyTarget == null) { if (replyTarget == null) {
@@ -26,6 +26,7 @@ import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent; import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
import net.draycia.carbon.api.users.CarbonPlayer; import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.users.UserManager; import net.draycia.carbon.api.users.UserManager;
import net.draycia.carbon.common.RawChat;
import net.draycia.carbon.common.command.CarbonCommand; import net.draycia.carbon.common.command.CarbonCommand;
import net.draycia.carbon.common.command.CommandSettings; import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
@@ -41,6 +42,7 @@ import net.draycia.carbon.common.messaging.packets.PacketFactory;
import net.draycia.carbon.common.messaging.packets.WhisperPacket; import net.draycia.carbon.common.messaging.packets.WhisperPacket;
import net.draycia.carbon.common.users.NetworkUsers; import net.draycia.carbon.common.users.NetworkUsers;
import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.common.util.CloudUtils;
import net.kyori.adventure.chat.ChatType;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound; import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@@ -49,9 +51,10 @@ import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier; import org.checkerframework.framework.qual.DefaultQualifier;
import org.incendo.cloud.CommandManager; import org.incendo.cloud.CommandManager;
import org.incendo.cloud.minecraft.signed.SignedString;
import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription; import static org.incendo.cloud.minecraft.extras.RichDescription.richDescription;
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser; import static org.incendo.cloud.minecraft.signed.SignedGreedyStringParser.signedGreedyStringParser;
@DefaultQualifier(NonNull.class) @DefaultQualifier(NonNull.class)
public final class WhisperCommand extends CarbonCommand { public final class WhisperCommand extends CarbonCommand {
@@ -88,7 +91,7 @@ public final class WhisperCommand extends CarbonCommand {
public void init() { public void init() {
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases()) final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
.required("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandWhisperArgumentPlayer())) .required("player", this.parserFactory.carbonPlayer(), richDescription(this.carbonMessages.commandWhisperArgumentPlayer()))
.required("message", greedyStringParser(), richDescription(this.carbonMessages.commandWhisperArgumentMessage())) .required("message", signedGreedyStringParser(), richDescription(this.carbonMessages.commandWhisperArgumentMessage()))
.permission("carbon.whisper.message") .permission("carbon.whisper.message")
.senderType(PlayerCommander.class) .senderType(PlayerCommander.class)
.commandDescription(richDescription(this.carbonMessages.commandWhisperDescription())) .commandDescription(richDescription(this.carbonMessages.commandWhisperDescription()))
@@ -100,7 +103,7 @@ public final class WhisperCommand extends CarbonCommand {
return; return;
} }
final String message = ctx.get("message"); final SignedString message = ctx.get("message");
final CarbonPlayer recipient = ctx.get("player"); final CarbonPlayer recipient = ctx.get("player");
this.whisper.whisper(sender, recipient, message, ctx.parsingContext("player").consumedInput()); this.whisper.whisper(sender, recipient, message, ctx.parsingContext("player").consumedInput());
@@ -121,6 +124,7 @@ public final class WhisperCommand extends CarbonCommand {
private final CarbonServer server; private final CarbonServer server;
private final CarbonEventHandler events; private final CarbonEventHandler events;
private final NetworkUsers network; private final NetworkUsers network;
private final Key rawChatKey;
@Inject @Inject
private WhisperHandler( private WhisperHandler(
@@ -132,7 +136,8 @@ public final class WhisperCommand extends CarbonCommand {
final UserManager<?> userManager, final UserManager<?> userManager,
final CarbonServer server, final CarbonServer server,
final CarbonEventHandler events, final CarbonEventHandler events,
final NetworkUsers network final NetworkUsers network,
@RawChat final Key rawChatKey
) { ) {
this.logger = logger; this.logger = logger;
this.messages = messages; this.messages = messages;
@@ -143,12 +148,13 @@ public final class WhisperCommand extends CarbonCommand {
this.server = server; this.server = server;
this.events = events; this.events = events;
this.network = network; this.network = network;
this.rawChatKey = rawChatKey;
} }
public void whisper( public void whisper(
final CarbonPlayer sender, final CarbonPlayer sender,
final CarbonPlayer recipient, final CarbonPlayer recipient,
final String message final SignedString message
) { ) {
this.whisper(sender, recipient, message, null); this.whisper(sender, recipient, message, null);
} }
@@ -156,7 +162,7 @@ public final class WhisperCommand extends CarbonCommand {
public void whisper( public void whisper(
final CarbonPlayer sender, final CarbonPlayer sender,
final CarbonPlayer recipient, final CarbonPlayer recipient,
final String message, final SignedString message,
final @Nullable String recipientInputString final @Nullable String recipientInputString
) { ) {
if (sender.equals(recipient)) { if (sender.equals(recipient)) {
@@ -199,7 +205,7 @@ public final class WhisperCommand extends CarbonCommand {
final Component senderDisplayName = sender.displayName(); final Component senderDisplayName = sender.displayName();
final Component recipientDisplayName = recipient.displayName(); final Component recipientDisplayName = recipient.displayName();
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message)); final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message.string()));
this.events.emit(privateChatEvent); this.events.emit(privateChatEvent);
if (privateChatEvent.cancelled()) { if (privateChatEvent.cancelled()) {
@@ -208,9 +214,17 @@ public final class WhisperCommand extends CarbonCommand {
} }
final String senderUsername = sender.username(); final String senderUsername = sender.username();
this.messages.whisperSender(SourcedAudience.of(sender, sender), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); message.sendMessage(
sender,
ChatType.chatType(this.rawChatKey),
this.messages.whisperSender(SourcedAudience.of(sender, sender), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message())
);
if (localRecipient) { if (localRecipient) {
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); message.sendMessage(
recipient,
ChatType.chatType(this.rawChatKey),
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message())
);
} }
this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message()); this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, privateChatEvent.message());
@@ -243,7 +257,9 @@ public final class WhisperCommand extends CarbonCommand {
final Component recipientDisplayName = recipient.displayName(); final Component recipientDisplayName = recipient.displayName();
recipient.whisperReplyTarget(sender.uuid()); recipient.whisperReplyTarget(sender.uuid());
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message()); SourcedAudience.of(sender, recipient).sendMessage(
this.messages.whisperRecipient(SourcedAudience.of(sender, recipient), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message())
);
this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message()); this.messages.whisperConsoleLog(this.server.console(), senderUsername, senderDisplayName, recipientUsername, recipientDisplayName, packet.message());
final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound(); final @Nullable Sound messageSound = this.configManager.primaryConfig().messageSound();
if (messageSound != null) { if (messageSound != null) {
@@ -108,8 +108,8 @@ public interface CarbonMessages {
*/ */
@Message("whisper.to") @Message("whisper.to")
void whisperSender( Component whisperSender(
SourcedAudience audience, @NotPlaceholder SourcedAudience audience,
String senderUsername, String senderUsername,
Component senderDisplayName, Component senderDisplayName,
String recipientUsername, String recipientUsername,
@@ -118,8 +118,8 @@ public interface CarbonMessages {
); );
@Message("whisper.from") @Message("whisper.from")
void whisperRecipient( Component whisperRecipient(
SourcedAudience audience, @NotPlaceholder SourcedAudience audience,
String senderUsername, String senderUsername,
Component senderDisplayName, Component senderDisplayName,
String recipientUsername, String recipientUsername,
@@ -0,0 +1,32 @@
/*
* CarbonChat
*
* Copyright (c) 2024 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 java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Target({ElementType.PARAMETER, ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface NotPlaceholder {
}
@@ -81,7 +81,7 @@ public final class StandardPlaceholderResolverStrategyButDifferent<R, I, F> impl
final Parameter parameter = methodParameters[idx]; final Parameter parameter = methodParameters[idx];
final @Nullable Object value = parameters[idx]; final @Nullable Object value = parameters[idx];
// Don't resolve Audiences for now // Don't resolve Audiences for now
if (value == null || parameter.getType() == Audience.class) { if (value == null || parameter.getType() == Audience.class || parameter.getAnnotation(NotPlaceholder.class) != null) {
// Nothing to resolve with. // Nothing to resolve with.
continue; continue;
} }
+3
View File
@@ -25,11 +25,14 @@ dependencies {
exclude("org.incendo", "cloud-core") exclude("org.incendo", "cloud-core")
exclude("org.incendo", "cloud-services") exclude("org.incendo", "cloud-services")
exclude("org.incendo", "cloud-brigadier") exclude("org.incendo", "cloud-brigadier")
exclude("org.incendo", "cloud-minecraft-signed-arguments")
exclude("io.leangen.geantyref") exclude("io.leangen.geantyref")
} }
modImplementation(libs.cloudFabric) modImplementation(libs.cloudFabric)
include(libs.cloudFabric) include(libs.cloudFabric)
implementation(libs.cloudSigned)
include(libs.cloudSigned)
modImplementation(libs.fabricPermissionsApi) modImplementation(libs.fabricPermissionsApi)
modImplementation(libs.adventurePlatformFabric) modImplementation(libs.adventurePlatformFabric)
@@ -33,6 +33,7 @@ import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.CarbonPlatformModule; import net.draycia.carbon.common.CarbonPlatformModule;
import net.draycia.carbon.common.DataDirectory; import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PlatformScheduler; import net.draycia.carbon.common.PlatformScheduler;
import net.draycia.carbon.common.RawChat;
import net.draycia.carbon.common.command.CommandSettings; import net.draycia.carbon.common.command.CommandSettings;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
@@ -44,6 +45,7 @@ import net.draycia.carbon.common.users.ProfileResolver;
import net.draycia.carbon.common.util.CloudUtils; import net.draycia.carbon.common.util.CloudUtils;
import net.draycia.carbon.fabric.command.FabricCommander; import net.draycia.carbon.fabric.command.FabricCommander;
import net.draycia.carbon.fabric.command.FabricPlayerCommander; import net.draycia.carbon.fabric.command.FabricPlayerCommander;
import net.draycia.carbon.fabric.listeners.FabricChatHandler;
import net.draycia.carbon.fabric.users.CarbonPlayerFabric; import net.draycia.carbon.fabric.users.CarbonPlayerFabric;
import net.draycia.carbon.fabric.users.FabricProfileResolver; import net.draycia.carbon.fabric.users.FabricProfileResolver;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
@@ -124,6 +126,7 @@ public final class CarbonChatFabricModule extends CarbonPlatformModule {
this.bind(PlatformScheduler.class).to(FabricScheduler.class); this.bind(PlatformScheduler.class).to(FabricScheduler.class);
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerFabric.class)); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerFabric.class));
this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(FabricMessageRenderer.class);
this.bind(Key.class).annotatedWith(RawChat.class).toProvider(() -> FabricChatHandler.CHAT_TYPE_KEY);
} }
} }
@@ -47,7 +47,7 @@ import org.jetbrains.annotations.Nullable;
public class FabricChatHandler extends ChatListenerInternal implements ServerMessageEvents.AllowChatMessage { public class FabricChatHandler extends ChatListenerInternal implements ServerMessageEvents.AllowChatMessage {
private static final ResourceLocation CHAT_TYPE_KEY = new ResourceLocation("carbonchat", "chat"); public static final ResourceLocation CHAT_TYPE_KEY = new ResourceLocation("carbonchat", "chat");
private final CarbonChatFabric carbonChat; private final CarbonChatFabric carbonChat;
private @MonotonicNonNull ResourceKey<ChatType> chatTypeResourceKey; private @MonotonicNonNull ResourceKey<ChatType> chatTypeResourceKey;
+7 -4
View File
@@ -13,10 +13,10 @@ gremlin = "0.0.6"
runTask = "2.3.0" runTask = "2.3.0"
adventure = "4.16.0" adventure = "4.16.0"
cloud = "2.0.0-beta.4" cloud = "2.0.0-beta.5"
cloudMinecraft = "2.0.0-beta.5" cloudMinecraft = "2.0.0-beta.6"
cloudModded = "2.0.0-beta.4" cloudModded = "2.0.0-beta.5"
cloudSponge = "2.0.0-SNAPSHOT" cloudSponge = "2.0.0-beta.6"
configurate = "4.2.0-SNAPSHOT" configurate = "4.2.0-SNAPSHOT"
checkerQual = "3.43.0" checkerQual = "3.43.0"
stylecheck = "0.2.1" stylecheck = "0.2.1"
@@ -88,9 +88,12 @@ kyoriMoonshineStandard = { group = "net.kyori.moonshine", name = "moonshine-stan
cloudBom = { module = "org.incendo:cloud-bom", version.ref = "cloud" } cloudBom = { module = "org.incendo:cloud-bom", version.ref = "cloud" }
cloudCore = { group = "org.incendo", name = "cloud-core", version.ref = "cloud" } cloudCore = { group = "org.incendo", name = "cloud-core", version.ref = "cloud" }
brigadier = "com.mojang:brigadier:1.0.18"
cloudMinecraftBom = { module = "org.incendo:cloud-minecraft-bom", version.ref = "cloudMinecraft" } cloudMinecraftBom = { module = "org.incendo:cloud-minecraft-bom", version.ref = "cloudMinecraft" }
cloudMinecraftExtras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloudMinecraft" } cloudMinecraftExtras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloudMinecraft" }
cloudPaper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloudMinecraft" } cloudPaper = { group = "org.incendo", name = "cloud-paper", version.ref = "cloudMinecraft" }
cloudSigned = { group = "org.incendo", name = "cloud-minecraft-signed-arguments", version.ref = "cloudMinecraft" }
cloudPaperSigned = { group = "org.incendo", name = "cloud-paper-signed-arguments", version.ref = "cloudMinecraft" }
cloudSponge = { group = "org.incendo", name = "cloud-sponge", version.ref = "cloudSponge" } cloudSponge = { group = "org.incendo", name = "cloud-sponge", version.ref = "cloudSponge" }
cloudVelocity = { group = "org.incendo", name = "cloud-velocity", version.ref = "cloudMinecraft" } cloudVelocity = { group = "org.incendo", name = "cloud-velocity", version.ref = "cloudMinecraft" }
cloudFabric = { group = "org.incendo", name = "cloud-fabric", version.ref = "cloudModded"} cloudFabric = { group = "org.incendo", name = "cloud-fabric", version.ref = "cloudModded"}
+3
View File
@@ -20,6 +20,7 @@ dependencies {
// Commands // Commands
implementation(libs.cloudPaper) implementation(libs.cloudPaper)
implementation(libs.cloudPaperSigned)
// Misc // Misc
implementation(libs.bstatsBukkit) implementation(libs.bstatsBukkit)
@@ -54,6 +55,8 @@ tasks {
shadowJar { shadowJar {
relocateDependency("io.papermc.papertrail") relocateDependency("io.papermc.papertrail")
relocateDependency("io.leangen.geantyref") relocateDependency("io.leangen.geantyref")
relocateDependency("xyz.jpenilla.reflectionremapper")
relocateDependency("net.fabricmc.mappingio")
relocateCloud() relocateCloud()
} }
withType(RunServer::class).configureEach { withType(RunServer::class).configureEach {
@@ -30,6 +30,7 @@ import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.CarbonPlatformModule; import net.draycia.carbon.common.CarbonPlatformModule;
import net.draycia.carbon.common.DataDirectory; import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PlatformScheduler; import net.draycia.carbon.common.PlatformScheduler;
import net.draycia.carbon.common.RawChat;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.integration.Integration; import net.draycia.carbon.common.integration.Integration;
@@ -48,6 +49,7 @@ import net.draycia.carbon.paper.listeners.PaperPlayerJoinListener;
import net.draycia.carbon.paper.messages.PaperMessageRenderer; import net.draycia.carbon.paper.messages.PaperMessageRenderer;
import net.draycia.carbon.paper.users.CarbonPlayerPaper; import net.draycia.carbon.paper.users.CarbonPlayerPaper;
import net.draycia.carbon.paper.users.PaperProfileResolver; import net.draycia.carbon.paper.users.PaperProfileResolver;
import net.kyori.adventure.key.Key;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.bukkit.Server; import org.bukkit.Server;
@@ -109,6 +111,7 @@ public final class CarbonChatPaperModule extends CarbonPlatformModule {
this.bind(PlatformScheduler.class).to(PaperScheduler.class); this.bind(PlatformScheduler.class).to(PaperScheduler.class);
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerPaper.class)); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerPaper.class));
this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(PaperMessageRenderer.class);
this.bind(Key.class).annotatedWith(RawChat.class).toInstance(Key.key("paper:raw"));
this.configureListeners(); this.configureListeners();
} }
@@ -34,6 +34,7 @@ import net.draycia.carbon.common.CarbonCommonModule;
import net.draycia.carbon.common.CarbonPlatformModule; import net.draycia.carbon.common.CarbonPlatformModule;
import net.draycia.carbon.common.DataDirectory; import net.draycia.carbon.common.DataDirectory;
import net.draycia.carbon.common.PlatformScheduler; import net.draycia.carbon.common.PlatformScheduler;
import net.draycia.carbon.common.RawChat;
import net.draycia.carbon.common.command.Commander; import net.draycia.carbon.common.command.Commander;
import net.draycia.carbon.common.command.ExecutionCoordinatorHolder; import net.draycia.carbon.common.command.ExecutionCoordinatorHolder;
import net.draycia.carbon.common.messages.CarbonMessageRenderer; import net.draycia.carbon.common.messages.CarbonMessageRenderer;
@@ -49,6 +50,7 @@ import net.draycia.carbon.velocity.listeners.VelocityPlayerJoinListener;
import net.draycia.carbon.velocity.listeners.VelocityPlayerLeaveListener; import net.draycia.carbon.velocity.listeners.VelocityPlayerLeaveListener;
import net.draycia.carbon.velocity.users.CarbonPlayerVelocity; import net.draycia.carbon.velocity.users.CarbonPlayerVelocity;
import net.draycia.carbon.velocity.users.VelocityProfileResolver; import net.draycia.carbon.velocity.users.VelocityProfileResolver;
import net.kyori.adventure.key.Key;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
@@ -115,6 +117,7 @@ public final class CarbonChatVelocityModule extends CarbonPlatformModule {
this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class); this.bind(PlatformScheduler.class).to(PlatformScheduler.RunImmediately.class);
this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerVelocity.class)); this.install(PlatformUserManager.PlayerFactory.moduleFor(CarbonPlayerVelocity.class));
this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class); this.bind(CarbonMessageRenderer.class).to(VelocityMessageRenderer.class);
this.bind(Key.class).annotatedWith(RawChat.class).toInstance(Key.key("unused:unused"));
this.configureListeners(); this.configureListeners();
} }