Search in sources :

Example 1 with CommandManager

use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.

the class IdentifyCommand method register.

@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
    BedrockHandler bedrockHandler = crossplatForms.getBedrockHandler();
    ServerHandler serverHandler = crossplatForms.getServerHandler();
    manager.command(defaultBuilder.literal(NAME).permission(sender -> sender.hasPermission(PERMISSION) && sender.isPlayer()).handler(context -> {
        CommandOrigin origin = context.getSender();
        String message;
        if (bedrockHandler.isBedrockPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new))) {
            message = "You are a bedrock player";
        } else {
            message = "You are not a bedrock player";
        }
        origin.sendMessage(message);
    }).build());
    manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider((context, s) -> serverHandler.getPlayers().stream().map(FormPlayer::getName).collect(Collectors.toList())).build()).permission(PERMISSION_OTHER).handler(context -> {
        CommandOrigin origin = context.getSender();
        String targetName = context.get("player");
        FormPlayer target = serverHandler.getPlayer(targetName);
        if (target == null) {
            origin.warn("That player doesn't exist");
        } else {
            String message = targetName + (bedrockHandler.isBedrockPlayer(target.getUuid()) ? " is a Bedrock player" : " is not a Bedrock player");
            origin.sendMessage(message);
        }
    }).build());
}
Also used : CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) StringArgument(cloud.commandframework.arguments.standard.StringArgument) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) NoSuchElementException(java.util.NoSuchElementException) Command(cloud.commandframework.Command) Collectors(java.util.stream.Collectors) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler)

Example 2 with CommandManager

use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.

the class InspectCommand method register.

@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
    ServerHandler serverHandler = crossplatForms.getServerHandler();
    BedrockFormRegistry bedrockRegistry = crossplatForms.getInterfacer().getBedrockRegistry();
    JavaMenuRegistry javaRegistry = crossplatForms.getInterfacer().getJavaRegistry();
    Command.Builder<CommandOrigin> base = defaultBuilder.literal(NAME).permission(PERMISSION);
    manager.command(base.literal("form").argument(StringArgument.<CommandOrigin>newBuilder("form").withSuggestionsProvider(((context, s) -> bedrockRegistry.getForms().values().stream().map(Interface::getIdentifier).collect(Collectors.toList())))).handler(context -> {
        CommandOrigin origin = context.getSender();
        String name = context.get("form");
        BedrockForm form = bedrockRegistry.getForm(name);
        if (form == null) {
            origin.warn("That form doesn't exist!");
        } else {
            origin.sendMessage("Inspection of form: " + name);
            origin.sendMessage(form.toString());
        }
    }));
    manager.command(base.literal("menu").argument(StringArgument.<CommandOrigin>newBuilder("menu").withSuggestionsProvider(((context, s) -> javaRegistry.getMenus().values().stream().map(Interface::getIdentifier).collect(Collectors.toList())))).handler(context -> {
        CommandOrigin origin = context.getSender();
        String name = context.get("menu");
        JavaMenu menu = javaRegistry.getMenu(name);
        if (menu == null) {
            origin.warn("That menu doesn't exist!");
        } else {
            origin.sendMessage("Inspection of menu: " + name);
            origin.sendMessage(CrossplatForms.PLAIN_SERIALIZER.deserialize(menu.toString()));
        }
    }));
}
Also used : BedrockForm(dev.projectg.crossplatforms.interfacing.bedrock.BedrockForm) BedrockFormRegistry(dev.projectg.crossplatforms.interfacing.bedrock.BedrockFormRegistry) JavaMenu(dev.projectg.crossplatforms.interfacing.java.JavaMenu) StringArgument(cloud.commandframework.arguments.standard.StringArgument) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) JavaMenuRegistry(dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry) Collectors(java.util.stream.Collectors) CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) Interface(dev.projectg.crossplatforms.interfacing.Interface) Command(cloud.commandframework.Command) BedrockForm(dev.projectg.crossplatforms.interfacing.bedrock.BedrockForm) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) Command(cloud.commandframework.Command) BedrockFormRegistry(dev.projectg.crossplatforms.interfacing.bedrock.BedrockFormRegistry) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) JavaMenu(dev.projectg.crossplatforms.interfacing.java.JavaMenu) JavaMenuRegistry(dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry) Interface(dev.projectg.crossplatforms.interfacing.Interface)

Example 3 with CommandManager

use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.

the class ListCommand method register.

@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
    BedrockHandler bedrockHandler = crossplatForms.getBedrockHandler();
    BedrockFormRegistry bedrockRegistry = crossplatForms.getInterfacer().getBedrockRegistry();
    JavaMenuRegistry javaRegistry = crossplatForms.getInterfacer().getJavaRegistry();
    manager.command(defaultBuilder.literal(NAME).permission(PERMISSION).handler(context -> {
        List<Interface> interfaces = new ArrayList<>();
        CommandOrigin origin = context.getSender();
        if (origin.isPlayer() && !origin.hasPermission(OpenCommand.PERMISSION_OTHER)) {
            if (bedrockHandler.isBedrockPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new))) {
                interfaces.addAll(bedrockRegistry.getForms().values());
                javaRegistry.getMenus().values().stream().filter(JavaMenu::isAllowBedrock).forEach(interfaces::add);
            } else {
                interfaces.addAll(javaRegistry.getMenus().values());
            }
        } else {
            // Origin is console or they have permission to send to others
            interfaces.addAll(bedrockRegistry.getForms().values());
            interfaces.addAll(javaRegistry.getMenus().values());
        }
        List<String> names = interfaces.stream().filter(ui -> origin.hasPermission(ui.permission(Interface.Limit.COMMAND))).map(Interface::getIdentifier).distinct().collect(Collectors.toList());
        if (names.isEmpty()) {
            context.getSender().sendMessage("There are no menus or forms to list.");
        } else {
            context.getSender().sendMessage("Available forms/menus:");
            context.getSender().sendMessage(String.join(", ", names));
        }
    }).build());
}
Also used : BedrockFormRegistry(dev.projectg.crossplatforms.interfacing.bedrock.BedrockFormRegistry) JavaMenu(dev.projectg.crossplatforms.interfacing.java.JavaMenu) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) JavaMenuRegistry(dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) List(java.util.List) Interface(dev.projectg.crossplatforms.interfacing.Interface) NoSuchElementException(java.util.NoSuchElementException) Command(cloud.commandframework.Command) BedrockFormRegistry(dev.projectg.crossplatforms.interfacing.bedrock.BedrockFormRegistry) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) ArrayList(java.util.ArrayList) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) JavaMenuRegistry(dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry) Interface(dev.projectg.crossplatforms.interfacing.Interface)

Example 4 with CommandManager

use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.

the class OpenCommand method register.

@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
    // Base open command
    manager.command(defaultBuilder.literal(OPEN_NAME).permission(origin -> origin.hasPermission(PERMISSION) && origin.isPlayer()).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> openSuggestions(context)).build()).handler(context -> {
        CommandOrigin origin = context.getSender();
        UUID uuid = origin.getUUID().orElseThrow(NoSuchElementException::new);
        FormPlayer player = Objects.requireNonNull(serverHandler.getPlayer(uuid));
        String identifier = context.get(ARGUMENT);
        Interface ui = interfacer.getInterface(identifier, bedrockHandler.isBedrockPlayer(uuid));
        if (ui == null) {
            origin.warn("'" + identifier + "' doesn't exist.");
            return;
        }
        if (origin.hasPermission(ui.permission(Interface.Limit.COMMAND))) {
            if (origin.hasPermission(ui.permission(Interface.Limit.USE))) {
                ui.send(player);
            } else {
                origin.warn("You don't have permission to use: " + identifier);
            }
        } else {
            origin.warn("You don't have permission to send: " + identifier);
        }
    }));
    // Send command to make other players open a form or menu
    manager.command(defaultBuilder.literal(SEND_NAME).permission(PERMISSION_OTHER).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider((context, s) -> serverHandler.getPlayers().stream().map(FormPlayer::getName).collect(Collectors.toList())).build()).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> sendSuggestions(context)).build()).handler(context -> {
        CommandOrigin origin = context.getSender();
        String target = context.get("player");
        FormPlayer targetPlayer = serverHandler.getPlayer(target);
        if (targetPlayer == null) {
            origin.warn("The player " + target + " doesn't exist.");
            return;
        }
        String identifier = context.get(ARGUMENT);
        Interface ui = this.interfacer.getInterface(identifier, bedrockHandler.isBedrockPlayer(targetPlayer.getUuid()));
        if (ui == null) {
            origin.warn("'" + identifier + "' doesn't exist.");
            return;
        }
        if (origin.hasPermission(ui.permission(Interface.Limit.COMMAND))) {
            if (targetPlayer.hasPermission(ui.permission(Interface.Limit.USE))) {
                ui.send(targetPlayer);
            } else {
                origin.warn(target + " doesn't have permission to use: " + identifier);
            }
        } else {
            origin.warn("You don't have permission to send: " + identifier);
        }
    }).build());
}
Also used : StringArgument(cloud.commandframework.arguments.standard.StringArgument) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) JavaMenuRegistry(dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) Objects(java.util.Objects) CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) List(java.util.List) Interface(dev.projectg.crossplatforms.interfacing.Interface) CommandContext(cloud.commandframework.context.CommandContext) Interfacer(dev.projectg.crossplatforms.interfacing.Interfacer) NoSuchElementException(java.util.NoSuchElementException) Command(cloud.commandframework.Command) Collections(java.util.Collections) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) UUID(java.util.UUID) Interface(dev.projectg.crossplatforms.interfacing.Interface)

Example 5 with CommandManager

use of cloud.commandframework.CommandManager in project CrossplatForms by ProjectG-Plugins.

the class GiveCommand method register.

@Override
public void register(CommandManager<CommandOrigin> manager, Command.Builder<CommandOrigin> defaultBuilder) {
    // Base open command
    manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> itemSuggestions(context)).build()).permission(origin -> origin.hasPermission(PERMISSION) && origin.isPlayer()).handler(context -> {
        CommandOrigin origin = context.getSender();
        FormPlayer player = serverHandler.getPlayer(origin.getUUID().orElseThrow(NoSuchElementException::new));
        String identifier = context.get(ARGUMENT);
        AccessItem item = itemRegistry.getItems().get(identifier);
        if (item == null) {
            origin.warn("'" + identifier + "' doesn't exist.");
            return;
        }
        if (origin.hasPermission(item.permission(AccessItem.Limit.COMMAND))) {
            if (origin.hasPermission(item.permission(AccessItem.Limit.POSSESS))) {
                if (!itemRegistry.giveAccessItem(player, item, false)) {
                    origin.warn("Your inventory is too full!");
                }
            } else {
                origin.warn("You don't have permission to have: " + identifier);
            }
        } else {
            origin.warn("You don't have permission to give: " + identifier);
        }
    }));
    // Additional command to make other players open a form or menu
    manager.command(defaultBuilder.literal(NAME).argument(StringArgument.<CommandOrigin>newBuilder(ARGUMENT).withSuggestionsProvider((context, s) -> itemSuggestions(context)).build()).argument(StringArgument.<CommandOrigin>newBuilder("player").withSuggestionsProvider(((context, s) -> playerSuggestions(context))).build()).permission(PERMISSION_OTHER).handler(context -> {
        CommandOrigin origin = context.getSender();
        String target = context.get("player");
        FormPlayer targetPlayer = serverHandler.getPlayer(target);
        if (targetPlayer == null) {
            origin.warn("The player " + target + " doesn't exist.");
            return;
        }
        String identifier = context.get(ARGUMENT);
        AccessItem item = itemRegistry.getItems().get(identifier);
        if (item == null) {
            origin.warn("'" + identifier + "' doesn't exist.");
            return;
        }
        if (origin.hasPermission(item.permission(AccessItem.Limit.COMMAND))) {
            if (targetPlayer.hasPermission(item.permission(AccessItem.Limit.POSSESS))) {
                if (!itemRegistry.giveAccessItem(targetPlayer, item, false)) {
                    origin.warn(String.format("%s's inventory is too full!", targetPlayer.getName()));
                }
            } else {
                origin.warn(target + " doesn't have permission to have: " + identifier);
            }
        } else {
            origin.warn("You don't have permission to give: " + identifier);
        }
    }).build());
}
Also used : StringArgument(cloud.commandframework.arguments.standard.StringArgument) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) FormsCommand(dev.projectg.crossplatforms.command.FormsCommand) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) Collectors(java.util.stream.Collectors) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) List(java.util.List) CommandContext(cloud.commandframework.context.CommandContext) NoSuchElementException(java.util.NoSuchElementException) Command(cloud.commandframework.Command) Collections(java.util.Collections) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

CommandManager (cloud.commandframework.CommandManager)6 Command (cloud.commandframework.Command)5 CrossplatForms (dev.projectg.crossplatforms.CrossplatForms)5 CommandOrigin (dev.projectg.crossplatforms.command.CommandOrigin)5 FormsCommand (dev.projectg.crossplatforms.command.FormsCommand)5 Collectors (java.util.stream.Collectors)5 StringArgument (cloud.commandframework.arguments.standard.StringArgument)4 BedrockHandler (dev.projectg.crossplatforms.handler.BedrockHandler)4 ServerHandler (dev.projectg.crossplatforms.handler.ServerHandler)4 NoSuchElementException (java.util.NoSuchElementException)4 FormPlayer (dev.projectg.crossplatforms.handler.FormPlayer)3 Interface (dev.projectg.crossplatforms.interfacing.Interface)3 JavaMenuRegistry (dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry)3 List (java.util.List)3 CommandContext (cloud.commandframework.context.CommandContext)2 BedrockFormRegistry (dev.projectg.crossplatforms.interfacing.bedrock.BedrockFormRegistry)2 JavaMenu (dev.projectg.crossplatforms.interfacing.java.JavaMenu)2 Collections (java.util.Collections)2 CommandExecutionCoordinator (cloud.commandframework.execution.CommandExecutionCoordinator)1 CloudInjectionModule (cloud.commandframework.velocity.CloudInjectionModule)1