Merge branch 'refs/heads/groupmanager'

This commit is contained in:
snowleo 2011-12-13 23:52:25 +01:00
commit 79861b1f10
11 changed files with 291 additions and 11 deletions

View File

@ -82,4 +82,6 @@ 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.
- Offline player checks now support partial name matches.
- Added custom events so plugins can now be notified of changes within GroupManager.
- GM now registers with Bukkits ServicesManager.

View File

@ -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;

View File

@ -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;
@ -37,8 +38,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.world.WorldListener;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;
@ -89,6 +92,9 @@ public class GroupManager extends JavaPlugin {
@Override
public void onDisable() {
setLoaded(false);
// Un-register this service.
this.getServer().getServicesManager().unregister(this);
disableScheduler(); // Shutdown before we save, so it doesn't interfere.
if (worldsHolder != null) {
@ -153,6 +159,9 @@ public class GroupManager extends JavaPlugin {
}
System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
// Register as a service
this.getServer().getServicesManager().register(AnjoPermissionsHandler.class, this.permissionHandler, this, ServicePriority.Normal);
}
public static boolean isLoaded() {
@ -1828,6 +1837,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

View File

@ -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.GROUP_INHERITANCE_CHANGED);
}
}
public boolean removeInherits(String inherit) {
if (this.inherits.contains(inherit.toLowerCase())) {
this.inherits.remove(inherit.toLowerCase());
flagAsChanged();
GroupManagerEventHandler.callEvent(this, Action.GROUP_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.GROUP_INFO_CHANGED);
}
}
}

View File

@ -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.USER_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.USER_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.USER_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.USER_INFO_CHANGED);
}
}
public User updatePlayer(Player player) {
@ -238,5 +248,4 @@ public class User extends DataUnit implements Cloneable {
}
return bukkitPlayer;
}
}

View File

@ -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());
}
}
}

View File

@ -0,0 +1,57 @@
package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.data.Group;
/**
* @author ElgarL
*
*/
public class GMGroupEvent extends GroupManagerEvent {
/**
*
*/
private static final long serialVersionUID = -5294917600434510451L;
protected Group group;
protected String groupName;
protected Action action;
public GMGroupEvent(Group group, Action action) {
super(action.toString());
this.group = group;
this.action = action;
this.groupName = group.getName();
}
public GMGroupEvent(String groupName, Action action) {
super(action.toString());
this.groupName = groupName;
this.action = action;
}
public Action getAction(){
return this.action;
}
public Group getGroup() {
return group;
}
public String getGroupName() {
return groupName;
}
public enum Action {
GROUP_PERMISSIONS_CHANGED,
GROUP_INHERITANCE_CHANGED,
GROUP_INFO_CHANGED,
GROUP_ADDED,
GROUP_REMOVED,
}
}

View File

@ -0,0 +1,32 @@
package org.anjocaido.groupmanager.events;
/**
* @author ElgarL
*
*/
public class GMSystemEvent extends GroupManagerEvent {
/**
*
*/
private static final long serialVersionUID = -8786811924448821548L;
protected Action action;
public GMSystemEvent(Action action) {
super(action.toString());
this.action = action;
}
public Action getAction(){
return this.action;
}
public enum Action {
RELOADED,
SAVED,
DEFAULT_GROUP_CHANGED,
VALIDATE_TOGGLE,
}
}

View File

@ -0,0 +1,59 @@
package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.data.User;
/**
* @author ElgarL
*
*/
public class GMUserEvent extends GroupManagerEvent {
/**
*
*/
private static final long serialVersionUID = -5294917600434510451L;
protected User user;
protected String userName;
protected Action action;
public GMUserEvent(User user, Action action) {
super(action.toString());
this.user = user;
this.action = action;
this.userName = user.getName();
}
public GMUserEvent(String userName, Action action) {
super(action.toString());
this.userName = userName;
this.action = action;
}
public Action getAction(){
return this.action;
}
public User getUser() {
return user;
}
public String getUserName() {
return userName;
}
public enum Action {
USER_PERMISSIONS_CHANGED,
USER_INHERITANCE_CHANGED,
USER_INFO_CHANGED,
USER_GROUP_CHANGED,
USER_SUBGROUP_CHANGED,
USER_ADDED,
USER_REMOVED,
}
}

View File

@ -0,0 +1,22 @@
package org.anjocaido.groupmanager.events;
import org.bukkit.event.Event;
/**
* @author ElgarL
*
*/
public abstract class GroupManagerEvent extends Event {
/**
*
*/
private static final long serialVersionUID = 8790362185329926951L;
protected GroupManagerEvent(String name) {
super(name);
}
}

View File

@ -0,0 +1,42 @@
package org.anjocaido.groupmanager.events;
import org.anjocaido.groupmanager.GroupManager;
import org.anjocaido.groupmanager.data.Group;
import org.anjocaido.groupmanager.data.User;
/**
* @author ElgarL
*
*/
public class GroupManagerEventHandler {
protected static void callEvent(GMGroupEvent event) {
GroupManager.callEvent(event);
}
protected static void callEvent(GMUserEvent event) {
GroupManager.callEvent(event);
}
protected static void callEvent(GMSystemEvent event) {
GroupManager.callEvent(event);
}
public static void callEvent(Group group, GMGroupEvent.Action action) {
callEvent(new GMGroupEvent(group, action));
}
public static void callEvent(String groupName, GMGroupEvent.Action action) {
callEvent(new GMGroupEvent(groupName, action));
}
public static void callEvent(User user, GMUserEvent.Action action) {
callEvent(new GMUserEvent(user, action));
}
public static void callEvent(String userName, GMUserEvent.Action action) {
callEvent(new GMUserEvent(userName, action));
}
public static void callEvent(GMSystemEvent.Action action) {
callEvent(new GMSystemEvent(action));
}
}