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