From 071279ff02df539d920660d74f1a2fb5885ed5dc Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Mon, 25 Mar 2013 17:51:01 +0100 Subject: [PATCH] Fix for Ticket #102 (missing dependency -> NoClassDefFoundError) --- .../limitedcreative/ModGameModePerm.java | 28 ++++++++-------- .../minecraft/limitedcreative/ModRegions.java | 16 ++++++--- .../gmperm/PermissionInterface.java | 33 +++++++++++++++++++ .../gmperm/PlayerListener.java | 2 +- src/main/resources/lang/messages.properties | 8 ++--- 5 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PermissionInterface.java diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java index 13d12ac..feb7e3b 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModGameModePerm.java @@ -1,11 +1,8 @@ package de.jaschastarke.minecraft.limitedcreative; -import net.milkbowl.vault.permission.Permission; - -import org.bukkit.plugin.RegisteredServiceProvider; - import de.jaschastarke.bukkit.lib.CoreModule; import de.jaschastarke.minecraft.limitedcreative.gmperm.GMPermConfig; +import de.jaschastarke.minecraft.limitedcreative.gmperm.PermissionInterface; import de.jaschastarke.minecraft.limitedcreative.gmperm.PlayerListener; import de.jaschastarke.modularize.IModule; import de.jaschastarke.modularize.ModuleEntry; @@ -13,8 +10,7 @@ import de.jaschastarke.modularize.ModuleEntry.ModuleState; public class ModGameModePerm extends CoreModule { private GMPermConfig config; - private Permission permission = null; - private RegisteredServiceProvider permissionProvider; + private PermissionInterface permission = null; public ModGameModePerm(LimitedCreative plugin) { super(plugin); @@ -31,15 +27,24 @@ public class ModGameModePerm extends CoreModule { config = new GMPermConfig(this, entry); plugin.getPluginConfig().registerSection(config); - permissionProvider = plugin.getServer().getServicesManager().getRegistration(Permission.class); + if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) { + if (config.getEnabled()) + getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); + entry.initialState = ModuleState.NOT_INITIALIZED; + return; + } + + permission = new PermissionInterface(this); if (config.getEnabled()) { - if (!plugin.getServer().getPluginManager().isPluginEnabled("Vault")) { + if (!permission.isPresent()) { getLog().warn(plugin.getLocale().trans("gmperm.warning.vault_not_found", getName())); entry.initialState = ModuleState.NOT_INITIALIZED; + return; } /*else if (!getVaultPermission().hasGroupSupport()) { getLog().warn(plugin.getLocale().trans("gmperm.warning.no_group_support", getName())); entry.initialState = ModuleState.NOT_INITIALIZED; + return; }*/ } } @@ -52,15 +57,12 @@ public class ModGameModePerm extends CoreModule { @Override public void onDisable() { super.onDisable(); - permission = null; + permission.clear(); } public GMPermConfig getConfig() { return config; } - public Permission getVaultPermission() { - if (permissionProvider != null && permission == null) { - permission = permissionProvider.getProvider(); - } + public PermissionInterface getPermissionInterface() { return permission; } } diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java index 7dbcd36..d442222 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/ModRegions.java @@ -33,6 +33,10 @@ public class ModRegions extends CoreModule { public ModRegions(LimitedCreative plugin) { super(plugin); } + @Override + public String getName() { + return "Regions"; + } @Override public void initialize(ModuleEntry pEntry) { @@ -44,6 +48,13 @@ public class ModRegions extends CoreModule { config = plugin.getPluginConfig().registerSection(new RegionConfig(this, entry)); + if (!plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { + if (config.getEnabled()) + getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName())); + entry.initialState = ModuleState.NOT_INITIALIZED; + return; + } + command = new RegionsCommand(this); listeners.addListener(new PlayerListener(this)); @@ -52,11 +63,6 @@ public class ModRegions extends CoreModule { listeners.addListener(new PlayerRegionListener(this)); // Fires Custom-Events listen by RegionListener FlagList.addFlags(Flags.getList()); - - if (config.getEnabled() && !plugin.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { - getLog().warn(plugin.getLocale().trans("region.warning.worldguard_not_found", getName())); - entry.initialState = ModuleState.NOT_INITIALIZED; - } } @Override diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PermissionInterface.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PermissionInterface.java new file mode 100644 index 0000000..cf202d5 --- /dev/null +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PermissionInterface.java @@ -0,0 +1,33 @@ +package de.jaschastarke.minecraft.limitedcreative.gmperm; + +import net.milkbowl.vault.permission.Permission; + +import org.bukkit.plugin.RegisteredServiceProvider; + +import de.jaschastarke.bukkit.lib.CoreModule; + +public class PermissionInterface { + //private CoreModule mod; + private Permission permission = null; + private RegisteredServiceProvider permissionProvider; + + public PermissionInterface(CoreModule mod) { + //this.mod = mod; + permissionProvider = mod.getPlugin().getServer().getServicesManager().getRegistration(Permission.class); + } + + public boolean isPresent() { + return permissionProvider != null && permissionProvider.getProvider() != null; + } + + public void clear() { + permission = null; + } + + public Permission getPermission() { + if (permission == null) + permission = permissionProvider.getProvider(); + return permission; + } + +} diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PlayerListener.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PlayerListener.java index d90c11e..781463a 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PlayerListener.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/gmperm/PlayerListener.java @@ -38,7 +38,7 @@ public class PlayerListener implements Listener { } protected Permission v() { - return mod.getVaultPermission(); + return mod.getPermissionInterface().getPermission(); } @EventHandler(priority = EventPriority.MONITOR) diff --git a/src/main/resources/lang/messages.properties b/src/main/resources/lang/messages.properties index c7394db..d1e456e 100644 --- a/src/main/resources/lang/messages.properties +++ b/src/main/resources/lang/messages.properties @@ -1,9 +1,9 @@ basic.loaded.module: Module loaded. inventory.warning.conflict: Due to conflict with the plugin {0}, the feature {1} is disabled -region.warning.worldguard_not_found: WorldGuard isn't found, the feature {0} is disabled -gmperm.warning.vault_not_found: Vault isn't found, the feature {0} is disabled -gmperm.warning.no_group_support: Your Permission-Plugin doesn't support groups, the feature {0} is disabled +region.warning.worldguard_not_found: WorldGuard isn''t found, the feature {0} is disabled +gmperm.warning.vault_not_found: Vault isn''t found, the feature {0} is disabled +gmperm.warning.no_group_support: "Your Permission-Plugin doesn''t support groups, the feature {0} is disabled" command.general: LimitedCreative: GameMode-Switch, Creative-Regions, Config and more command.regions: LimitedCreative-Region-Command: configure creative regions @@ -12,7 +12,7 @@ command.switch.creative: Changes the game mode of a player to creative command.switch.adventure: Changes the game mode of a player to adventure command.config.reload: Reloads configuration and re-initializes all active modules. command.config.reload.success: The plugin was successfully reloaded. -command.gamemode.changed: {0}'s game mode has been changed +command.gamemode.changed: {0}''s game mode has been changed command.gamemode.no_change: Already in that game mode. command.worldguard.alias: Alias for //region-command