Hello i need help I want, when I place sign, if this sign have displayname ( and lore) it place sign with line 1 first lore line etc etc for 4 lines, I tried 2 differents ways I found on this forum: 1st try Code: @EventHandler public void CreateSign(BlockPlaceEvent e){ Player p = e.getPlayer(); Block b = e.getBlock(); if (b instanceof Sign ) { Sign sign = (Sign)e.getBlockPlaced(); if (p.getItemInHand().hasItemMeta()) { ItemMeta meta = p.getItemInHand().getItemMeta(); if (meta.equals(ChatColor.LIGHT_PURPLE + "Death Sign")){ if (meta.hasLore()) // checking it has lore { String lore = meta.getLore().get(0); String lore1 = meta.getLore().get(1); String lore2 = meta.getLore().get(2); String lore3 = meta.getLore().get(3); sign.setLine(0, lore); sign.setLine(1, lore1); sign.setLine(2, lore2); sign.setLine(3, lore3); sign.update(); } } } } } and the second : Code: @EventHandler public void SignPlace(PlayerInteractEvent e) { Player p = e.getPlayer(); Block sign = (Block) e.getClickedBlock(); if (p instanceof Player && e.getAction() == Action.RIGHT_CLICK_BLOCK) { if (!(p.getItemInHand() instanceof Sign)) return; if (!p.getItemInHand().hasItemMeta()) return; if (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "Death Sign")) { sign.setType(Material.SIGN); ItemMeta meta = p.getItemInHand().getItemMeta(); String lore = meta.getLore().get(0); String lore1 = meta.getLore().get(1); String lore2 = meta.getLore().get(2); String lore3 = meta.getLore().get(3); ((Sign) sign).setLine(0, lore); ((Sign) sign).setLine(1, lore1); ((Sign) sign).setLine(2, lore2); ((Sign) sign).setLine(3, lore3); ((BlockState) sign).update(); if (p.getItemInHand().getAmount() > 1) { p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1); }else{ p.getItemInHand().setType(Material.AIR); } } } } I don't have any error in console, and yes I registered the event. Thanks in advance !
@lilian58660 You'll have to listen for the SignChangeEvent instead, as that is the event that is called when a player inputs text into a sign.
@lilian58660 try this: Code: @EventHandler public void onSignChange(SignChangeEvent e) { if (e.getLine(0).equalsIgnoreCase("Something")) { //this checks if a player on change has on it's first line (line 0 ) has the word: Something e.setLine(0, "§6[lol]"); //here you can change the lines, line 0 in the code is line 1 in minecraft. e.setLine(1, "§1hi"); //you can use color codes and everything e.setLine(2, "§1hello"); e.setLine(2, "§1how are you doing"); } } hope this helped
Okay, I will explain what I want to do : I want : when a player place a sign with lore and displayname, the sign place with in lines, the 4 lores lines. Hope you understand ( sorry for my bad english, i'm french ) ^^
You need the BlockPlaceEvent Check if event.getItemInHand()'s material is Material.SIGN, then get the lore from the item. Then cast the event.getBlockPlaced().getState() to sign and change the lines of the sign
@FisheyLP SignChangeEvent* Because BlockPlaceEvent is when the player places the sign, not when they're done editing it
I got this : Code: @EventHandler public void CreateSign(BlockPlaceEvent e){ Player p = e.getPlayer(); Sign b = (Sign) e.getBlockPlaced().getState(); if (b instanceof Sign ) { if (p.getItemInHand().equals(Material.SIGN)) { if (p.getItemInHand().hasItemMeta()) { ItemMeta meta = p.getItemInHand().getItemMeta(); if (meta.equals(ChatColor.LIGHT_PURPLE + "Death Sign")){ if (meta.hasLore()) // checking it has lore { String lore = meta.getLore().get(0); String lore1 = meta.getLore().get(1); String lore2 = meta.getLore().get(2); String lore3 = meta.getLore().get(3); b.setLine(0, lore); b.setLine(1, lore1); b.setLine(2, lore2); b.setLine(3, lore3); b.update(); } } } } } } Not working.
Code: if (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "Death Sign")){ Used this, but not working.
Code: Sign s = (Sign) block.getState(); Then just use s.setLine(0,"Im a line!"); Import org.bukkit.block.Sign EDIT: Use the event SignChangeEvent instead of BlockPlaceEvent
Why are you still posting? More than one person has already told you what you did wrong, and you keep ignoring us.
I can't use blockplaceevent because I need to get lore lines on the item placed... witch is not possible in sign chance event ?