Sign click event

Discussion in 'Plugin Development' started by n31ln3t, Apr 7, 2013.

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

    n31ln3t

    Hello, is there a way to find out if player has clicked on a sign with a specific text?
    This is my code http://pastebin.com/90gGSinK

    You see how I have signChangeEvent in there? It basicly just changes [map] into [MAP], so how do I make it so that when player clicks on the sign, the [map] sign, the event is trigged and I can use the code I want? Like for example, in mobarena the [archer] sign, when you click on it, it triggers an event which gives you a bow and says you're now archer.
     
  2. Offline

    MrTheNewGuy

    i hope this will help
     
  3. Offline

    xize

    try this:), I never knew this whas possible without nms:p

    Code:
    @EventHandler
    public void mobdamage(PlayerInteractEvent e) {
      if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
      if(e.getClickedBlock().getType() == Material.SIGN || e.getClickedBlock().getType() == Material.SIGN_POST || e.getClickedBlock().getType() == Material.WALL_SIGN) {
        Sign sign = (Sign) e.getClickedBlock().getState();
        if(sign.getLine(0).equalsIgnoreCase("test")) {
        sign.setLine(1, "hello " + e.getPlayer().getName());
        sign.update();
        } else {
       
        }
      } else{
       
      }
      } else {
      //do nothing
      }
    }
    
    also if you want to update text (like essentials) you need to use SignChangeEvent if the player clicks done when placing a sign
     
  4. Offline

    n31ln3t

    Thanks guys, you both really helped me, just another issue. have a look at this code:
    ItemStack currentitem = event.getCurrentItem();
    if(currentitem==282)

    The 282 means the item id of mushroom stew,
    I want it to check if the currentitem = mushroom stew, but eclipse keeps saying: mismatch from itemstack to int

    EDIT:
    Nvm, I just read something, I think it's currentitem.contains(282); the proper way :p
     
  5. Offline

    MrTheNewGuy

    wen is it suppposed to check if it is mushroomstew?
    you can do this:
    Code:
    Player player = event.getPlayer();
            int blockid = player.getItemInHand().getTypeId();
           
            if(blockid == 353){
                World world = player.getWorld();
                Location location = player.getLocation();
                world.createExplosion(location, 3);
                player.chat(ChatColor.DARK_RED + "BOOM!!!");
            }
     
  6. Offline

    n31ln3t

    Hmm, guys, what does .getState() do? It says on the javadoc it returns the state, but what state? I don't have any idea what state is.

    Btw, thanks for that, although it works but when I make it check to see if the text = [MAP] it doesn't work.

    Here is my code:
    if (event.getClickedBlock().getState() instanceof Sign){
    Sign sign = (Sign) event.getClickedBlock().getState();
    if(sign.getLine(0).equalsIgnoreCase("[map]")) {
    event.getPlayer().sendMessage("Works!");
    }
    }
    EDIT: IGNORE THE TOP, I found out it was .consists by looking at another thread.

    EDIT: to check if a sign line is empty do I do if(sign.getLine(1)==null) ?

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

    xize

    Just do

    Code:
    if(s.getLine(0).length != 0) {
    
    } else (
    
    } else if(s.getLine(1).length != 0){
    
    } else {
    
    }
    
    Or use a equalsIgnorecase() case or contains()
     
Thread Status:
Not open for further replies.

Share This Page