Spawn Tag Plugin

Discussion in 'Plugin Development' started by HCMatt, Jan 9, 2018.

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

    HCMatt

    Hi,

    I am trying to create a spawntag system. It works perfectly just how i want it to apart from 1 thing.

    How it works:

    Player attacks a player, Both players then become spawn tagged. This adds the players names to an arraylist. Once added to the arraylist a timer is set to remove them after a set amount of time that can be found in the config. This arraylist is called if the player tries to /spawn. If the arraylist containts the players name when they /spawn they get a message saying they cant because they are spawn tagged. Messages when untagged are sent to both players.

    Part that doesnt work:

    I am trying to make it to where if the arraylist contains the player's name and they are spawntagged again, the timer resets. I tried removing them from the arraylist and adding them back and setting another timer by using
    if (spawntag.contains(p.getName()){
    spawntag.remove(p);
    Bukkit.getScheduler().scheduleSyncDelayedTask(this, () -> {
    // add back to the arraylist
    }


    this isnt working can anyone please help? thanks.
     
  2. Offline

    Zombie_Striker

    @HCMatt
    Don't use schedulers for this. If a player gets hit multiple times, this will either A) Remove them from the array multiple times, or B) Remove them from the arraylist sooner than expected.

    Instead, use a Hashmap. The keys will be the UUIDs of the player, and the value will be a Long (which represents the time when they were last hit). When a player gets hit, store the current time in millis in the hashmap. When checking if a player can use /spawn, check if the new current time minus the time in the hashmap is greater than some time (Use (Seconds * 1000) to get the time)
     
    ipodtouch0218 likes this.
  3. Offline

    Max8801

    That would require him to set up a scheduler to achieve this:
     
  4. Offline

    HCMatt

    @Zombie_Striker It isnt the /spawn command that isnt working with the scheduler. It is the fact that if you are hit multiple times, once the spawn tag is up, it will tell you you are no longer spawn tagged for each time that you were hit or hit someone.
     
  5. Offline

    Zombie_Striker

    @HCMatt
    Which is why you would change the system to use Hashmaps to log the timestamp. By relying on a hashmap, the timestamp will change for each new hit when the player gets hit, meaning the last time the player was hit will be the one that will be stored and used.
     
  6. Offline

    HCMatt

    im not super experienced in coding, could you give me an example of what you mean please?
     
  7. Offline

    Max8801

Thread Status:
Not open for further replies.

Share This Page