diff --git a/src/java/com/threerings/crowd/server/PlaceManager.java b/src/java/com/threerings/crowd/server/PlaceManager.java index 17de349f9..c3a15bc98 100644 --- a/src/java/com/threerings/crowd/server/PlaceManager.java +++ b/src/java/com/threerings/crowd/server/PlaceManager.java @@ -114,6 +114,15 @@ public class PlaceManager protected Class _delegateClass; } + /** Used with {@link #updateOccupantInfo}. */ + public static interface OccInfoUpdater + { + /** + * 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 boolean updateOccupantInfo ( + int bodyOid, OccInfoUpdater 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. */ diff --git a/src/java/com/threerings/crowd/server/PlaceRegistry.java b/src/java/com/threerings/crowd/server/PlaceRegistry.java index 1ce7fcba5..3376db80e 100644 --- a/src/java/com/threerings/crowd/server/PlaceRegistry.java +++ b/src/java/com/threerings/crowd/server/PlaceRegistry.java @@ -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 boolean updateOccupantInfo ( + BodyObject body, PlaceManager.OccInfoUpdater updater) + { + PlaceManager pmgr = getPlaceManager(body.getPlaceOid()); + return (pmgr == null) ? false : pmgr.updateOccupantInfo(body.getOid(), updater); + } + // from interface ShutdownManager.Shutdowner public void shutdown () {