Right Click Sign Event

Discussion in 'Plugin Development' started by MrGiGimz, Apr 22, 2014.

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

    MrGiGimz

    On a right click event, if the sign line 3 reads a certain phrase, how do you make an action happen such as teleporting the player that just right clicked the sign.
     
  2. PlayerInteractEvent, check if the player right clicked a sign, check the line, do stuff.
     
  3. Offline

    BillyBobJoe168

  4. Offline

    MrGiGimz

    ok but how to i get if the line is that though. I have this:

    @EventHandler
    public void onRightClick(PlayerInteractEvent e){

    }

    how do i get the data of the sign
     
  5. Offline

    Adriani6

    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if (e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
    5. Sign s = (Sign) e.getClickedBlock().getState();
    6. if (s.getLine(2).equalsIgnoreCase("LINE 3 TEXT HERE")) {
    7. //Do your magic here.
    8. }
    9. }
    10. }
    11. }


    You can grab a player who clicked the sign using this;

    Code:java
    1. Player p = (Player) e.getPlayer();


    You may then teleport a player using the following
    Code:java
    1. p.teleport(new Location (Bukkit.getWorld("WORLD NAME"), x, y, z));


    Signs might be confusing,
    Line 1 would be .getLine(0)
    Line 2 would be .getLine(1)
    Line 3 would be .getLine(2)
    Line 4 would be .getLine(3)
     
  6. Offline

    MrGiGimz

    hey Adriani6 i have
    Code:java
    1. @EventHandler
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. if (e.getClickedBlock().getType() == Material.WALL_SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
    5. Sign s = (Sign) e.getClickedBlock().getState();
    6. if (s.getLine(0).equalsIgnoreCase("choose")) {
    7. s.setLine(1, "OKAAY");
    8. s.update();
    9. }
    10. }
    11. }
    12. }

    and when i put test on the first line it didnt update it. any help?
     
  7. Offline

    Adriani6

    MrGiGimz

    I bet you haven't registered your events in onEnable.
     
    TigerHix likes this.
Thread Status:
Not open for further replies.

Share This Page