Decouple iConomy and Permissions from Core. Closes #32

This commit is contained in:
Eric Stokes 2011-07-06 18:10:36 -06:00
parent 79fba462b9
commit 8ecfebe480
4 changed files with 42 additions and 75 deletions

View File

@ -1,14 +1,18 @@
package com.onarandombox.MultiverseCore;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.nijiko.permissions.PermissionHandler;
public class MVPermissions {
private MultiverseCore plugin;
public PermissionHandler permissions = null;
/**
* Constructor FTW
@ -17,6 +21,11 @@ public class MVPermissions {
*/
public MVPermissions(MultiverseCore plugin) {
this.plugin = plugin;
// We have to see if permissions was loaded before MV was
if(this.plugin.getServer().getPluginManager().getPlugin("Permissions") != null) {
this.setPermissions(((com.nijikokun.bukkit.Permissions.Permissions)this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
this.plugin.log(Level.INFO, "- Attached to Permissions");
}
}
/**
@ -30,8 +39,8 @@ public class MVPermissions {
public boolean has(Player p, String node) {
boolean result = false;
if (MultiverseCore.Permissions != null) {
result = MultiverseCore.Permissions.has(p, node);
if (this.permissions != null) {
result = this.permissions.has(p, node);
} else if (p.isOp()) {
result = true;
}
@ -49,19 +58,18 @@ public class MVPermissions {
if (player.isOp() && opFallback) {
// If Player is Op we always let them use it if they have the fallback enabled!
return true;
} else if (MultiverseCore.Permissions != null && MultiverseCore.Permissions.has(player, node)) {
} else if (this.permissions != null && this.permissions.has(player, node)) {
// If Permissions is enabled we check against them.
return true;
}
// If the Player doesn't have Permissions and isn't an Op then
// we return true if OP is not required, otherwise we return false
// This allows us to act as a default permission guidance
// This allows us to act as a default permission guidance
// If they have the op fallback disabled, NO commands will work without a permissions plugin.
return !isOpRequired && opFallback;
}
/**
* Check if a Player can teleport to the Destination world from there current world. This checks against the Worlds Blacklist
*
@ -97,7 +105,7 @@ public class MVPermissions {
*/
public Boolean canEnterWorld(Player p, World w) {
if(!this.plugin.isMVWorld(w.getName())) {
if (!this.plugin.isMVWorld(w.getName())) {
return false;
}
List<String> whiteList = this.plugin.getMVWorld(w.getName()).getPlayerWhitelist();
@ -141,10 +149,14 @@ public class MVPermissions {
* @return True if the player is in the group, false if not.
*/
private boolean inGroup(Player player, String worldName, String group) {
if (MultiverseCore.Permissions != null) {
return MultiverseCore.Permissions.inGroup(worldName, player.getName(), group);
if (this.permissions != null) {
return this.permissions.inGroup(worldName, player.getName(), group);
} else {
return player.isOp();
}
}
public void setPermissions(PermissionHandler handler) {
this.permissions = handler;
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.event.server.PluginEnableEvent;
import org.bukkit.event.server.ServerListener;
import org.bukkit.plugin.Plugin;
import com.iConomy.iConomy;
import com.nijikokun.bukkit.Permissions.Permissions;
public class MVPluginListener extends ServerListener {
@ -23,12 +22,11 @@ public class MVPluginListener extends ServerListener {
*/
@Override
public void onPluginEnable(PluginEnableEvent event) {
/**
* Check to see if Permissions was just enabled, we only wan't to perform the following if GroupManager is not found.
* Check to see if Permissions was just enabled
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
MultiverseCore.Permissions = ((Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler();
this.plugin.ph.setPermissions(((Permissions) this.plugin.getServer().getPluginManager().getPlugin("Permissions")).getHandler());
this.plugin.log(Level.INFO, "- Attached to Permissions");
}
// TODO: Use AllPay
@ -36,13 +34,13 @@ public class MVPluginListener extends ServerListener {
* Use the METHOD supplied by iConomy to register it etc...
*/
if(event.getPlugin().getDescription().getName().equals("iConomy")) {
Plugin iConomy = this.plugin.getServer().getPluginManager().getPlugin("iConomy");
//Plugin iConomy = this.plugin.getServer().getPluginManager().getPlugin("iConomy");
if (iConomy != null) {
if (iConomy.isEnabled()) {
MultiverseCore.iConomy = (iConomy) iConomy;
}
}
// if (iConomy != null) {
// if (iConomy.isEnabled()) {
// MultiverseCore.iConomy = (iConomy) iConomy;
// }
// }
}
}
@ -55,15 +53,16 @@ public class MVPluginListener extends ServerListener {
* Check to see if Permissions just disabled.
*/
if (event.getPlugin().getDescription().getName().equals("Permissions")) {
MultiverseCore.Permissions = null;
this.plugin.log(Level.INFO, "Permissions disabled");
this.plugin.ph.setPermissions(null);
}
/**
* Check to see if iConomy just disabled.
*/
if (MultiverseCore.getiConomy() != null) {
MultiverseCore.iConomy = null;
}
// if (MultiverseCore.getiConomy() != null) {
// MultiverseCore.iConomy = null;
// }
}
}

View File

@ -21,9 +21,6 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.config.Configuration;
import com.iConomy.iConomy;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.onarandombox.MultiverseCore.command.CommandManager;
import com.onarandombox.MultiverseCore.command.commands.*;
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
@ -46,14 +43,7 @@ public class MultiverseCore extends JavaPlugin {
private final String tag = "[Multiverse-Core]";
// Multiverse Permissions Handler
public MVPermissions ph = new MVPermissions(this);
// Permissions Handler
public static PermissionHandler Permissions = null;
// iConomy Handler
public static iConomy iConomy = null;
public static boolean useiConomy = false;
public MVPermissions ph;
// Configurations
public Configuration configMV = null;
@ -89,17 +79,15 @@ public class MultiverseCore extends JavaPlugin {
public void onEnable() {
// Output a little snippet to show it's enabled.
this.log(Level.INFO, "- Version " + this.getDescription().getVersion() + " Enabled - By " + getAuthors());
// Setup all the Events the plugin needs to Monitor.
this.registerEvents();
// Setup Permissions, we'll do an initial check for the Permissions plugin then fall back on isOP().
this.setupPermissions();
this.ph = new MVPermissions(this);
// Setup the command manager
this.commandManager = new CommandManager(this);
// Setup the world purger
this.worldPurger = new PurgeWorlds(this);
// Setup iConomy.
this.setupEconomy();
// Call the Function to assign all the Commands to their Class.
this.registerCommands();
@ -138,33 +126,6 @@ public class MultiverseCore extends JavaPlugin {
// pm.registerEvent(Event.Type.EXPLOSION_PRIMED, entityListener, Priority.Normal, this); // Try to prevent Ghasts from blowing up structures.
}
/**
* Check for Permissions plugin and then setup our own Permissions Handler.
*/
private void setupPermissions() {
Plugin p = this.getServer().getPluginManager().getPlugin("Permissions");
if (MultiverseCore.Permissions == null) {
if (p != null && p.isEnabled()) {
MultiverseCore.Permissions = ((Permissions) p).getHandler();
log(Level.INFO, "- Attached to Permissions");
}
}
}
/**
* Check for the iConomy plugin and set it up accordingly.
*/
private void setupEconomy() {
Plugin test = this.getServer().getPluginManager().getPlugin("iConomy");
if (MultiverseCore.iConomy == null) {
if (test != null) {
MultiverseCore.iConomy = (iConomy) test;
}
}
}
/**
* Load the Configuration files OR create the default config files.
*/
@ -442,7 +403,6 @@ public class MultiverseCore extends JavaPlugin {
*/
public void onDisable() {
debugLog.close();
MultiverseCore.Permissions = null;
log(Level.INFO, "- Disabled");
}
@ -470,15 +430,6 @@ public class MultiverseCore extends JavaPlugin {
return new MVTeleport(this);
}
/**
* Grab the iConomy setup.
*
* @return
*/
public static iConomy getiConomy() {
return iConomy;
}
/**
* Grab the Permissions Handler for MultiVerse
*/

View File

@ -6,7 +6,12 @@
# none: You will always respawn in the same world you died in
notchrespawnstyle: none
#
# Should multivers spawn players at their bed if they've slept there?
# This value will OVERRIDE notchrespawnstyle
bedrespawn: true
# Used only in notchrespawnstyle, this is the default world players will spawn in if they die.
# If you type some world that does not exist, this will default to your default world.
defaultspawnworld: world
# How long to leave in between sending a message to the player.