Solved Open inventory when i click in a sign

Discussion in 'Plugin Development' started by idkG0D, Jan 30, 2019.

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

    idkG0D

    I want to open a inventory when the palyer click in a Sign with a specific text in a specific line...
    Like as...

    If "resoup" was written in the line(2) & Event.getAction() == Action.RIGHT_CLICK_BLOCK then
    Player will open a new inventory with soups.

    My code:
    Code:
    @EventHandler
        public void placaClick(PlayerInteractEvent e){
            Sign placa = (Sign) e.getClickedBlock();
            Player p = e.getPlayer();
    
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock() == placa) {
                    if (placa.getLine(2).equals("§a§lRESOUP")) {
                        Inventory resoup = Bukkit.createInventory(null, 54, "§a§lRESOUP");
                        p.openInventory(resoup);
                        p.playSound(p.getLocation(), Sound.LEVEL_UP, 10F, 10F);
                    }
    
    
                }
            }
    
    
        }
    Help please :c
     
  2. Offline

    Tango_

    You got most of the way there, there may have been an issue with your imports, but it should be something like this:

    Code:
        @EventHandler
        public void placaClick(PlayerInteractEvent e){
            Block b = e.getClickedBlock();
            Player p = e.getPlayer();
    
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (e.getClickedBlock().getType() == Material.SIGN || e.getClickedBlock().getType() == Material.SIGN_POST) {
                    org.bukkit.block.Sign sign = (org.bukkit.block.Sign) b.getState();
                    if (sign.getLine(2).equals("§a§lRESOUP")) {
                        Inventory resoup = Bukkit.createInventory(null, 54, "§a§lRESOUP");
                        for(int i = 0; resoup.getSize() > i; i++) resoup.setItem(i, new ItemStack(Material.MUSHROOM_SOUP, 1));
                        p.openInventory(resoup);
                        p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 10F, 10F);
                    }
                }
            }
        }
    And then when you click a sign that looks like this:
    Sign example (open)

    [​IMG]
    [​IMG]


    it will run :p
     
  3. Offline

    KarimAKL

    @idkG0D Try something like this:
    Code:Java
    1. @EventHandler
    2. public void placaClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    5. if (e.getClickedBlock() instanceof Sign) {
    6. Sign placa = (Sign) e.getClickedBlock();
    7. if (placa.getLine(2).equals("§a§lRESOUP")) {
    8. Inventory resoup = Bukkit.createInventory(null, 54, "§a§lRESOUP");
    9. p.openInventory(resoup);
    10. p.playSound(p.getLocation(), Sound.LEVEL_UP, 10F, 10F);
    11. }
    12. }
    13. }
    14. }

    Also try putting messages in between the code to see where it stops if it doesn't open the inventory.
     
  4. Offline

    idkG0D

    It did'nt worked :c

    IT RUUN!!! Just changed the e.getClickedBlock.getType() == Material.SIGN_POST
    to
    Material.WALL_SIGN :v
    Thanks a lot bro!! <3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 31, 2019
Thread Status:
Not open for further replies.

Share This Page