Solved Cancel event while other is running

Discussion in 'Plugin Development' started by Failplease, Jan 7, 2014.

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

    Failplease

    I have an event that makes it so that when a block is clicked with an item, the block is added the the config and item meta is added to the item.

    I also have an event that makes it so that when a block that is registered in the config is clicked with an item that has the item meta from the previous event, the block becomes unregistered and the item loses its meta.

    What happens is that when I click a block when the item has no meta, the block becomes registered and the items gains its meta, but now since the block is registered and the item has that meta, the other event runs which unregisters the block and removes the item's meta. How do I stop this from happening?
     
  2. Offline

    Garris0n

    Well, first of all you should just put them both in one listener and choose the order. Second, to actually answer your question, who knows unless you set event priorities for both of them. It's probably put into some weird order, maybe just random.
     
  3. Offline

    Failplease

    Garris0n
    Changing the priority/the order of the events only reverses the order of my problem.

    Is there anyone that can help me here?
     
  4. Offline

    JRL1004

    Failplease Why not just add a cooldown between when the player registers the block and when they can unregister it?
     
  5. Offline

    Failplease

    JRL1004
    Sounds good, but tell me how I would do that...
     
  6. Offline

    JRL1004

    Failplease make it so the events add a player's NAME (never use an actual player instance) in a list/HashSet/TreeSet/etc and then make a runnable to remove the player from it. On the other method, check if the player is in the list before registering/unregistering the block.
     
  7. Offline

    Failplease

    JRL1004
    Ok I see, thanks.
    Before you had posted I had already been playing around with lists..
     
  8. Offline

    JRL1004

    Failplease I prefer HashSets since it only allows for one of each variable. This makes it so that the player cannot be added to the list multiple times.
     
  9. Offline

    Garris0n

    Do the already registered check first. If it is, just unregister it and return. Then add the register code below it...
     
  10. Offline

    Failplease

    JRL1004 and Garris0n
    I have made the following method:
    Code:
    public void angelCoolDown(long seconds, final Player player, final List<String> list) {
        Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
            public void run() {
                if(list.contains(player.getName())) {
                    list.remove(player.getName());
                }
            }}, 20*seconds);
    }
    I use the following code after it for the cooldown:
    Code:
    angelCoolDown(1, p, a);
    if(!a.contains(p.getName())) {
      //my event runs
    }
    When I do this, nothing has changed from my error...
    How do I continue?
     
  11. Offline

    Garris0n

    I'm a bit confused as to exactly what you're trying to do. Could you post all the relevant code (such as your event listeners)?
     
  12. Offline

    JRL1004

    Garris0n I think Failplease is adding a cooldown between register/unregister events to stop the block from doing one then instantly reverting.
     
  13. Offline

    Failplease

    Garris0n and JRL1004
    Thank you for your help. The problem was that I was not putting the whole code that I wanted to delay into the Runnable. Everything works fine now. :D
     
  14. Offline

    JRL1004

    Failplease Okay. If everything is working now then go ahead and mark this thread as solved. Otherwise, if you want/need some more help, this is a great place to ask another question.
     
Thread Status:
Not open for further replies.

Share This Page