Scheduler problems

Discussion in 'Plugin Development' started by nopresnik, Feb 10, 2013.

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


    Hey guys. Currently working on a big plugin and I've seem to run into a dead end.
    My code, here

    It seems to be doing It's job but the potion effect seems to be jerking on/off. I'm looking for a solid potion effect on the player.


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


    Damn I hate it when my potion effect jerks off.
    microgeek and ZeusAllMighty11 like this.
  3. Offline


    It could be because it is reapplying every 10 seconds or it could be caused by the mega lag this process will cause. Scanning every player on the server every 10 seconds on the main thread to see if they are wearing iron armour and applying an effect is pretty heavy duty.

    I don't think there is an event for potion applying/wearing off... but if you just check players inventory on inventory close event and (if wearing the armour you want), put their name in a hashmap and just check and reapply effect to those in the hashmap every x amount of ticks. Would also think an async task would be better.

    I Would also remove players from hashmap on quit (or onDisable) and recheck their inventory when they join (and when onEnable is called).

    Will be a gazillion times faster and more effective.
  4. Offline


    Another option. Listen to an InventoryEvent, since it's player related it only fires when they change their inventory. When you apply the armor check to see if they have full iron armor, and give them a very long potion effect (tick count is in integers so just give it a time of 2,147,483,647) and whenever they don't have it and they have the potion effect just remove it.
    Geekola likes this.
  5. Offline


    Actually, a much better approach.
  6. Offline


    Thanks for all your replies! I'll give each a shot.
Thread Status:
Not open for further replies.

Share This Page