How to cancel events from separate events?

Discussion in 'Plugin Development' started by ariaDEE, Apr 24, 2014.

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

    ariaDEE

    Hey. So I've been looking around for a while and can't figure out how to cancel a specific event within another event. For example, I have an event where it checks if the player hasn't moved in 5 minutes. If they haven't, I want to cancel a different event I have (PlayerDeathEvent).
    I've tried things like onPlayerDeath.setCancelled, but they don't work.
     
  2. Offline

    ariaDEE


    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent event){
    3. long lastMoved = System.currentTimeMillis();
    4. lastMoved = System.currentTimeMillis();
    5. if (System.currentTimeMillis() - lastMoved >= 300){
    6. //cancel other event
    7. }
    8. }


    Code:java
    1. @EventHandler
    2. public void onPlayerDeath(PlayerDeathEvent event) {
    3. //event stuff
    4. }
     
  3. You'll want to store the lastMoved per player, like in a hashmap. And then in the PlayerDeathEvent, check the value.
     
  4. Offline

    ariaDEE

    Why would I need to store it in a hashmap? And what do you mean by check the value?
     
  5. ariaDEE Because you can't cancel an event from a different event. And by check the value I mean... check the value?

    Code:
    if(System.currentTimeMillis()- lastMoved >=300){
     
Thread Status:
Not open for further replies.

Share This Page