mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-21 10:52:01 +00:00
Added custom events so plugins can now be notified of changes within
GroupManager.
This commit is contained in:
parent
0e0b441168
commit
759892078a
|
@ -82,4 +82,5 @@ v 1.6:
|
||||||
- Added file details in error messages for loading groups/users.
|
- Added file details in error messages for loading groups/users.
|
||||||
v 1.7:
|
v 1.7:
|
||||||
- GM now supports offline players without having to mantogglevalidate
|
- GM now supports offline players without having to mantogglevalidate
|
||||||
- Offline player checks now support partial name matches.
|
- Offline player checks now support partial name matches.
|
||||||
|
- Added custom events so plugins can now be notified of changes within GroupManager.
|
|
@ -14,6 +14,8 @@ import java.util.Set;
|
||||||
import java.util.logging.Level;
|
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.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.bukkit.configuration.MemorySection;
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
@ -243,6 +245,8 @@ public class GlobalGroups {
|
||||||
|
|
||||||
newGroup(groupToAdd);
|
newGroup(groupToAdd);
|
||||||
haveGroupsChanged = true;
|
haveGroupsChanged = true;
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(groupToAdd, GMGroupEvent.Action.GROUP_ADDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -270,6 +274,8 @@ public class GlobalGroups {
|
||||||
if (groups.containsKey(groupName.toLowerCase())) {
|
if (groups.containsKey(groupName.toLowerCase())) {
|
||||||
groups.remove(groupName.toLowerCase());
|
groups.remove(groupName.toLowerCase());
|
||||||
this.setGroupsChanged(true);
|
this.setGroupsChanged(true);
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
import org.anjocaido.groupmanager.dataholder.worlds.WorldsHolder;
|
||||||
import org.anjocaido.groupmanager.events.GMWorldListener;
|
import org.anjocaido.groupmanager.events.GMWorldListener;
|
||||||
|
import org.anjocaido.groupmanager.events.GroupManagerEvent;
|
||||||
import org.anjocaido.groupmanager.utils.GMLoggerHandler;
|
import org.anjocaido.groupmanager.utils.GMLoggerHandler;
|
||||||
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
import org.anjocaido.groupmanager.utils.PermissionCheckResult;
|
||||||
import org.anjocaido.groupmanager.utils.Tasks;
|
import org.anjocaido.groupmanager.utils.Tasks;
|
||||||
|
@ -1828,6 +1829,15 @@ public class GroupManager extends JavaPlugin {
|
||||||
return match;
|
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
|
* @return the config
|
||||||
|
|
|
@ -6,6 +6,9 @@ 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.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;
|
||||||
|
@ -13,7 +16,7 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author gabrielcouto
|
* @author gabrielcouto/ElgarL
|
||||||
*/
|
*/
|
||||||
public class Group extends DataUnit implements Cloneable {
|
public class Group extends DataUnit implements Cloneable {
|
||||||
|
|
||||||
|
@ -45,7 +48,7 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
public Group(String name) {
|
public Group(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clone this group
|
* Clone this group
|
||||||
* @return a clone of this group
|
* @return a clone of this group
|
||||||
|
@ -114,14 +117,17 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
inherits.add(inherit.getName().toLowerCase());
|
inherits.add(inherit.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
if (GroupManager.isLoaded())
|
if (GroupManager.isLoaded()) {
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.INHERITANCE_CHANGED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeInherits(String inherit) {
|
public boolean removeInherits(String inherit) {
|
||||||
if (this.inherits.contains(inherit.toLowerCase())) {
|
if (this.inherits.contains(inherit.toLowerCase())) {
|
||||||
this.inherits.remove(inherit.toLowerCase());
|
this.inherits.remove(inherit.toLowerCase());
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.INHERITANCE_CHANGED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -145,7 +151,9 @@ public class Group extends DataUnit implements Cloneable {
|
||||||
variables.addVar(key, temp.getVarObject(key));
|
variables.addVar(key, temp.getVarObject(key));
|
||||||
}
|
}
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
if (GroupManager.isLoaded())
|
if (GroupManager.isLoaded()) {
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.INFO_CHANGED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,9 @@ 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 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;
|
||||||
|
@ -16,7 +19,7 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author gabrielcouto
|
* @author gabrielcouto/ElgarL
|
||||||
*/
|
*/
|
||||||
public class User extends DataUnit implements Cloneable {
|
public class User extends DataUnit implements Cloneable {
|
||||||
|
|
||||||
|
@ -139,6 +142,8 @@ 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.GROUP_CHANGED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,9 +158,11 @@ public class User extends DataUnit implements Cloneable {
|
||||||
removeSubGroup(subGroup);
|
removeSubGroup(subGroup);
|
||||||
subGroups.add(subGroup.getName());
|
subGroups.add(subGroup.getName());
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
if (GroupManager.isLoaded())
|
if (GroupManager.isLoaded()) {
|
||||||
if (GroupManager.BukkitPermissions.player_join = false)
|
if (GroupManager.BukkitPermissions.player_join = false)
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.SUBGROUP_CHANGED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int subGroupsSize() {
|
public int subGroupsSize() {
|
||||||
|
@ -177,6 +184,7 @@ public class User extends DataUnit implements Cloneable {
|
||||||
if (GroupManager.isLoaded())
|
if (GroupManager.isLoaded())
|
||||||
if (GroupManager.BukkitPermissions.player_join = false)
|
if (GroupManager.BukkitPermissions.player_join = false)
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.SUBGROUP_CHANGED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -220,9 +228,11 @@ public class User extends DataUnit implements Cloneable {
|
||||||
variables.addVar(key, varList.get(key));
|
variables.addVar(key, varList.get(key));
|
||||||
}
|
}
|
||||||
flagAsChanged();
|
flagAsChanged();
|
||||||
if (GroupManager.isLoaded())
|
if (GroupManager.isLoaded()) {
|
||||||
if (GroupManager.BukkitPermissions.player_join = false)
|
if (GroupManager.BukkitPermissions.player_join = false)
|
||||||
GroupManager.BukkitPermissions.updateAllPlayers();
|
GroupManager.BukkitPermissions.updateAllPlayers();
|
||||||
|
GroupManagerEventHandler.callEvent(this, Action.INFO_CHANGED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public User updatePlayer(Player player) {
|
public User updatePlayer(Player player) {
|
||||||
|
@ -238,5 +248,4 @@ public class User extends DataUnit implements Cloneable {
|
||||||
}
|
}
|
||||||
return bukkitPlayer;
|
return bukkitPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,11 @@ import java.util.logging.Logger;
|
||||||
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.data.User;
|
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.anjocaido.groupmanager.permissions.AnjoPermissionsHandler;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
@ -144,6 +149,8 @@ public class WorldDataHolder {
|
||||||
removeUser(theUser.getName());
|
removeUser(theUser.getName());
|
||||||
users.put(theUser.getName().toLowerCase(), theUser);
|
users.put(theUser.getName().toLowerCase(), theUser);
|
||||||
haveUsersChanged = true;
|
haveUsersChanged = true;
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(theUser, Action.USER_ADDED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,6 +162,8 @@ public class WorldDataHolder {
|
||||||
if (users.containsKey(userName.toLowerCase())) {
|
if (users.containsKey(userName.toLowerCase())) {
|
||||||
users.remove(userName.toLowerCase());
|
users.remove(userName.toLowerCase());
|
||||||
haveUsersChanged = true;
|
haveUsersChanged = true;
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(userName, GMUserEvent.Action.USER_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -179,6 +188,8 @@ public class WorldDataHolder {
|
||||||
}
|
}
|
||||||
defaultGroup = this.getGroup(group.getName());
|
defaultGroup = this.getGroup(group.getName());
|
||||||
haveGroupsChanged = true;
|
haveGroupsChanged = true;
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.DEFAULT_GROUP_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,6 +232,7 @@ public class WorldDataHolder {
|
||||||
public void addGroup(Group groupToAdd) {
|
public void addGroup(Group groupToAdd) {
|
||||||
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);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,10 +242,12 @@ public class WorldDataHolder {
|
||||||
removeGroup(groupToAdd.getName());
|
removeGroup(groupToAdd.getName());
|
||||||
groups.put(groupToAdd.getName().toLowerCase(), groupToAdd);
|
groups.put(groupToAdd.getName().toLowerCase(), groupToAdd);
|
||||||
haveGroupsChanged = true;
|
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
|
* @param groupName
|
||||||
* @return true if had something to remove. false the group was default or non-existant
|
* @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())) {
|
if (groups.containsKey(groupName.toLowerCase())) {
|
||||||
groups.remove(groupName.toLowerCase());
|
groups.remove(groupName.toLowerCase());
|
||||||
haveGroupsChanged = true;
|
haveGroupsChanged = true;
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(groupName.toLowerCase(), GMGroupEvent.Action.GROUP_REMOVED);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -345,6 +361,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,6 +392,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -936,6 +954,9 @@ public class WorldDataHolder {
|
||||||
ph.groupsFile = groupsFile;
|
ph.groupsFile = groupsFile;
|
||||||
ph.setTimeStampGroups(groupsFile.lastModified());
|
ph.setTimeStampGroups(groupsFile.lastModified());
|
||||||
ph.removeGroupsChangedFlag();
|
ph.removeGroupsChangedFlag();
|
||||||
|
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED);
|
||||||
|
|
||||||
/*FileWriter tx = null;
|
/*FileWriter tx = null;
|
||||||
try {
|
try {
|
||||||
|
@ -1010,6 +1031,9 @@ public class WorldDataHolder {
|
||||||
ph.setTimeStampUsers(usersFile.lastModified());
|
ph.setTimeStampUsers(usersFile.lastModified());
|
||||||
ph.removeUsersChangedFlag();
|
ph.removeUsersChangedFlag();
|
||||||
|
|
||||||
|
if (GroupManager.isLoaded())
|
||||||
|
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED);
|
||||||
|
|
||||||
/*FileWriter tx = null;
|
/*FileWriter tx = null;
|
||||||
try {
|
try {
|
||||||
tx = new FileWriter(usersFile, false);
|
tx = new FileWriter(usersFile, false);
|
||||||
|
@ -1191,5 +1215,6 @@ public class WorldDataHolder {
|
||||||
setTimeStampGroups(groupsFile.lastModified());
|
setTimeStampGroups(groupsFile.lastModified());
|
||||||
if (usersFile != null)
|
if (usersFile != null)
|
||||||
setTimeStampUsers(usersFile.lastModified());
|
setTimeStampUsers(usersFile.lastModified());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue