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

@ -203,4 +203,6 @@ v 2.0:
- Add alphabetically sorted user lists. - Add alphabetically sorted user lists.
- allWorldsDataList now returns fully mirrored worlds which are not identical mirrors (fixes the /manselect list). - allWorldsDataList now returns fully mirrored worlds which are not identical mirrors (fixes the /manselect list).
- Add support for Rcon. - Add support for Rcon.
- Prevent GM commands from being used on CommandBlocks. - 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.data.Group;
import org.anjocaido.groupmanager.events.GMGroupEvent; import org.anjocaido.groupmanager.events.GMGroupEvent;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.PermissionCheckResult;
import org.anjocaido.groupmanager.utils.Tasks; import org.anjocaido.groupmanager.utils.Tasks;
import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.DumperOptions;
@ -308,7 +307,7 @@ public class GlobalGroups {
newGroup(groupToAdd); newGroup(groupToAdd);
haveGroupsChanged = true; haveGroupsChanged = true;
if (GroupManager.isLoaded()) 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()); groups.remove(groupName.toLowerCase());
this.setGroupsChanged(true); this.setGroupsChanged(true);
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED); GroupManager.getGMEventHandler().callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true; return true;
} }
return false; return false;

View File

@ -65,6 +65,8 @@ public class GroupManager extends JavaPlugin {
protected static GlobalGroups globalGroups; protected static GlobalGroups globalGroups;
private GMLoggerHandler ch; private GMLoggerHandler ch;
private static GroupManagerEventHandler GMEventHandler;
public static BukkitPermissions BukkitPermissions; public static BukkitPermissions BukkitPermissions;
private static GMWorldListener WorldEvents; private static GMWorldListener WorldEvents;
public static final Logger logger = Logger.getLogger(GroupManager.class.getName()); public static final Logger logger = Logger.getLogger(GroupManager.class.getName());
@ -83,7 +85,10 @@ public class GroupManager extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
/*
* Initialize the event handler
*/
setGMEventHandler(new GroupManagerEventHandler(this.getServer()));
onEnable(false); onEnable(false);
} }
@ -399,7 +404,7 @@ public class GroupManager extends JavaPlugin {
senderPlayer = (Player) sender; senderPlayer = (Player) sender;
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { 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; return true;
} }
@ -414,7 +419,7 @@ public class GroupManager extends JavaPlugin {
} else if ((sender instanceof ConsoleCommandSender) || (sender instanceof RemoteConsoleCommandSender)) { } else if ((sender instanceof ConsoleCommandSender) || (sender instanceof RemoteConsoleCommandSender)) {
if (!lastError.isEmpty() && !commandLabel.equalsIgnoreCase("manload")) { 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; return true;
} }
@ -726,7 +731,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]); auxUser = dataHolder.getUser(args[0]);
} }
// Validating your permissions // 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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
return false; return false;
} }
@ -959,7 +964,7 @@ public class GroupManager extends JavaPlugin {
} }
// Validating your permissions // Validating your permissions
permissionResult = permissionHandler.checkFullUserPermission(senderUser, args[1]); 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."); sender.sendMessage(ChatColor.RED + "You can't add a permission you don't have.");
return false; return false;
} }
@ -1112,7 +1117,7 @@ public class GroupManager extends JavaPlugin {
// auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]); // auxString = permissionHandler.checkUserOnlyPermission(auxUser, args[1]);
if (permissionResult.owner instanceof Group) { if (permissionResult.owner instanceof Group) {
if (permissionResult.resultType.equals(PermissionCheckResult.Type.NEGATION)) { 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 { } else {
sender.sendMessage(ChatColor.YELLOW + "The user inherits the permission from group: " + permissionResult.owner.getName()); 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]); auxUser = dataHolder.getUser(args[0]);
} }
// Validating permission // 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."); sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return false; return false;
} }
@ -1584,7 +1589,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]); auxUser = dataHolder.getUser(args[0]);
} }
// Validating permission // 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."); sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return false; return false;
} }
@ -1681,7 +1686,7 @@ public class GroupManager extends JavaPlugin {
if (args.length > 0) { if (args.length > 0) {
if (!lastError.isEmpty()) { 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; return true;
} }
@ -1702,7 +1707,7 @@ public class GroupManager extends JavaPlugin {
isLoaded = true; isLoaded = true;
BukkitPermissions.updateAllPlayers(); BukkitPermissions.reset();
} else { } else {
@ -1723,7 +1728,7 @@ public class GroupManager extends JavaPlugin {
* Fire an event as none will have been triggered in the reload. * Fire an event as none will have been triggered in the reload.
*/ */
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.RELOADED);
return true; return true;
@ -2050,4 +2055,14 @@ public class GroupManager extends JavaPlugin {
return globalGroups; 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.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMGroupEvent.Action; import org.anjocaido.groupmanager.events.GMGroupEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -144,7 +142,7 @@ public class Group extends DataUnit implements Cloneable {
flagAsChanged(); flagAsChanged();
if (GroupManager.isLoaded()) { if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers(); 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()); clone.remove(inherit.toLowerCase());
inherits = Collections.unmodifiableList(clone); inherits = Collections.unmodifiableList(clone);
flagAsChanged(); flagAsChanged();
GroupManagerEventHandler.callEvent(this, Action.GROUP_INHERITANCE_CHANGED); GroupManager.getGMEventHandler().callEvent(this, Action.GROUP_INHERITANCE_CHANGED);
return true; return true;
} }
} }
@ -187,7 +185,7 @@ public class Group extends DataUnit implements Cloneable {
flagAsChanged(); flagAsChanged();
if (GroupManager.isLoaded()) { if (GroupManager.isLoaded()) {
GroupManager.BukkitPermissions.updateAllPlayers(); 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.GroupManager;
import org.anjocaido.groupmanager.dataholder.WorldDataHolder; import org.anjocaido.groupmanager.dataholder.WorldDataHolder;
import org.anjocaido.groupmanager.events.GMUserEvent.Action; import org.anjocaido.groupmanager.events.GMUserEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import java.util.Map; import java.util.Map;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -148,7 +146,7 @@ public class User extends DataUnit implements Cloneable {
if (notify) if (notify)
GroupManager.notify(this.getName(), String.format(" moved to the group %s.", group.getName())); 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.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join()) if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); GroupManager.getGMEventHandler().callEvent(this, Action.USER_SUBGROUP_CHANGED);
} }
return true; return true;
@ -204,7 +202,7 @@ public class User extends DataUnit implements Cloneable {
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
if (!GroupManager.BukkitPermissions.isPlayer_join()) if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer()); GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED); GroupManager.getGMEventHandler().callEvent(this, Action.USER_SUBGROUP_CHANGED);
return true; return true;
} }
} catch (Exception e) { } catch (Exception e) {
@ -257,7 +255,7 @@ public class User extends DataUnit implements Cloneable {
if (GroupManager.isLoaded()) { if (GroupManager.isLoaded()) {
//if (!GroupManager.BukkitPermissions.isPlayer_join()) //if (!GroupManager.BukkitPermissions.isPlayer_join())
// GroupManager.BukkitPermissions.updatePlayer(this.getName()); // 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.GMSystemEvent;
import org.anjocaido.groupmanager.events.GMUserEvent; import org.anjocaido.groupmanager.events.GMUserEvent;
import org.anjocaido.groupmanager.events.GMUserEvent.Action; import org.anjocaido.groupmanager.events.GMUserEvent.Action;
import org.anjocaido.groupmanager.events.GroupManagerEventHandler;
import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler; import org.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -137,7 +136,7 @@ public class WorldDataHolder {
getUsers().put(theUser.getName().toLowerCase(), theUser); getUsers().put(theUser.getName().toLowerCase(), theUser);
setUsersChanged(true); setUsersChanged(true);
if (GroupManager.isLoaded()) 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()); getUsers().remove(userName.toLowerCase());
setUsersChanged(true); setUsersChanged(true);
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED); GroupManager.getGMEventHandler().callEvent(userName, GMUserEvent.Action.USER_REMOVED);
return true; return true;
} }
return false; return false;
@ -181,7 +180,7 @@ public class WorldDataHolder {
groups.setDefaultGroup(getGroup(group.getName())); groups.setDefaultGroup(getGroup(group.getName()));
setGroupsChanged(true); setGroupsChanged(true);
if (GroupManager.isLoaded()) 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:")) { if (groupToAdd.getName().toLowerCase().startsWith("g:")) {
GroupManager.getGlobalGroups().addGroup(groupToAdd); GroupManager.getGlobalGroups().addGroup(groupToAdd);
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); GroupManager.getGMEventHandler().callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
return; return;
} }
@ -243,7 +242,7 @@ public class WorldDataHolder {
getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd); getGroups().put(groupToAdd.getName().toLowerCase(), groupToAdd);
setGroupsChanged(true); setGroupsChanged(true);
if (GroupManager.isLoaded()) 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()); getGroups().remove(groupName.toLowerCase());
setGroupsChanged(true); setGroupsChanged(true);
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED); GroupManager.getGMEventHandler().callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true; return true;
} }
return false; return false;
@ -374,7 +373,7 @@ public class WorldDataHolder {
Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex);
} }
GroupManager.setLoaded(true); 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); Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex);
} }
GroupManager.setLoaded(true); GroupManager.setLoaded(true);
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.RELOADED);
} }
public void loadGroups(File groupsFile) { public void loadGroups(File groupsFile) {
@ -1002,7 +1001,7 @@ public class WorldDataHolder {
ph.removeGroupsChangedFlag(); ph.removeGroupsChangedFlag();
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.SAVED);
/* /*
* FileWriter tx = null; try { tx = new FileWriter(groupsFile, false); * FileWriter tx = null; try { tx = new FileWriter(groupsFile, false);
@ -1081,7 +1080,7 @@ public class WorldDataHolder {
ph.removeUsersChangedFlag(); ph.removeUsersChangedFlag();
if (GroupManager.isLoaded()) if (GroupManager.isLoaded())
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); GroupManager.getGMEventHandler().callEvent(GMSystemEvent.Action.SAVED);
/* /*
* FileWriter tx = null; try { tx = new FileWriter(usersFile, false); * FileWriter tx = null; try { tx = new FileWriter(usersFile, false);

View File

@ -74,14 +74,16 @@ public class GMGroupEvent extends Event {
public void schedule(final GMGroupEvent event) { public void schedule(final GMGroupEvent event) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() { synchronized (GroupManager.getGMEventHandler().getServer()) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
@Override
public void run() { @Override
public void run() {
Bukkit.getServer().getPluginManager().callEvent(event);
} Bukkit.getServer().getPluginManager().callEvent(event);
}, 1) == -1) }
GroupManager.logger.warning("Could not schedule GM Event."); }, 1) == -1)
GroupManager.logger.warning("Could not schedule GM Event.");
}
} }
} }

View File

@ -1,7 +1,7 @@
package org.anjocaido.groupmanager.events; package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.GroupManager;
import org.bukkit.Bukkit; import org.bukkit.Server;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -30,11 +30,12 @@ public class GMSystemEvent extends Event {
////////////////////////////// //////////////////////////////
protected Action action; protected Action action;
protected Server server;
public GMSystemEvent(Action action) { public GMSystemEvent(Action action) {
super(); super();
this.action = action; this.action = action;
} }
@ -49,14 +50,16 @@ public class GMSystemEvent extends Event {
public void schedule(final GMSystemEvent 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() { @Override
public void run() {
Bukkit.getServer().getPluginManager().callEvent(event);
} server.getPluginManager().callEvent(event);
}, 1) == -1) }
GroupManager.logger.warning("Could not schedule GM Event."); }, 1) == -1)
GroupManager.logger.warning("Could not schedule GM Event.");
}
} }
} }

View File

@ -74,14 +74,16 @@ public class GMUserEvent extends Event {
public void schedule(final GMUserEvent event) { public void schedule(final GMUserEvent event) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() { synchronized (GroupManager.getGMEventHandler().getServer()) {
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
@Override
public void run() { @Override
public void run() {
Bukkit.getServer().getPluginManager().callEvent(event);
} Bukkit.getServer().getPluginManager().callEvent(event);
}, 1) == -1) }
GroupManager.logger.warning("Could not schedule GM Event."); }, 1) == -1)
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.Group;
import org.anjocaido.groupmanager.data.User; import org.anjocaido.groupmanager.data.User;
import org.bukkit.Server;
/** /**
* @author ElgarL * @author ElgarL
@ -10,44 +11,67 @@ import org.anjocaido.groupmanager.data.User;
* *
*/ */
public class GroupManagerEventHandler { public class GroupManagerEventHandler {
protected Server server;
public GroupManagerEventHandler(Server server) {
this.server = server;
}
protected static void callEvent(GMGroupEvent event) { protected void callEvent(GMGroupEvent event) {
event.schedule(event); event.schedule(event);
} }
protected static void callEvent(GMUserEvent event) { protected void callEvent(GMUserEvent event) {
event.schedule(event); event.schedule(event);
} }
protected static void callEvent(GMSystemEvent event) { protected void callEvent(GMSystemEvent event) {
event.schedule(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)); 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)); 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)); 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)); callEvent(new GMUserEvent(userName, action));
} }
public static void callEvent(GMSystemEvent.Action action) { public void callEvent(GMSystemEvent.Action action) {
callEvent(new GMSystemEvent(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() { public void reset() {
/*
* collect new permissions
* and register all attachments.
*/
this.collectPermissions(); this.collectPermissions();
this.updateAllPlayers(); this.updateAllPlayers();
} }
@ -382,8 +387,10 @@ public class BukkitPermissions {
*/ */
private void removeAttachment(String playerName) { private void removeAttachment(String playerName) {
if (attachments.containsKey(playerName)) if (attachments.containsKey(playerName)) {
attachments.get(playerName).remove();
attachments.remove(playerName); attachments.remove(playerName);
}
} }
/** /**
@ -391,6 +398,12 @@ public class BukkitPermissions {
*/ */
public void removeAllAttachments() { public void removeAllAttachments() {
/*
* Remove all attachments.
*/
for (String key : attachments.keySet()) {
attachments.get(key).remove();
}
attachments.clear(); attachments.clear();
} }