Override essentials interactevent

Discussion in 'Plugin Development' started by leimekiller, Mar 5, 2014.

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

    leimekiller

    Hello, is it possible to override essentials interact event?

    This is the code I currently use.

    Code:java
    1. @EventHandler(priority=EventPriority.LOWEST)
    2. public void onPlayerInteract(PlayerInteractEvent event)
    3. {
    4. event.setCancelled(false);
    5.  
    6. Block block = event.getClickedBlock();
    7. BlockState state = block.getState();
    8. Action action = event.getAction();
    9. Player player = event.getPlayer();
    10.  
    11. if(state instanceof Sign && action == Action.RIGHT_CLICK_BLOCK)
    12. {
    13. Sign sign = (Sign) state;
    14.  
    15. if(sign.getLine(0).contains("Buy"))
    16. {
    17. Block resBlock = sign.getLocation().add(0, 1, 0).getBlock();
    18. BlockState resState = resBlock.getState();
    19.  
    20. if(resState instanceof Sign)
    21. {
    22. Sign resSign = (Sign) resState;
    23.  
    24. if(resSign.getLine(0).contains("Restricted"))
    25. {
    26. PermissionUser user = PermissionsEx.getUser(player);
    27.  
    28. if(!user.getGroups()[0].getName().equalsIgnoreCase(resSign.getLine(1)))
    29. {
    30. event.setCancelled(true);
    31. player.sendMessage(ChatColor.RED + "You don't have permissions to buy that!");
    32. }
    33. }
    34. }
    35. }
    36. }
    37. }


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

    Arcoz

    Maybe you shouldn't use @EventHandler(priority=EventPriority.LOWEST)
    You set your own interaction Event to be read under all other interactions events..
     
    Pimp_like_me likes this.
  3. Offline

    Pimp_like_me

    Yeah credz to Arcoz, try using
    @EventHandler(priority = EventPriority.MONITOR) instead
     
  4. Offline

    Arcoz

    Pimp_like_me It's really not needed, since normally essentials got priority set to low, so an event without any priorities(that means that they're normal priority) would overwrite essentials.

    And yeah as stated below, you can just disable essentials buy sign
     
  5. Offline

    Pimp_like_me

    Also from what i remember from essentials, you can enable and disable certain signs in the config file. Just a thought
     
  6. Offline

    CubieX

    Don't use MONITOR if you are changing the outcome of the event. (e.g. cancelling it or changing parameters)
    Use HIGH or HIGHEST if necessary.
     
  7. Offline

    Panjab

    Bukkit's system is reversed: HIGHEST < HIGH < LOW < LOWEST
    To ignore any overwriting for sure use:

    Code:
    @EventHandler(priority = EventPriority.LOWST, ignoreCancelled = true)
    
     
  8. Offline

    leimekiller

    I can't turn the sign off in essentials, only people with the right group must be able to buy from a sign which means if there is a sign above the buy sign with another rank name than the player is, they shouldn't be able to buy. Otherwise, they can buy from it.
     
  9. Offline

    AoH_Ruthless

    Panjab
    I don't think you understand what you're talking about.

    leimekiller
    The Events are called in the following order:

    LOWEST
    LOW
    NORMAL (Or Blank)
    HIGH
    HIGHEST
    MONITOR

    Let's say I had a PlayerMoveEvent, and I wanted to cancel the outcome.
    Code:
    @EventHandler (priority = EventPriority.LOWEST)
    public void onMove(PlayerMoveEvent e) {
        e.setCancelled(true);
    }
    Now the event is always cancelled. But say, in another plugin, a PlayerMoveEvent is called and it set's the cancel boolean to false. If the event priority is low, normal, high, highest or monitor it will change the outcome.

    Code:
    @EventHandler (priority = EventPriority.LOW)
    public void onMove(PlayerMoveEvent e) {
        e.setCancelled(false);
    }
    So, first, the LOWEST priority is called. Then Bukkit checks to see if that should be changed. A LOW priority will be called next, then a Normal, and so on. The priority MONITOR has the final say in the outcome of the event.

    Take that with a grain of salt, however. MONITOR should be reserved to plugins that log, for example. At the MONITOR Stage, you should never alter the outcome of the event. So, you can use HIGHEST. (Just as CubieX mentioned)

    Also, essentials events are on LOW priority, meaning you can use NORMAL or blank to override it. You can even disable essentials signs in the config.yml.
     
    NathanWolf likes this.
  10. Offline

    leimekiller

    AoH_Ruthless Check one post up, I cannot disable them, also none of the priorities stop essentials. I use event.setcancelled(true), I don't know if it's enough to stop essentials from doing it's work.
     
  11. Offline

    AoH_Ruthless

    leimekiller
    There's a permission to use the buy signs; you can give those to players if you want them to be able to use it.
     
  12. Offline

    leimekiller

    AoH_Ruthless I want it so they can only buy the items they have permissions for.
     
  13. Offline

    Panjab

    AoH_Ruthless

    So, what exactly different did you tell him about the order how events are called?
     
  14. Offline

    AoH_Ruthless

    Panjab
    You told him the complete opposite of what I did (which was also incorrect).
     
Thread Status:
Not open for further replies.

Share This Page