mirror of
https://github.com/asofold/CompatNoCheatPlus.git
synced 2025-02-20 02:02:34 +01:00
(6.1.0)
- (add) Generic hooks: block-break and block-place. Some defaults added for MachinaCraft. - (refactor) Re structured generic hooks configuration handling.
This commit is contained in:
parent
e94eb5ead8
commit
39534cc5af
@ -29,11 +29,23 @@ Citizens2 / Player class: make configurable (hidden) Or do internally: List of c
|
||||
|
||||
Generic abstract class for the mcMMO style cancelling of next x events + ticks alive etc
|
||||
|
||||
add stats hook ?
|
||||
|
||||
|
||||
*** 6.1.X
|
||||
!(add) Use some exemption mechanism for npcs (generic player class hook + citizens).
|
||||
? add event before reading config (for better hook integration).
|
||||
|
||||
*** 6.1.0
|
||||
consider adding a permission to hooksetspeed.
|
||||
|
||||
VERSION HISTORY
|
||||
---------------------------
|
||||
|
||||
(6.1.0)
|
||||
- (add) Generic hooks: block-break and block-place. Some defaults added for MachinaCraft.
|
||||
- (refactor) Re structured generic hooks configuration handling.
|
||||
|
||||
(6.0.1)
|
||||
- (bugfix) Citizens2 hook should unregister correctly on reloading etc.
|
||||
|
||||
|
@ -3,15 +3,19 @@ package me.asofold.bpl.cncp;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import me.asofold.bpl.cncp.config.Settings;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
||||
import me.asofold.bpl.cncp.hooks.Hook;
|
||||
import me.asofold.bpl.cncp.hooks.generic.ConfigurableHook;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookBlockBreak;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookBlockPlace;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookPlayerClass;
|
||||
import me.asofold.bpl.cncp.hooks.generic.HookSetSpeed;
|
||||
import me.asofold.bpl.cncp.setttings.Settings;
|
||||
import me.asofold.bpl.cncp.utils.Utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -41,9 +45,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||
|
||||
private static final Set<Hook> registeredHooks = new HashSet<Hook>();
|
||||
|
||||
private final HookPlayerClass hookPlayerClass = new HookPlayerClass();
|
||||
|
||||
private HookSetSpeed hookSetSpeed = null;
|
||||
private final List<Hook> builtinHooks = new LinkedList<Hook>();
|
||||
|
||||
/**
|
||||
* Flag if plugin is enabled.
|
||||
@ -140,31 +142,51 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before loading settings.
|
||||
*/
|
||||
private void setupBuiltinHooks() {
|
||||
builtinHooks.clear();
|
||||
// Might-fail hooks:
|
||||
try{
|
||||
builtinHooks.add(new me.asofold.bpl.cncp.hooks.generic.HookSetSpeed());
|
||||
}
|
||||
catch (Throwable t){}
|
||||
// Simple hooks:
|
||||
for (Hook hook : new Hook[]{
|
||||
new HookPlayerClass(),
|
||||
new HookBlockBreak(),
|
||||
new HookBlockPlace(),
|
||||
}){
|
||||
builtinHooks.add(hook);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add standard hooks if available.
|
||||
*/
|
||||
private void addAvailableHooks() {
|
||||
// Set speed
|
||||
if (settings.setSpeedEnabled){
|
||||
try{
|
||||
hookSetSpeed = new me.asofold.bpl.cncp.hooks.generic.HookSetSpeed();
|
||||
hookSetSpeed.setFlySpeed(settings.flySpeed);
|
||||
hookSetSpeed.setWalkSpeed(settings.walkSpeed);
|
||||
// hookSetSpeed.setAllowFlightPerm(settings.allowFlightPerm);
|
||||
hookSetSpeed.init();
|
||||
addHook(hookSetSpeed);
|
||||
|
||||
// Add built in hooks:
|
||||
for (Hook hook : builtinHooks){
|
||||
boolean add = true;
|
||||
if (hook instanceof ConfigurableHook){
|
||||
if (!((ConfigurableHook)hook).isEnabled()) add = false;
|
||||
}
|
||||
if (add){
|
||||
try{
|
||||
addHook(hook);
|
||||
}
|
||||
catch (Throwable t){}
|
||||
}
|
||||
catch (Throwable t){}
|
||||
}
|
||||
|
||||
// Citizens 2
|
||||
try{
|
||||
addHook(new me.asofold.bpl.cncp.hooks.citizens2.HookCitizens2());
|
||||
}
|
||||
catch (Throwable t){}
|
||||
// Player class (NPCs, Citizens 1)
|
||||
if (settings.playerClassEnabled)
|
||||
addHook(hookPlayerClass);
|
||||
// mcMMO
|
||||
try{
|
||||
addHook(new me.asofold.bpl.cncp.hooks.mcmmo.HookmcMMO());
|
||||
@ -179,6 +201,7 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||
|
||||
// Settings:
|
||||
settings.clear();
|
||||
setupBuiltinHooks();
|
||||
loadSettings();
|
||||
// Register own listener:
|
||||
final PluginManager pm = getServer().getPluginManager();
|
||||
@ -203,24 +226,28 @@ public class CompatNoCheatPlus extends JavaPlugin implements Listener {
|
||||
CompatConfig cfg = new NewConfig(file);
|
||||
cfg.load();
|
||||
boolean changed = false;
|
||||
if (cfg.getInt("configversion", 0) == 0){
|
||||
cfg.remove("plugins");
|
||||
changed = true;
|
||||
}
|
||||
// General settings:
|
||||
if (Settings.addDefaults(cfg)) changed = true;
|
||||
if (changed) cfg.save();
|
||||
settings.fromConfig(cfg);
|
||||
// Set hookPlayerClass properties
|
||||
hookPlayerClass.setClassNames(settings.exemptPlayerClassNames);
|
||||
hookPlayerClass.setExemptAll(settings.exemptAllPlayerClassNames);
|
||||
hookPlayerClass.setPlayerClassName(settings.playerClassName);
|
||||
hookPlayerClass.setCheckSuperClass(settings.exemptSuperClass);
|
||||
// Set hookSetSpeed properties (for future purposes):
|
||||
if (hookSetSpeed != null){
|
||||
hookSetSpeed.setFlySpeed(settings.flySpeed);
|
||||
hookSetSpeed.setWalkSpeed(settings.walkSpeed);
|
||||
// hookSetSpeed.setAllowFlightPerm(settings.allowFlightPerm);
|
||||
// Settings for builtin hooks:
|
||||
for (Hook hook : builtinHooks){
|
||||
if (hook instanceof ConfigurableHook){
|
||||
try{
|
||||
ConfigurableHook cfgHook = (ConfigurableHook) hook;
|
||||
if (cfgHook.updateConfig(cfg, "hooks.")) changed = true;
|
||||
cfgHook.applyConfig(cfg, "hooks.");
|
||||
}
|
||||
catch (Throwable t){
|
||||
getLogger().severe("[cncp] Hook failed to process config ("+hook.getHookName() +" / " + hook.getHookVersion()+"): " + t.getClass().getSimpleName() + ": "+t.getMessage());
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
// save back config if changed:
|
||||
if (changed) cfg.save();
|
||||
|
||||
|
||||
|
||||
// Re-enable plugins that were not yet on the list:
|
||||
Server server = getServer();
|
||||
Logger logger = server.getLogger();
|
||||
|
@ -0,0 +1,57 @@
|
||||
package me.asofold.bpl.cncp.config;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
||||
|
||||
public class Settings {
|
||||
public int configVersion = 1;
|
||||
|
||||
public Set<String> forceEnableLater = new LinkedHashSet<String>();
|
||||
public Set<String> loadPlugins = new LinkedHashSet<String>();
|
||||
|
||||
public static Set<String> preventAddHooks = new HashSet<String>();
|
||||
|
||||
public static CompatConfig getDefaultConfig(){
|
||||
CompatConfig cfg = new NewConfig(null);
|
||||
Settings ref = new Settings();
|
||||
cfg.set("plugins.force-enable-later", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "NoCheatPlus" }));
|
||||
cfg.set("plugins.ensure-enable", ConfigUtil.asList(new String[]{ "WorldGuard" }));
|
||||
cfg.set("hooks.prevent-add", new LinkedList<String>());
|
||||
cfg.set("configversion", ref.configVersion);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public static boolean addDefaults(CompatConfig cfg){
|
||||
boolean changed = false;
|
||||
if (cfg.getInt("configversion", 0) == 0){
|
||||
cfg.remove("plugins");
|
||||
cfg.set("configversion", new Settings().configVersion); // hum.
|
||||
changed = true;
|
||||
}
|
||||
if (ConfigUtil.forceDefaults(getDefaultConfig(), cfg)) changed = true;
|
||||
return changed;
|
||||
}
|
||||
|
||||
public boolean fromConfig(CompatConfig cfg){
|
||||
// Settings ref = new Settings();
|
||||
|
||||
// plugins to force enabling after this plugin.
|
||||
ConfigUtil.readStringSetFromList(cfg, "plugins.force-enable-later", forceEnableLater, true, true, false);
|
||||
ConfigUtil.readStringSetFromList(cfg, "plugins.ensure-enable", loadPlugins, true, true, false);
|
||||
|
||||
// General
|
||||
ConfigUtil.readStringSetFromList(cfg, "hooks.prevent-add", preventAddHooks, true, true, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
forceEnableLater.clear();
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,7 @@ public class HookCitizens2 extends AbstractHook {
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "2.0.0";
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,107 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
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 org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
|
||||
|
||||
/**
|
||||
* Exempting players by class names for some class.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public abstract class ClassExemptionHook extends ExemptionHook implements ConfigurableHook{
|
||||
|
||||
protected final List<String> defaultClasses = new LinkedList<String>();
|
||||
protected final LinkedHashSet<String> classes = new LinkedHashSet<String>();
|
||||
|
||||
protected boolean defaultEnabled = true;
|
||||
protected boolean enabled = true;
|
||||
|
||||
protected final String configPrefix;
|
||||
|
||||
public ClassExemptionHook(String configPrefix){
|
||||
this.configPrefix = configPrefix;
|
||||
}
|
||||
|
||||
public void setClasses(final Collection<String> classes){
|
||||
this.classes.clear();
|
||||
this.classes.addAll(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a player is to be exempted and exempt for the check type.
|
||||
* @param player
|
||||
* @param clazz
|
||||
* @param checkType
|
||||
* @return If exempted.
|
||||
*/
|
||||
public boolean checkExempt(final Player player, final Class<?> clazz, final CheckType checkType){
|
||||
if (!classes.contains(clazz.getSimpleName())) return false;
|
||||
addExemption(player.getName());
|
||||
exempt(player, checkType);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player
|
||||
* @param checkType
|
||||
* @return If the player is still exempted.
|
||||
*/
|
||||
public boolean checkUnexempt(final Player player, final Class<?> clazz, final CheckType checkType){
|
||||
if (!classes.contains(clazz.getSimpleName())) return false;
|
||||
if (removeExemption(player.getName())) return true;
|
||||
else {
|
||||
unexempt(player, checkType);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the API access from listeners potentially.
|
||||
* @param player
|
||||
* @param checkType
|
||||
*/
|
||||
public void exempt(final Player player, final CheckType checkType){
|
||||
NCPExemptionManager.exemptPermanently(player, checkType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the API access from listeners potentially.
|
||||
* @param player
|
||||
* @param checkType
|
||||
*/
|
||||
public void unexempt(final Player player, final CheckType checkType){
|
||||
NCPExemptionManager.unexempt(player, checkType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfig(CompatConfig cfg, String prefix) {
|
||||
enabled = cfg.getBoolean(prefix + configPrefix + "enabled", defaultEnabled);
|
||||
ConfigUtil.readStringSetFromList(cfg, prefix + configPrefix + "exempt-names", classes, true, true, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateConfig(CompatConfig cfg, String prefix) {
|
||||
CompatConfig defaults = CompatConfigFactory.getConfig(null);
|
||||
defaults.set(prefix + configPrefix + "enabled", defaultEnabled);
|
||||
defaults.set(prefix + configPrefix + "exempt-names", defaultClasses);
|
||||
return ConfigUtil.forceDefaults(defaults, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
|
||||
/**
|
||||
* A hook that is using configuration.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public interface ConfigurableHook {
|
||||
|
||||
/**
|
||||
* Adjust internals to the given configuration.
|
||||
* @param cfg
|
||||
* @param prefix
|
||||
*/
|
||||
public void applyConfig(CompatConfig cfg, String prefix);
|
||||
|
||||
/**
|
||||
* Update the given configuration with defaults where / if necessary (no blunt overwrite, it is a users config).
|
||||
* @param cfg
|
||||
* @param prefix
|
||||
* @return If the configuration was changed.
|
||||
*/
|
||||
public boolean updateConfig(CompatConfig cfg, String prefix);
|
||||
|
||||
/**
|
||||
* If the hook is enabled by configuration or not.
|
||||
* @return
|
||||
*/
|
||||
public boolean isEnabled();
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import me.asofold.bpl.cncp.hooks.AbstractHook;
|
||||
|
||||
/**
|
||||
* Auxiliary methods and data structure to handle simple sort of exemption.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public abstract class ExemptionHook extends AbstractHook{
|
||||
|
||||
|
||||
protected final Map<String, Integer> exemptions = new LinkedHashMap<String, Integer>(30);
|
||||
|
||||
/**
|
||||
* Increment exemption count.
|
||||
* @param name
|
||||
*/
|
||||
public void addExemption(final String name){
|
||||
final Integer count = exemptions.get(name);
|
||||
if (count == null){
|
||||
exemptions.put(name, 1);
|
||||
}
|
||||
else{
|
||||
exemptions.put(name, count.intValue() + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrement exemption count.
|
||||
* @param name
|
||||
* @return If the player is still exempted.
|
||||
*/
|
||||
public boolean removeExemption(final String name){
|
||||
final Integer count = exemptions.remove(name);
|
||||
if (count == null) return false;
|
||||
final int v = count.intValue();
|
||||
if (v == 1) return false;
|
||||
else{
|
||||
exemptions.put(name, v - 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
/**
|
||||
* Wrap block break events to exempt players from checks by comparison of event class names.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class HookBlockBreak extends ClassExemptionHook implements Listener {
|
||||
|
||||
public HookBlockBreak() {
|
||||
super("block-break.");
|
||||
defaultClasses.addAll(Arrays.asList(new String[]{
|
||||
// MachinaCraft
|
||||
"ArtificialBlockBreakEvent",
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "BlockBreak(default)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener[] getListeners() {
|
||||
return new Listener[]{this};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfig(CompatConfig cfg, String prefix) {
|
||||
super.applyConfig(cfg, prefix);
|
||||
if (classes.isEmpty()) enabled = false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
final void onBlockBreakLowest(final BlockBreakEvent event){
|
||||
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
final void onBlockBreakMonitor(final BlockBreakEvent event){
|
||||
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKBREAK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
/**
|
||||
* Wrap block place events to exempt players from checks by comparison of event class names.
|
||||
* @author mc_dev
|
||||
*
|
||||
*/
|
||||
public class HookBlockPlace extends ClassExemptionHook implements Listener{
|
||||
|
||||
public HookBlockPlace() {
|
||||
super("block-place.");
|
||||
defaultClasses.addAll(Arrays.asList(new String[]{
|
||||
// MachinaCraft
|
||||
"ArtificialBlockPlaceEvent"
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "BlockPlace(default)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Listener[] getListeners() {
|
||||
return new Listener[]{this};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfig(CompatConfig cfg, String prefix) {
|
||||
super.applyConfig(cfg, prefix);
|
||||
if (classes.isEmpty()) enabled = false;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
final void onBlockPlaceLowest(final BlockPlaceEvent event){
|
||||
checkExempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
final void onBlockPlaceMonitor(final BlockPlaceEvent event){
|
||||
checkUnexempt(event.getPlayer(), event.getClass(), CheckType.BLOCKPLACE);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
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.AbstractHook;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,7 +14,7 @@ import org.bukkit.entity.Player;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
import fr.neatmonster.nocheatplus.hooks.NCPHook;
|
||||
|
||||
public final class HookPlayerClass extends AbstractHook {
|
||||
public final class HookPlayerClass extends AbstractHook implements ConfigurableHook {
|
||||
|
||||
private final Set<String> classNames = new HashSet<String>();
|
||||
|
||||
@ -21,6 +24,8 @@ public final class HookPlayerClass extends AbstractHook {
|
||||
|
||||
private Object ncpHook = null;
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
/**
|
||||
* Normal class name.
|
||||
*/
|
||||
@ -29,23 +34,6 @@ public final class HookPlayerClass extends AbstractHook {
|
||||
public HookPlayerClass(){
|
||||
this.classNames.addAll(classNames);
|
||||
}
|
||||
|
||||
public final void setClassNames(final Collection<String> classNames){
|
||||
this.classNames.clear();
|
||||
this.classNames.addAll(classNames);
|
||||
}
|
||||
|
||||
public final void setExemptAll(final boolean exemptAll){
|
||||
this.exemptAll = exemptAll;
|
||||
}
|
||||
|
||||
public final void setPlayerClassName(final String playerClassName){
|
||||
this.playerClassName = playerClassName;
|
||||
}
|
||||
|
||||
public final void setCheckSuperClass(final boolean superClass){
|
||||
this.checkSuperClass = superClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getHookName() {
|
||||
@ -57,8 +45,6 @@ public final class HookPlayerClass extends AbstractHook {
|
||||
return "1.0";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public NCPHook getNCPHook() {
|
||||
if (ncpHook == null){
|
||||
@ -90,7 +76,7 @@ public final class HookPlayerClass extends AbstractHook {
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "1.0";
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -102,4 +88,29 @@ public final class HookPlayerClass extends AbstractHook {
|
||||
return (NCPHook) ncpHook;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfig(CompatConfig cfg, String prefix) {
|
||||
enabled = cfg.getBoolean(prefix + "player-class.enabled", true);
|
||||
ConfigUtil.readStringSetFromList(cfg, prefix + "player-class.exempt-names", classNames, true, true, false);
|
||||
exemptAll = cfg.getBoolean(prefix + "player-class.exempt-all", true);
|
||||
playerClassName = cfg.getString(prefix + "player-class.class-name", "CraftPlayer");
|
||||
checkSuperClass = cfg.getBoolean(prefix + "player-class.super-class", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateConfig(CompatConfig cfg, String prefix) {
|
||||
CompatConfig defaults = CompatConfigFactory.getConfig(null);
|
||||
defaults.set(prefix + "player-class.enabled", true);
|
||||
defaults.set(prefix + "player-class.exempt-names", new LinkedList<String>());
|
||||
defaults.set(prefix + "player-class.exempt-all", true);
|
||||
defaults.set(prefix + "player-class.class-name", "CraftPlayer");
|
||||
defaults.set(prefix + "player-class.super-class", true);
|
||||
return ConfigUtil.forceDefaults(defaults, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package me.asofold.bpl.cncp.hooks.generic;
|
||||
|
||||
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.AbstractHook;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -9,12 +12,14 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
public class HookSetSpeed extends AbstractHook implements Listener{
|
||||
public class HookSetSpeed extends AbstractHook implements Listener, ConfigurableHook{
|
||||
|
||||
private float flySpeed = 1.0f;
|
||||
|
||||
private float walkSpeed = 1.0f;
|
||||
|
||||
private boolean enabled = false;
|
||||
|
||||
// private String allowFlightPerm = "cncp.allow-flight";
|
||||
|
||||
public HookSetSpeed() throws SecurityException, NoSuchMethodException{
|
||||
@ -34,7 +39,7 @@ public class HookSetSpeed extends AbstractHook implements Listener{
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "1.0";
|
||||
return "2.0";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -44,24 +49,13 @@ public class HookSetSpeed extends AbstractHook implements Listener{
|
||||
|
||||
@Override
|
||||
public Listener[] getListeners() {
|
||||
try{
|
||||
// Initialize here, at the end of enable.
|
||||
init();
|
||||
}
|
||||
catch (Throwable t){}
|
||||
return new Listener[]{this} ;
|
||||
}
|
||||
|
||||
public float getFlySpeed() {
|
||||
return flySpeed;
|
||||
}
|
||||
|
||||
public void setFlySpeed(float flySpeed) {
|
||||
this.flySpeed = flySpeed;
|
||||
}
|
||||
|
||||
public float getWalkSpeed() {
|
||||
return walkSpeed;
|
||||
}
|
||||
|
||||
public void setWalkSpeed(float walkSpeed) {
|
||||
this.walkSpeed = walkSpeed;
|
||||
}
|
||||
|
||||
public final void setSpeed(final Player player){
|
||||
// if (allowFlightPerm.equals("") || player.hasPermission(allowFlightPerm)) player.setAllowFlight(true);
|
||||
@ -73,6 +67,29 @@ public class HookSetSpeed extends AbstractHook implements Listener{
|
||||
setSpeed(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyConfig(CompatConfig cfg, String prefix) {
|
||||
enabled = cfg.getBoolean(prefix + "set-speed.enabled", false);
|
||||
flySpeed = cfg.getDouble(prefix + "set-speed.fly-speed", 1.0).floatValue();
|
||||
walkSpeed = cfg.getDouble(prefix + "set-speed.walk-speed", 1.0).floatValue();
|
||||
// allowFlightPerm = cfg.getString(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateConfig(CompatConfig cfg, String prefix) {
|
||||
CompatConfig defaults = CompatConfigFactory.getConfig(null);
|
||||
defaults.set(prefix + "set-speed.enabled", false);
|
||||
defaults.set(prefix + "set-speed.fly-speed", 1.0);
|
||||
defaults.set(prefix + "set-speed.walk-speed", 1.0);
|
||||
// cfg.set(prefix + "set-speed.allow-flight-permission", ref.allowFlightPerm);
|
||||
return ConfigUtil.forceDefaults(defaults, cfg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// public String getAllowFlightPerm() {
|
||||
// return allowFlightPerm;
|
||||
// }
|
||||
|
@ -45,12 +45,12 @@ public final class HookmcMMO extends AbstractHook implements Listener {
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "mcMMO(default)";
|
||||
return "mcMMO(cncp)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookVersion() {
|
||||
return "1.0";
|
||||
return "1.1";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,81 +0,0 @@
|
||||
package me.asofold.bpl.cncp.setttings;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import me.asofold.bpl.cncp.config.compatlayer.CompatConfig;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.ConfigUtil;
|
||||
import me.asofold.bpl.cncp.config.compatlayer.NewConfig;
|
||||
|
||||
public class Settings {
|
||||
public int configVersion = 1;
|
||||
|
||||
public Set<String> forceEnableLater = new LinkedHashSet<String>();
|
||||
public Set<String> loadPlugins = new LinkedHashSet<String>();
|
||||
public Set<String> exemptPlayerClassNames = new HashSet<String>();
|
||||
|
||||
public boolean playerClassEnabled = false;
|
||||
public boolean exemptAllPlayerClassNames = true;
|
||||
public String playerClassName = "CraftPlayer";
|
||||
public boolean exemptSuperClass = true;
|
||||
|
||||
public boolean setSpeedEnabled = false;
|
||||
public float flySpeed = 1.0f;
|
||||
public float walkSpeed = 1.0f;
|
||||
// public String allowFlightPerm = "cncp.allow-flight";
|
||||
|
||||
public static Set<String> preventAddHooks = new HashSet<String>();
|
||||
|
||||
public static CompatConfig getDefaultConfig(){
|
||||
CompatConfig cfg = new NewConfig(null);
|
||||
Settings ref = new Settings();
|
||||
cfg.set("plugins.force-enable-later", new LinkedList<String>()); // ConfigUtil.asList(new String[]{ "NoCheatPlus" }));
|
||||
cfg.set("plugins.ensure-enable", ConfigUtil.asList(new String[]{ "WorldGuard" }));
|
||||
cfg.set("hooks.player-class.enabled", ref.playerClassEnabled);
|
||||
cfg.set("hooks.player-class.exempt-names", new LinkedList<String>());
|
||||
cfg.set("hooks.player-class.exempt-all", ref.exemptAllPlayerClassNames);
|
||||
cfg.set("hooks.player-class.class-name", ref.playerClassName);
|
||||
cfg.set("hooks.player-class.super-class", ref.exemptSuperClass);
|
||||
cfg.set("hooks.set-speed.enabled", ref.setSpeedEnabled);
|
||||
cfg.set("hooks.set-speed.fly-speed", ref.flySpeed);
|
||||
cfg.set("hooks.set-speed.walk-speed", ref.walkSpeed);
|
||||
// cfg.set("hooks.set-speed.allow-flight-permission", ref.allowFlightPerm);
|
||||
cfg.set("hooks.prevent-add", new LinkedList<String>());
|
||||
cfg.set("configversion", ref.configVersion);
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public static boolean addDefaults(CompatConfig cfg){
|
||||
return ConfigUtil.forceDefaults(getDefaultConfig(), cfg);
|
||||
}
|
||||
|
||||
public boolean fromConfig(CompatConfig cfg){
|
||||
Settings ref = new Settings();
|
||||
// plugins to force enabling after this plugin.
|
||||
ConfigUtil.readStringSetFromList(cfg, "plugins.force-enable-later", forceEnableLater, true, true, false);
|
||||
ConfigUtil.readStringSetFromList(cfg, "plugins.ensure-enable", loadPlugins, true, true, false);
|
||||
// Generic player class name hook:
|
||||
playerClassEnabled = cfg.getBoolean("hooks.player-class.enabled", ref.playerClassEnabled);
|
||||
ConfigUtil.readStringSetFromList(cfg, "hooks.player-class.exempt-names", exemptPlayerClassNames, true, true, false);
|
||||
exemptAllPlayerClassNames = cfg.getBoolean("hooks.player-class.exempt-all", ref.exemptAllPlayerClassNames);
|
||||
playerClassName = cfg.getString("hooks.player-class.class-name", ref.playerClassName);
|
||||
exemptSuperClass = cfg.getBoolean("hooks.player-class.super-class", ref.exemptSuperClass);
|
||||
|
||||
// Set speed hook
|
||||
setSpeedEnabled = cfg.getBoolean("hooks.set-speed.enabled", ref.setSpeedEnabled);
|
||||
flySpeed = cfg.getDouble("hooks.set-speed.fly-speed", (double) ref.flySpeed).floatValue();
|
||||
walkSpeed = cfg.getDouble("hooks.set-speed.walk-speed", (double) ref.walkSpeed).floatValue();
|
||||
// allowFlightPerm = cfg.getString("hooks.set-speed.allow-flight-permission", ref.allowFlightPerm);
|
||||
|
||||
// General
|
||||
ConfigUtil.readStringSetFromList(cfg, "hooks.prevent-add", preventAddHooks, true, true, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
forceEnableLater.clear();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user