Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## it.gotoandplay.smartfoxclient.data
Class User

    java.lang.Object
      it.gotoandplay.smartfoxclient.data.User

    public class User

extends java.lang.Object

The User class stores the properties of each user.

This class is used internally by the `SmartFoxClient` class; also, User objects are returned by various methods and events of the SmartFoxServer API.

NOTE: in the provided examples, `user` always indicates a User instance.

Since:
  1.0.0
Author:
  The gotoAndPlay() Team
  http://www.smartfoxserver.com
  http://www.gotoandplay.it

Constructor Summary
`User(int id, java.lang.String name)`

Method Summary
`void` | `clearVariables()`
`int` | `getId()` Get the id of the user.
`java.lang.String` | `getName()` Get the name of the user.
`int` | `getPlayerId()` Retrieve the player id of the user.
`SFSVariable` | `getVariable(java.lang.String varName)` Retrieve a User Variable.
`java.util.Map<java.lang.String,SFSVariable>` | `getVariables()` Retrieve all User Variables.
`boolean` | `isModerator()` A boolean flag indicating if the user is a Moderator in the current zone.
`boolean` | `isSpectator()` A boolean flag indicating if the user is a spectator in the current room.
`void` | `setIsSpectator(boolean b)`
`void` | `setModerator(boolean b)`
`void` | `setPlayerId(int pid)`
`void` | `setVariables(java.util.Map<java.lang.String,SFSVariable> vars)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### User

    public User(int id,
                java.lang.String name)

Method Detail

### getId

    public int getId()

  Get the id of the user.

  Returns:
    The user id.

    Example

         System.out.println("User id:" + user.getId());

  Since:
    SmartFoxServer Basic / Pro v1.x.x
  See Also:
    `getName()`

### getName

    public java.lang.String getName()

  Get the name of the user.

  Returns:
    The user name.

    Example

         System.out.println("User name:" + user.getName());

  Since:
    SmartFoxServer Basic / Pro v1.x.x
  See Also:
    `getId()`

### getVariable

    public SFSVariable getVariable(java.lang.String varName)

  Retrieve a User Variable.

  Parameters:
    `varName` - the name of the variable to retrieve.
  Returns:
    The User Variable.

    Example

         int age = Integer.parseInt(room.getVariable("age").getValue());

  Since:
    SmartFoxServer Basic / Pro v1.x.x
  See Also:
    `getVariables()`, `SFSVariable`, `SmartFoxClient.setUserVariables(java.util.Map)`

### getVariables

    public java.util.Map<java.lang.String,SFSVariable> getVariables()

  Retrieve all User Variables.

  Returns:
    A `Map` containing User Variables, where the key is the variable name.

    Example

         Map<String, SFSVariable> userVars = user.getVariables();

         for(String varName : userVars.keySet())
         {
             System.out.println("Name: " + varName + " | Value: " + userVars.get(varName));
         }

  Since:
    SmartFoxServer Basic / Pro v1.x.x
  See Also:
    `getVariable(java.lang.String)`, `SmartFoxClient.setUserVariables(java.util.Map)`

### setVariables

    public void setVariables(java.util.Map<java.lang.String,SFSVariable> vars)

### clearVariables

    public void clearVariables()

### setIsSpectator

    public void setIsSpectator(boolean b)

### isSpectator

    public boolean isSpectator()

  A boolean flag indicating if the user is a spectator in the current room.

  Returns:
    `true` if the user is a spectator.

    Example

         if (user.isSpectator())
         {
             System.out.println("The user is a spectator");
         }

  Since:
    SmartFoxServer Basic / Pro v1.x.x

### setModerator

    public void setModerator(boolean b)

### isModerator

    public boolean isModerator()

  A boolean flag indicating if the user is a Moderator in the current zone.

  Returns:
    `true` if the user is a Moderator.

    Example

         if (user.isModerator())
         {
             System.out.println("The user is a Moderator");
         }

  Since:
    SmartFoxServer Basic / Pro v1.x.x

### getPlayerId

    public int getPlayerId()

  Retrieve the player id of the user. The user must be a player inside a game room for this method to work properly. This id is 1-based (player 1, player 2, etc.), but if the user is a spectator its value is -1.

  Returns:
    The current player id.

    Example

         System.out.println("The user's player id is " + user.getPlayerId());

  Since:
    SmartFoxServer Basic / Pro v1.x.x

### setPlayerId

    public void setPlayerId(int pid)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD