Skip to content

Commit

Permalink
Update Cloud to 2.0 beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Feb 15, 2024
1 parent 8030dac commit 80cfa48
Show file tree
Hide file tree
Showing 23 changed files with 254 additions and 331 deletions.
2 changes: 1 addition & 1 deletion bungee/base/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
}

relocate("net.kyori")
relocate("cloud.commandframework")
relocate("org.incendo.cloud")
relocate("io.leangen.geantyref") // used in cloud

// these dependencies are already present on the platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,28 @@

package org.geysermc.floodgate.bungee.module;

import cloud.commandframework.CommandManager;
import cloud.commandframework.bungee.BungeeCommandManager;
import cloud.commandframework.execution.CommandExecutionCoordinator;
import io.micronaut.context.annotation.Bean;
import io.micronaut.context.annotation.Factory;
import jakarta.inject.Named;
import jakarta.inject.Singleton;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Plugin;
import org.geysermc.floodgate.core.connection.audience.FloodgateCommandPreprocessor;
import org.geysermc.floodgate.core.connection.audience.FloodgateSenderMapper;
import org.geysermc.floodgate.core.connection.audience.UserAudience;
import org.geysermc.floodgate.core.platform.command.CommandUtil;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.bungee.BungeeCommandManager;
import org.incendo.cloud.execution.ExecutionCoordinator;

@Factory
public final class BungeePlatformModule {
@Bean
@Singleton
public CommandManager<UserAudience> commandManager(CommandUtil commandUtil, Plugin plugin) {
CommandManager<UserAudience> commandManager = new BungeeCommandManager<>(
var commandManager = new BungeeCommandManager<>(
plugin,
CommandExecutionCoordinator.simpleCoordinator(),
commandUtil::getUserAudience,
audience -> (CommandSender) audience.source()
ExecutionCoordinator.simpleCoordinator(),
new FloodgateSenderMapper<>(commandUtil)
);
commandManager.registerCommandPreProcessor(new FloodgateCommandPreprocessor<>(commandUtil));
return commandManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,8 @@

package org.geysermc.floodgate.core.command;

import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.context.CommandContext;
import static org.incendo.cloud.parser.standard.StringParser.stringParser;

import io.micronaut.context.annotation.Secondary;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand All @@ -40,7 +37,6 @@
import org.geysermc.floodgate.core.command.util.Permission;
import org.geysermc.floodgate.core.config.FloodgateConfig;
import org.geysermc.floodgate.core.connection.audience.ProfileAudience;
import org.geysermc.floodgate.core.connection.audience.ProfileAudienceArgument;
import org.geysermc.floodgate.core.connection.audience.UserAudience;
import org.geysermc.floodgate.core.connection.audience.UserAudience.PlayerAudience;
import org.geysermc.floodgate.core.link.CommonPlayerLink;
Expand All @@ -50,6 +46,10 @@
import org.geysermc.floodgate.core.platform.command.TranslatableMessage;
import org.geysermc.floodgate.core.util.Constants;
import org.geysermc.floodgate.core.util.Utils;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.description.Description;

@Singleton
@Secondary
Expand All @@ -59,20 +59,19 @@ public final class LinkAccountCommand implements FloodgateCommand {
@Inject FloodgateLogger logger;

@Override
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
public Command<PlayerAudience> buildCommand(CommandManager<UserAudience> commandManager) {
return commandManager.commandBuilder("linkaccount",
ArgumentDescription.of("Link your Java account with your Bedrock account"))
Description.of("Link your Java account with your Bedrock account"))
.senderType(PlayerAudience.class)
.permission(Permission.COMMAND_LINK.get())
.argument(ProfileAudienceArgument.of("player", true))
.argument(StringArgument.optional("code"))
.argument(ProfileAudience.ofAnyUsernameBoth("player"))
.optional("code", stringParser())
.handler(this::execute)
.build();
}

@Override
public void execute(CommandContext<UserAudience> context) {
UserAudience sender = context.getSender();
public void execute(CommandContext<PlayerAudience> context) {
UserAudience sender = context.sender();

//todo make this less hacky
if (link instanceof GlobalPlayerLinking) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,39 @@

package org.geysermc.floodgate.core.command;

import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.arguments.standard.StringArgument;
import cloud.commandframework.arguments.standard.UUIDArgument;
import cloud.commandframework.context.CommandContext;
import static org.incendo.cloud.parser.standard.StringParser.stringParser;
import static org.incendo.cloud.parser.standard.UUIDParser.uuidParser;

import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import java.util.concurrent.ExecutionException;
import org.geysermc.floodgate.core.config.FloodgateConfig;
import org.geysermc.floodgate.core.connection.audience.UserAudience;
import org.geysermc.floodgate.core.connection.audience.UserAudience.ConsoleAudience;
import org.geysermc.floodgate.core.link.CommonPlayerLink;
import org.geysermc.floodgate.core.platform.command.FloodgateCommand;
import org.geysermc.floodgate.core.util.Constants;
import org.geysermc.floodgate.core.util.Utils;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;

@Singleton
public class TestCommand implements FloodgateCommand {
@Inject CommonPlayerLink link;

@Override
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
public Command<ConsoleAudience> buildCommand(CommandManager<UserAudience> commandManager) {
return commandManager.commandBuilder("floodgate-test")
.senderType(UserAudience.ConsoleAudience.class)
.senderType(ConsoleAudience.class)
.required("xuid", stringParser())
.required("uuid", uuidParser())
.required("name", stringParser())
.handler(this::execute)
.argument(StringArgument.of("xuid"))
.argument(UUIDArgument.of("uuid"))
.argument(StringArgument.of("name"))
.build();
}

@Override
public void execute(CommandContext<UserAudience> context) {
public void execute(CommandContext<ConsoleAudience> context) {
try {
link.addLink(context.get("uuid"), context.get("name"), Utils.getJavaUuid(context.get("xuid"))).get();
} catch (InterruptedException | ExecutionException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

package org.geysermc.floodgate.core.command;

import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.context.CommandContext;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
import lombok.Getter;
Expand All @@ -41,24 +37,27 @@
import org.geysermc.floodgate.core.platform.command.FloodgateCommand;
import org.geysermc.floodgate.core.platform.command.TranslatableMessage;
import org.geysermc.floodgate.core.util.Constants;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.description.Description;

@Singleton
public final class UnlinkAccountCommand implements FloodgateCommand {
@Inject CommonPlayerLink link;

@Override
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
public Command<PlayerAudience> buildCommand(CommandManager<UserAudience> commandManager) {
return commandManager.commandBuilder("unlinkaccount",
ArgumentDescription.of("Unlink your Java account from your Bedrock account"))
Description.of("Unlink your Java account from your Bedrock account"))
.senderType(PlayerAudience.class)
.permission(Permission.COMMAND_UNLINK.get())
.handler(this::execute)
.build();
}

@Override
public void execute(CommandContext<UserAudience> context) {
UserAudience sender = context.getSender();
public void execute(CommandContext<PlayerAudience> context) {
UserAudience sender = context.sender();

//todo make this less hacky
if (link instanceof GlobalPlayerLinking) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@

package org.geysermc.floodgate.core.command;

import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.Command;
import cloud.commandframework.CommandManager;
import cloud.commandframework.context.CommandContext;
import io.micronaut.http.client.exceptions.HttpClientResponseException;
import jakarta.inject.Inject;
import jakarta.inject.Singleton;
Expand All @@ -39,13 +35,15 @@
import org.geysermc.floodgate.core.config.FloodgateConfig;
import org.geysermc.floodgate.core.config.ProxyFloodgateConfig;
import org.geysermc.floodgate.core.connection.audience.ProfileAudience;
import org.geysermc.floodgate.core.connection.audience.ProfileAudienceArgument;
import org.geysermc.floodgate.core.connection.audience.UserAudience;
import org.geysermc.floodgate.core.http.xbox.XboxClient;
import org.geysermc.floodgate.core.platform.command.CommandUtil;
import org.geysermc.floodgate.core.platform.command.FloodgateCommand;
import org.geysermc.floodgate.core.platform.command.TranslatableMessage;
import org.geysermc.floodgate.core.platform.util.PlayerType;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.description.Description;

@Singleton
public class WhitelistCommand implements FloodgateCommand {
Expand All @@ -56,23 +54,23 @@ public class WhitelistCommand implements FloodgateCommand {
@Override
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
Command.Builder<UserAudience> builder = commandManager.commandBuilder("fwhitelist",
ArgumentDescription.of("Easy way to whitelist Bedrock players"))
Description.of("Easy way to whitelist Bedrock players"))
.permission(Permission.COMMAND_WHITELIST.get());

commandManager.command(builder
.literal("add", "a")
.argument(ProfileAudienceArgument.of("player", true, true, PlayerType.ONLY_BEDROCK))
.argument(ProfileAudience.ofAnyIdentifierBedrock("player"))
.handler(context -> performCommand(context, true)));

return builder
.literal("remove", "r")
.argument(ProfileAudienceArgument.of("player", true, true, PlayerType.ONLY_BEDROCK))
.argument(ProfileAudience.ofAnyIdentifierBedrock("player"))
.handler(context -> performCommand(context, false))
.build();
}

public void performCommand(CommandContext<UserAudience> context, boolean add) {
UserAudience sender = context.getSender();
UserAudience sender = context.sender();
ProfileAudience profile = context.get("player");
UUID uuid = profile.uuid();
String name = profile.username();
Expand Down Expand Up @@ -181,11 +179,6 @@ public void performCommand(CommandContext<UserAudience> context, boolean add) {
});
}

@Override
public void execute(CommandContext<UserAudience> context) {
// ignored, all the logic is in the other method
}

@Override
public boolean shouldRegister(FloodgateConfig config) {
// currently only Spigot (our only non-Proxy platform) has a whitelist build-in.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static org.geysermc.floodgate.core.util.Constants.COLOR_CHAR;

import cloud.commandframework.context.CommandContext;
import com.google.gson.JsonElement;
import it.unimi.dsi.fastutil.Pair;
import jakarta.inject.Inject;
Expand All @@ -41,6 +40,7 @@
import org.geysermc.floodgate.core.util.HttpClient;
import org.geysermc.floodgate.core.util.HttpClient.HttpResponse;
import org.geysermc.floodgate.core.util.Utils;
import org.incendo.cloud.context.CommandContext;

final class FirewallCheckSubcommand extends FloodgateSubCommand {
@Inject HttpClient httpProvider;
Expand All @@ -67,7 +67,7 @@ public Permission permission() {

@Override
public void execute(CommandContext<UserAudience> context) {
UserAudience sender = context.getSender();
UserAudience sender = context.sender();
executeChecks(
globalApiCheck(sender)
).whenComplete((response, $) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,35 @@
package org.geysermc.floodgate.core.command.main;

import static org.geysermc.floodgate.core.util.Constants.COLOR_CHAR;
import static org.incendo.cloud.description.Description.description;

import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.Command;
import cloud.commandframework.Command.Builder;
import cloud.commandframework.CommandManager;
import cloud.commandframework.context.CommandContext;
import jakarta.inject.Singleton;
import java.util.Locale;
import org.geysermc.floodgate.core.command.util.Permission;
import org.geysermc.floodgate.core.connection.audience.UserAudience;
import org.geysermc.floodgate.core.platform.command.FloodgateCommand;
import org.geysermc.floodgate.core.platform.command.FloodgateSubCommand;
import org.geysermc.floodgate.core.platform.command.SubCommands;
import org.incendo.cloud.Command;
import org.incendo.cloud.Command.Builder;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.context.CommandContext;
import org.incendo.cloud.description.Description;

@Singleton
public final class MainCommand extends SubCommands implements FloodgateCommand {
@Override
public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandManager) {
Builder<UserAudience> builder = commandManager.commandBuilder(
"floodgate",
ArgumentDescription.of("A set of Floodgate related actions in one command"))
Description.of("A set of Floodgate related actions in one command"))
.senderType(UserAudience.class)
.permission(Permission.COMMAND_MAIN.get())
.handler(this::execute);

for (FloodgateSubCommand subCommand : subCommands()) {
commandManager.command(builder
.literal(subCommand.name().toLowerCase(Locale.ROOT), subCommand.description())
.literal(subCommand.name().toLowerCase(Locale.ROOT), description(subCommand.description()))
.permission(subCommand.permission().get())
.handler(subCommand::execute)
);
Expand All @@ -63,19 +64,18 @@ public Command<UserAudience> buildCommand(CommandManager<UserAudience> commandMa
return builder.build();
}

@Override
public void execute(CommandContext<UserAudience> context) {
StringBuilder helpMessage = new StringBuilder("Available subcommands are:\n");

for (FloodgateSubCommand subCommand : subCommands()) {
if (context.getSender().hasPermission(subCommand.permission().get())) {
if (context.sender().hasPermission(subCommand.permission().get())) {
helpMessage.append('\n').append(COLOR_CHAR).append('b')
.append(subCommand.name().toLowerCase(Locale.ROOT))
.append(COLOR_CHAR).append("f - ").append(COLOR_CHAR).append('7')
.append(subCommand.description());
}
}

context.getSender().sendMessage(helpMessage.toString());
context.sender().sendMessage(helpMessage.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static org.geysermc.floodgate.core.util.Constants.COLOR_CHAR;

import cloud.commandframework.context.CommandContext;
import com.google.gson.JsonElement;
import jakarta.inject.Inject;
import org.geysermc.floodgate.api.logger.FloodgateLogger;
Expand All @@ -37,6 +36,7 @@
import org.geysermc.floodgate.core.platform.command.FloodgateSubCommand;
import org.geysermc.floodgate.core.util.Constants;
import org.geysermc.floodgate.core.util.HttpClient;
import org.incendo.cloud.context.CommandContext;

public class VersionSubcommand extends FloodgateSubCommand {
@Inject HttpClient httpClient;
Expand Down Expand Up @@ -64,7 +64,7 @@ public Permission permission() {

@Override
public void execute(CommandContext<UserAudience> context) {
UserAudience sender = context.getSender();
UserAudience sender = context.sender();
sender.sendMessage(String.format(
COLOR_CHAR + "7You're currently on " + COLOR_CHAR + "b%s" +
COLOR_CHAR + "7 (branch: " + COLOR_CHAR + "b%s" + COLOR_CHAR + "7)\n" +
Expand Down
Loading

0 comments on commit 80cfa48

Please sign in to comment.