Class SetUserVariablesRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class SetUserVariablesRequest
    extends BaseRequest
    Sets one or more custom User Variables for the current user.

    When a User Variable is set, the userVariablesUpdate event is dispatched to all the users in all the Rooms joined by the current user, including himself.

    NOTE: the userVariablesUpdate event is dispatched to users in a specific Room only if it is configured to allow this event (see the RoomSettings.permissions parameter).

    Example
    The following example sets a number of User Variables and handles the respective update event:

     private void someMethod() {
         sfs.addEventListener(SFSEvent.USER_VARIABLES_UPDATE, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 List changedVars = (List)evt.getArguments().get("changedVars");
                 User user = (User)evt.getArguments().get("user");
                 
                 // Check if the user changed his x and y user variables
                 if (changedVars.indexOf("x") != -1 || changedVars.indexOf("y") != -1)
                 {
                     // Move the user avatar to a new position
                     ...
                 }
             }
         });
     
         // Create some User Variables
         List userVars = new ArrayList();
         userVars.add(new SFSUserVariable("avatarType", "SwedishCook"));
         userVars.add(new SFSUserVariable("country", "Sweden"));
         userVars.add(new SFSUserVariable("x", 10));
         userVars.add(new SFSUserVariable("y", 5));
         
         sfs.send(new SetUserVariablesRequest(userVars));
     }
     
    See Also:
    SFSEvent.USER_VARIABLES_UPDATE, RoomSettings.getPermissions()
    • Field Detail

      • KEY_USER

        public static final java.lang.String KEY_USER
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_VAR_LIST

        public static final java.lang.String KEY_VAR_LIST
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • SetUserVariablesRequest

        public SetUserVariablesRequest​(java.util.List<UserVariable> userVariables)
        Creates a new SetUserVariablesRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        userVariables - A list of UserVariable objects representing the User Variables to be set.
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), UserVariable
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *