Merge branch 'groupmanager' into 2.9

This commit is contained in:
Chris Ward 2013-01-10 04:57:10 +11:00
commit 79004c7098
11 changed files with 131 additions and 76 deletions

View File

@ -204,3 +204,5 @@ v 2.0:
- allWorldsDataList now returns fully mirrored worlds which are not identical mirrors (fixes the /manselect list).
- Add support for Rcon.
- Prevent GM commands from being used on CommandBlocks.
- Clear our attachment map upon a manload so we correctly reconfigure a players new permissions.
- Synchronize the raising of GroupManager events to Bukkit.getServer() (should prevent deadlocks).

View File

@ -16,7 +16,6 @@ import java.util.logging.Level;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.events.GMGroupEvent;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.Tasks;
import org.yaml.snakeyaml.DumperOptions;
@ -308,7 +307,7 @@ public class GlobalGroups {
newGroup(groupToAdd);
haveGroupsChanged = true;
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
GroupManager.getGMEventHandler().callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
}
/**
@ -339,7 +338,7 @@ public class GlobalGroups {
groups.remove(groupName.toLowerCase());
this.setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
GroupManager.getGMEventHandler().callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true;
}
return false;

View File

@ -65,6 +65,8 @@ public class GroupManager extends JavaPlugin {
protected static GlobalGroups globalGroups;
private GMLoggerHandler ch;
private static GroupManagerEventHandler GMEventHandler;
public static BukkitPermissions BukkitPermissions;
private static GMWorldListener WorldEvents;
public static final Logger logger = Logger.getLogger(GroupManager.class.getName());
@ -83,7 +85,10 @@ public class GroupManager extends JavaPlugin {
@Override
public void onEnable() {
/*
* Initialize the event handler
*/
setGMEventHandler(new GroupManagerEventHandler(this.getServer()));
onEnable(false);
}
@ -399,7 +404,7 @@ public class GroupManager extends JavaPlugin {
senderPlayer = (Player) sender;
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) {
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error." + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + " and then try a '/manload'.");
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. " + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + "" + ChatColor.RED + " and then try a '/manload'.");
return true;
}
@ -414,7 +419,7 @@ public class GroupManager extends JavaPlugin {
} else if ((sender instanceof ConsoleCommandSender) || (sender instanceof RemoteConsoleCommandSender)) {
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) {
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error." + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + " and then try a '/manload'.");
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. " + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + "" + ChatColor.RED + " and then try a '/manload'.");
return true;
}
@ -726,7 +731,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating your permissions
if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
return false;
}
@ -959,7 +964,7 @@ public class GroupManager extends JavaPlugin {
}
// Validating your permissions
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]);
if (!isConsole && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
if (!isConsole && !isOpOverride && (permissionResult.resultType.equals(PermissionCheckResult.Type.NOTFOUND) || permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION))) {
sender.sendMessage(ChatColor.RED + "You can't add a permission you don't have.");
return false;
}
@ -1112,7 +1117,7 @@ public class GroupManager extends JavaPlugin {
// auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
if (permissionResult.owner instanceof Group) {
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) {
sender.sendMessage(ChatColor.RED + "The group inherits the a negation permission from group: " + permissionResult.owner.getName());
sender.sendMessage(ChatColor.RED + "The group inherits the negation permission from group: " + permissionResult.owner.getName());
} else {
sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName());
}
@ -1550,7 +1555,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating permission
if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false;
}
@ -1584,7 +1589,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating permission
if (!isConsole && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getName(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return false;
}
@ -1681,7 +1686,7 @@ public class GroupManager extends JavaPlugin {
if (args.length > 0) {
if (!lastError.isEmpty()) {
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error." + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + " and then try a '/manload'.");
sender.sendMessage(ChatColor.RED + "All commands are locked due to an error. " + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "Check the log" + ChatColor.RESET + "" + ChatColor.RED + " and then try a '/manload'.");
return true;
}
@ -1702,7 +1707,7 @@ public class GroupManager extends JavaPlugin {
isLoaded = true;
BukkitPermissions.updateAllPlayers();
BukkitPermissions.reset();
} else {
@ -1723,7 +1728,7 @@ public class GroupManager extends JavaPlugin {
* Fire an event as none will have been triggered in the reload.
*/
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.RELOADED);
return true;
@ -2050,4 +2055,14 @@ public class GroupManager extends JavaPlugin {
return globalGroups;
}
public static GroupManagerEventHandler getGMEventHandler() {
return GMEventHandler;
}
public static void setGMEventHandler(GroupManagerEventHandler gMEventHandler) {
GMEventHandler = gMEventHandler;
}
}

View File

@ -7,8 +7,6 @@ package org.anjocaido.groupmanager.data;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMGroupEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -144,7 +142,7 @@ public class Group extends DataUnit implements Cloneable {
flagAsChanged();
if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
}
}
}
@ -157,7 +155,7 @@ public class Group extends DataUnit implements Cloneable {
clone.remove(inherit.toLowerCase());
inherits = Collections.unmodifiableList(clone);
flagAsChanged();
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
return true;
}
}
@ -187,7 +185,7 @@ public class Group extends DataUnit implements Cloneable {
flagAsChanged();
if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers();
GroupManagerEventHandler.callEvent(this, Action.GROUP_INFO_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INFO_CHANGED);
}
}
}

View File

@ -12,8 +12,6 @@ import java.util.List;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMUserEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import java.util.Map;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -148,7 +146,7 @@ public class User extends DataUnit implements Cloneable {
if (notify)
GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName()));
GroupManagerEventHandler.callEvent(this, Action.USER_GROUP_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.USER_GROUP_CHANGED);
}
}
@ -172,7 +170,7 @@ public class User extends DataUnit implements Cloneable {
if (GroupManager.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.USER_SUBGROUP_CHANGED);
}
return true;
@ -204,7 +202,7 @@ public class User extends DataUnit implements Cloneable {
if (GroupManager.isLoaded())
if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.USER_SUBGROUP_CHANGED);
return true;
}
} catch (Exception e) {
@ -257,7 +255,7 @@ public class User extends DataUnit implements Cloneable {
if (GroupManager.isLoaded()) {
//if (!GroupManager.BukkitPermissions.isPlayer_join())
// GroupManager.BukkitPermissions.updatePlayer(this.getName());
GroupManagerEventHandler.callEvent(this, Action.USER_INFO_CHANGED);
GroupManager.getGMEventHandler().callEvent(this, Action.USER_INFO_CHANGED);
}
}

View File

@ -28,7 +28,6 @@ import org.anjocaido.groupmanager.events.GMGroupEvent;
import org.anjocaido.groupmanager.events.GMSystemEvent;
import org.anjocaido.groupmanager.events.GMUserEvent;
import org.anjocaido.groupmanager.events.GMUserEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.Server;
import org.bukkit.plugin.Plugin;
@ -137,7 +136,7 @@ public class WorldDataHolder {
getUsers().put(theUser.getName().toLowerCase(), theUser);
setUsersChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED);
GroupManager.getGMEventHandler().callEvent(theUser, Action.USER_ADDED);
}
/**
@ -152,7 +151,7 @@ public class WorldDataHolder {
getUsers().remove(userName.toLowerCase());
setUsersChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED);
GroupManager.getGMEventHandler().callEvent(userName, GMUserEvent.Action.USER_REMOVED);
return true;
}
return false;
@ -181,7 +180,7 @@ public class WorldDataHolder {
groups.setDefaultGroup(getGroup(group.getName()));
setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED);
}
/**
@ -232,7 +231,7 @@ public class WorldDataHolder {
if (groupToAdd.getName().toLowerCase().startsWith("g:")) {
GroupManager.getGlobalGroups().addGroup(groupToAdd);
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
GroupManager.getGMEventHandler().callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
return;
}
@ -243,7 +242,7 @@ public class WorldDataHolder {
getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd);
setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
GroupManager.getGMEventHandler().callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
}
/**
@ -266,7 +265,7 @@ public class WorldDataHolder {
getGroups().remove(groupName.toLowerCase());
setGroupsChanged(true);
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
GroupManager.getGMEventHandler().callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true;
}
return false;
@ -374,7 +373,7 @@ public class WorldDataHolder {
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex);
}
GroupManager.setLoaded(true);
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.RELOADED);
}
/**
@ -406,7 +405,7 @@ public class WorldDataHolder {
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex);
}
GroupManager.setLoaded(true);
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.RELOADED);
}
public void loadGroups(File groupsFile) {
@ -1002,7 +1001,7 @@ public class WorldDataHolder {
ph.removeGroupsChangedFlag();
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.SAVED);
/*
* FileWriter tx = null; try { tx = new FileWriter(groupsFile, false);
@ -1081,7 +1080,7 @@ public class WorldDataHolder {
ph.removeUsersChangedFlag();
if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED);
GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.SAVED);
/*
* FileWriter tx = null; try { tx = new FileWriter(usersFile, false);

View File

@ -74,6 +74,7 @@ public class GMGroupEvent extends Event {
public void schedule(final GMGroupEvent event) {
synchronized (GroupManager.getGMEventHandler().getServer()) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
@Override
@ -85,3 +86,4 @@ public class GMGroupEvent extends Event {
GroupManager.logger.warning("Could not schedule GM Event.");
}
}
}

View File

@ -1,7 +1,7 @@
package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.GroupManager;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
@ -30,6 +30,7 @@ public class GMSystemEvent extends Event {
//////////////////////////////
protected Action action;
protected Server server;
public GMSystemEvent(Action action) {
@ -49,14 +50,16 @@ public class GMSystemEvent extends Event {
public void schedule(final GMSystemEvent event) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
synchronized (GroupManager.getGMEventHandler().getServer()) {
if (server.getScheduler().scheduleSyncDelayedTask(server.getPluginManager().getPlugin("GroupManager"), new Runnable() {
@Override
public void run() {
Bukkit.getServer().getPluginManager().callEvent(event);
server.getPluginManager().callEvent(event);
}
}, 1) == -1)
GroupManager.logger.warning("Could not schedule GM Event.");
}
}
}

View File

@ -74,6 +74,7 @@ public class GMUserEvent extends Event {
public void schedule(final GMUserEvent event) {
synchronized (GroupManager.getGMEventHandler().getServer()) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
@Override
@ -85,3 +86,4 @@ public class GMUserEvent extends Event {
GroupManager.logger.warning("Could not schedule GM Event.");
}
}
}

View File

@ -2,6 +2,7 @@ package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.data.User;
import org.bukkit.Server;
/**
* @author ElgarL
@ -11,43 +12,66 @@ import org.anjocaido.groupmanager.data.User;
*/
public class GroupManagerEventHandler {
protected static void callEvent(GMGroupEvent event) {
protected Server server;
public GroupManagerEventHandler(Server server) {
this.server = server;
}
protected void callEvent(GMGroupEvent event) {
event.schedule(event);
}
protected static void callEvent(GMUserEvent event) {
protected void callEvent(GMUserEvent event) {
event.schedule(event);
}
protected static void callEvent(GMSystemEvent event) {
protected void callEvent(GMSystemEvent event) {
event.schedule(event);
}
public static void callEvent(Group group, GMGroupEvent.Action action) {
public void callEvent(Group group, GMGroupEvent.Action action) {
callEvent(new GMGroupEvent(group, action));
}
public static void callEvent(String groupName, GMGroupEvent.Action action) {
public void callEvent(String groupName, GMGroupEvent.Action action) {
callEvent(new GMGroupEvent(groupName, action));
}
public static void callEvent(User user, GMUserEvent.Action action) {
public void callEvent(User user, GMUserEvent.Action action) {
callEvent(new GMUserEvent(user, action));
}
public static void callEvent(String userName, GMUserEvent.Action action) {
public void callEvent(String userName, GMUserEvent.Action action) {
callEvent(new GMUserEvent(userName, action));
}
public static void callEvent(GMSystemEvent.Action action) {
public void callEvent(GMSystemEvent.Action action) {
callEvent(new GMSystemEvent(action));
}
/**
* @return the server
*/
public Server getServer() {
return server;
}
/**
* @param server the server to set
*/
public void setServer(Server server) {
this.server = server;
}
}

View File

@ -103,6 +103,11 @@ public class BukkitPermissions {
}
public void reset() {
/*
* collect new permissions
* and register all attachments.
*/
this.collectPermissions();
this.updateAllPlayers();
}
@ -382,15 +387,23 @@ public class BukkitPermissions {
*/
private void removeAttachment(String playerName) {
if (attachments.containsKey(playerName))
if (attachments.containsKey(playerName)) {
attachments.get(playerName).remove();
attachments.remove(playerName);
}
}
/**
* Remove all attachments in case of a restart or reload.
*/
public void removeAllAttachments() {
/*
* Remove all attachments.
*/
for (String key : attachments.keySet()) {
attachments.get(key).remove();
}
attachments.clear();
}