Created
January 4, 2014 03:42
-
-
Save yannicklamprecht/8251347 to your computer and use it in GitHub Desktop.
A description of my CommandAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package commands; | |
import org.bukkit.command.Command; | |
import org.bukkit.command.CommandExecutor; | |
import org.bukkit.command.CommandSender; | |
import lib.CustomCommand; | |
import lib.Factorizer; | |
public class ConfigReload extends CustomCommand{ | |
public ConfigReload() { | |
super("cr", "commandAPI reload", "/cr", "capi.reload", new CommandExecutor() { | |
@Override | |
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, | |
String[] args) { | |
Factorizer.createHelpFormatLoader().loadConfig(); | |
Factorizer.createPluginConfigLoader().loadConfig(); | |
Factorizer.createCommandConfig().loadConfig(); | |
Factorizer.createSettingsConfig().loadConfig(); | |
sender.sendMessage(Factorizer.createSettingsConfig().getConfigReloadMessage()); | |
return true; | |
} | |
}); | |
} | |
} | |
The next step is registering the Command with the Factorizer e.g.: | |
@Override | |
public void onEnable(){ | |
Factorizer.createPluginConfigLoader(); | |
Factorizer.createCommandMaper().register(new Help()); | |
Factorizer.createCommandMaper().register(new ConfigReload()); | |
Factorizer.createCommandMaper().register(new HelpPermission()); | |
} | |
Each command with it's description, usage, permission and commandname e.g. don't change the bold value it acts as a key: | |
cr: | |
permission: capi.reload | |
aliases: [] | |
usage: /cr | |
desc: commandAPI reload | |
command: cr | |
Easier config creation is included too. | |
Example Config: | |
package config; | |
import java.util.ArrayList; | |
import config.YamlConfigLoader; | |
public class CommandConfig extends YamlConfigLoader { | |
public CommandConfig() { | |
super("CommandAPI/Commands/", "command.yml"); | |
this.saveConfig(); | |
} | |
public String get(String command, CMD sub, String defaultValue) { | |
if (!this.config.contains(command.concat(sub.value()))) { | |
this.config.addDefault(command.concat(sub.value()), defaultValue); | |
this.config.options().copyDefaults(true); | |
this.saveConfig(); | |
this.loadConfig(); | |
} | |
return this.config.getString(command.concat(sub.value()), | |
command.concat(sub.value())); | |
} | |
public ArrayList<String> getAliases(String command, | |
ArrayList<String> defaultValue) { | |
if (!this.config.contains(command.concat(CMD.ALIASES.value()))) { | |
this.config.addDefault(command.concat(CMD.ALIASES.value()), defaultValue); | |
this.config.options().copyDefaults(true); | |
this.saveConfig(); | |
this.loadConfig(); | |
} | |
return (ArrayList<String>) this.config.getList( | |
command.concat(CMD.ALIASES.value()), defaultValue); | |
} | |
} | |
I would recommend to register the Config as a Singletonpattern like this.: | |
public class Factory { | |
private static CommandConfig commandconfig; | |
public static CommandConfig createCommandConfig(){ | |
if(commandconfig==null){ | |
commandconfig = new CommandConfig(); | |
} | |
return commandconfig; | |
} | |
} | |
FileTree: | |
- plugins | |
- Commands | |
- command.yml | |
- help.yml | |
- hidden.yml | |
- settings.yml | |
help.yml : | |
help: | |
format: '&2%command %desc &6%perm' | |
page: '&aHELP' | |
type: '&6type ' | |
noperm: §8 // color of the description if player has no permissions | |
perm: §7 // color of the description if player has permissions | |
registered: true //if true only commands registered with this api will be shown | |
hidden.yml: | |
# Every Plugin listed here will be hidden from the pluginlist /pl or /plugins | |
hidden-plugins: | |
- CommandAPI | |
- SmartServerTool | |
- Groupmanager | |
settings.yml: | |
message: | |
permission: §4you don't have the permission to perform this command // default nopermissionmessage | |
reload: §2Config succesfully reloaded //default config has been reloaded message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment