Scheduling Events for each Player

Discussion in 'Plugin Development' started by Qwahchees, Feb 11, 2013.

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

    Qwahchees

    So I'm developing a plugin for my RPG Server, and you can obtain passive powers like Strength 2. I wanted to make a debuff for when you die, but I have the buff reactivate on inventoryOpen().

    So how would I create a scheduler for each player, that when a player dies they will get a timer and during that timer a debuff is activated (potion effect).

    I started off with using, PlayerSpawnEvent() but it hasn't been buffing after you respawn which I can't understand why.


    Thanks.
     
  2. Offline

    slater96

    PlayerRespawnEvent and add a potion effect for so long?
    Not sure what you mean totally.
     
  3. Offline

    drtshock

    Show some of your code, even if it isn't working at all. People are more likely to help out if they see you've tried yourself :)
     
  4. Offline

    Qwahchees

    I'm currently in class bored out of my mind, but.

    p.addPotionEffect() is what I use to add the effect, so ignore the "so long".
    As for the code ill add it tonight.

    The scheduling or a timer for an individual entity is what I find difficult.
     
  5. Offline

    mastermustard

    http://wiki.bukkit.org/Scheduler_Programming
     
  6. Offline

    Qwahchees

    Code:
    public class OnRespawnListener implements Listener{
        public static PotionPermissions plugin;
     
        public OnRespawnListener(PotionPermissions instance) {
            plugin = instance;
        }
     
        @EventHandler(priority = EventPriority.HIGH)
        public void onRespawn(PlayerRespawnEvent event) {
            Player p = (Player) event.getPlayer();
            // Speed
            if (p.hasPermission("potionpermissions.speed.one")) {
                p.removePotionEffect(PotionEffectType.SPEED);
                p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 36000, 0));
            }
    This is my code, and I've applied this in the main class:

    Code:
            private final OnRespawnListener rL = new OnRespawnListener(this);
    public void onEnable() {
     
    PluginManager pm = getServer().getPluginManager();
                    pm.registerEvents(rL, this);
    }
     
    public void onDisable() {
    //
    }
    }
    Er, so I'm gonna update this.

    What I wanted to do was have a Task Scheduler repeat itself every 10 seconds to check a .txt or .config file for if the player was eligible for a buff. When a player dies, their profile in the .txt file sets the buffable: 1 to 0, which denies them a buff onRespawn. A timestamp is given to them and placed in the their .txt file. The Task Scheduler checks the .txt file every 10 seconds, and if the server time is passed or equal to the time stamp, it removes the time stamp and changes buffable to 1, as well as rebuffing the player and removing all previous debuffs.

    That is the story.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  7. Offline

    Scipione

    Dunno how many players you have, but adding a repeateable task for every single player that checks every 10 seconds will need some performance

    as for the problem itself, you could add a single repeated task timer which checks a hashmap for playername entry with a timestamp (Which you can fill on playerdeath event). But you should check if the player is still online b4 trying to apply the buff.
     
  8. Offline

    Qwahchees

    So inside a Hashmap, does that data stay loaded within the RAM till the server stops? Is there a way to save the upon a server stop? And if a player logs out, would I store the data and upon login, check each player for a data file of a debuff?
     
Thread Status:
Not open for further replies.

Share This Page