Time between running commands to stop spam

Discussion in 'Plugin Development' started by AtillaBosma, Sep 9, 2012.

Thread Status:
Not open for further replies.
  1. I am at the moment creating a plugin that sends various commands to people, but it has the problem that it is easily spammable.
    Is there a way to put a timer between running the command and then running it again?
     
  2. Offline

    skore87

    One simple method is HashMap<String,Long> where you store their name and the current system time + cooldown. Check on that map onCommand and if the current system time is past their map entry, permit the command.

    Use this to get the system time: System.currentTimeMillis()

    You can't be more vague than that? If you're going to even mention it, at least give direction...

    For this method to create a cooldown effect, you would first want an ArrayList<String> containing player names that you add when they use a command. When they send the command, start a delayed scheduled task to remove them from that arraylist. If they aren't on the arraylist then permit the command.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  3. Thanks for the response, I still do not quite understand Hashmapping and Arraylists, but I will try to learn more about them.
     
Thread Status:
Not open for further replies.

Share This Page