31.08.2014, 11:26
@DrumYum: The PlayerLifecycleHolder will create and destroy custom player objects when a player connects or disconnect. It was made, because you can't extend the player class. With .getObject you can get a custom object that is assigned to that player. It is like having a Map<Player, GamePlayer> (GamePlayer is a custom class, with adminLevel, isOnline, level, server-side money etc.). You need to call the .registerClass to let the PlayerLifecycleHolder know, that he should create a GamePlayer object for every player that connects (and destroy it when he disconnects).
The GamePlayer class has to extend the PlayerLifecycleObject, because it contains some methods and variables.
You can only register classes, that extend the PlayerLifecycleObject.
Example use:
The GamePlayer class has to extend the PlayerLifecycleObject, because it contains some methods and variables.
You can only register classes, that extend the PlayerLifecycleObject.
Example use:
PHP код:
//OnPlayerConnect
getEventManager().registerHandler(PlayerConnectEvent.class, (event) -> {
GamePlayer gamePlayer = playerLifecycleHolder.getObject(event.getPlayer(), GamePlayer.class); //Getting the players custom object with all information in it like adminLevel, money etc.
if(event.getPlayer().getName().equals("123marvin123")) //Check if player's name equals 123marvin123
gamePlayer.setAdminLevel(5); //assign admin level 5 to player
});
//OnPlayerDisconnect
getEventManager().registerHandler(PlayerDisconnectEvent.class, event -> {
GamePlayer gamePlayer = playerLifecycleHolder.getObject(event.getPlayer(), GamePlayer.class); //Getting the players custom object with all information in it like adminLevel, money etc.
event.getPlayer().sendMessage(Color.WHITE, "You had adminlevel " + gamePlayer.getAdminLevel()); //Send message with his current adminlevel as information
});