mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-11-03 09:30:28 +01:00
Synchronize the raising of GroupManager events to Bukkit.getServer()
(should prevent deadlocks).
This commit is contained in:
parent
cde95d832e
commit
f256930269
@ -205,3 +205,4 @@ v 2.0:
|
||||
- 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).
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -1718,7 +1723,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;
|
||||
|
||||
@ -2045,4 +2050,14 @@ public class GroupManager extends JavaPlugin {
|
||||
return globalGroups;
|
||||
|
||||
}
|
||||
|
||||
public static GroupManagerEventHandler getGMEventHandler() {
|
||||
|
||||
return GMEventHandler;
|
||||
}
|
||||
|
||||
public static void setGMEventHandler(GroupManagerEventHandler gMEventHandler) {
|
||||
|
||||
GMEventHandler = gMEventHandler;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -74,14 +74,16 @@ public class GMGroupEvent extends 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);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
server.getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
@ -74,14 +74,16 @@ public class GMUserEvent extends 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);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
}, 1) == -1)
|
||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user