mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2024-08-21 02:42: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
|
@ -83,3 +83,4 @@ v 1.6:
|
|||
v 1.7:
|
||||
- GM now supports offline players without having to mantogglevalidate
|
||||
- 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 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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -1829,6 +1830,15 @@ public class GroupManager extends JavaPlugin {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -937,6 +955,9 @@ public class WorldDataHolder {
|
|||
ph.setTimeStampGroups(groupsFile.lastModified());
|
||||
ph.removeGroupsChangedFlag();
|
||||
|
||||
if (GroupManager.isLoaded())
|
||||
GroupManagerEventHandler.callEvent(GMSystemEvent.Action.SAVED);
|
||||
|
||||
/*FileWriter tx = null;
|
||||
try {
|
||||
tx = new FileWriter(groupsFile, false);
|
||||
|
@ -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);
|
||||
|
@ -1192,4 +1216,5 @@ public class WorldDataHolder {
|
|||
if (usersFile != null)
|
||||
setTimeStampUsers(usersFile.lastModified());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue