0

I've a problem about typing confirmation. I'm doing Virtual Spawner plugin.

If player has enough money and typing Y his spawner gonna upgrade to Lvl2.

My question is how can I do this Y or N confirmation? I thought with AsyncPlayerChatEvent. But this time every Y or N trigger Upgrading.

public static void jlvlup(Player player,int currentLevel) {
    String lvlup2= ChatColor.DARK_RED+"Do you confirm upgrade spawner to Level 2 for 5000000$ ?(Y/N) Write to chat.";
    if(currentLevel==1) {
         player.sendMessage(lvlup2);
         player.closeInventory(); 
    }
}
pppery
  • 3,731
  • 22
  • 33
  • 46
Archuleus
  • 1
  • 1

1 Answers1

0

You need to filter if you are waiting for player confirmation. You can do it in lot of way, but I suggest you to create a list, and put all players that need to confirm. For example:

public static List<Player> waitingConfirmations = new ArrayList<>(); // create the list

public static void jlvlup(Player player,int currentLevel) {
    if(currentLevel == 1) {
         player.sendMessage(ChatColor.DARK_RED + "Do you confirm upgrade spawner to Level 2 for 5000000$ ? (Y/N) Write to chat.");
         player.closeInventory(); 
         waitingConfirmations.add(player); // here add to list
    }
}

Then, for the chat, do:

if(message.equalsIgnoreCase("Y") && waitingConfirmations.contains(player)) { // check if in list
    // here pass to level 2
}

Note: message is the chat message. I didn't wrote full method as you didn't give it

Elikill58
  • 4,050
  • 24
  • 23
  • 45