I have a problem that today is wearing me down deeply, I created a plugin that adds player to an arraylist when clicking in an inventory (I did so unfortunately because I'm not very good), the game is only one and contains 2 player, I can't make sure that if a player exits, through a method, he can give victory to the other Player, I tried a lot of methods, this is the last one (In this code below I try to put a method where if I remotely understood it should send a victory message to the player, which obviously it does not and then execute LobbyJoin, which is a method that takes you to the lobby):
private void makeWinSupport(Player winner, Player loser) {
if (playerInGame.contains(winner) && playerInGame.contains(loser)) {
winner.sendMessage(plugin.cc("&6(!) Hai vinto!"));
LobbyJoin(loser);
LobbyJoin(winner);
playerInGame.remove(winner);
playerInGame.remove(loser);
}
}
public void makePlayerWin(Player loser) {
Iterator<Player> i = playerInGame.iterator();
System.out.println(1);
if(i.hasNext() && i == loser) {
makeWinSupport(i.next(), loser);
} else {
makeWinSupport(playerInGame.get(0), loser);
}
@EventHandler
public void onQuit(PlayerQuitEvent e) {
e.setQuitMessage("");
Player p = e.getPlayer();
if(playerInGame.contains(p)) {
makePlayerWin(p);
}
}
}