Save Data

Discussion in 'Plugin Development' started by WickedFaction, Feb 17, 2016.

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

    WickedFaction

    Okay, I've coded a wilderness plugin. Everything works properly and how I want except one thing:

    How do I make it does when a player leaves they can't join and use the /wild command again.

    Code: http://pastebin.com/Qg6Re2Gw

    Please provide the ALL possible information I would need, I'm a new person.
     
  2. Offline

    Zombie_Striker

    @WickedFaction
    Why can't this go back on the original thread you created a while back?

    Why are you creating a repeating task? Why not just create a delayed task that waits ___ ticks before removing the player from the cooldown?

    Unless your server reloads, this should not even be an issue. You can try storing the player's cooldown time in a config if you want to reapply cooldowns after reloads/restarts.
     
  3. Offline

    MOMOTHEREAL

    You should not be using the Player object as a key inside a Map. Instead, you should be using the player's Unique ID, as per convention, to link an object to a particular player. To do that, use UUID as your HashMaps key object, and use "containsKey(player.getUniqueId());", for example.

    Second of which, using Bukkit scheduling is a large overkill from the actual solution. Instead, you could only be using a single HashMap to handle all of this:

    Store a timestamp using a HashMap (HashMap<UUID, Long>). When the player executes the command, check if the player's Long object (stored in Milliseconds) has a delay of at least X amount of time (being the cooldown time). If the player's timestamp is over X amount of time, update the HashMap to the current timestamp, using System.currentTimeMillis().

    Sample code for your command method:

    Code:
        Player player = (Player) sender;
        long playerTime = cooldown.get(player.getUniqueId());
        long current = System.currentTimeMillis();
    
        if (current - playerTime < 10*1000L) { // Cooldown of 10 seconds
          player.sendMessage("Wow, you are going too fast!");
          return false;
        }
    
        // **Teleport player here**
        cooldown.put(player.getUniqueId(), current);
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page