Delays & Permissions

Discussion in 'Plugin Development' started by beachyboy18, Jul 4, 2014.

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

    beachyboy18

    Making a plugin where certain players can type certain commands.
    For example: If the Rank 'Donator' has the permission 'plugin.permission', they can use the command 'command' every 5 seconds or so.
    I basically would like to learn how to make delays on commands and how to make permissions so if you had pex for example, you can give them the specific node.

    Any help is appreciated!:)
     
  2. Offline

    RingOfStorms

    For permissions there is a built in Player.hasPermission("yourplugin.perm") that returns true or false. For a delay to a command you can add a player's name to a list and then remove it using a delayed task. When they try to use the command, check if they are in the list, if so then cancel the command.

    Here is some info on scheduler programming
     
  3. Offline

    beachyboy18

    I looked at the link but I'm not sure how to make it so you can only use the command every 5 seconds or so?
     
  4. Offline

    fireblast709

    beachyboy18 each time they use the command, check if they have an active cooldown. If not, give them one. If they do, then cancel the command (if it is yours, just do the check in the onCommand() method, otherwise use PlayerCommandPreprocessEvent).

    The cooldown itself has two popular variants. One is the use of a List/Set(for better performance than a List) and a scheduler. As RingOfStorms said, the check is basically a contains() call to see if they are in the List/Set, and the cooldown is just adding them to the List/Set and scheduling a delayed task that removes them (look at the page he linked for more on scheduling tasks)

    The second option is using a Map. First check if the Map contains the key (playername or UUID, depending on whether you need it to be saved to a config - if the latter the UUID is kind of a must for long delays). If it does, return whether System.currentTimeMillis() > cooldown from Map. (In this example, the value put in the Map is the current time + cooldown)
     
Thread Status:
Not open for further replies.

Share This Page