mirror of
https://e.coding.net/circlecloud/Residence.git
synced 2025-11-24 21:46:16 +00:00
@@ -1,22 +1,25 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
|
||||
package com.bekvon.bukkit.residence.permissions;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||
import com.bekvon.bukkit.residence.vaultinterface.ResidenceVaultAdapter;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.bekvon.bukkit.residence.Residence;
|
||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||
import com.bekvon.bukkit.residence.vaultinterface.ResidenceVaultAdapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Administrator
|
||||
@@ -29,23 +32,36 @@ public class PermissionManager {
|
||||
|
||||
public PermissionManager(FileConfiguration config) {
|
||||
try {
|
||||
groups = Collections
|
||||
.synchronizedMap(new HashMap<String, PermissionGroup>());
|
||||
playersGroup = Collections
|
||||
.synchronizedMap(new HashMap<String, String>());
|
||||
groups = Collections.synchronizedMap(new HashMap<String, PermissionGroup>());
|
||||
playersGroup = Collections.synchronizedMap(new HashMap<String, String>());
|
||||
globalFlagPerms = new FlagPermissions();
|
||||
this.readConfig(config);
|
||||
boolean enable = config
|
||||
.getBoolean("Global.EnablePermissions", true);
|
||||
boolean enable = config.getBoolean("Global.EnablePermissions", true);
|
||||
if (enable) {
|
||||
this.checkPermissions();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(PermissionManager.class.getName()).log(
|
||||
Level.SEVERE, null, ex);
|
||||
Residence.getLog().warning("权限管理载入失败,请报告以下错误给作者,谢谢!");
|
||||
Residence.getLog().warning("错误: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkPermissions() {
|
||||
Server server = Residence.getServ();
|
||||
Plugin p = server.getPluginManager().getPlugin("Vault");
|
||||
if (p != null) {
|
||||
ResidenceVaultAdapter vault = new ResidenceVaultAdapter(server);
|
||||
if (vault.permissionsOK()) {
|
||||
perms = vault;
|
||||
Residence.getLog().info("发现 Vault 使用权限系统:" + vault.getPermissionsName());
|
||||
return;
|
||||
} else {
|
||||
Residence.getLog().info("发现 Vault, 但是 Vault 未找到权限系统...");
|
||||
}
|
||||
}
|
||||
Residence.getLog().warning("权限系统未找到!");
|
||||
}
|
||||
|
||||
public PermissionGroup getGroup(Player player) {
|
||||
return groups.get(this.getGroupNameByPlayer(player));
|
||||
}
|
||||
@@ -56,15 +72,13 @@ public class PermissionManager {
|
||||
|
||||
public PermissionGroup getGroupByName(String group) {
|
||||
group = group.toLowerCase();
|
||||
if (!groups.containsKey(group)) {
|
||||
if (!groups.containsKey(group))
|
||||
return groups.get(Residence.getConfigManager().getDefaultGroup());
|
||||
}
|
||||
return groups.get(group);
|
||||
}
|
||||
|
||||
public String getGroupNameByPlayer(Player player) {
|
||||
return this.getGroupNameByPlayer(player.getName(), player.getWorld()
|
||||
.getName());
|
||||
return this.getGroupNameByPlayer(player.getName(), player.getWorld().getName());
|
||||
}
|
||||
|
||||
public String getGroupNameByPlayer(String player, String world) {
|
||||
@@ -73,22 +87,19 @@ public class PermissionManager {
|
||||
String group = playersGroup.get(player);
|
||||
if (group != null) {
|
||||
group = group.toLowerCase();
|
||||
if (group != null && groups.containsKey(group)) {
|
||||
if (group != null && groups.containsKey(group))
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
String group = this.getPermissionsGroup(player, world);
|
||||
if (group == null || !groups.containsKey(group)) {
|
||||
if (group == null || !groups.containsKey(group))
|
||||
return Residence.getConfigManager().getDefaultGroup().toLowerCase();
|
||||
} else {
|
||||
else
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
||||
public String getPermissionsGroup(Player player) {
|
||||
return this.getPermissionsGroup(player.getName(), player.getWorld()
|
||||
.getName());
|
||||
return this.getPermissionsGroup(player.getName(), player.getWorld().getName());
|
||||
}
|
||||
|
||||
public String getPermissionsGroup(String player, String world) {
|
||||
@@ -97,33 +108,20 @@ public class PermissionManager {
|
||||
return perms.getPlayerGroup(player, world);
|
||||
}
|
||||
|
||||
public PermissionsInterface getPermissionsPlugin() {
|
||||
return perms;
|
||||
}
|
||||
|
||||
public boolean hasGroup(String group) {
|
||||
group = group.toLowerCase();
|
||||
return groups.containsKey(group);
|
||||
}
|
||||
|
||||
public boolean isResidenceAdmin(Player player) {
|
||||
return (player.hasPermission("residence.admin") || (player.isOp() && Residence
|
||||
.getConfigManager().getOpsAreAdmins()));
|
||||
}
|
||||
|
||||
private void checkPermissions() {
|
||||
Server server = Residence.getServ();
|
||||
Plugin p = server.getPluginManager().getPlugin("Vault");
|
||||
if (p != null) {
|
||||
ResidenceVaultAdapter vault = new ResidenceVaultAdapter(server);
|
||||
if (vault.permissionsOK()) {
|
||||
perms = vault;
|
||||
Logger.getLogger("Minecraft").log(
|
||||
Level.INFO,
|
||||
"[Residence] 发现 Vault 使用权限系统:"
|
||||
+ vault.getPermissionsName());
|
||||
return;
|
||||
} else {
|
||||
Logger.getLogger("Minecraft")
|
||||
.log(Level.INFO,
|
||||
"[Residence] 发现 Vault, 但是 Vault 未找到权限系统...");
|
||||
}
|
||||
}
|
||||
Logger.getLogger("Minecraft").log(Level.INFO,
|
||||
"[Residence] 权限系统未找到!");
|
||||
}
|
||||
|
||||
private void readConfig(FileConfiguration config) {
|
||||
String defaultGroup = Residence.getConfigManager().getDefaultGroup();
|
||||
globalFlagPerms = FlagPermissions.parseFromConfigNode("FlagPermission",
|
||||
@@ -136,45 +134,27 @@ public class PermissionManager {
|
||||
groups.put(
|
||||
key.toLowerCase(),
|
||||
new PermissionGroup(key.toLowerCase(), nodes
|
||||
.getConfigurationSection(key),
|
||||
globalFlagPerms));
|
||||
List<String> mirrors = nodes.getConfigurationSection(key)
|
||||
.getStringList("Mirror");
|
||||
.getConfigurationSection(key), globalFlagPerms));
|
||||
List<String> mirrors = nodes.getConfigurationSection(key).getStringList(
|
||||
"Mirror");
|
||||
for (String group : mirrors) {
|
||||
groups.put(
|
||||
group.toLowerCase(),
|
||||
new PermissionGroup(key.toLowerCase(), nodes
|
||||
.getConfigurationSection(key),
|
||||
globalFlagPerms));
|
||||
groups.put(group.toLowerCase(), new PermissionGroup(key.toLowerCase(),
|
||||
nodes.getConfigurationSection(key), globalFlagPerms));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
System.out
|
||||
.println("[Residence] 错误 从配置文件读取:"
|
||||
+ key + " 抛出异常:" + ex);
|
||||
Residence.getLog().info("错误 从配置文件读取:" + key + " 抛出异常:" + ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!groups.containsKey(defaultGroup)) {
|
||||
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
||||
}
|
||||
Set<String> keys = config.getConfigurationSection("GroupAssignments")
|
||||
.getKeys(false);
|
||||
Set<String> keys = config.getConfigurationSection("GroupAssignments").getKeys(false);
|
||||
if (keys != null) {
|
||||
for (String key : keys) {
|
||||
playersGroup.put(
|
||||
key.toLowerCase(),
|
||||
config.getString("GroupAssignments." + key,
|
||||
defaultGroup).toLowerCase());
|
||||
playersGroup.put(key.toLowerCase(),
|
||||
config.getString("GroupAssignments." + key, defaultGroup).toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasGroup(String group) {
|
||||
group = group.toLowerCase();
|
||||
return groups.containsKey(group);
|
||||
}
|
||||
|
||||
public PermissionsInterface getPermissionsPlugin() {
|
||||
return perms;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user