Add server requesting with custom names

This commit is contained in:
cswhite2000 2019-03-26 21:44:59 -07:00 committed by Austin Mayes
parent 7ed61a0984
commit e39fc6e9df
No known key found for this signature in database
GPG Key ID: 72C78ABE045D34F6
2 changed files with 7 additions and 1 deletions

View File

@ -10,4 +10,5 @@ import tc.oc.api.queue.MessageDefaults;
@MessageDefaults.ExpirationMillis(10000) @MessageDefaults.ExpirationMillis(10000)
public interface UseServerRequest extends Message { public interface UseServerRequest extends Message {
@Nonnull String user_id(); @Nonnull String user_id();
@Nonnull String server_name();
} }

View File

@ -75,17 +75,22 @@ public class ServerCommands implements Commands {
@Command( @Command(
aliases = {"requestserver", "re"}, aliases = {"requestserver", "re"},
desc = "Request a server for yourself" desc = "Request a server for yourself",
max = 1
) )
@CommandPermissions("ocn.requestserver") @CommandPermissions("ocn.requestserver")
public void request(final CommandContext args, CommandSender sender) throws CommandException { public void request(final CommandContext args, CommandSender sender) throws CommandException {
if(sender instanceof ProxiedPlayer) { if(sender instanceof ProxiedPlayer) {
final ProxiedPlayer player = (ProxiedPlayer) sender; final ProxiedPlayer player = (ProxiedPlayer) sender;
final String name = player.hasPermission("ocn.requestserver.custom") && args.argsLength() > 0 ? args.getString(0) : "";
commandExecutor.callback( commandExecutor.callback(
serverService.requestServer(new UseServerRequest() { serverService.requestServer(new UseServerRequest() {
@Nonnull @Override public String user_id() { @Nonnull @Override public String user_id() {
return userStore.getUser(player)._id(); return userStore.getUser(player)._id();
} }
@Nonnull @Override public String server_name() {
return name;
}
}), (response) -> { }), (response) -> {
if (response.now()) { if (response.now()) {
player.connect(proxy.getServerInfo(response.server_name())); player.connect(proxy.getServerInfo(response.server_name()));