Essentials Interact With Sign Event Type Help

Discussion in 'Plugin Development' started by SuperOriginal, Mar 12, 2014.

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

    SuperOriginal

    Hello,
    I was wondering how to check if a player right clicks a buy or a sell sign?
     
  2. Offline

    bubba1234119

    One way would use a player interact event, check if its a sign and check the lines. Besides that check the essentials github and look at the API.
     
  3. Offline

    SuperOriginal

    bubba1234119 I tried your method of checking if the sign had [buy], but the code doesn't reach that far. Here is my code:
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. Bukkit.broadcastMessage("1");
    4. Player p = (Player) e.getPlayer();
    5. if(!p.hasPermission("donate.swag")){
    6. Bukkit.broadcastMessage("2");
    7. if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){
    8. if(e.getClickedBlock().getState() instanceof Sign){
    9. Bukkit.broadcastMessage("3");
    10. Sign sign = (Sign) e.getClickedBlock();
    11. if(sign.getLine(0).contains("[Buy]")){
    12. e.setCancelled(true);
    13. p.sendMessage(ChatColor.RED + "You do not have access to that sign!");
    14. }
    15.  
    16. }
    17. }


    Bukkit only broadcasts 1 and 2 which means an Essentials Sign is not being read as Material.SIGN. However, if I use Material.SIGN_POST, it works. But I can't check line numbers of a sign post.

    - Super

    EDIT: I realized that I needed to check the BlockState, not BlockType and it is line 0 not line 1. But the transaction still happens even if I cancel the interaction.
     
  4. Offline

    bubba1234119

    Edit: Try setting it to the highest priority.
     
  5. Offline

    SuperOriginal

    bubba1234119 I really appreciate your help thus far, but now I have come to another issue. Even when I cancel the interaction, the transaction still happens!
     
  6. Offline

    ledship

    The transaction still happens because you are only canceling the event for your plugin, Not for essentials.
     
  7. Offline

    SuperOriginal

    ledship bubba1234119 Ok so I took a different route and dove into essentials API and I came up with this
    Code:java
    1. @EventHandler
    2. public void onInteract(SignInteractEvent e){
    3. if(e.getEssentialsSign().getClass().equals(SignBuy.class)){
    4.  
    5. e.setCancelled(true);
    6. e.getUser().sendMessage(ChatColor.RED + "You do not have access to that sign!");
    7. }
    8.  
    9.  
    10. }


    I don't know if you guys have any idea on this but how could I check if User has a permission? Or how can I cast a User to a Player so I can use that? Because the essentials IUser doesn't have a built in ability to check perms that I can see.
     
  8. Offline

    bubba1234119

    I was just looking into the API actually.
    Try this Player player = (Player)e.getUser();
     
  9. Offline

    SuperOriginal

    I tried it, it threw an error saying User cannot be cast to Player :(
     
  10. Offline

    bubba1234119

  11. Offline

    SuperOriginal

    I figured it out. You need e.getUser().getBase().hasPermission(...); Thanks for the help guys!
     
  12. Offline

    bubba1234119

    Glad you got it working!
     
    supercube101 likes this.
Thread Status:
Not open for further replies.

Share This Page