@Override public void onEnable() { instance = this; if (!is1_9OrNewer) { System.out.println("[ForceResourcePack] The plugin work only on a 1.8 or newer version."); getServer().getPluginManager().disablePlugin(instance); return; } /*Configurations*/ saveDefaultConfig(); configUtils = new ConfigUtils(getConfig()); /*Events*/ new EventsManager(this).registerEvents(); /*Commands*/ final PluginCommand command = getCommand("forceresourcepack"); command.setAliases(Collections.singletonList("frp")); command.setExecutor(new FrpCommand()); /*If server was reloaded*/ for (Player player : Bukkit.getOnlinePlayers()) new ForcePlayer(player); }
@Override public void registerCommands() { new MainCommand(); MainCommand.subCommands.add(new Template()); MainCommand.subCommands.add(new Setup()); MainCommand.subCommands.add(new DebugUUID()); MainCommand.subCommands.add(new DebugFill()); MainCommand.subCommands.add(new DebugSaveTest()); MainCommand.subCommands.add(new DebugLoadTest()); MainCommand.subCommands.add(new CreateRoadSchematic()); MainCommand.subCommands.add(new RegenAllRoads()); MainCommand.subCommands.add(new DebugClear()); MainCommand.subCommands.add(new Claim()); MainCommand.subCommands.add(new Auto()); MainCommand.subCommands.add(new Home()); MainCommand.subCommands.add(new Visit()); MainCommand.subCommands.add(new TP()); MainCommand.subCommands.add(new Set()); MainCommand.subCommands.add(new Toggle()); MainCommand.subCommands.add(new Clear()); MainCommand.subCommands.add(new Delete()); MainCommand.subCommands.add(new SetOwner()); if (Settings.ENABLE_CLUSTERS) { MainCommand.subCommands.add(new Cluster()); } MainCommand.subCommands.add(new Trust()); MainCommand.subCommands.add(new Add()); MainCommand.subCommands.add(new Deny()); MainCommand.subCommands.add(new Untrust()); MainCommand.subCommands.add(new Remove()); MainCommand.subCommands.add(new Undeny()); MainCommand.subCommands.add(new Info()); MainCommand.subCommands.add(new list()); MainCommand.subCommands.add(new Help()); MainCommand.subCommands.add(new Debug()); MainCommand.subCommands.add(new SchematicCmd()); MainCommand.subCommands.add(new plugin()); MainCommand.subCommands.add(new Inventory()); MainCommand.subCommands.add(new Purge()); MainCommand.subCommands.add(new Reload()); MainCommand.subCommands.add(new Merge()); MainCommand.subCommands.add(new Unlink()); MainCommand.subCommands.add(new Kick()); MainCommand.subCommands.add(new Rate()); MainCommand.subCommands.add(new DebugClaimTest()); MainCommand.subCommands.add(new Inbox()); MainCommand.subCommands.add(new Comment()); MainCommand.subCommands.add(new Database()); MainCommand.subCommands.add(new Unclaim()); MainCommand.subCommands.add(new Swap()); MainCommand.subCommands.add(new MusicSubcommand()); MainCommand.subCommands.add(new DebugRoadRegen()); MainCommand.subCommands.add(new Trim()); MainCommand.subCommands.add(new DebugExec()); MainCommand.subCommands.add(new FlagCmd()); MainCommand.subCommands.add(new Target()); MainCommand.subCommands.add(new DebugFixFlags()); MainCommand.subCommands.add(new Move()); MainCommand.subCommands.add(new Condense()); MainCommand.subCommands.add(new Confirm()); MainCommand.subCommands.add(new Copy()); MainCommand.subCommands.add(new Chat()); final BukkitCommand bcmd = new BukkitCommand(); final PluginCommand plotCommand = getCommand("plots"); plotCommand.setExecutor(bcmd); plotCommand.setAliases(Arrays.asList("p", "ps", "plotme", "plot")); plotCommand.setTabCompleter(bcmd); }
@SuppressWarnings("unchecked") public void register(Command command, Map<String, Object> cmdParams) { String cmdName = command.getCommandName(); log.devDebug("register() command=", command, ",cmdParams=", cmdParams); command.setPlugin(plugin); command.setCommandParameters(cmdParams); if (cmdParams.containsKey("name")) cmdName = (String) cmdParams.get("name"); // we never load the same command twice if (loadedCommands.contains(cmdName)) return; CraftServer cs = (CraftServer) Bukkit.getServer(); SimpleCommandMap commandMap = cs.getCommandMap(); try { Constructor<PluginCommand> constructor = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class); constructor.setAccessible(true); // construct a new PluginCommand object PluginCommand pc = constructor.newInstance(cmdName, plugin); pc.setExecutor(command); pc.setLabel(cmdName); if (command.getUsage() != null) pc.setUsage(command.getUsage()); // don't set Permission node, not all permission plugins behave // with superperms command permissions nicely. // pc.setPermission(command.getCommandPermissionNode()); // check for aliases defined in the configuration Object o = cmdParams.get("aliases"); if (o != null) { List<String> aliases = null; if (o instanceof List) { aliases = (List<String>) o; } else if (o instanceof String) { aliases = new ArrayList<String>(2); aliases.add((String) o); } else log.warn("invalid aliases defined for command ", cmdName, ": ", o); if (aliases == null) aliases = new ArrayList<String>(1); aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias pc.setAliases(aliases); } // otherwise set whatever the command has defined else { List<String> aliases = new ArrayList<String>(5); String[] strAliases = command.getCommandAliases(); if (strAliases != null) { for (String alias : strAliases) { aliases.add(alias); } } aliases.add("hsp" + command.getCommandName()); // all commands have "hsp" prefix alias pc.setAliases(aliases); } // register it commandMap.register("hsp", pc); loadedCommands.add(cmdName); Debug.getInstance().devDebug("register() command ", command, " registered"); } catch (Exception e) { e.printStackTrace(); } }