Cancel VehicleExit event?

Discussion in 'Plugin Development' started by Mathias Eklund, Sep 27, 2013.

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

    Mathias Eklund

    Hey, just wondering if it's possible to cancel the vehicle exit event if a player is in a hashmap. Been trying, but can't seem to figure it out. . .
    Code:java
    1. @EventHandler
    2. public void onVehicleExit(VehicleExitEvent event){
    3. Player player = (Player) event.getExited();
    4. if ((event.getExited() instanceof Player) && (arrested.containsKey(player))){
    5. event.setCancelled(true);
    6.  
    7. }
    8. }
    This code is not working.
     
  2. Offline

    1Achmed1

    Is your hash map setup?
     
  3. Offline

    Mathias Eklund

    1Achmed1 yes it is :)
    Code:java
    1. public final HashMap<Player, ArrayList<Block>> cop = new HashMap<Player, ArrayList<Block>>();
    2. public final HashMap<Player, ArrayList<Block>> civ = new HashMap<Player, ArrayList<Block>>();
    3. public final HashMap<Player, ArrayList<Block>> arrested = new HashMap<Player, ArrayList<Block>>();

    Thats all my hashmaps for this plugin :)
     
  4. Offline

    1Achmed1

    Then two things:
    1. Are you hash maps setup on a different file?
    2. You may want to make your event priority highest.
     
  5. Offline

    Mathias Eklund

    1Achmed1 All my code is in one class, and added (priority = EventPriority.HIGH), no diffrence, I think i have to use another method. Just can't figure out which one.
     
  6. Offline

    1Achmed1

    Try highest
     
  7. Offline

    Tirelessly

    Don't store Player objects, store their name instead.
     
  8. Offline

    1Achmed1

    Also, try
    Player player = event.getPlayer();
    This works because the event was already triggered.
     
  9. Offline

    Mathias Eklund

    If i put it to highest i can't even get the player arrested, so no. Does not work 1Achmed1

    That doesn't work :)

    I don't see how that helps my situation?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  10. Offline

    Tirelessly

    It helps your plugin, the server, and possibly your problem.
     
  11. Offline

    Mathias Eklund

    Yes i know it helps the plugin, but as of yet it isn't that demanding, once i've got all the features that i want made, i will change the saving system, just has it this way cause it's easier.
     
  12. Offline

    Tirelessly

    Well it is demanding, because every player that gets added to those maps will have their instance remain in memory forever (until a restart). That's a big cause of memory leaks.
     
  13. Offline

    Mathias Eklund

    Yes i know, and fyi, this plugin will never get released, It's for my upcoming RP server which is still in dev. So no worries about that atm. As we are only testing.
     
Thread Status:
Not open for further replies.

Share This Page