About the API
This API add some usefull methods to avoid to write a ton of code over and over again.
Methods
MainHelper.reformateText("&cSome text");
This will give back the colored text. You can use '&' and 'ยง'.
MainHelper.hasPermission(player, permission);
Will check if the given Player has op, * or the given permission
permission can be of type String or Permission
MainHelper.isPluginThere(mainPlugin, "Litebans");
Will check if the given pluginname is in the Pluginsfolder.
MainHelper.addLore(lore, itemstack);
Will add the given lore to the itemstack
lore has to be a list of Strings
MainHelper.getRenamedItemstack(customname, itemstack);
Will rename the given itemstack with the given name. (The name can be colored)
Other features
- Adds an UpdateChecker function
private void checkUpdate() { UpdateChecker updater = new UpdateChecker(this, 52712, false); UpdateChecker.UpdateResult result = updater.getResult(); switch (result) { case NO_UPDATE: { getLogger().info(perfix + MainHelper.reformateText("&6There is no update available! Everything is up to date!")); break; } case UPDATE_AVAILABLE: { // TODO: 4/12/2017 Fix link getLogger().info(perfix + MainHelper.reformateText("&aThere is an update available! You can download it at https://www.spigotmc.org/resources/anti-combat-log.52712/")); break; } case FAIL_SPIGOT: { getLogger().info(perfix + MainHelper.reformateText("&cThere is a problem with Spigot. sorry for the inconvenience")); break; } case BAD_RESOURCEID: { getLogger().info(perfix + MainHelper.reformateText("&cStupid me. I placed the wrong ResourceID. Contact him on Spigot!")); break; } } }
If you insert and call this in your main plugin class it will check if the given resourceID has an update. (Change "52712" to your plugin id and ofcourse the link)
- A ConfigHandler which makes it super easy to have more than 1 config file. Just make a class for each configfile and extends ConfigHandler. Implement the constructor.
Once you've done that, go to where you want to init your configs and use the following syntax:
For example:
Config config = new Config(plugin, "config.yml");
After you made the config.yml file inside the src folder, add static methods for each value you want to have access to. Add a load methode and add getters and you can access them from everywhere in your project.
Here is an example Configfile from AntiCombatLog.
config.yml
#Enables if you want to auto check for updates updatechecker: true #These commands will be disabled when being in combat. command-blacklist: - /spawn - /ci #When this is allowed, players can be punished for combat logging allow-punishments: true
Config.java
public class Config extends ConfigHandler { private static boolean updateChecker; private static boolean punishmentsAllowed; private static List<String> blacklistedCommands; public Config(JavaPlugin plugin, String filename) { super(plugin, filename); loadConfig(); } private void loadConfig() { updateChecker = getConfig().getBoolean("updatechecker"); punishmentsAllowed = getConfig().getBoolean("allow-punishments"); blacklistedCommands= getConfig().getStringList("command-blacklist"); } public static List<String> getBlacklistedCommands() { return blacklistedCommands; } public static boolean isUpdateChecker() { return updateChecker; } public static boolean ispunishmentsAllowed () { return punishmentsAllowed ; } }
Now wherever you need it, you can call
Config.ispunishmentsAllowed();
Plugins who currently use this API
If you are using this plugin feel free to let me know and I'll add you on this list.
Developers
Feel free to add this plugin to your libraries. No maven support yet.