You have to type a command within 5 seconds

Discussion in 'Spigot Plugin Help' started by KoalaOnCaffeine6, Jul 15, 2018.

Thread Status:
Not open for further replies.
  1. Hi I was wondering how to make it so you have to confirm a command, like the askyblock /is reset command, where you have to type it withing 10 seconds, I know you need a hashmap and a runnable, but it is just going right over my head xd. Any help with this will be appreciated. Thanks!
    -Koala
     
  2. Answer you're looking for is in your question
     
  3. i dont know how to do it is the problem
     
  4. Like you said, use a bukkit runnable. If you're looking for spoon feeding, look else where
     
  5. This is the general structure of a BukkitRunnable:
    Code (Java):
    new BukkitRunnable() {
        public void run() {
            //magic
        }
    }.runTask(plugin);
    This would run the code inside of it one tick later. If you want to run the task x amount of ticks later, you'd do this:
    Code (Java):
    new BukkitRunnable() {
        public void run() {
            //more magic
        }
    }.runTaskLater(plugin, 100L);
    100L, L represents a long and 100 would be 5 seconds in ticks.
    You don't really need a HashMap, since you only need to store one thing (the player) when the command is first done, then remove them when the confirmation is given. This can be easily done with a Set/HashSet (a set would be preferable to a hashset, like a map would be preferable to a hashmap, by Liskov Substitution Principle).
    You could listen into the CommandPreProcessEvent and, if both the command is the confirmation command and the player is in the set, do whatever.
     
    • Informative Informative x 1
  6. i was looking for help so please, chill.
     
  7. I am chill. No need to worry
     
  8. Strahan

    Benefactor

    I wouldn't futz with a runnable, I'd just use a HashMap<UUID, Long> and when they run the command, check if the UUID is in the map. If not, add them to the map with UUID and current time + 5000 and do whatever you do for the first step. If they are in the map, check the current time against what's in the map. If the map is larger than current time, tell them it's too soon. If it isn't, do the second stage of the command.

    Just remember to add an onQuit to remove their UUID from the map if it exists.
     
Thread Status:
Not open for further replies.