From 79ed68efbd0b7fb56fde71b7c9ff4f7984dcb306 Mon Sep 17 00:00:00 2001 From: asofold Date: Sat, 6 Jun 2015 22:30:37 +0200 Subject: [PATCH] Change compatibility module config: allow disabling CB modules. --- .../nocheatplus/config/ConfPaths.java | 13 ++++- .../nocheatplus/config/DefaultConfig.java | 5 +- .../neatmonster/nocheatplus/NoCheatPlus.java | 3 +- .../nocheatplus/compat/MCAccessConfig.java | 18 +++++++ .../nocheatplus/compat/MCAccessFactory.java | 50 +++++++++---------- 5 files changed, 59 insertions(+), 30 deletions(-) create mode 100644 NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessConfig.java diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java index 802d5c5e..29d898fd 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -627,12 +627,19 @@ public abstract class ConfPaths { // Compatibility section (possibly temporary). @GlobalConfig public static final String COMPATIBILITY = "compatibility."; + public static final String COMPATIBILITY_MANAGELISTENERS = COMPATIBILITY + "managelisteners"; + public static final String COMPATIBILITY_EXEMPTIONS = COMPATIBILITY + "exemptions."; public static final String COMPATIBILITY_EXEMPTIONS_REMOVE = COMPATIBILITY_EXEMPTIONS + "remove."; public static final String COMPATIBILITY_EXEMPTIONS_REMOVE_JOIN = COMPATIBILITY_EXEMPTIONS_REMOVE + "join"; public static final String COMPATIBILITY_EXEMPTIONS_REMOVE_LEAVE = COMPATIBILITY_EXEMPTIONS_REMOVE + "leave"; - public static final String COMPATIBILITY_MANAGELISTENERS = COMPATIBILITY + "managelisteners"; - public static final String COMPATIBILITY_BUKKITONLY = COMPATIBILITY + "bukkitapionly"; + + public static final String COMPATIBILITY_SERVER = COMPATIBILITY + "server."; + public static final String COMPATIBILITY_SERVER_CBDEDICATED = COMPATIBILITY_SERVER + "cbdedicated."; + public static final String COMPATIBILITY_SERVER_CBDEDICATED_ENABLE = COMPATIBILITY_SERVER_CBDEDICATED + "enable"; + public static final String COMPATIBILITY_SERVER_CBREFLECT = COMPATIBILITY_SERVER + "cbreflect."; + public static final String COMPATIBILITY_SERVER_CBREFLECT_ENABLE = COMPATIBILITY_SERVER_CBREFLECT + "enable"; + public static final String COMPATIBILITY_BLOCKS = COMPATIBILITY + "blocks."; // Deprecated (don't use fields from above). @@ -688,5 +695,7 @@ public abstract class ConfPaths { public static final String FIGHT_KNOCKBACK_ACTIONS = "checks.fight.knockback.actions"; @Deprecated public static final String NET_FLYINGFREQUENCY_MAXPACKETS = "checks.net.flyingfrequency.maxpackets"; + @Deprecated + public static final String COMPATIBILITY_BUKKITONLY = "compatibility.bukkitapionly"; } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 2e8aaf9a..59fe8ef1 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -529,10 +529,11 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".tempkick5", "ncp tempkick [player] 5 You have five minutes to think about it!"); // Compatibility settings. + set(ConfPaths.COMPATIBILITY_MANAGELISTENERS, false); set(ConfPaths.COMPATIBILITY_EXEMPTIONS_REMOVE_JOIN, true); set(ConfPaths.COMPATIBILITY_EXEMPTIONS_REMOVE_LEAVE, true); - set(ConfPaths.COMPATIBILITY_MANAGELISTENERS, false); - set(ConfPaths.COMPATIBILITY_BUKKITONLY, false); + set(ConfPaths.COMPATIBILITY_SERVER_CBDEDICATED_ENABLE, true); + set(ConfPaths.COMPATIBILITY_SERVER_CBREFLECT_ENABLE, true); set(ConfPaths.COMPATIBILITY_BLOCKS + ConfPaths.SUB_IGNOREPASSABLE, Arrays.asList( Material.WOODEN_DOOR.name(), Material.IRON_DOOR_BLOCK.name(), Material.TRAP_DOOR.name(), diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java index e97f79f3..6c1f1408 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -49,6 +49,7 @@ import fr.neatmonster.nocheatplus.command.admin.VersionCommand; import fr.neatmonster.nocheatplus.compat.BridgeMisc; import fr.neatmonster.nocheatplus.compat.DefaultComponentFactory; import fr.neatmonster.nocheatplus.compat.MCAccess; +import fr.neatmonster.nocheatplus.compat.MCAccessConfig; import fr.neatmonster.nocheatplus.compat.MCAccessFactory; import fr.neatmonster.nocheatplus.compat.versions.BukkitVersion; import fr.neatmonster.nocheatplus.compat.versions.ServerVersion; @@ -1033,7 +1034,7 @@ public class NoCheatPlus extends JavaPlugin implements NoCheatPlusAPI { public MCAccess initMCAccess(final ConfigFile config) { // Reset MCAccess. // TODO: Might fire a NCPSetMCAccessFromFactoryEvent (include getting and setting)! - final MCAccess mcAccess = new MCAccessFactory().getMCAccess(config.getBoolean(ConfPaths.COMPATIBILITY_BUKKITONLY)); + final MCAccess mcAccess = new MCAccessFactory().getMCAccess(new MCAccessConfig()); setMCAccess(mcAccess); return mcAccess; } diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessConfig.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessConfig.java new file mode 100644 index 00000000..5a813542 --- /dev/null +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessConfig.java @@ -0,0 +1,18 @@ +package fr.neatmonster.nocheatplus.compat; + +import fr.neatmonster.nocheatplus.config.ConfPaths; +import fr.neatmonster.nocheatplus.config.ConfigFile; +import fr.neatmonster.nocheatplus.config.ConfigManager; + +public class MCAccessConfig { + + public final boolean enableCBDedicated; + public final boolean enableCBReflect; + + public MCAccessConfig() { + final ConfigFile config = ConfigManager.getConfigFile(); + this.enableCBDedicated = config.getBoolean(ConfPaths.COMPATIBILITY_SERVER_CBDEDICATED_ENABLE); + this.enableCBReflect = config.getBoolean(ConfPaths.COMPATIBILITY_SERVER_CBREFLECT_ENABLE); + } + +} diff --git a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java index ce72fdec..6d8fd9be 100644 --- a/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java +++ b/NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/compat/MCAccessFactory.java @@ -20,7 +20,7 @@ public class MCAccessFactory { private final String[] updateLocs = new String[]{ "[NoCheatPlus] Check for updates and support at BukkitDev: http://dev.bukkit.org/server-mods/nocheatplus/", - "[NoCheatPlus] Development builds (unsupported by the Bukkit Staff, at your own risk): http://ci.md-5.net/job/NoCheatPlus/changes", + "[NoCheatPlus] Development builds (unsupported by the Bukkit Staff, use at your own risk): http://ci.md-5.net/job/NoCheatPlus/changes", }; /** @@ -29,49 +29,49 @@ public class MCAccessFactory { * @return * @throws RuntimeException if no access can be set. */ - public MCAccess getMCAccess(final boolean bukkitOnly) { + public MCAccess getMCAccess(final MCAccessConfig config) { final List throwables = new ArrayList(); - + MCAccess mcAccess = null; // Try to set up native access. - if (!bukkitOnly) { - // CraftBukkit (dedicated). - MCAccess mcAccess = getMCAccessCraftBukkit(throwables); + + // CraftBukkit (dedicated). + if (config.enableCBDedicated) { + mcAccess = getMCAccessCraftBukkit(throwables); if (mcAccess != null) { return mcAccess; } - // CraftBukkit (reflection). + } + + // CraftBukkit (reflection). + if (config.enableCBReflect) { try { return new MCAccessCBReflect(); } catch (Throwable t) { throwables.add(t); } - // Glowstone. - try { - return new MCAccessGlowstone(); - } catch(Throwable t) { - throwables.add(t); - }; } + // Glowstone. + try { + return new MCAccessGlowstone(); + } catch(Throwable t) { + throwables.add(t); + }; + // Try to set up api-only access (since 1.4.6). - try{ + try { + mcAccess = new MCAccessBukkit(); final String msg; - if (bukkitOnly) { - msg = "[NoCheatPlus] The plugin is configured for Bukkit-API-only access."; - } - else{ - msg = "[NoCheatPlus] Could not set up native access for the server-mod (" + Bukkit.getServer().getVersion() + "). Please check for updates and consider to request support."; - for (String uMsg : updateLocs) { - StaticLog.logWarning(uMsg); - } - } + msg = "[NoCheatPlus] Running in Bukkit-API-only mode (" + Bukkit.getServer().getVersion() + "). If this is not intended, please check for updates and consider to request support."; StaticLog.logWarning(msg); - final MCAccess mcAccess = new MCAccessBukkit(); + for (String uMsg : updateLocs) { + StaticLog.logWarning(uMsg); + } // if (ConfigManager.getConfigFile().getBoolean(ConfPaths.LOGGING_EXTENDED_STATUS)) { // log(throwables); // Maybe later activate with TRACE explicitly set // } - StaticLog.logWarning("[NoCheatPlus] Bukkit-API-only access: Some features will likely not function properly, performance might suffer."); + StaticLog.logWarning("[NoCheatPlus] Bukkit-API-only mode: Some features will likely not function properly, performance might suffer."); return mcAccess; } catch(Throwable t) {