Casting to Sign

Discussion in 'Spigot Plugin Development' started by anakinsky249, Aug 9, 2018.

  1. Hi, so I'm using spigot 1.13. I'm trying to get the first line of a sign when it's placed. Here's what I'm currently using:
    Code (Text):
    Sign sign = (Sign) e.getBlock().getState();
    However, when using this, nothing gets printed to the console. I know it reaches this bit of code since adding another println with whatever text right above it works for that one, but not the sign one. Not using the getState() part makes it impossible to cast. There are no errors, so I can't really figure out what's going on. I can't use the SignChangeEvent, since I also need to use some methods from BlockPlaceEvent, such as getBlockAgaisnt().

    Am I missing something there ?
  2. I think the BlockPlace event is fired when you place the sign, not when you complete the lines.
    At that point line0 is empty

    Edit: Use Logger instead of System.out.println
    • Agree Agree x 1
  3. So I would assume the SignChangeEvent is the only option then ? Also, I don't really care about logger or sysout, it's just for debugging purposes. I don't have any of theses in my final code.
  4. Strahan


    Yup. At least, as far as automatic triggers go.

    Even in debugging it's best to use proper standards, otherwise you build bad habits.
  5. So then how can I get the BlockAgaisnt ? I need to check if its placed next to a certain block type and the SignChangeEvent doesn't allow that... There's not even a way to get the sign's location...
  6. event.getBlock().getRelative(BlockFace)
  7. Strahan


    Eh? Of course you can get the sign location. That event exposes .getBlock().


    Code (Text):

    public void onChange(SignChangeEvent e) {
      Block b = e.getBlock();
      if (b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
        Sign s = (Sign)b.getState().getData();
        Block attached = b.getRelative(s.getAttachedFace());
        e.getPlayer().sendMessage("Block attached to " + attached.getType().name());
    Be sure you are importing sign from material.
    #7 Strahan, Aug 9, 2018
    Last edited by a moderator: Aug 9, 2018
  8. Oh, sorry I'm dumb I was only looking at its direct methods... Not the inherited ones...
    #8 anakinsky249, Aug 9, 2018
    Last edited by a moderator: Aug 9, 2018