Merge pull request #53 from NuclearW/permissions

Added PEX and Bukkit Permissions.
This commit is contained in:
nossr50 2011-07-17 21:32:19 -07:00
commit 4a6405d62f
3 changed files with 215 additions and 45 deletions

View File

@ -10,12 +10,9 @@ import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.skills.*;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijiko.permissions.PermissionHandler;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.plugin.Plugin;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@ -49,13 +46,13 @@ public class mcMMO extends JavaPlugin
* Donate via paypal to nossr50@gmail.com (A million thanks to anyone that does!)
*/
public static String maindirectory = "plugins/mcMMO/";
public static String maindirectory = "plugins + File.separator + mcMMO";
File file = new File(maindirectory + File.separator + "config.yml");
public static final Logger log = Logger.getLogger("Minecraft");
private final mcPlayerListener playerListener = new mcPlayerListener(this);
private final mcBlockListener blockListener = new mcBlockListener(this);
private final mcEntityListener entityListener = new mcEntityListener(this);
public static PermissionHandler permissionHandler;
public static mcPermissions permissionHandler = new mcPermissions();
private Permissions permissions;
private Timer mcMMO_Timer = new Timer(true); //BLEED AND REGENERATION
@ -71,9 +68,9 @@ public class mcMMO extends JavaPlugin
public void onEnable()
{
//new File(maindirectory).mkdir();
new File(maindirectory).mkdir();
setupPermissions();
mcPermissions.initialize(getServer());
config.configCheck();
if(!LoadProperties.useMySQL)
@ -121,25 +118,6 @@ public class mcMMO extends JavaPlugin
//mcMMO_SpellTimer.schedule(new mcTimerSpells(this), (long)0, (long)(100));
}
private void setupPermissions()
{
if (permissionHandler != null)
{
return;
}
Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
if (permissionsPlugin == null)
{
//log.log(Level.INFO, "[mcMMO] Permission system not detected, defaulting to OP");
return;
}
permissionHandler = ((Permissions) permissionsPlugin).getHandler();
//log.log(Level.INFO, "[mcMMO] Found and will use plugin "+((Permissions)permissionsPlugin).getDescription().getFullName());
}
public boolean inSameParty(Player playera, Player playerb){
if(Users.getProfile(playera).inParty() && Users.getProfile(playerb).inParty()){
if(Users.getProfile(playera).getParty().equals(Users.getProfile(playerb).getParty())){

View File

@ -1,32 +1,51 @@
package com.gmail.nossr50;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import ru.tehkode.permissions.PermissionManager;
import ru.tehkode.permissions.bukkit.PermissionsEx;
import com.nijiko.permissions.PermissionHandler;
import com.nijikokun.bukkit.Permissions.Permissions;
public class mcPermissions
{
private static Permissions permissionsPlugin;
public static boolean permissionsEnabled = false;
private static volatile mcPermissions instance;
private enum PermissionType {
PEX, PERMISSIONS, BUKKIT
}
private static PermissionType permissionType;
private static Object PHandle;
public static boolean permissionsEnabled = false;
public static void initialize(Server server)
{
Logger log = Logger.getLogger("Minecraft");
if(permissionsEnabled && permissionType != PermissionType.PERMISSIONS) return;
Plugin PEXtest = server.getPluginManager().getPlugin("PermissionsEx");
Plugin test = server.getPluginManager().getPlugin("Permissions");
if (test != null)
{
Logger log = Logger.getLogger("Minecraft");
permissionsPlugin = ((Permissions) test);
if(PEXtest != null) {
PHandle = (PermissionManager) PermissionsEx.getPermissionManager();
permissionType = PermissionType.PEX;
permissionsEnabled = true;
log.log(Level.INFO, "[mcMMO] Permissions enabled.");
} else
{
Logger log = Logger.getLogger("Minecraft");
log.log(Level.SEVERE, "[mcMMO] Permissions isn't loaded, there are no restrictions.");
log.info("[mcMMO] PermissionsEx found, using PermissionsEx.");
} else if(test != null) {
PHandle = (PermissionHandler) ((Permissions) test).getHandler();
permissionType = PermissionType.PERMISSIONS;
permissionsEnabled = true;
log.info("[mcMMO] Permissions version "+test.getDescription().getVersion()+" found, using Permissions.");
} else {
permissionType = PermissionType.BUKKIT;
permissionsEnabled = true;
log.info("[mcMMO] Using Bukkit Permissions.");
}
}
@ -35,9 +54,19 @@ public class mcPermissions
return permissionsEnabled;
}
private static boolean permission(Player player, String string)
private static boolean permission(Player player, String permission)
{
return permissionsPlugin.getHandler().has(player, string);
if(!permissionsEnabled) return player.isOp();
switch(permissionType) {
case PEX:
return ((PermissionManager) PHandle).has(player, permission);
case PERMISSIONS:
return ((PermissionHandler) PHandle).has(player, permission);
case BUKKIT:
return player.hasPermission(permission);
default:
return true;
}
}
public boolean admin(Player player){
if (permissionsEnabled) {

View File

@ -64,3 +64,166 @@ commands:
description: Toggle Admin chat or send admin chat messages
sorcery:
description: Detailed skill info
permissions:
mcmmo.*:
description: Implies all mcmmo permissions.
children:
mcmmo.admin: true
mcmmo.tools.*: true
mcmmo.ability.*: true
mcmmo.item.*: true
mcmmo.tools.*: true
mcmmo.regeneration: true
mcmmo.motd: true
mcmmo.commands.*: true
mcmmo.chat.*: true
mcmmo.skills.*: true
mcmmo.admin:
default: op
mcmmo.tools.*:
description: Implies all mcmmo.tools permissions.
children:
mcmmo.tools.mcrefresh: true
mcmmo.tools.mmoedit: true
mcmmo.tools.mcgod: true
mcmmo.tools.mcrefresh:
default: op
mcmmo.tools.mmoedit:
default: op
mcmmo.tools.mcgod:
default: op
mcmmo.ability.*:
description: Implies all mcmmo.ability permissions.
children:
mcmmo.ability.herbalism: true
mcmmo.ability.excavation: true
mcmmo.ability.unarmed: true
mcmmo.ability.mining: true
mcmmo.ability.axes: true
mcmmo.ability.swords: true
mcmmo.ability.woodcutting: true
mcmmo.ability.herbalism:
default: true
mcmmo.ability.excavation:
default: true
mcmmo.ability.unarmed:
default: true
mcmmo.ability.mining:
default: true
mcmmo.ability.axes:
default: true
mcmmo.ability.swords:
default: true
mcmmo.ability.woodcutting:
default: true
mcmmo.item.*:
description: Implies all mcmmo.item permissions.
children:
mcmmo.item.chimaerawing: true
mcmmo.item.chimaerawing:
default: true
mcmmo.regeneration:
default: true
mcmmo.motd:
default: true
mcmmo.commands.*:
description: Implies all mcmmo.commands permissions.
children:
mcmmo.commands.ability: true
mcmmo.commands.myspawn: true
mcmmo.commands.setmyspawn: true
mcmmo.commands.ptp: true
mcmmo.commands.whois: true
mcmmo.commands.party: true
mcmmo.commands.ability:
default: true
mcmmo.commands.myspawn:
default: true
mcmmo.commands.setmyspawn:
default: true
mcmmo.commands.ptp:
default: true
mcmmo.commands.whois:
default: true
mcmmo.commands.party:
default: true
mcmmo.chat.*:
description: Implies all mcmmo.chat permissions. (Warning, contains adminchat)
children:
mcmmo.chat.adminchat: true
mcmmo.chat.partychat: true
mcmmo.chat.adminchat:
default: op
mcmmo.chat.partychat:
default: true
mcmmo.skills.*:
description: Implies all mcmmo.skills permissions.
children:
mcmmo.skills.sorcery.*: true
mcmmo.skills.curative.*: true
mcmmo.skills.taming: true
mcmmo.skills.mining: true
mcmmo.skills.woodcutting: true
mcmmo.skills.repair: true
mcmmo.skills.unarmed: true
mcmmo.skills.archery: true
mcmmo.skills.herbalism: true
mcmmo.skills.excavation: true
mcmmo.skills.swords: true
mcmmo.skills.axes: true
mcmmo.skills.acrobatics: true
mcmmo.skills.sorcery.*:
description: Implies all mcmmo.skills.sorcery permissions.
children:
mcmmo.skills.sorcery: true
mcmmo.skills.sorcery.water: true
mcmmo.skills.sorcery.water.thunder: true
mcmmo.skills.curative.*:
description: Implies all mcmmo.skills.curative permissions.
children:
mcmmo.skills.curative: true
mcmmo.skills.curative.heal.other: true
mcmmo.skills.curative.heal.self: true
mcmmo.skills.sorcery:
default: true
mcmmo.skills.sorcery.water:
default: true
mcmmo.skills.sorcery.water.thunder:
default: true
mcmmo.skills.curative:
default: true
mcmmo.skills.curative.heal.other:
default: true
mcmmo.skills.curative.heal.self:
default: true
mcmmo.skills.taming:
default: true
mcmmo.skills.mining:
default: true
mcmmo.skills.woodcutting:
default: true
mcmmo.skills.repair:
default: true
mcmmo.skills.unarmed:
default: true
mcmmo.skills.archery:
default: true
mcmmo.skills.herbalism:
default: true
mcmmo.skills.excavation:
default: true
mcmmo.skills.swords:
default: true
mcmmo.skills.axes:
default: true
mcmmo.skills.acrobatics:
default: true