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.
try this, I never knew this whas possible without nms 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
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
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!!!"); }
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.
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()