From d93c7d11663998b98b7fc8f96a81c3e3301f70fd Mon Sep 17 00:00:00 2001 From: asofold Date: Wed, 6 Feb 2013 09:41:13 +0100 Subject: [PATCH] Add AbstractConfigurableHook. --- .../cncp/hooks/AbstractConfigurableHook.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 CompatNoCheatPlus/src/me/asofold/bpl/cncp/hooks/AbstractConfigurableHook.java diff --git a/CompatNoCheatPlus/src/me/asofold/bpl/cncp/hooks/AbstractConfigurableHook.java b/CompatNoCheatPlus/src/me/asofold/bpl/cncp/hooks/AbstractConfigurableHook.java new file mode 100644 index 0000000..81e2b83 --- /dev/null +++ b/CompatNoCheatPlus/src/me/asofold/bpl/cncp/hooks/AbstractConfigurableHook.java @@ -0,0 +1,56 @@ +package me.asofold.bpl.cncp.hooks; + +import me.asofold.bpl.cncp.config.compatlayer.CompatConfig; +import me.asofold.bpl.cncp.config.compatlayer.CompatConfigFactory; +import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil; +import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook; + +/** + * Reads an enabled flag from the config (true by default). The prefix given will be something like "hooks.", so add your hook name to the path like:
+ * prefix + "myhook.extra-config" + * @author mc_dev + * + */ +public class AbstractConfigurableHook extends AbstractHook implements + ConfigurableHook { + + protected final String configPrefix; + protected final String hookName, hookVersion; + + protected boolean enabled = true; + + public AbstractConfigurableHook(String hookName, String hookVersion, String configPrefix){ + this.configPrefix = configPrefix; + this.hookName = hookName; + this.hookVersion = hookVersion; + } + + @Override + public String getHookName() { + return hookName; + } + + @Override + public String getHookVersion() { + return hookVersion; + } + + @Override + public void applyConfig(CompatConfig cfg, String prefix) { + enabled = cfg.getBoolean(prefix + configPrefix + "enabled", true); + } + + @Override + public boolean updateConfig(CompatConfig cfg, String prefix) { + CompatConfig defaults = CompatConfigFactory.getConfig(null); + defaults.set(prefix + configPrefix + "enabled", true); + return ConfigUtil.forceDefaults(defaults, cfg); + } + + @Override + public boolean isEnabled() { + return enabled; + } + + +}