1.14.4 Checkink right click signs

Discussion in 'Spigot Plugin Development' started by FraterClub, Jan 16, 2020.

  1. I'm trying to put in a hashmap the right clicked sign, but with the signs update in 1.14, I'm not able. How should I do it?

    My code is this:

    Code (Java):
       @EventHandler
        public void clickSign(PlayerInteractEvent e) {
            Player p = e.getPlayer();

            if(e.getAction() == Action.RIGHT_CLICK_BLOCK && e.getClickedBlock() instanceof Sign) {
                s.getSigns().put(p, (Sign)e.getClickedBlock());
                p.sendMessage("Guardado");
            }

        }
     
  2. use e.getBlock().getState()
     
    • Agree Agree x 1
  3. Adding to that, you could also get the type of the Block (Block#getType(), which returns a Material)
    If you are unsure about what the actual Type of the Block is, you can always print the type
    Code (Java):
    System.out.println(e.getClickedBlock().getClass());
    In most cases, however, a block (as @robertlit said) is better defined by its block-state.
     
  4. Remember the built in spawn protection in server.properties prevents right clicks in spawn so turn it off or don't test in protected spawn area ;)
     
  5. Strahan

    Benefactor

    Also be sure you imported Sign properly. You want it from org.bukkit.block not the one from org.bukkit.material.
     
    • Agree Agree x 1
  6. If the replys above dont solve your problem, you can try checking for diffrent signtypes.

    SIGNPOST, WALLSIGN etc.....
     
  7. Strahan

    Benefactor

    "Sign" covers them as well:

    [​IMG]
     
  8. To add on, I’d suggest storing the location not the Sign instance itself.
     
    • Like Like x 1
    • Agree Agree x 1
  9. yea storing objects in a map prevents them from unloading, basically a memory leak
     
  10. You’d store a Location because it makes sense, not because it causes a memory leak. You can leak memory storing anything if you don’t remove it, just storing a block doesn’t cause a memory leak in itself.