Search in sources :

Example 1 with BedrockHandler

use of dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.

the class ProxyCommandManager method load.

private void load() {
    if (configManager.getConfig(GeneralConfig.class).isEmpty()) {
        return;
    }
    GeneralConfig config = configManager.getConfig(GeneralConfig.class).get();
    commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, config.isUnsafeCommandRegistration());
    registeredCommands.clear();
    for (ProxyCommand command : config.getCommands().values()) {
        String name = command.getName();
        if (command.getPermission() == null || command.getPermission().isBlank()) {
            command.setPermission(Constants.ID + ".shortcut." + name);
        }
        CommandType type = command.getMethod();
        if (type == CommandType.REGISTER) {
            if (commandManager.getCommandTree().getNamedNode(name) == null) {
                // any references to the command are done through the map so that it can be updated after a reload
                if (commandManager.isCommandRegistrationAllowed()) {
                    Logger.getLogger().debug("Registering shortcut command: " + command.getName());
                    commandManager.command(commandManager.commandBuilder(name).permission((origin) -> {
                        ProxyCommand target = registeredCommands.get(name);
                        if (target == null) {
                            // no longer present in the config
                            return false;
                        } else {
                            return origin.isPlayer() && origin.hasPermission(target.getPermission());
                        }
                    }).handler((context) -> {
                        FormPlayer player = Objects.requireNonNull(serverHandler.getPlayer(context.getSender().getUUID().orElseThrow()));
                        registeredCommands.get(name).run(player, interfaceManager, bedrockHandler);
                    }));
                } else {
                    Logger.getLogger().warn("Unable to register shortcut command '" + name + "' because registration is no longer possible. Restart the server for changes to apply.");
                }
            }
            // store the command
            registeredCommands.put(name, command);
        } else if (type == CommandType.INTERCEPT_CANCEL || type == CommandType.INTERCEPT_PASS) {
            serverHandler.registerProxyCommand(command);
        } else {
            Logger.getLogger().severe("Unhandled CommandType enum constant: " + type);
        }
    }
}
Also used : Constants(dev.projectg.crossplatforms.Constants) ReloadableRegistry(dev.projectg.crossplatforms.reloadable.ReloadableRegistry) ConfigManager(dev.projectg.crossplatforms.config.ConfigManager) CommandManager(cloud.commandframework.CommandManager) CommandOrigin(dev.projectg.crossplatforms.command.CommandOrigin) HashMap(java.util.HashMap) ServerHandler(dev.projectg.crossplatforms.handler.ServerHandler) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) Objects(java.util.Objects) InterfaceManager(dev.projectg.crossplatforms.interfacing.InterfaceManager) CrossplatForms(dev.projectg.crossplatforms.CrossplatForms) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) CommandType(dev.projectg.crossplatforms.command.CommandType) Map(java.util.Map) Logger(dev.projectg.crossplatforms.Logger) GeneralConfig(dev.projectg.crossplatforms.config.GeneralConfig) Reloadable(dev.projectg.crossplatforms.reloadable.Reloadable) FormPlayer(dev.projectg.crossplatforms.handler.FormPlayer) CommandType(dev.projectg.crossplatforms.command.CommandType) GeneralConfig(dev.projectg.crossplatforms.config.GeneralConfig)

Example 2 with BedrockHandler

use of dev.projectg.crossplatforms.handler.BedrockHandler 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 3 with BedrockHandler

use of dev.projectg.crossplatforms.handler.BedrockHandler 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 BedrockHandler

use of dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.

the class OpenCommand method sendSuggestions.

private List<String> sendSuggestions(CommandContext<CommandOrigin> context) {
    CommandOrigin origin = context.getSender();
    if (origin.isBedrockPlayer(bedrockHandler)) {
        return Collections.emptyList();
    }
    String recipient = context.get("player");
    FormPlayer target = serverHandler.getPlayer(recipient);
    if (target == null) {
        return Collections.emptyList();
    }
    return interfacer.getInterfaces(bedrockHandler.isBedrockPlayer(target.getUuid())).stream().filter(ui -> origin.hasPermission(ui.permission(Interface.Limit.COMMAND)) && target.hasPermission(ui.permission(Interface.Limit.USE))).map(Interface::getIdentifier).distinct().collect(Collectors.toList());
}
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) Interface(dev.projectg.crossplatforms.interfacing.Interface)

Example 5 with BedrockHandler

use of dev.projectg.crossplatforms.handler.BedrockHandler in project CrossplatForms by ProjectG-Plugins.

the class BungeeCordHandler method onPreProcessCommand.

@EventHandler
public void onPreProcessCommand(ChatEvent event) {
    Connection connection = event.getSender();
    if (event.isCancelled() || !(connection instanceof ProxiedPlayer) || !event.isCommand() || !event.isProxyCommand()) {
        return;
    }
    String input = event.getMessage().substring(1);
    Logger.get().debug("preprocess command: [" + event.getMessage() + "] -> [" + input + "]");
    // attempt to find an exact match
    InterceptCommand command = findCommand(input);
    if (command != null) {
        ProxiedPlayer player = (ProxiedPlayer) connection;
        BedrockHandler bedrockHandler = CrossplatForms.getInstance().getBedrockHandler();
        if (command.getPlatform().matches(player.getUniqueId(), bedrockHandler)) {
            String permission = command.getPermission();
            if (permission == null || player.hasPermission(permission)) {
                command.run(new BungeeCordPlayer(player));
                if (command.getMethod() == CommandType.INTERCEPT_CANCEL) {
                    event.setCancelled(true);
                }
            }
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) InterceptCommand(dev.projectg.crossplatforms.command.custom.InterceptCommand) Connection(net.md_5.bungee.api.connection.Connection) BedrockHandler(dev.projectg.crossplatforms.handler.BedrockHandler) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

BedrockHandler (dev.projectg.crossplatforms.handler.BedrockHandler)9 FormPlayer (dev.projectg.crossplatforms.handler.FormPlayer)6 CrossplatForms (dev.projectg.crossplatforms.CrossplatForms)5 CommandManager (cloud.commandframework.CommandManager)4 CommandOrigin (dev.projectg.crossplatforms.command.CommandOrigin)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 Command (cloud.commandframework.Command)3 FormsCommand (dev.projectg.crossplatforms.command.FormsCommand)3 InterceptCommand (dev.projectg.crossplatforms.command.custom.InterceptCommand)3 ServerHandler (dev.projectg.crossplatforms.handler.ServerHandler)3 NoSuchElementException (java.util.NoSuchElementException)3 StringArgument (cloud.commandframework.arguments.standard.StringArgument)2 Logger (dev.projectg.crossplatforms.Logger)2 CommandType (dev.projectg.crossplatforms.command.CommandType)2 PlaceholderHandler (dev.projectg.crossplatforms.handler.PlaceholderHandler)2 Interface (dev.projectg.crossplatforms.interfacing.Interface)2 InterfaceManager (dev.projectg.crossplatforms.interfacing.InterfaceManager)2 JavaMenuRegistry (dev.projectg.crossplatforms.interfacing.java.JavaMenuRegistry)2 ArrayList (java.util.ArrayList)2