diff options
Diffstat (limited to 'EssentialsGroupManager')
6 files changed, 70 insertions, 11 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt index 00df6628d..7561214fd 100644 --- a/EssentialsGroupManager/src/Changelog.txt +++ b/EssentialsGroupManager/src/Changelog.txt @@ -82,4 +82,5 @@ v 1.6: - Added file details in error messages for loading groups/users.
v 1.7:
- GM now supports offline players without having to mantogglevalidate
- - Offline player checks now support partial name matches.
\ No newline at end of file + - Offline player checks now support partial name matches.
+ - Added custom events so plugins can now be notified of changes within GroupManager.
\ No newline at end of file diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java index d7971d424..33b7b46f1 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GlobalGroups.java @@ -14,6 +14,8 @@ import java.util.Set; 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.bukkit.configuration.MemorySection;
@@ -243,6 +245,8 @@ public class GlobalGroups { newGroup(groupToAdd);
haveGroupsChanged = true;
+ if (GroupManager.isLoaded())
+ GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
}
/**
@@ -270,6 +274,8 @@ public class GlobalGroups { if (groups.containsKey(groupName.toLowerCase())) {
groups.remove(groupName.toLowerCase());
this.setGroupsChanged(true);
+ if (GroupManager.isLoaded())
+ GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
return true;
}
return false;
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java index 37131f888..ab8eefb36 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java @@ -26,6 +26,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder; import org.anjocaido.groupmanager.events.GMWorldListener; +import org.anjocaido.groupmanager.events.GroupManagerEvent; import org.anjocaido.groupmanager.utils.GMLoggerHandler; import org.anjocaido.groupmanager.utils.PermissionCheckResult; import org.anjocaido.groupmanager.utils.Tasks; @@ -1828,6 +1829,15 @@ public class GroupManager extends JavaPlugin { return match; } + + /** + * Triggers all GroupManager events for other plugins to see. + * + * @param event + */ + public static void callEvent(GroupManagerEvent event) { + Bukkit.getServer().getPluginManager().callEvent(event); + } /** * @return the config diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java index ba8915a18..a0b50bf5b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/Group.java @@ -6,6 +6,9 @@ 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; @@ -13,7 +16,7 @@ import java.util.Map; /** * - * @author gabrielcouto + * @author gabrielcouto/ElgarL */ public class Group extends DataUnit implements Cloneable { @@ -45,7 +48,7 @@ public class Group extends DataUnit implements Cloneable { public Group(String name) { super(name); } - + /** * Clone this group * @return a clone of this group @@ -114,14 +117,17 @@ public class Group extends DataUnit implements Cloneable { inherits.add(inherit.getName().toLowerCase()); } flagAsChanged(); - if (GroupManager.isLoaded()) + if (GroupManager.isLoaded()) { GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.INHERITANCE_CHANGED); + } } public boolean removeInherits(String inherit) { if (this.inherits.contains(inherit.toLowerCase())) { this.inherits.remove(inherit.toLowerCase()); flagAsChanged(); + GroupManagerEventHandler.callEvent(this, Action.INHERITANCE_CHANGED); return true; } return false; @@ -145,7 +151,9 @@ public class Group extends DataUnit implements Cloneable { variables.addVar(key, temp.getVarObject(key)); } flagAsChanged(); - if (GroupManager.isLoaded()) + if (GroupManager.isLoaded()) { GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.INFO_CHANGED); + } } } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java index 10757475d..81d188c80 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/data/User.java @@ -9,6 +9,9 @@ import java.util.ArrayList; 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; @@ -16,7 +19,7 @@ import org.bukkit.entity.Player; /** * - * @author gabrielcouto + * @author gabrielcouto/ElgarL */ public class User extends DataUnit implements Cloneable { @@ -139,6 +142,8 @@ 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.GROUP_CHANGED); } } @@ -153,9 +158,11 @@ public class User extends DataUnit implements Cloneable { removeSubGroup(subGroup); subGroups.add(subGroup.getName()); flagAsChanged(); - if (GroupManager.isLoaded()) + if (GroupManager.isLoaded()) { if (GroupManager.BukkitPermissions.player_join = false) GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.SUBGROUP_CHANGED); + } } public int subGroupsSize() { @@ -177,6 +184,7 @@ public class User extends DataUnit implements Cloneable { if (GroupManager.isLoaded()) if (GroupManager.BukkitPermissions.player_join = false) GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.SUBGROUP_CHANGED); return true; } } catch (Exception e) { @@ -220,9 +228,11 @@ public class User extends DataUnit implements Cloneable { variables.addVar(key, varList.get(key)); } flagAsChanged(); - if (GroupManager.isLoaded()) + if (GroupManager.isLoaded()) { if (GroupManager.BukkitPermissions.player_join = false) GroupManager.BukkitPermissions.updateAllPlayers(); + GroupManagerEventHandler.callEvent(this, Action.INFO_CHANGED); + } } public User updatePlayer(Player player) { @@ -238,5 +248,4 @@ public class User extends DataUnit implements Cloneable { } return bukkitPlayer; } - } diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java index 4ef77687a..2a944856b 100644 --- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java +++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java @@ -22,6 +22,11 @@ import java.util.logging.Logger; import org.anjocaido.groupmanager.GroupManager; import org.anjocaido.groupmanager.data.Group; import org.anjocaido.groupmanager.data.User; +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; @@ -144,6 +149,8 @@ public class WorldDataHolder { removeUser(theUser.getName()); users.put(theUser.getName().toLowerCase(), theUser); haveUsersChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED); } /** @@ -155,6 +162,8 @@ public class WorldDataHolder { if (users.containsKey(userName.toLowerCase())) { users.remove(userName.toLowerCase()); haveUsersChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED); return true; } return false; @@ -179,6 +188,8 @@ public class WorldDataHolder { } defaultGroup = this.getGroup(group.getName()); haveGroupsChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED); } /** @@ -221,6 +232,7 @@ public class WorldDataHolder { public void addGroup(Group groupToAdd) { if (groupToAdd.getName().toLowerCase().startsWith("g:")) { GroupManager.getGlobalGroups().addGroup(groupToAdd); + GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); return; } @@ -230,10 +242,12 @@ public class WorldDataHolder { removeGroup(groupToAdd.getName()); groups.put(groupToAdd.getName().toLowerCase(), groupToAdd); haveGroupsChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED); } /** - * Remove the group to the list + * Remove the group from the list * @param groupName * @return true if had something to remove. false the group was default or non-existant */ @@ -248,6 +262,8 @@ public class WorldDataHolder { if (groups.containsKey(groupName.toLowerCase())) { groups.remove(groupName.toLowerCase()); haveGroupsChanged = true; + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED); return true; } return false; @@ -345,6 +361,7 @@ public class WorldDataHolder { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } GroupManager.setLoaded(true); + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); } /** @@ -375,6 +392,7 @@ public class WorldDataHolder { Logger.getLogger(WorldDataHolder.class.getName()).log(Level.WARNING, null, ex); } GroupManager.setLoaded(true); + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.RELOADED); } /** @@ -936,6 +954,9 @@ public class WorldDataHolder { ph.groupsFile = groupsFile; ph.setTimeStampGroups(groupsFile.lastModified()); ph.removeGroupsChangedFlag(); + + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); /*FileWriter tx = null; try { @@ -1010,6 +1031,9 @@ public class WorldDataHolder { ph.setTimeStampUsers(usersFile.lastModified()); ph.removeUsersChangedFlag(); + if (GroupManager.isLoaded()) + GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED); + /*FileWriter tx = null; try { tx = new FileWriter(usersFile, false); @@ -1191,5 +1215,6 @@ public class WorldDataHolder { setTimeStampGroups(groupsFile.lastModified()); if (usersFile != null) setTimeStampUsers(usersFile.lastModified()); - } + } + } |