You can use PlayerQuitEvent to remove players from your plugin when they leave. I made this example assuming you have a list called yourPlayerList
which stores the 2 competing players, but you can modify it to work with more players.
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
if(yourPlayerList.remove(event.getPlayer())){//only true if the player was removed from the queue, which only happens if it was in the queue originally
Player loser=event.getPlayer();//the loser
Player winner=yourPlayerList.get(0);//the other player is still in the queue
makeWinSupport(winner,loser);
}
}
Don't forget to register the event in the event manager.
EDIT: If you want to remove the player from the list and only end the game if there is only one player left, you can do something like this:
@EventHandler
public void onPlayerLeave(PlayerQuitEvent event) {
if(yourPlayerList.remove(event.getPlayer())&&yourPlayerList.size()==1){//removes the player and checks the amount of active players
Player winner=yourPlayerList.get(0);
//here you can call a method which accepts only the winning player. If you have 4 players, there is no reason to include a 'loser' player.
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…