This is my code. But user = null
How to get user by id and disconnect user?
Zone zone = (Zone)event.getParameter(SFSEventParam.ZONE);
User user = zone.getUserById(1);
this.getApi().disconnectUser(user,ClientDisconnectionReason.IDLE);
This is my code. But user = null
How to get user by id and disconnect user?
Zone zone = (Zone)event.getParameter(SFSEventParam.ZONE);
User user = zone.getUserById(1);
this.getApi().disconnectUser(user,ClientDisconnectionReason.IDLE);
You are getting user by id = 1 , the id may be not valid , the id that SFS gives for every user may be vary , it's not like an array that starts from 0 , it may change every time some one connect or disconnect , when a player connect to sfs , it takes an id , when he disconnect , some one else may take it , you can get user id by this :
Collection<User> users = getParentExtension().getParentZone().getUserList();
while (users.iterator().hasNext())
{
int id = users.iterator().next().getId();
}
and then use disconnect function to disconnect him or just user the user from collection to disconnect him.