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:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,8 @@ import com.threerings.presents.server.InvocationException;
|
||||
import com.threerings.presents.server.InvocationManager;
|
||||
import com.threerings.presents.server.ShutdownManager;
|
||||
|
||||
import com.threerings.crowd.data.BodyObject;
|
||||
import com.threerings.crowd.data.OccupantInfo;
|
||||
import com.threerings.crowd.data.PlaceConfig;
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
|
||||
@@ -165,6 +167,21 @@ public class PlaceRegistry
|
||||
return _pmgrs.values().iterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates the {@link PlaceManager} that manages the place occupied by the supplied body,
|
||||
* obtains the canonical {@link OccupantInfo} record for that body, runs your updater to effect
|
||||
* any desired modifications to the occupant info record and then broadcasts the updates by
|
||||
* calling {@link PlaceManager#updateOccupantInfo}.
|
||||
*
|
||||
* @return true if the update was sent, false if the supplied body is not currently in a place.
|
||||
*/
|
||||
public <T extends OccupantInfo> boolean updateOccupantInfo (
|
||||
BodyObject body, PlaceManager.OccInfoUpdater<T> updater)
|
||||
{
|
||||
PlaceManager pmgr = getPlaceManager(body.getPlaceOid());
|
||||
return (pmgr == null) ? false : pmgr.updateOccupantInfo(body.getOid(), updater);
|
||||
}
|
||||
|
||||
// from interface ShutdownManager.Shutdowner
|
||||
public void shutdown ()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user