I am simply trying to set a room variable (adding the user's name to a room varible) in my UserJoinedRoomHandler: From my JAVA extension:
public class UserJoinedRoomHandler extends BaseServerEventHandler
{
@Override
public void handleServerEvent(ISFSEvent arg0) throws SFSException
{
User user = (User) arg0.getParameter(SFSEventParam.USER);
Room room = (Room) arg0.getParameter(SFSEventParam.ROOM);
trace("add p1 = " + user.getName() + " to room=" + room.getId());
List<RoomVariable> listOfVars = new ArrayList<RoomVariable>();
listOfVars.add( new SFSRoomVariable("player1Name", user.getName()) );
((MyExtension) getParentExtension()).sfsApi.setRoomVariables(user, room, listOfVars); // NullPointerException here :(
}
}
Note, I grab the sfsAPI when in MyExtention init() function:
ISFSApi sfsApi = SmartFoxServer.getInstance().getAPIManager().getSFSApi();
To me this should work, the only thing I can think of is that the room might not have fully initialised (the user had just created the room before this event is fired). But in any case I thought this should be a trivial scenario, but it has cost me a good handful of hours already.
Cheers for any help.
The solution was to use the Api directly:
((MyExtension) getParentExtension()).getApi().setRoomVariables(user, room, listOfVars);
PS: Unfortunately there is no method to issue 1 Room Variable. You have to submit a list, even if its only 1 in length.