-
-
Notifications
You must be signed in to change notification settings - Fork 0
The Event Waiter
James Harrell edited this page Sep 23, 2020
·
1 revision
The event waiter allows you to reduce the boilerplate of creating some sort of map or list of UUIDs who you are waiting on an event for. It lets you turn your multi-class layout of waiting for someone to do something into a single consice block of code.
The following is an example use case of a plugin where you run a command, then type a message and it sends you your message back. This is a very basic use case, but it shows that you are able to get user inputs without a whole mess of other classes.
fun example(somePlayer: Player, yourPlugin: JavaPlugin) {
somePlayer.send("&aPlease let us know your name, so we know what to call you!")
yourPlugin.waitForEvent<AsyncPlayerChatEvent>( // wait for the AsyncPlayerChatEvent
timeoutTicks = 20 * 30, //give them 30 seconds to respond
predicate = { it.player.uniqueId == somePlayer.uniqueId }, // only accepts messages from the same player
timeoutAction = { somePlayer.send("&cPlease run the command again! We didn't hear back in time") }, // what to do when they run out of time
action = { somePlayer.send("&aThanks, ${it.message}! This is what we'll call you from now on!") } // the action to run when you get the message back
)
}
As you can see, this is a very clear and consise way to get user inputs using a prompt. This can be used for any of the Bukkit Events. Enjoy!
Come chat with us at discord.jaims.dev! You can receive support in my discord above or in the issues tab!