mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 01:27:40 +01:00
Merge branch 'refs/heads/groupmanager'
This commit is contained in:
commit
fa73394113
@ -521,10 +521,10 @@ public class NijikoPermissionsProxy extends PermissionHandler {
|
||||
|
||||
@Override
|
||||
public boolean has(String world, String playerName, String permission) {
|
||||
if (permission == null || permission.equals("")) {
|
||||
if (permission == null || permission.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
if (playerName == null || playerName == "") {
|
||||
if (playerName == null || playerName.isEmpty()) {
|
||||
GroupManager.logger.severe("A plugin is asking permission '" + permission + "' for a null player... Which plugin does that? Bastards!");
|
||||
return false;
|
||||
}
|
||||
|
@ -75,4 +75,7 @@ v 1.5:
|
||||
- Fixed a crash on reload due to bukkit not unloading plugins before reloading.
|
||||
v 1.6:
|
||||
- Prevent Group.equals tests throwing a NullPointerException for GlobalGroups.
|
||||
- Stop throwing errors on an empty users file.
|
||||
- Stop throwing errors on an empty users file.
|
||||
- Optimize sorting to speedup permission tests.
|
||||
- Fix superperms to pass all tests http://dev.bukkit.org/server-mods/superpermstest/
|
||||
- Optimizations include changing the return of comparePermissionString.
|
@ -6,6 +6,8 @@ package org.anjocaido.groupmanager.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||
import org.anjocaido.groupmanager.utils.StringPermissionComparator;
|
||||
@ -18,7 +20,7 @@ public abstract class DataUnit {
|
||||
|
||||
private WorldDataHolder dataSource;
|
||||
private String name;
|
||||
private boolean changed;
|
||||
private boolean changed, sorted = false;
|
||||
private ArrayList<String> permissions = new ArrayList<String>();
|
||||
|
||||
public DataUnit(WorldDataHolder dataSource, String name) {
|
||||
@ -91,6 +93,7 @@ public abstract class DataUnit {
|
||||
// for(StackTraceElement st: Thread.currentThread().getStackTrace()){
|
||||
// GroupManager.logger.finest(st.toString());
|
||||
// }
|
||||
sorted = false;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
@ -132,11 +135,18 @@ public abstract class DataUnit {
|
||||
* You can't edit the permissions using the returned ArrayList instance
|
||||
* @return a copy of the permission list
|
||||
*/
|
||||
public ArrayList<String> getPermissionList() {
|
||||
return new ArrayList<String>(permissions);
|
||||
public List<String> getPermissionList() {
|
||||
return Collections.unmodifiableList(permissions);
|
||||
}
|
||||
|
||||
public boolean isSorted() {
|
||||
return this.sorted;
|
||||
}
|
||||
|
||||
public void sortPermissions() {
|
||||
Collections.sort(permissions, StringPermissionComparator.getInstance());
|
||||
if (!isSorted()) {
|
||||
Collections.sort(permissions, StringPermissionComparator.getInstance());
|
||||
sorted = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,6 +7,8 @@ package org.anjocaido.groupmanager.data;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -92,13 +94,13 @@ public class Group extends DataUnit implements Cloneable {
|
||||
}
|
||||
|
||||
/**
|
||||
* a COPY of inherits list
|
||||
* an unmodifiable list of inherits list
|
||||
* You can't manage the list by here
|
||||
* Lol... version 0.6 had a problem because this.
|
||||
* @return the inherits
|
||||
*/
|
||||
public ArrayList<String> getInherits() {
|
||||
return new ArrayList<String>(inherits);
|
||||
public List<String> getInherits() {
|
||||
return Collections.unmodifiableList(inherits);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -10,209 +10,232 @@ import java.util.ArrayList;
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author gabrielcouto
|
||||
*/
|
||||
public class User extends DataUnit implements Cloneable {
|
||||
|
||||
/**
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String group = null;
|
||||
private ArrayList<String> subGroups = new ArrayList<String>();
|
||||
/**
|
||||
*This one holds the fields in INFO node.
|
||||
* like prefix = 'c'
|
||||
* or build = false
|
||||
*/
|
||||
private UserVariables variables = new UserVariables(this);
|
||||
private String group = null;
|
||||
private ArrayList<String> subGroups = new ArrayList<String>();
|
||||
/**
|
||||
* This one holds the fields in INFO node. like prefix = 'c' or build =
|
||||
* false
|
||||
*/
|
||||
private UserVariables variables = new UserVariables(this);
|
||||
private transient Player bukkitPlayer = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public User(WorldDataHolder source, String name) {
|
||||
super(source, name);
|
||||
this.group = source.getDefaultGroup().getName();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
public User(WorldDataHolder source, String name) {
|
||||
super(source, name);
|
||||
this.group = source.getDefaultGroup().getName();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return User clone
|
||||
*/
|
||||
@Override
|
||||
public User clone() {
|
||||
User clone = new User(getDataSource(), this.getName());
|
||||
clone.group = this.group;
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
//clone.variables = this.variables.clone();
|
||||
//clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return User clone
|
||||
*/
|
||||
@Override
|
||||
public User clone() {
|
||||
User clone = new User(getDataSource(), this.getName());
|
||||
clone.group = this.group;
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
// clone.variables = this.variables.clone();
|
||||
// clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this to deliver a user from one WorldDataHolder to another
|
||||
* @param dataSource
|
||||
* @return null if given dataSource already contains the same user
|
||||
*/
|
||||
public User clone(WorldDataHolder dataSource) {
|
||||
if (dataSource.isUserDeclared(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
User clone = dataSource.createUser(this.getName());
|
||||
if (dataSource.getGroup(group) == null) {
|
||||
clone.setGroup(dataSource.getDefaultGroup());
|
||||
} else {
|
||||
clone.setGroup(dataSource.getGroup(this.getGroupName()));
|
||||
}
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
//clone.variables = this.variables.clone();
|
||||
clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
/**
|
||||
* Use this to deliver a user from one WorldDataHolder to another
|
||||
*
|
||||
* @param dataSource
|
||||
* @return null if given dataSource already contains the same user
|
||||
*/
|
||||
public User clone(WorldDataHolder dataSource) {
|
||||
if (dataSource.isUserDeclared(this.getName())) {
|
||||
return null;
|
||||
}
|
||||
User clone = dataSource.createUser(this.getName());
|
||||
if (dataSource.getGroup(group) == null) {
|
||||
clone.setGroup(dataSource.getDefaultGroup());
|
||||
} else {
|
||||
clone.setGroup(dataSource.getGroup(this.getGroupName()));
|
||||
}
|
||||
for (String perm : this.getPermissionList()) {
|
||||
clone.addPermission(perm);
|
||||
}
|
||||
// clone.variables = this.variables.clone();
|
||||
clone.flagAsChanged();
|
||||
return clone;
|
||||
}
|
||||
|
||||
public Group getGroup() {
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
this.setGroup(getDataSource().getDefaultGroup());
|
||||
result = getDataSource().getDefaultGroup();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Group getGroup() {
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
this.setGroup(getDataSource().getDefaultGroup());
|
||||
result = getDataSource().getDefaultGroup();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the group
|
||||
*/
|
||||
public String getGroupName() {
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
group = getDataSource().getDefaultGroup().getName();
|
||||
}
|
||||
return group;
|
||||
}
|
||||
/**
|
||||
* @return the group
|
||||
*/
|
||||
public String getGroupName() {
|
||||
Group result = getDataSource().getGroup(group);
|
||||
if (result == null) {
|
||||
group = getDataSource().getDefaultGroup().getName();
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group the group to set
|
||||
*/
|
||||
@Deprecated
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if(GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
/**
|
||||
* @param group
|
||||
* the group to set
|
||||
*/
|
||||
@Deprecated
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group the group to set
|
||||
*/
|
||||
public void setGroup(Group group) {
|
||||
if (!this.getDataSource().groupExists(group.getName())) {
|
||||
getDataSource().addGroup(group);
|
||||
}
|
||||
group = getDataSource().getGroup(group.getName());
|
||||
String oldGroup = this.group;
|
||||
this.group = group.getName();
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded()) {
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
|
||||
// Do we notify of the group change?
|
||||
String defaultGroupName = getDataSource().getDefaultGroup().getName();
|
||||
// if we were not in the default group
|
||||
// or we were in the default group and the move is to a different group.
|
||||
boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName))) ;
|
||||
|
||||
if (notify) GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName()));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param group
|
||||
* the group to set
|
||||
*/
|
||||
public void setGroup(Group group) {
|
||||
if (!this.getDataSource().groupExists(group.getName())) {
|
||||
getDataSource().addGroup(group);
|
||||
}
|
||||
group = getDataSource().getGroup(group.getName());
|
||||
String oldGroup = this.group;
|
||||
this.group = group.getName();
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded()) {
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
|
||||
public void addSubGroup(Group subGroup) {
|
||||
if (this.group.equalsIgnoreCase(subGroup.getName())) {
|
||||
return;
|
||||
}
|
||||
if (!this.getDataSource().groupExists(subGroup.getName())) {
|
||||
getDataSource().addGroup(subGroup);
|
||||
}
|
||||
subGroup = getDataSource().getGroup(subGroup.getName());
|
||||
removeSubGroup(subGroup);
|
||||
subGroups.add(subGroup.getName());
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
// Do we notify of the group change?
|
||||
String defaultGroupName = getDataSource().getDefaultGroup().getName();
|
||||
// if we were not in the default group
|
||||
// or we were in the default group and the move is to a different
|
||||
// group.
|
||||
boolean notify = (!oldGroup.equalsIgnoreCase(defaultGroupName)) || ((oldGroup.equalsIgnoreCase(defaultGroupName)) && (!this.group.equalsIgnoreCase(defaultGroupName)));
|
||||
|
||||
public int subGroupsSize() {
|
||||
return subGroups.size();
|
||||
}
|
||||
if (notify)
|
||||
GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSubGroupsEmpty() {
|
||||
return subGroups.isEmpty();
|
||||
}
|
||||
public void addSubGroup(Group subGroup) {
|
||||
if (this.group.equalsIgnoreCase(subGroup.getName())) {
|
||||
return;
|
||||
}
|
||||
if (!this.getDataSource().groupExists(subGroup.getName())) {
|
||||
getDataSource().addGroup(subGroup);
|
||||
}
|
||||
subGroup = getDataSource().getGroup(subGroup.getName());
|
||||
removeSubGroup(subGroup);
|
||||
subGroups.add(subGroup.getName());
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
|
||||
public boolean containsSubGroup(Group subGroup) {
|
||||
return subGroups.contains(subGroup.getName());
|
||||
}
|
||||
public int subGroupsSize() {
|
||||
return subGroups.size();
|
||||
}
|
||||
|
||||
public boolean removeSubGroup(Group subGroup) {
|
||||
try {
|
||||
if (subGroups.remove(subGroup.getName())) {
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isSubGroupsEmpty() {
|
||||
return subGroups.isEmpty();
|
||||
}
|
||||
|
||||
public ArrayList<Group> subGroupListCopy() {
|
||||
ArrayList<Group> val = new ArrayList<Group>();
|
||||
for (String gstr : subGroups) {
|
||||
Group g = getDataSource().getGroup(gstr);
|
||||
if (g == null) {
|
||||
removeSubGroup(g);
|
||||
continue;
|
||||
}
|
||||
val.add(g);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
public boolean containsSubGroup(Group subGroup) {
|
||||
return subGroups.contains(subGroup.getName());
|
||||
}
|
||||
|
||||
public ArrayList<String> subGroupListStringCopy() {
|
||||
return new ArrayList<String>(subGroups);
|
||||
}
|
||||
public boolean removeSubGroup(Group subGroup) {
|
||||
try {
|
||||
if (subGroups.remove(subGroup.getName())) {
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the variables
|
||||
*/
|
||||
public UserVariables getVariables() {
|
||||
return variables;
|
||||
}
|
||||
public ArrayList<Group> subGroupListCopy() {
|
||||
ArrayList<Group> val = new ArrayList<Group>();
|
||||
for (String gstr : subGroups) {
|
||||
Group g = getDataSource().getGroup(gstr);
|
||||
if (g == null) {
|
||||
removeSubGroup(g);
|
||||
continue;
|
||||
}
|
||||
val.add(g);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
public ArrayList<String> subGroupListStringCopy() {
|
||||
return new ArrayList<String>(subGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the variables
|
||||
*/
|
||||
public UserVariables getVariables() {
|
||||
return variables;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param varList
|
||||
*/
|
||||
public void setVariables(Map<String, Object> varList) {
|
||||
UserVariables temp = new UserVariables(this, varList);
|
||||
variables.clearVars();
|
||||
for (String key : temp.getVarKeyList()) {
|
||||
variables.addVar(key, temp.getVarObject(key));
|
||||
}
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
|
||||
public User updatePlayer(Player player) {
|
||||
if (player != null) {
|
||||
bukkitPlayer = player;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Player getBukkitPlayer() {
|
||||
if (bukkitPlayer == null) {
|
||||
bukkitPlayer = Bukkit.getPlayer(this.getName());
|
||||
}
|
||||
return bukkitPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param varList
|
||||
*/
|
||||
public void setVariables(Map<String, Object> varList) {
|
||||
UserVariables temp = new UserVariables(this, varList);
|
||||
variables.clearVars();
|
||||
for (String key : temp.getVarKeyList()) {
|
||||
variables.addVar(key, temp.getVarObject(key));
|
||||
}
|
||||
flagAsChanged();
|
||||
if (GroupManager.isLoaded())
|
||||
if (GroupManager.BukkitPermissions.player_join = false)
|
||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||
}
|
||||
}
|
||||
|
@ -44,12 +44,13 @@ public class OverloadedWorldHolder extends WorldDataHolder {
|
||||
@Override
|
||||
public User getUser(String userName) {
|
||||
//OVERLOADED CODE
|
||||
if (overloadedUsers.containsKey(userName.toLowerCase())) {
|
||||
return overloadedUsers.get(userName.toLowerCase());
|
||||
String userNameLowered = userName.toLowerCase();
|
||||
if (overloadedUsers.containsKey(userNameLowered)) {
|
||||
return overloadedUsers.get(userNameLowered);
|
||||
}
|
||||
//END CODE
|
||||
if (users.containsKey(userName.toLowerCase())) {
|
||||
return users.get(userName.toLowerCase());
|
||||
if (users.containsKey(userNameLowered)) {
|
||||
return users.get(userNameLowered);
|
||||
}
|
||||
User newUser = createUser(userName);
|
||||
haveUsersChanged = true;
|
||||
|
@ -268,9 +268,10 @@ public class WorldsHolder {
|
||||
* @return OverloadedWorldHolder
|
||||
*/
|
||||
public OverloadedWorldHolder getWorldData(String worldName) {
|
||||
OverloadedWorldHolder data = worldsData.get(worldName.toLowerCase());
|
||||
if (mirrors.containsKey(worldName.toLowerCase())) {
|
||||
String realOne = mirrors.get(worldName.toLowerCase());
|
||||
String worldNameLowered = worldName.toLowerCase();
|
||||
OverloadedWorldHolder data = worldsData.get(worldNameLowered);
|
||||
if (mirrors.containsKey(worldNameLowered)) {
|
||||
String realOne = mirrors.get(worldNameLowered);
|
||||
data = worldsData.get(realOne.toLowerCase());
|
||||
}
|
||||
if (data == null) {
|
||||
|
@ -8,7 +8,7 @@ import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.data.Group;
|
||||
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
|
||||
@ -17,6 +17,7 @@ import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||
import org.anjocaido.groupmanager.utils.PermissionCheckResult.Type;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
/**
|
||||
* Everything here maintains the model created by Nijikokun
|
||||
@ -62,7 +63,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
*/
|
||||
@Override
|
||||
public boolean permission(Player player, String permission) {
|
||||
return checkUserPermission(ph.getUser(player.getName()), permission);
|
||||
return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,43 +98,60 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
@Override
|
||||
public List<String> getAllPlayersPermissions(String userName) {
|
||||
|
||||
List<String> playerPermArray = new ArrayList<String>(ph.getUser(userName).getPermissionList());
|
||||
List<String> playerPermArray = new ArrayList<String>();
|
||||
|
||||
for (String perm : ph.getUser(userName).getPermissionList()) {
|
||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||
playerPermArray.add(perm);
|
||||
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||
|
||||
if (children != null) {
|
||||
for (String child : children.keySet()) {
|
||||
if (children.get(child))
|
||||
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
|
||||
playerPermArray.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String group : getGroups(userName)) {
|
||||
if (group.startsWith("g:") && GroupManager.getGlobalGroups().hasGroup(group)) {
|
||||
for (String perm : GroupManager.getGlobalGroups().getGroupsPermissions(group)) {
|
||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||
playerPermArray.add(perm);
|
||||
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||
if (children != null) {
|
||||
for (String child : children.keySet()) {
|
||||
if (children.get(child))
|
||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
|
||||
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child)))
|
||||
playerPermArray.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (String perm : ph.getGroup(group).getPermissionList()) {
|
||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm))) {
|
||||
playerPermArray.add(perm);
|
||||
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getChildren(perm);
|
||||
Map<String, Boolean> children = GroupManager.BukkitPermissions.getAllChildren(perm, playerPermArray);
|
||||
if (children != null) {
|
||||
for (String child : children.keySet()) {
|
||||
if (children.get(child))
|
||||
if ((!playerPermArray.contains(perm)) && (!playerPermArray.contains("-" + perm)))
|
||||
if ((!playerPermArray.contains(child)) && (!playerPermArray.contains("-" + child))) {
|
||||
playerPermArray.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Collections.sort(playerPermArray,
|
||||
// StringPermissionComparator.getInstance());
|
||||
|
||||
return playerPermArray;
|
||||
}
|
||||
@ -227,7 +245,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
/**
|
||||
* Check if user can build. Checks inheritance and subgroups.
|
||||
*
|
||||
* @param userName Player's name
|
||||
* @param userName
|
||||
* Player's name
|
||||
* @return true if the user can build
|
||||
*/
|
||||
public boolean canUserBuild(String userName) {
|
||||
@ -267,8 +286,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the specified group for the Info Build node.
|
||||
* Does NOT check inheritance
|
||||
* Checks the specified group for the Info Build node. Does NOT check
|
||||
* inheritance
|
||||
*
|
||||
* @param groupName
|
||||
* @return true if can build
|
||||
@ -599,15 +618,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
result.askedPermission = permission;
|
||||
result.owner = user;
|
||||
for (String access : user.getPermissionList()) {
|
||||
if (comparePermissionString(access, permission)) {
|
||||
result.accessLevel = access;
|
||||
if (access.startsWith("-")) {
|
||||
result.resultType = PermissionCheckResult.Type.NEGATION;
|
||||
} else if (access.startsWith("+")) {
|
||||
result.resultType = PermissionCheckResult.Type.EXCEPTION;
|
||||
} else {
|
||||
result.resultType = PermissionCheckResult.Type.FOUND;
|
||||
}
|
||||
result.resultType = comparePermissionString(access, permission);
|
||||
if (result.resultType != PermissionCheckResult.Type.NOTFOUND) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -629,15 +641,8 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
result.owner = group;
|
||||
result.askedPermission = permission;
|
||||
for (String access : group.getPermissionList()) {
|
||||
if (comparePermissionString(access, permission)) {
|
||||
result.accessLevel = access;
|
||||
if (access.startsWith("-")) {
|
||||
result.resultType = PermissionCheckResult.Type.NEGATION;
|
||||
} else if (access.startsWith("+")) {
|
||||
result.resultType = PermissionCheckResult.Type.EXCEPTION;
|
||||
} else {
|
||||
result.resultType = PermissionCheckResult.Type.FOUND;
|
||||
}
|
||||
result.resultType = comparePermissionString(access, permission);
|
||||
if (result.resultType != PermissionCheckResult.Type.NOTFOUND) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -653,12 +658,10 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
* @return true if permission was found. false if not, or was negated.
|
||||
*/
|
||||
public boolean checkUserPermission(User user, String permission) {
|
||||
PermissionCheckResult result = checkFullUserPermission(user, permission);
|
||||
if (result.resultType.equals(PermissionCheckResult.Type.EXCEPTION) || result.resultType.equals(PermissionCheckResult.Type.FOUND)) {
|
||||
PermissionCheckResult result = checkFullGMPermission(user, permission, true);
|
||||
if (result.resultType == PermissionCheckResult.Type.EXCEPTION || result.resultType == PermissionCheckResult.Type.FOUND) {
|
||||
return true;
|
||||
}
|
||||
if ((Bukkit.getPlayer(user.getName()) != null) && (Bukkit.getPlayer(user.getName()).hasPermission(permission)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -672,39 +675,59 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
* @return PermissionCheckResult
|
||||
*/
|
||||
public PermissionCheckResult checkFullUserPermission(User user, String targetPermission) {
|
||||
|
||||
return checkFullGMPermission(user, targetPermission, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check user and groups with inheritance and Bukkit if bukkit = true return
|
||||
* a PermissionCheckResult.
|
||||
*
|
||||
* @param user
|
||||
* @param targetPermission
|
||||
* @param checkBukkit
|
||||
* @return PermissionCheckResult
|
||||
*/
|
||||
public PermissionCheckResult checkFullGMPermission(User user, String targetPermission, Boolean checkBukkit) {
|
||||
PermissionCheckResult result = new PermissionCheckResult();
|
||||
result.askedPermission = targetPermission;
|
||||
result.accessLevel = targetPermission;
|
||||
result.resultType = PermissionCheckResult.Type.NOTFOUND;
|
||||
|
||||
if (user == null || targetPermission == null || targetPermission.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (checkBukkit) {
|
||||
// Check Bukkit perms to support plugins which add perms via code
|
||||
// (Heroes).
|
||||
final Player player = user.getBukkitPlayer();
|
||||
final Permission bukkitPerm = Bukkit.getPluginManager().getPermission(targetPermission);
|
||||
if (player != null && bukkitPerm != null) {
|
||||
result.resultType = player.hasPermission(bukkitPerm) ? PermissionCheckResult.Type.FOUND : PermissionCheckResult.Type.NEGATION;
|
||||
result.owner = user;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
PermissionCheckResult resultUser = checkUserOnlyPermission(user, targetPermission);
|
||||
if (!resultUser.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
|
||||
if (resultUser.resultType != PermissionCheckResult.Type.NOTFOUND) {
|
||||
return resultUser;
|
||||
}
|
||||
|
||||
// IT ONLY CHECKS GROUPS PERMISSIONS IF RESULT FOR USER IS NOT FOUND
|
||||
PermissionCheckResult resultGroup = checkGroupPermissionWithInheritance(user.getGroup(), targetPermission);
|
||||
if (!resultGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
|
||||
if (resultGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
|
||||
return resultGroup;
|
||||
}
|
||||
|
||||
// SUBGROUPS CHECK
|
||||
for (Group subGroup : user.subGroupListCopy()) {
|
||||
PermissionCheckResult resultSubGroup = checkGroupPermissionWithInheritance(subGroup, targetPermission);
|
||||
if (!resultSubGroup.resultType.equals(PermissionCheckResult.Type.NOTFOUND)) {
|
||||
if (resultSubGroup.resultType != PermissionCheckResult.Type.NOTFOUND) {
|
||||
return resultSubGroup;
|
||||
}
|
||||
}
|
||||
|
||||
if ((Bukkit.getPlayer(user.getName()) != null) && (Bukkit.getPlayer(user.getName()).hasPermission(targetPermission))) {
|
||||
result.resultType = PermissionCheckResult.Type.FOUND;
|
||||
result.owner = user;
|
||||
return result;
|
||||
}
|
||||
|
||||
// THEN IT RETURNS A NOT FOUND
|
||||
return result;
|
||||
}
|
||||
@ -960,53 +983,43 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
|
||||
* Every '-' or '+' in the beginning is ignored. It will match only node
|
||||
* names.
|
||||
*
|
||||
* @param userAcessLevel
|
||||
* @param userAccessLevel
|
||||
* @param fullPermissionName
|
||||
* @return true if found a matching token. false if not.
|
||||
* @return PermissionCheckResult.Type
|
||||
*/
|
||||
public boolean comparePermissionString(String userAcessLevel, String fullPermissionName) {
|
||||
if (userAcessLevel == null || fullPermissionName == null) {
|
||||
return false;
|
||||
}
|
||||
GroupManager.logger.finest("COMPARING " + userAcessLevel + " WITH " + fullPermissionName);
|
||||
|
||||
if (userAcessLevel.startsWith("+")) {
|
||||
userAcessLevel = userAcessLevel.substring(1);
|
||||
} else if (userAcessLevel.startsWith("-")) {
|
||||
userAcessLevel = userAcessLevel.substring(1);
|
||||
public PermissionCheckResult.Type comparePermissionString(String userAccessLevel, String fullPermissionName) {
|
||||
int userAccessLevelLength;
|
||||
if (userAccessLevel == null || fullPermissionName == null || fullPermissionName.length() == 0 || (userAccessLevelLength = userAccessLevel.length()) == 0) {
|
||||
return PermissionCheckResult.Type.NOTFOUND;
|
||||
}
|
||||
|
||||
if (fullPermissionName.startsWith("+")) {
|
||||
fullPermissionName = fullPermissionName.substring(1);
|
||||
} else if (fullPermissionName.startsWith("-")) {
|
||||
fullPermissionName = fullPermissionName.substring(1);
|
||||
PermissionCheckResult.Type result = PermissionCheckResult.Type.FOUND;
|
||||
int userAccessLevelOffset = 0;
|
||||
if (userAccessLevel.charAt(0) == '+') {
|
||||
userAccessLevelOffset = 1;
|
||||
result = PermissionCheckResult.Type.EXCEPTION;
|
||||
} else if (userAccessLevel.charAt(0) == '-') {
|
||||
userAccessLevelOffset = 1;
|
||||
result = PermissionCheckResult.Type.NEGATION;
|
||||
}
|
||||
if ("*".regionMatches(0, userAccessLevel, userAccessLevelOffset, userAccessLevelLength - userAccessLevelOffset)) {
|
||||
return result;
|
||||
}
|
||||
int fullPermissionNameOffset;
|
||||
if (fullPermissionName.charAt(0) == '+' || fullPermissionName.charAt(0) == '-') {
|
||||
fullPermissionNameOffset = 1;
|
||||
} else {
|
||||
fullPermissionNameOffset = 0;
|
||||
}
|
||||
|
||||
StringTokenizer levelATokenizer = new StringTokenizer(userAcessLevel, ".");
|
||||
StringTokenizer levelBTokenizer = new StringTokenizer(fullPermissionName, ".");
|
||||
while (levelATokenizer.hasMoreTokens() && levelBTokenizer.hasMoreTokens()) {
|
||||
String levelA = levelATokenizer.nextToken();
|
||||
String levelB = levelBTokenizer.nextToken();
|
||||
GroupManager.logger.finest("ROUND " + levelA + " AGAINST " + levelB);
|
||||
if (levelA.contains("*")) {
|
||||
GroupManager.logger.finest("WIN");
|
||||
return true;
|
||||
}
|
||||
if (levelA.equalsIgnoreCase(levelB)) {
|
||||
if (!levelATokenizer.hasMoreTokens() && !levelBTokenizer.hasMoreTokens()) {
|
||||
GroupManager.logger.finest("WIN");
|
||||
return true;
|
||||
}
|
||||
GroupManager.logger.finest("NEXT");
|
||||
continue;
|
||||
} else {
|
||||
GroupManager.logger.finest("FAIL");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (userAccessLevel.charAt(userAccessLevel.length() - 1) == '*') {
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset, userAccessLevelLength - userAccessLevelOffset - 1) ?
|
||||
result : PermissionCheckResult.Type.NOTFOUND;
|
||||
} else {
|
||||
return userAccessLevel.regionMatches(true, userAccessLevelOffset, fullPermissionName, fullPermissionNameOffset,
|
||||
Math.max(userAccessLevelLength - userAccessLevelOffset, fullPermissionName.length() - fullPermissionNameOffset)) ?
|
||||
result : PermissionCheckResult.Type.NOTFOUND;
|
||||
}
|
||||
GroupManager.logger.finest("FAIL");
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -18,14 +18,14 @@ package org.anjocaido.groupmanager.permissions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.anjocaido.groupmanager.GroupManager;
|
||||
import org.anjocaido.groupmanager.data.User;
|
||||
import org.anjocaido.groupmanager.dataholder.OverloadedWorldHolder;
|
||||
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -49,246 +49,292 @@ import org.bukkit.plugin.PluginManager;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* BukkitPermissions overrides to force GM reponses to Superperms
|
||||
*
|
||||
*
|
||||
* @author ElgarL, based upon PermissionsEX implementation
|
||||
*/
|
||||
public class BukkitPermissions {
|
||||
|
||||
protected Map<Player, PermissionAttachment> attachments = new HashMap<Player, PermissionAttachment>();
|
||||
protected Set<Permission> registeredPermissions = new HashSet<Permission>();
|
||||
protected GroupManager plugin;
|
||||
protected boolean dumpAllPermissions = true;
|
||||
protected boolean dumpMatchedPermissions = true;
|
||||
public boolean player_join = false;
|
||||
protected Map<Player, PermissionAttachment> attachments = new HashMap<Player, PermissionAttachment>();
|
||||
protected LinkedList<Permission> registeredPermissions = new LinkedList<Permission>();
|
||||
protected GroupManager plugin;
|
||||
protected boolean dumpAllPermissions = true;
|
||||
protected boolean dumpMatchedPermissions = true;
|
||||
public boolean player_join = false;
|
||||
|
||||
public BukkitPermissions(GroupManager plugin) {
|
||||
this.plugin = plugin;
|
||||
public BukkitPermissions(GroupManager plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
this.collectPermissions();
|
||||
this.registerEvents();
|
||||
this.collectPermissions();
|
||||
this.registerEvents();
|
||||
|
||||
this.updateAllPlayers();
|
||||
this.updateAllPlayers();
|
||||
|
||||
GroupManager.logger.info("Superperms support enabled.");
|
||||
}
|
||||
GroupManager.logger.info("Superperms support enabled.");
|
||||
}
|
||||
|
||||
private void registerEvents() {
|
||||
PluginManager manager = plugin.getServer().getPluginManager();
|
||||
private void registerEvents() {
|
||||
PluginManager manager = plugin.getServer().getPluginManager();
|
||||
|
||||
PlayerEvents playerEventListener = new PlayerEvents();
|
||||
PlayerEvents playerEventListener = new PlayerEvents();
|
||||
|
||||
manager.registerEvent(Event.Type.PLAYER_JOIN, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_KICK, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_QUIT, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_JOIN, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_KICK, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_QUIT, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
|
||||
manager.registerEvent(Event.Type.PLAYER_RESPAWN, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_TELEPORT, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_PORTAL, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_RESPAWN, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_TELEPORT, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
manager.registerEvent(Event.Type.PLAYER_PORTAL, playerEventListener, Event.Priority.Lowest, plugin);
|
||||
|
||||
ServerListener serverListener = new BukkitEvents();
|
||||
ServerListener serverListener = new BukkitEvents();
|
||||
|
||||
manager.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Event.Priority.Normal, plugin);
|
||||
manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
|
||||
}
|
||||
manager.registerEvent(Event.Type.PLUGIN_ENABLE, serverListener, Event.Priority.Normal, plugin);
|
||||
manager.registerEvent(Event.Type.PLUGIN_DISABLE, serverListener, Event.Priority.Normal, plugin);
|
||||
}
|
||||
|
||||
public void collectPermissions() {
|
||||
registeredPermissions.clear();
|
||||
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
|
||||
for(Permission permission : bukkitPlugin.getDescription().getPermissions())
|
||||
registeredPermissions.add(permission);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePermissions(Player player){
|
||||
this.updatePermissions(player, null);
|
||||
}
|
||||
|
||||
public void updatePermissions(Player player, String world) {
|
||||
if (player == null || !GroupManager.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
public void collectPermissions() {
|
||||
registeredPermissions.clear();
|
||||
for (Plugin bukkitPlugin : Bukkit.getServer().getPluginManager().getPlugins()) {
|
||||
for (Permission permission : bukkitPlugin.getDescription().getPermissions())
|
||||
registeredPermissions.push(permission);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.attachments.containsKey(player)) {
|
||||
this.attachments.put(player, player.addAttachment(plugin));
|
||||
}
|
||||
public void updatePermissions(Player player) {
|
||||
this.updatePermissions(player, null);
|
||||
}
|
||||
|
||||
if(world == null){
|
||||
world = player.getWorld().getName();
|
||||
}
|
||||
|
||||
// All permissions registered with Bukkit for this player
|
||||
PermissionAttachment attachment = this.attachments.get(player);
|
||||
|
||||
OverloadedWorldHolder worldData = plugin.getWorldsHolder().getWorldData(world);
|
||||
public void updatePermissions(Player player, String world) {
|
||||
if (player == null || !GroupManager.isLoaded()) {
|
||||
return;
|
||||
}
|
||||
|
||||
User user = worldData.getUser(player.getName());
|
||||
|
||||
// clear permissions
|
||||
for (String permission : attachment.getPermissions().keySet())
|
||||
attachment.unsetPermission(permission);
|
||||
|
||||
/*
|
||||
* find matching permissions
|
||||
*
|
||||
* and base bukkit perms if we are set to allow bukkit permissions to override.
|
||||
*/
|
||||
Boolean value;
|
||||
for (Permission permission : registeredPermissions) {
|
||||
|
||||
value = worldData.getPermissionsHandler().checkUserPermission(user, permission.getName());
|
||||
|
||||
// Only check bukkit override IF we don't have the permission directly.
|
||||
if (value = false) {
|
||||
PermissionDefault permDefault = permission.getDefault();
|
||||
|
||||
if ((plugin.getGMConfig().isBukkitPermsOverride())
|
||||
&& ((permDefault == PermissionDefault.TRUE)
|
||||
|| ((permDefault == PermissionDefault.NOT_OP) && !player.isOp())
|
||||
|| ((permDefault == PermissionDefault.OP) && player.isOp())))
|
||||
value = true;
|
||||
}
|
||||
|
||||
if (value == true){
|
||||
// Set the root permission
|
||||
attachment.setPermission(permission, value);
|
||||
// fetch and set all children of this permission node
|
||||
Map<String, Boolean> children = permission.getChildren();
|
||||
if (children != null) {
|
||||
for (String child : children.keySet()) {
|
||||
if (children.get(child))
|
||||
attachment.setPermission(child, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Add any missing permissions for this player (non bukkit plugins)
|
||||
List<String> playerPermArray = new ArrayList<String>(worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName()));
|
||||
|
||||
for (String permission : playerPermArray) {
|
||||
value = true;
|
||||
if (permission.startsWith("-")) {
|
||||
permission = permission.substring(1); // cut off -
|
||||
value = false;
|
||||
}
|
||||
if (!this.attachments.containsKey(player)) {
|
||||
this.attachments.put(player, player.addAttachment(plugin));
|
||||
}
|
||||
|
||||
if (!attachment.getPermissions().containsKey(permission)) {
|
||||
attachment.setPermission(permission, value);
|
||||
}
|
||||
}
|
||||
player.recalculatePermissions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the child permissions as defined by the supplying plugin
|
||||
* null is empty
|
||||
*
|
||||
* @param node
|
||||
* @return Map of child permissions
|
||||
*/
|
||||
public Map<String, Boolean> getChildren(String node) {
|
||||
for (Permission permission : registeredPermissions) {
|
||||
if (permission.getName() == node) {
|
||||
return permission.getChildren();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<String> listPerms(Player player) {
|
||||
List<String> perms = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
// All permissions registered with Bukkit for this player
|
||||
PermissionAttachment attachment = this.attachments.get(player);
|
||||
|
||||
// List perms for this player
|
||||
perms.add("Attachment Permissions:");
|
||||
for(Map.Entry<String, Boolean> entry : attachment.getPermissions().entrySet()){
|
||||
perms.add(" " + entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
*/
|
||||
if (world == null) {
|
||||
world = player.getWorld().getName();
|
||||
}
|
||||
|
||||
perms.add("Effective Permissions:");
|
||||
for(PermissionAttachmentInfo info : player.getEffectivePermissions()){
|
||||
if (info.getValue() == true)
|
||||
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
// All permissions registered with Bukkit for this player
|
||||
PermissionAttachment attachment = this.attachments.get(player);
|
||||
|
||||
public void updateAllPlayers() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
updatePermissions(player);
|
||||
}
|
||||
}
|
||||
OverloadedWorldHolder worldData = plugin.getWorldsHolder().getWorldData(world);
|
||||
|
||||
protected class PlayerEvents extends PlayerListener {
|
||||
User user = worldData.getUser(player.getName());
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
player_join = true;
|
||||
Player player = event.getPlayer();
|
||||
//force GM to create the player if they are not already listed.
|
||||
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
||||
player_join = false;
|
||||
updatePermissions(event.getPlayer());
|
||||
} else
|
||||
player_join = false;
|
||||
}
|
||||
// clear permissions
|
||||
for (String permission : attachment.getPermissions().keySet())
|
||||
attachment.unsetPermission(permission);
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world
|
||||
if(event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())){ // only if world actually changed
|
||||
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* find matching permissions
|
||||
*
|
||||
* and base bukkit perms if we are set to allow bukkit permissions to
|
||||
* override.
|
||||
*/
|
||||
Boolean value = false;
|
||||
|
||||
for (Permission permission : registeredPermissions) {
|
||||
|
||||
PermissionCheckResult result = worldData.getPermissionsHandler().checkFullGMPermission(user, permission.getName(), false);
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) { // can be respawned in another world
|
||||
updatePermissions(event.getPlayer(), event.getRespawnLocation().getWorld().getName());
|
||||
}
|
||||
// Only check bukkit override IF we don't have the permission
|
||||
// directly.
|
||||
if (result.resultType == PermissionCheckResult.Type.NOTFOUND) {
|
||||
PermissionDefault permDefault = permission.getDefault();
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) { // can be teleported into another world
|
||||
if (event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
|
||||
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
||||
}
|
||||
}
|
||||
if ((plugin.getGMConfig().isBukkitPermsOverride()) && ((permDefault == PermissionDefault.TRUE)
|
||||
|| ((permDefault == PermissionDefault.NOT_OP) && !player.isOp())
|
||||
|| ((permDefault == PermissionDefault.OP) && player.isOp()))) {
|
||||
value = true;
|
||||
} else {
|
||||
value = false;
|
||||
}
|
||||
} else if (result.resultType == PermissionCheckResult.Type.NEGATION) {
|
||||
value = false;
|
||||
} else {
|
||||
value = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
|
||||
attachments.remove(event.getPlayer());
|
||||
}
|
||||
// Set the root permission
|
||||
if ((value == true) || (result.resultType == PermissionCheckResult.Type.NEGATION)) {
|
||||
attachment.setPermission(permission, value);
|
||||
}
|
||||
/*
|
||||
if ((value == true) || (result.resultType == PermissionCheckResult.Type.NOTFOUND)) {
|
||||
// fetch and set all children of this permission node
|
||||
Map<String, Boolean> children = permission.getChildren();
|
||||
if (children != null) {
|
||||
for (String child : children.keySet()) {
|
||||
if (children.get(child))
|
||||
attachment.setPermission(child, value);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
attachments.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class BukkitEvents extends ServerListener {
|
||||
// Add any missing permissions for this player (non bukkit plugins and child nodes)
|
||||
List<String> playerPermArray = worldData.getPermissionsHandler().getAllPlayersPermissions(player.getName());
|
||||
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
for (String permission : playerPermArray) {
|
||||
value = true;
|
||||
if (permission.startsWith("-")) {
|
||||
permission = permission.substring(1); // cut off -
|
||||
value = false;
|
||||
}
|
||||
|
||||
if (!attachment.getPermissions().containsKey(permission)) {
|
||||
attachment.setPermission(permission, value);
|
||||
}
|
||||
}
|
||||
player.recalculatePermissions();
|
||||
}
|
||||
|
||||
collectPermissions();
|
||||
updateAllPlayers();
|
||||
}
|
||||
/**
|
||||
* Returns a map of the ALL child permissions as defined by the supplying plugin
|
||||
* null is empty
|
||||
*
|
||||
* @param node
|
||||
* @return Map of child permissions
|
||||
*/
|
||||
public Map<String, Boolean> getAllChildren(String node, List<String> playerPermArray) {
|
||||
|
||||
LinkedList<String> stack = new LinkedList<String>();
|
||||
Map<String, Boolean> alreadyVisited = new HashMap<String, Boolean>();
|
||||
stack.push(node);
|
||||
alreadyVisited.put(node, true);
|
||||
|
||||
while (!stack.isEmpty()) {
|
||||
String now = stack.pop();
|
||||
|
||||
Map<String, Boolean> children = getChildren(now);
|
||||
|
||||
if ((children != null) && (!playerPermArray.contains("-"+now))) {
|
||||
for (String childName : children.keySet()) {
|
||||
if (!alreadyVisited.containsKey(childName)) {
|
||||
stack.push(childName);
|
||||
alreadyVisited.put(childName, children.get(childName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
alreadyVisited.remove(node);
|
||||
if (!alreadyVisited.isEmpty()) return alreadyVisited;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map of the child permissions (1 node deep) as defined by the supplying plugin
|
||||
* null is empty
|
||||
*
|
||||
* @param node
|
||||
* @return Map of child permissions
|
||||
*/
|
||||
public Map<String, Boolean> getChildren(String node) {
|
||||
for (Permission permission : registeredPermissions) {
|
||||
if (permission.getName().equalsIgnoreCase(node)) {
|
||||
return permission.getChildren();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
//collectPermissions();
|
||||
//updateAllPlayers();
|
||||
}
|
||||
}
|
||||
public List<String> listPerms(Player player) {
|
||||
List<String> perms = new ArrayList<String>();
|
||||
|
||||
/*
|
||||
* // All permissions registered with Bukkit for this player
|
||||
* PermissionAttachment attachment = this.attachments.get(player);
|
||||
*
|
||||
* // List perms for this player perms.add("Attachment Permissions:");
|
||||
* for(Map.Entry<String, Boolean> entry :
|
||||
* attachment.getPermissions().entrySet()){ perms.add(" " +
|
||||
* entry.getKey() + " = " + entry.getValue()); }
|
||||
*/
|
||||
|
||||
perms.add("Effective Permissions:");
|
||||
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
||||
if (info.getValue() == true)
|
||||
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
||||
}
|
||||
return perms;
|
||||
}
|
||||
|
||||
public void updateAllPlayers() {
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
updatePermissions(player);
|
||||
}
|
||||
}
|
||||
|
||||
protected class PlayerEvents extends PlayerListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
player_join = true;
|
||||
Player player = event.getPlayer();
|
||||
// force GM to create the player if they are not already listed.
|
||||
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
||||
player_join = false;
|
||||
updatePermissions(event.getPlayer());
|
||||
} else
|
||||
player_join = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) { // will portal into another world
|
||||
if (event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
|
||||
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) { // can be respawned in another world
|
||||
updatePermissions(event.getPlayer(), event.getRespawnLocation().getWorld().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) { // can be teleported into another world
|
||||
if (event.getTo() != null && !event.getFrom().getWorld().equals(event.getTo().getWorld())) { // only if world actually changed
|
||||
updatePermissions(event.getPlayer(), event.getTo().getWorld().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
|
||||
attachments.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerKick(PlayerKickEvent event) {
|
||||
attachments.remove(event.getPlayer());
|
||||
}
|
||||
}
|
||||
|
||||
protected class BukkitEvents extends ServerListener {
|
||||
|
||||
@Override
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (!GroupManager.isLoaded())
|
||||
return;
|
||||
|
||||
collectPermissions();
|
||||
updateAllPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
// collectPermissions();
|
||||
// updateAllPlayers();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user