Made it easier to update occupant info the correct way in hopes of discouraging

people from updating it the wrong way.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5572 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2008-12-04 23:28:50 +00:00
parent 46a5bbd0cc
commit 420333df51
2 changed files with 48 additions and 0 deletions
@@ -114,6 +114,15 @@ public class PlaceManager
protected Class<? extends PlaceManagerDelegate> _delegateClass;
}
/** Used with {@link #updateOccupantInfo}. */
public static interface OccInfoUpdater<T extends OccupantInfo>
{
/**
* Make whatever changes are desired to your {@link OccupantInfo} here.
*/
public void update (T info);
}
/**
* Returns a reference to our place configuration object.
*/
@@ -179,6 +188,28 @@ public class PlaceManager
_plobj.updateOccupantInfo((OccupantInfo)occInfo.clone());
}
/**
* Calls the supplied updater on the canonical occupant info record for the specified body
* (which must be an occupant of this place) and broadcasts the update to all other occupants.
*
* @return true if the updater was called and the update sent, false if the body could not be
* located (was not an occupant of this place).
*
* @exception ClassCastException thrown if the type of the supplied updater does not match the
* type of {@link OccupantInfo} record used for the occupant. Caveat utilitor.
*/
public <T extends OccupantInfo> boolean updateOccupantInfo (
int bodyOid, OccInfoUpdater<T> updater)
{
@SuppressWarnings("unchecked") T info = (T)getOccupantInfo(bodyOid);
if (info == null) {
return false;
}
updater.update(info);
updateOccupantInfo(info);
return true;
}
/**
* Called by the place registry after creating this place manager.
*/