Search in sources :

Example 1 with PaperCommandManager

use of co.aikar.commands.PaperCommandManager in project GDHooks by bloodmc.

the class GDHooks method registerBaseCommands.

public void registerBaseCommands() {
    PaperCommandManager manager = new PaperCommandManager(GDHooksBootstrap.getInstance().getLoader());
    this.commandManager = manager;
    manager.getCommandReplacements().addReplacements("reload", this.getCommandDescriptionTranslation(MessageConfig.DESCRIPTION_RELOAD), "version", this.getCommandDescriptionTranslation(MessageConfig.DESCRIPTION_VERSION));
    manager.registerCommand(new CommandReload());
    manager.registerCommand(new CommandVersion());
    this.registerCommandCompletions();
}
Also used : CommandReload(com.griefdefender.hooks.command.CommandReload) CommandVersion(com.griefdefender.hooks.command.CommandVersion) PaperCommandManager(co.aikar.commands.PaperCommandManager)

Example 2 with PaperCommandManager

use of co.aikar.commands.PaperCommandManager in project commands by aikar.

the class ACFExample method registerCommands.

private void registerCommands() {
    // 1: Create Command Manager for your respective platform
    commandManager = new PaperCommandManager(this);
    // enable brigadier integration for paper servers
    commandManager.enableUnstableAPI("brigadier");
    // optional: enable unstable api to use help
    commandManager.enableUnstableAPI("help");
    // 2: Setup some replacement values that may be used inside of the annotations dynamically.
    commandManager.getCommandReplacements().addReplacements(// key - value
    "test", "foobar", // key - demonstrate that % is ignored  - value
    "%foo", "barbaz");
    // Another replacement for piped values
    commandManager.getCommandReplacements().addReplacement("testcmd", "test4|foobar|barbaz");
    // 3: Register Custom Command Contexts
    commandManager.getCommandContexts().registerContext(/* The class of the object to resolve*/
    SomeObject.class, /* A resolver method - Placed the resolver in its own class for organizational purposes */
    SomeObject.getContextResolver());
    // 4: Register Command Completions - this will be accessible with @CommandCompletion("@test")
    commandManager.getCommandCompletions().registerAsyncCompletion("test", c -> Arrays.asList("foo123", "bar123", "baz123"));
    // 5: Register Command Conditions
    commandManager.getCommandConditions().addCondition(SomeObject.class, "limits", (c, exec, value) -> {
        if (value == null) {
            return;
        }
        if (c.hasConfig("min") && c.getConfigValue("min", 0) > value.getValue()) {
            throw new ConditionFailedException("Min value must be " + c.getConfigValue("min", 0));
        }
        if (c.hasConfig("max") && c.getConfigValue("max", 3) < value.getValue()) {
            throw new ConditionFailedException("Max value must be " + c.getConfigValue("max", 3));
        }
    });
    // 6: (Optionally) Register dependencies - Dependencies can be injected into fields of command classes by
    // marking them with @Dependency. Some classes, like your Plugin, are already registered by default.
    SomeHandler someHandler = new SomeHandler();
    someHandler.setSomeField("Secret");
    commandManager.registerDependency(SomeHandler.class, someHandler);
    commandManager.registerDependency(String.class, "Test3");
    commandManager.registerDependency(String.class, "test", "Test");
    commandManager.registerDependency(String.class, "test2", "Test2");
    // 7: Register your commands - This first command demonstrates adding an exception handler to that command
    commandManager.registerCommand(new SomeCommand().setExceptionHandler((command, registeredCommand, sender, args, t) -> {
        sender.sendMessage(MessageType.ERROR, MessageKeys.ERROR_GENERIC_LOGGED);
        // mark as handeled, default message will not be send to sender
        return true;
    }));
    // 8: Register an additional command. This one happens to share the same CommandAlias as the previous command
    // This means it simply registers additional sub commands under the same command, but organized into separate
    // Classes (Maybe different permission sets)
    commandManager.registerCommand(new SomeCommand_ExtraSubs());
    commandManager.registerCommand(new SomeOtherCommand());
    // 9: Register default exception handler for any command that doesn't supply its own
    commandManager.setDefaultExceptionHandler((command, registeredCommand, sender, args, t) -> {
        getLogger().warning("Error occurred while executing command " + command.getName());
        // mark as unhandeled, sender will see default message
        return false;
    });
    // test command for brigadier
    commandManager.getCommandCompletions().registerAsyncCompletion("someobject", c -> Arrays.asList("1", "2", "3", "4", "5"));
    commandManager.registerCommand(new BrigadierTest());
}
Also used : PaperCommandManager(co.aikar.commands.PaperCommandManager) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) Arrays(java.util.Arrays) MessageKeys(co.aikar.commands.MessageKeys) ConditionFailedException(co.aikar.commands.ConditionFailedException) PaperBrigadierManager(co.aikar.commands.PaperBrigadierManager) MessageType(co.aikar.commands.MessageType) ConditionFailedException(co.aikar.commands.ConditionFailedException) PaperCommandManager(co.aikar.commands.PaperCommandManager)

Example 3 with PaperCommandManager

use of co.aikar.commands.PaperCommandManager in project ArmorSwap by taggernation.

the class ArmorSwap method onEnable.

@Override
public void onEnable() {
    try {
        configData = new ConfigData(this);
        configData.updateConfig(this.getDescription().getVersion(), ConfigDataType.VERSION.getName());
    } catch (IOException | InvalidConfigurationException e) {
        e.printStackTrace();
    }
    new UpdateChecker(this, 97332).getVersion(version -> {
        if (this.getDescription().getVersion().equals(version)) {
            getLogger().info("There is not a new update available.");
        } else {
            getLogger().info("There is a new update available." + "\n" + ChatColor.RED + "https://www.spigotmc.org/resources/armorswap-swap-items-by-right-clicking.97332/");
        }
    });
    // bStats metrics
    // https://bstats.org/what-is-my-plugin-id
    Metrics metrics = new Metrics(this, 14140);
    setPlugin(this);
    // Events
    getServer().getPluginManager().registerEvents(new OnJoin(), this);
    try {
        getServer().getPluginManager().registerEvents(new ClickEvent(configData, this), this);
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Checks if server is running on Paper or not
    boolean isOnPaper = false;
    try {
        Class.forName("com.destroystokyo.paper");
        isOnPaper = true;
    } catch (ClassNotFoundException ignored) {
    }
    // Initializing Command manager
    if (isOnPaper) {
        PaperCommandManager pcm = new PaperCommandManager(this);
        pcm.registerCommand(new CommandManager(configData, this));
    } else {
        BukkitCommandManager bcm = new BukkitCommandManager(this);
        bcm.registerCommand(new CommandManager(configData, this));
    }
    // Config
    getLogger().info(ChatColor.AQUA + "ArmorSwap " + ChatColor.UNDERLINE + "Successfully loaded.");
}
Also used : BukkitCommandManager(co.aikar.commands.BukkitCommandManager) PaperCommandManager(co.aikar.commands.PaperCommandManager) ClickEvent(com.toonystank.armorswap.Events.ClickEvent) OnJoin(com.toonystank.armorswap.Events.OnJoin) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) Metrics(com.toonystank.armorswap.utils.Metrics) CommandManager(com.toonystank.armorswap.Commands.CommandManager) PaperCommandManager(co.aikar.commands.PaperCommandManager) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) ConfigData(com.toonystank.armorswap.utils.ConfigData) UpdateChecker(com.toonystank.armorswap.utils.UpdateChecker)

Example 4 with PaperCommandManager

use of co.aikar.commands.PaperCommandManager in project PrivateMines by UntouchedOdin0.

the class PrivateMines method registerCommands.

private void registerCommands() {
    PaperCommandManager paperCommandManager = new PaperCommandManager(this);
    paperCommandManager.registerCommand(new PrivateMinesCommand(this));
    paperCommandManager.registerCommand(new UsePlayerShop(this, mineStorage));
}
Also used : PaperCommandManager(co.aikar.commands.PaperCommandManager) UsePlayerShop(me.untouchedodin0.privatemines.commands.UsePlayerShop) PrivateMinesCommand(me.untouchedodin0.privatemines.commands.PrivateMinesCommand)

Example 5 with PaperCommandManager

use of co.aikar.commands.PaperCommandManager in project LevelTools by byteful.

the class LevelToolsPlugin method onEnable.

@Override
public void onEnable() {
    instance = this;
    if (!getDataFolder().exists()) {
        getDataFolder().mkdirs();
    }
    // Support older file names.
    final Path blocksFile = getDataFolder().toPath().resolve("player_placed_blocks.db");
    final Path oldFile = getDataFolder().toPath().resolve("blocks.db");
    if (Files.exists(oldFile)) {
        if (Files.exists(blocksFile)) {
            getLogger().warning("Found old 'blocks.db' file, but ignored it because a newer 'player_placed_blocks.db' file exists!");
        } else {
            try {
                Files.move(oldFile, blocksFile, StandardCopyOption.COPY_ATTRIBUTES);
                getLogger().warning("Found old 'blocks.db' file... Moved to newer 'player_placed_blocks.db' file.");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (!Files.exists(blocksFile)) {
        try {
            blocksFile.toFile().createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    blockDataManager = BlockDataManager.createSQLite(this, blocksFile, true, true);
    blockDataManager.migrate();
    getLogger().info("Loaded BlockDataManager...");
    saveDefaultConfig();
    getConfig().options().copyDefaults(true).copyHeader(true);
    setAnvilCombineMode();
    getLogger().info("Loaded configuration...");
    registerListeners();
    getLogger().info("Registered listeners...");
    commandManager = new PaperCommandManager(this);
    commandManager.enableUnstableAPI("brigadier");
    commandManager.enableUnstableAPI("help");
    commandManager.registerCommand(new LevelToolsCommand());
    getLogger().info("Registered commands...");
    if (getServer().getPluginManager().isPluginEnabled("PlaceholderAPI")) {
        new LevelToolsPlaceholders().register();
    }
    getLogger().info("Successfully started " + getDescription().getFullName() + "!");
}
Also used : Path(java.nio.file.Path) PaperCommandManager(co.aikar.commands.PaperCommandManager) IOException(java.io.IOException)

Aggregations

PaperCommandManager (co.aikar.commands.PaperCommandManager)10 IOException (java.io.IOException)3 Metrics (org.bstats.bukkit.Metrics)2 GrimDebug (ac.grim.grimac.commands.GrimDebug)1 GrimPerf (ac.grim.grimac.commands.GrimPerf)1 BukkitCommandManager (co.aikar.commands.BukkitCommandManager)1 ConditionFailedException (co.aikar.commands.ConditionFailedException)1 MessageKeys (co.aikar.commands.MessageKeys)1 MessageType (co.aikar.commands.MessageType)1 PaperBrigadierManager (co.aikar.commands.PaperBrigadierManager)1 AbilityManager (com.archyx.aureliumskills.ability.AbilityManager)1 OptionL (com.archyx.aureliumskills.configuration.OptionL)1 PlayerManager (com.archyx.aureliumskills.data.PlayerManager)1 LegacyFileBackup (com.archyx.aureliumskills.data.backup.LegacyFileBackup)1 MysqlBackup (com.archyx.aureliumskills.data.backup.MysqlBackup)1 YamlBackup (com.archyx.aureliumskills.data.backup.YamlBackup)1 LegacyFileToYamlConverter (com.archyx.aureliumskills.data.converter.LegacyFileToYamlConverter)1 LegacyMysqlToMysqlConverter (com.archyx.aureliumskills.data.converter.LegacyMysqlToMysqlConverter)1 MySqlStorageProvider (com.archyx.aureliumskills.data.storage.MySqlStorageProvider)1 YamlStorageProvider (com.archyx.aureliumskills.data.storage.YamlStorageProvider)1