Solved Wait for confirmation before executing command

Discussion in 'Plugin Development' started by jonapap, Dec 22, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    I am making a plugin which ask my confirmation if a command is executed? How can I make it so it wait my confirmation before executing? For now, after a certain command is typed, it send me a message and start a scheduler each seconds 10 times to check if I confirmed the command, but the problem is the main thread continue and accept the command, even if I do event.setCancelled(true) in the scheduler.
  2. Easy way to do it is to save the command and the sender in a list, then you simply keep it there till onCommand triggers with confirmation, when it does, you run the command.
  3. Offline


    @BreezerFly You also need to remove him from the list after some time, such as 10 seconds.
  4. Yeah, well, you can schedule that. Or just use your next onCommand to clean the list (or remove him if it's him issuing a new command.)
    That's what I'd do.
  5. Offline


    So, I should always cancel the command and if I accept, resend it with Bukkit.dispatchCommand()?
  6. Online

    timtower Administrator Administrator Moderator

    @jonapap Yes, and then you need to make sure that you plugin doesn't intercept it again. Because that would cause an infinite loop.
  7. Offline


    Looking at the collections in Java, I think it would be the best to use a LinkedHashMap, right? This way, I could support multiple commands.
  8. Offline


    You can make a class called something like ConfirmCommand with methods called accept() and deny(), then store that in a hashmap with the player's UUID, if they perform a command get their stored ConfirmCommand then perform accept(), if they do the no command perform deny(), then just use a runnable to cancel it automatically after 10 seconds if nothing was taken.
  9. Offline


    I am currently trying another way without having a separate class, with LinkedHashMap.

    I got it working but apparently, PlayerCommandPreprocessEvent doesn't pick command sent with Bukkit.dispatchCommand.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Dec 23, 2015
Thread Status:
Not open for further replies.

Share This Page