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();
}
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());
}
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.");
}
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));
}
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() + "!");
}
Aggregations