Sign place

Discussion in 'Plugin Development' started by lilian58660, Jul 6, 2015.

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

    lilian58660

    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 !
     
  2. Offline

    mythbusterma

    @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.
     
  3. Offline

    lilian58660

    How I detect what I replace ? because I need to hook what I want to replace
     
  4. Offline

    mythbusterma

  5. Offline

    HenkDeKipGaming

    @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 :)
     
  6. @lilian58660
    You're casting from block to sign, which will cause a ClassCastException
     
  7. Offline

    lilian58660

    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 ) ^^
     
  8. 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
     
  9. @FisheyLP
    SignChangeEvent* Because BlockPlaceEvent is when the player places the sign, not when they're done editing it
     
  10. Offline

    lilian58660

    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.
     
  11. meta isn't equal to a string
    Check the displayName of the meta instead
     
  12. Offline

    lilian58660

    Code:
                        if (p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.LIGHT_PURPLE + "Death Sign")){
    Used this, but not working.
     
  13. Offline

    lilian58660

    Bump I need this c:
     
  14. 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
     
  15. Actually: No. Read the thread
     
  16. Offline

    mythbusterma

    Why are you still posting? More than one person has already told you what you did wrong, and you keep ignoring us.

     
  17. Offline

    lilian58660

    I can't use blockplaceevent because I need to get lore lines on the item placed... witch is not possible in sign chance event ?
     
  18. Offline

    mythbusterma

  19. Offline

    lilian58660

    how ? what is the best way
     
  20. Offline

    mythbusterma

Thread Status:
Not open for further replies.

Share This Page