mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Fixes for sponge platform
This commit is contained in:
14 files changed
+158
-54
No files matched your search
@@ -2,6 +2,9 @@ package net.draycia.carbon.common;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.common.command.commands.ContinueCommand;
|
||||
import net.draycia.carbon.common.command.commands.ReplyCommand;
|
||||
import net.draycia.carbon.common.command.commands.WhisperCommand;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@@ -9,6 +12,9 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
public abstract class CarbonChatCommon implements CarbonChat {
|
||||
|
||||
public final void initialize(final Injector injector) {
|
||||
injector.getInstance(ContinueCommand.class);
|
||||
injector.getInstance(ReplyCommand.class);
|
||||
injector.getInstance(WhisperCommand.class);
|
||||
// lol, bukkit module can't extend Common and it can't call this
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
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;
|
||||
@@ -13,6 +14,7 @@ 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;
|
||||
|
||||
@@ -44,12 +46,18 @@ public final class BasicChatChannel implements ChatChannel {
|
||||
return this.service.basicChatFormat(
|
||||
recipient,
|
||||
sender.uuid(),
|
||||
sender.displayName(),
|
||||
Objects.requireNonNullElseGet(sender.displayName(), () -> Component.text(sender.username())),
|
||||
sender.username(),
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String quickPrefix() {
|
||||
// todo
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
import com.google.inject.TypeLiteral;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -105,8 +104,7 @@ public class CarbonChannelRegistry extends RegistryImpl<Key, ChatChannel> implem
|
||||
}
|
||||
|
||||
try (final Stream<Path> paths = Files.walk(channelDirectory)) {
|
||||
final CommandManager<Commander> commandManager = (CommandManager<Commander>)
|
||||
this.injector.getInstance(com.google.inject.Key.get(new TypeToken<CommandManager<Commander>>() {}.getType()));
|
||||
final CommandManager<Commander> commandManager = this.injector.getInstance(com.google.inject.Key.get(new TypeLiteral<CommandManager<Commander>>() {}));
|
||||
|
||||
paths.forEach(path -> {
|
||||
final String fileName = path.getFileName().toString();
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ public interface ConfigChannelMessageService {
|
||||
Component chatFormat(
|
||||
final SourcedAudience audience,
|
||||
@Placeholder UUID uuid,
|
||||
@Placeholder("displayname") Component displayName,
|
||||
@Placeholder Component displayname,
|
||||
@Placeholder String username,
|
||||
@Placeholder Component message
|
||||
);
|
||||
|
||||
+22
-30
@@ -3,31 +3,27 @@ package net.draycia.carbon.common.command.arguments;
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.captions.Caption;
|
||||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import java.util.stream.StreamSupport;
|
||||
import net.draycia.carbon.api.CarbonServer;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CarbonPlayerArgument {
|
||||
|
||||
final Injector injector;
|
||||
private final CarbonServer server;
|
||||
|
||||
@Inject
|
||||
public CarbonPlayerArgument(final Injector injector) {
|
||||
this.injector = injector;
|
||||
public CarbonPlayerArgument(final CarbonServer server) {
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
public CommandArgument<Commander, CarbonPlayer> newInstance(boolean required, final String name) {
|
||||
return new CarbonPlayerArgumentImpl(required, name, this.injector.getInstance(CarbonPlayerArgumentParser.class), CarbonPlayer.class);
|
||||
return new CarbonPlayerArgumentImpl(required, name, new CarbonPlayerArgumentParser(this.server), CarbonPlayer.class);
|
||||
}
|
||||
|
||||
public static final class CarbonPlayerArgumentImpl extends CommandArgument<Commander, CarbonPlayer> {
|
||||
@@ -40,52 +36,44 @@ public class CarbonPlayerArgument {
|
||||
|
||||
private static final class CarbonPlayerArgumentParser implements ArgumentParser<Commander, CarbonPlayer> {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CarbonServer server;
|
||||
|
||||
@Inject
|
||||
public CarbonPlayerArgumentParser(final CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
public CarbonPlayerArgumentParser(final CarbonServer carbonServer) {
|
||||
this.server = carbonServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<@NonNull CarbonPlayer> parse(@NonNull CommandContext<@NonNull Commander> commandContext, @NonNull Queue<@NonNull String> inputQueue) {
|
||||
final String input = inputQueue.poll();
|
||||
final String input = inputQueue.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(CarbonPlayerArgumentParser.class, commandContext));
|
||||
}
|
||||
|
||||
for (var player : this.carbonChat.server().players()) {
|
||||
for (var player : this.server.players()) {
|
||||
if (player.username().equalsIgnoreCase(input)) {
|
||||
inputQueue.remove();
|
||||
return ArgumentParseResult.success(player);
|
||||
}
|
||||
}
|
||||
|
||||
return ArgumentParseResult.failure(new PlayerParseException(input, commandContext));
|
||||
return ArgumentParseResult.failure(new PlayerParseException(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(@NonNull CommandContext<Commander> commandContext, @NonNull String input) {
|
||||
return ArgumentParser.super.suggestions(commandContext, input);
|
||||
return StreamSupport.stream(this.server.players().spliterator(), false)
|
||||
.map(CarbonPlayer::username)
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class PlayerParseException extends ParserException {
|
||||
public static final class PlayerParseException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = -8703083769083215214L;
|
||||
private final String input;
|
||||
|
||||
public PlayerParseException(
|
||||
final @NonNull String input,
|
||||
final @NonNull CommandContext<?> context
|
||||
final @NonNull String input
|
||||
) {
|
||||
super(
|
||||
CarbonPlayerArgumentParser.class,
|
||||
context,
|
||||
Caption.of("No player with that name was found!"),
|
||||
CaptionVariable.of("input", input)
|
||||
);
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
@@ -93,6 +81,10 @@ public class CarbonPlayerArgument {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "No player found for input: '" + this.input + "'";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class LocaleSerializerConfigurate implements TypeSerializer<Locale> {
|
||||
if (obj == null) {
|
||||
node.set(null);
|
||||
} else {
|
||||
node.set(obj.toLanguageTag());
|
||||
node.set(obj.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user