Package sfs2x.client.requests
Class PlayerToSpectatorRequest
- java.lang.Object
-
- sfs2x.client.requests.BaseRequest
-
- sfs2x.client.requests.PlayerToSpectatorRequest
-
- All Implemented Interfaces:
sfs2x.client.requests.IRequest
public class PlayerToSpectatorRequest extends BaseRequest
Turns the current user from player to spectator in a Game Room.If the operation is successful, all the users in the target Room are notified with the playerToSpectator event. The operation could fail if no spectator slots are available in the Game Room at the time of the request; in this case the playerToSpectatorError event is dispatched to the requester's client.
Example
The following example turns the current user from player to spectator in the last joined Game Room:private void someMethod() { sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Player " + (User)evt.getArguments().get("user") + " is now a spectator"); } }); sfs.addEventListener(SFSEvent.PLAYER_TO_SPECTATOR_ERROR, new IEventListener() { public void dispatch(BaseEvent evt) throws SFSException { System.out.println("Unable to become a spectator due to the following error: " + evt.getArguments().get("errorMessage")); } }); // Switch player to spectator sfs.send(new PlayerToSpectatorRequest()); }
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
KEY_ROOM_ID
* API internal usage only *static java.lang.String
KEY_USER_ID
* API internal usage only *-
Fields inherited from class sfs2x.client.requests.BaseRequest
AddBuddy, AdminMessage, AutoJoin, BanUser, BlockBuddy, CallExtension, ChangeRoomCapacity, ChangeRoomName, ChangeRoomPassword, ClusterInviteUsers, ClusterJoinOrCreate, CreateRoom, CreateSFSGame, FindRooms, FindUsers, GameServerConnectionRequired, GenericMessage, GetRoomList, GoOnline, Handshake, InitBuddyList, InvitationReply, InviteUser, JoinRoom, JoinRoomInvite, KEY_ERROR_CODE, KEY_ERROR_PARAMS, KickUser, LeaveRoom, Login, Logout, ManualDisconnection, ModeratorMessage, ObjectMessage, PingPong, PlayerToSpectator, PrivateMessage, PublicMessage, QuickJoinGame, QuickJoinOrCreateRoom, RemoveBuddy, SetBuddyVariables, SetRoomVariables, SetUserPosition, SetUserVariables, SpectatorToPlayer, SubscribeRoomGroup, UnsubscribeRoomGroup
-
-
Constructor Summary
Constructors Constructor Description PlayerToSpectatorRequest()
PlayerToSpectatorRequest(Room targetRoom)
Creates a new PlayerToSpectatorRequest instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
execute(ISmartFox sfs)
* API internal usage only *void
validate(ISmartFox sfs)
* API internal usage only *-
Methods inherited from class sfs2x.client.requests.BaseRequest
getId, getMessage, getTargetController, isEncrypted, setEncrypted, setId, setTargetController
-
-
-
-
Field Detail
-
KEY_ROOM_ID
public static final java.lang.String KEY_ROOM_ID
* API internal usage only *- See Also:
- Constant Field Values
-
KEY_USER_ID
public static final java.lang.String KEY_USER_ID
* API internal usage only *- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PlayerToSpectatorRequest
public PlayerToSpectatorRequest(Room targetRoom)
Creates a new PlayerToSpectatorRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.- Parameters:
targetRoom
- The Room object corresponding to the Room in which the player should be turned to spectator. Ifnull
, the last Room joined by the user is used.- See Also:
SmartFox.send(sfs2x.client.requests.IRequest)
,Room
-
PlayerToSpectatorRequest
public PlayerToSpectatorRequest()
-
-