Class SFSUserVariable
java.lang.Object
com.smartfoxserver.entities.variables.BaseVariable
com.smartfoxserver.entities.variables.SFSUserVariable
- All Implemented Interfaces:
UserVariable,Variable,Serializable,Cloneable
- Direct Known Subclasses:
MMOItemVariable,SFSRoomVariable
public class SFSUserVariable
extends com.smartfoxserver.entities.variables.BaseVariable
implements UserVariable
UserVariables are custom values assigned to User objects that are automatically synchronized between client and server
on every change. They are particularly useful to assign custom data such as profile data, game related state etc... And keep it
updated among all Users in the same Room(s)
UserVariables support a number of different data types:
- Null
- Bool
- Byte
- Short
- Int
- Long
- Float
- Double
- Vector2
- Vector3
- String
- SFSObject
- SFSArray
UserVariables are visible (and updated) to all Users in the same Room, with the exclusion of those marked as hidden or private.
- Hidden: a hidden User Variable is only available on the server-side and never transmitted to other clients, including the owner.
- Private: a private User Variable is only visible to its owner and never transmitted to other clients.
var userVars = List.of((UserVariable) new SFSUserVariable("Country", "Italy"), new SFSUserVariable("Age", 30));
getApi().setUserVariables(user, userVars);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected booleanprotected booleanFields inherited from class com.smartfoxserver.entities.variables.BaseVariable
name, type, value -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSFSUserVariable(String name) protectedSFSUserVariable(String name, VariableType type, String literal) SFSUserVariable(String name, Object value) Create a new UserVariableSFSUserVariable(String name, Object value, boolean isHidden) Create a new UserVariableSFSUserVariable(String name, Object value, boolean isHidden, boolean isPrivate) Create a new UserVariableprotectedSFSUserVariable(String name, String type, String literal) -
Method Summary
Modifier and TypeMethodDescriptionclone()Deprecated.booleanisHidden()Checks if the variable is hiddenbooleanChecks whether a UserVariable is private.booleanStorable variables can be saved by the Room Persistence APIstatic SFSUserVariablenewFromSFSArray(ISFSArray array) static SFSUserVariablenewFromStringLiteral(String name, String type, String literal) static SFSUserVariablenewPrivateVariable(String name, Object value) Creates a private variablevoidsetHidden(boolean flag) Set the variable as hidden.voidsetPrivate(boolean value) Setting a UserVariable as private restricts its visibility to the owner only.voidsetStorable(boolean value) Flags this variable as storable (default = true).toString()Methods inherited from class com.smartfoxserver.entities.variables.BaseVariable
getBoolValue, getByteValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getName, getSFSArrayValue, getSFSObjectValue, getShortValue, getStringValue, getType, getValue, getVector2Value, getVector3Value, isNull, populateArrayWithValue, setNull, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValueFromStringLiteralMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.smartfoxserver.entities.variables.UserVariable
setNullMethods inherited from interface com.smartfoxserver.entities.variables.Variable
getBoolValue, getByteValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getName, getSFSArrayValue, getSFSObjectValue, getShortValue, getStringValue, getType, getValue, getVector2Value, getVector3Value, isNull
-
Field Details
-
priv
protected boolean priv -
storable
protected boolean storable
-
Constructor Details
-
SFSUserVariable
Create a new UserVariable- Parameters:
name- name of the variablevalue- value of the variable (using any of the supported types)
-
SFSUserVariable
Create a new UserVariable- Parameters:
name- name of the variablevalue- value of the variableisHidden- true if the variable needs to be server-side onlyisPrivate- true if the variable can only be seen by it's owner
-
SFSUserVariable
Create a new UserVariable- Parameters:
name- name of the variablevalue- value of the variableisHidden- true if the variable needs to be server-side only
-
SFSUserVariable
-
SFSUserVariable
-
SFSUserVariable
-
-
Method Details
-
newFromStringLiteral
- Internal
-
newFromSFSArray
- Internal
-
newPrivateVariable
Creates a private variable -
isHidden
public boolean isHidden()Checks if the variable is hidden- Specified by:
isHiddenin interfaceUserVariable- Returns:
- true if the variable is hidden
- See Also:
-
setHidden
public void setHidden(boolean flag) Description copied from interface:UserVariableSet the variable as hidden. When this flag is turned on the variable will be available exclusively on the server side and it will never be transmitted to clients.- Specified by:
setHiddenin interfaceUserVariable- Parameters:
flag-- Internal
-
isPrivate
public boolean isPrivate()Checks whether a UserVariable is private. Private UserVariables are only visible to the owner.- Specified by:
isPrivatein interfaceUserVariable- Returns:
- true if the UserVariable is private
- Since:
- 2.12
-
setPrivate
public void setPrivate(boolean value) Setting a UserVariable as private restricts its visibility to the owner only. All other users in the same Room will not be able to see the variable nor they will be notified of any changes.When the flag is false, the UserVariable will be visible by all users in the same Room.
- Specified by:
setPrivatein interfaceUserVariable- Parameters:
value-- Since:
- 2.12
-
toSFSArray
- Specified by:
toSFSArrayin interfaceVariable- Internal
-
isStorable
public boolean isStorable()Storable variables can be saved by the Room Persistence API- Specified by:
isStorablein interfaceUserVariable- Returns:
- true if the variable is storable, false otherwise
-
setStorable
public void setStorable(boolean value) Flags this variable as storable (default = true). All non-storable variables are ignored by the Room Persistence API- Specified by:
setStorablein interfaceUserVariable
-
clone
Deprecated. -
toString
-