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
|
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||||
* and open the template in the editor.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.bekvon.bukkit.residence.permissions;
|
package com.bekvon.bukkit.residence.permissions;
|
||||||
|
|
||||||
import com.bekvon.bukkit.residence.Residence;
|
import java.util.Collections;
|
||||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
import java.util.HashMap;
|
||||||
import com.bekvon.bukkit.residence.vaultinterface.ResidenceVaultAdapter;
|
import java.util.List;
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.Set;
|
||||||
import java.util.logging.Logger;
|
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.Plugin;
|
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
|
* @author Administrator
|
||||||
@@ -29,23 +32,36 @@ public class PermissionManager {
|
|||||||
|
|
||||||
public PermissionManager(FileConfiguration config) {
|
public PermissionManager(FileConfiguration config) {
|
||||||
try {
|
try {
|
||||||
groups = Collections
|
groups = Collections.synchronizedMap(new HashMap<String, PermissionGroup>());
|
||||||
.synchronizedMap(new HashMap<String, PermissionGroup>());
|
playersGroup = Collections.synchronizedMap(new HashMap<String, String>());
|
||||||
playersGroup = Collections
|
|
||||||
.synchronizedMap(new HashMap<String, String>());
|
|
||||||
globalFlagPerms = new FlagPermissions();
|
globalFlagPerms = new FlagPermissions();
|
||||||
this.readConfig(config);
|
this.readConfig(config);
|
||||||
boolean enable = config
|
boolean enable = config.getBoolean("Global.EnablePermissions", true);
|
||||||
.getBoolean("Global.EnablePermissions", true);
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
this.checkPermissions();
|
this.checkPermissions();
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(PermissionManager.class.getName()).log(
|
Residence.getLog().warning("权限管理载入失败,请报告以下错误给作者,谢谢!");
|
||||||
Level.SEVERE, null, ex);
|
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) {
|
public PermissionGroup getGroup(Player player) {
|
||||||
return groups.get(this.getGroupNameByPlayer(player));
|
return groups.get(this.getGroupNameByPlayer(player));
|
||||||
}
|
}
|
||||||
@@ -56,15 +72,13 @@ public class PermissionManager {
|
|||||||
|
|
||||||
public PermissionGroup getGroupByName(String group) {
|
public PermissionGroup getGroupByName(String group) {
|
||||||
group = group.toLowerCase();
|
group = group.toLowerCase();
|
||||||
if (!groups.containsKey(group)) {
|
if (!groups.containsKey(group))
|
||||||
return groups.get(Residence.getConfigManager().getDefaultGroup());
|
return groups.get(Residence.getConfigManager().getDefaultGroup());
|
||||||
}
|
|
||||||
return groups.get(group);
|
return groups.get(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupNameByPlayer(Player player) {
|
public String getGroupNameByPlayer(Player player) {
|
||||||
return this.getGroupNameByPlayer(player.getName(), player.getWorld()
|
return this.getGroupNameByPlayer(player.getName(), player.getWorld().getName());
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGroupNameByPlayer(String player, String world) {
|
public String getGroupNameByPlayer(String player, String world) {
|
||||||
@@ -73,22 +87,19 @@ public class PermissionManager {
|
|||||||
String group = playersGroup.get(player);
|
String group = playersGroup.get(player);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
group = group.toLowerCase();
|
group = group.toLowerCase();
|
||||||
if (group != null && groups.containsKey(group)) {
|
if (group != null && groups.containsKey(group))
|
||||||
return group;
|
return group;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String group = this.getPermissionsGroup(player, world);
|
String group = this.getPermissionsGroup(player, world);
|
||||||
if (group == null || !groups.containsKey(group)) {
|
if (group == null || !groups.containsKey(group))
|
||||||
return Residence.getConfigManager().getDefaultGroup().toLowerCase();
|
return Residence.getConfigManager().getDefaultGroup().toLowerCase();
|
||||||
} else {
|
else
|
||||||
return group;
|
return group;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermissionsGroup(Player player) {
|
public String getPermissionsGroup(Player player) {
|
||||||
return this.getPermissionsGroup(player.getName(), player.getWorld()
|
return this.getPermissionsGroup(player.getName(), player.getWorld().getName());
|
||||||
.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPermissionsGroup(String player, String world) {
|
public String getPermissionsGroup(String player, String world) {
|
||||||
@@ -97,33 +108,20 @@ public class PermissionManager {
|
|||||||
return perms.getPlayerGroup(player, world);
|
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) {
|
public boolean isResidenceAdmin(Player player) {
|
||||||
return (player.hasPermission("residence.admin") || (player.isOp() && Residence
|
return (player.hasPermission("residence.admin") || (player.isOp() && Residence
|
||||||
.getConfigManager().getOpsAreAdmins()));
|
.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) {
|
private void readConfig(FileConfiguration config) {
|
||||||
String defaultGroup = Residence.getConfigManager().getDefaultGroup();
|
String defaultGroup = Residence.getConfigManager().getDefaultGroup();
|
||||||
globalFlagPerms = FlagPermissions.parseFromConfigNode("FlagPermission",
|
globalFlagPerms = FlagPermissions.parseFromConfigNode("FlagPermission",
|
||||||
@@ -136,45 +134,27 @@ public class PermissionManager {
|
|||||||
groups.put(
|
groups.put(
|
||||||
key.toLowerCase(),
|
key.toLowerCase(),
|
||||||
new PermissionGroup(key.toLowerCase(), nodes
|
new PermissionGroup(key.toLowerCase(), nodes
|
||||||
.getConfigurationSection(key),
|
.getConfigurationSection(key), globalFlagPerms));
|
||||||
globalFlagPerms));
|
List<String> mirrors = nodes.getConfigurationSection(key).getStringList(
|
||||||
List<String> mirrors = nodes.getConfigurationSection(key)
|
"Mirror");
|
||||||
.getStringList("Mirror");
|
|
||||||
for (String group : mirrors) {
|
for (String group : mirrors) {
|
||||||
groups.put(
|
groups.put(group.toLowerCase(), new PermissionGroup(key.toLowerCase(),
|
||||||
group.toLowerCase(),
|
nodes.getConfigurationSection(key), globalFlagPerms));
|
||||||
new PermissionGroup(key.toLowerCase(), nodes
|
|
||||||
.getConfigurationSection(key),
|
|
||||||
globalFlagPerms));
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out
|
Residence.getLog().info("错误 从配置文件读取:" + key + " 抛出异常:" + ex);
|
||||||
.println("[Residence] 错误 从配置文件读取:"
|
|
||||||
+ key + " 抛出异常:" + ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!groups.containsKey(defaultGroup)) {
|
if (!groups.containsKey(defaultGroup)) {
|
||||||
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
groups.put(defaultGroup, new PermissionGroup(defaultGroup));
|
||||||
}
|
}
|
||||||
Set<String> keys = config.getConfigurationSection("GroupAssignments")
|
Set<String> keys = config.getConfigurationSection("GroupAssignments").getKeys(false);
|
||||||
.getKeys(false);
|
|
||||||
if (keys != null) {
|
if (keys != null) {
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
playersGroup.put(
|
playersGroup.put(key.toLowerCase(),
|
||||||
key.toLowerCase(),
|
config.getString("GroupAssignments." + key, defaultGroup).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