addSubGroup now returns a boolean for success/failure.

'/manuaddsub' now correctly reports if it was able to add the sub
group.
This commit is contained in:
ElgarL 2012-01-24 14:21:07 +00:00
parent 1dab4f95dd
commit 145b0be2f3
3 changed files with 23 additions and 14 deletions

View File

@ -113,4 +113,7 @@ v 1.9:
- Fixed infinite loop error on player join.
- Optimized code to only update the player logging in instead of all players online.
- Added recursive loop detection for World mirroring (you may not set the main world as a mirror of another).
- Fixed fetching world data so it no longer returns the mirrored world for groups. Each world data holder now points to the correct data set, so can be returned as an object.
- Fixed fetching world data so it no longer returns the mirrored world for groups. Each world data holder now points to the correct data set, so can be returned as an object.
- Changed addSubGroup() to only add the group if it doesn't already exist (no need to update an already existing group).
- addSubGroup now returns a boolean for success/failure.
- '/manuaddsub' now correctly reports if it was able to add the sub group.

View File

@ -489,8 +489,10 @@ public class GroupManager extends JavaPlugin {
return false;
}
// PARECE OK
auxUser.addSubGroup(auxGroup);
sender.sendMessage(ChatColor.YELLOW + "You added subgroup '" + auxGroup.getName() + "' to player '" + auxUser.getName() + "'.");
if (auxUser.addSubGroup(auxGroup))
sender.sendMessage(ChatColor.YELLOW + "You added subgroup '" + auxGroup.getName() + "' to player '" + auxUser.getName() + "'.");
else
sender.sendMessage(ChatColor.RED + "The subgroup '" + auxGroup.getName() + "' is already available to '" + auxUser.getName() + "'.");
targetPlayer = this.getServer().getPlayer(auxUser.getName());
if (targetPlayer != null)

View File

@ -147,22 +147,26 @@ public class User extends DataUnit implements Cloneable {
}
}
public void addSubGroup(Group subGroup) {
public boolean addSubGroup(Group subGroup) {
// Don't allow adding a subgroup if it's already set as the primary.
if (this.group.equalsIgnoreCase(subGroup.getName())) {
return;
return false;
}
if (!this.getDataSource().groupExists(subGroup.getName())) {
getDataSource().addGroup(subGroup);
flagAsChanged();
if (GroupManager.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED);
}
return true;
}
subGroup = getDataSource().getGroup(subGroup.getName());
removeSubGroup(subGroup);
subGroups.add(subGroup.getName());
flagAsChanged();
if (GroupManager.isLoaded()) {
if (!GroupManager.BukkitPermissions.isPlayer_join())
GroupManager.BukkitPermissions.updatePlayer(getBukkitPlayer());
GroupManagerEventHandler.callEvent(this, Action.USER_SUBGROUP_CHANGED);
}
//subGroup = getDataSource().getGroup(subGroup.getName());
//removeSubGroup(subGroup);
//subGroups.add(subGroup.getName());
return false;
}
public int subGroupsSize() {