[Solved] Sign is not a sign?

I am trying to get the text from a sign when it is right clicked but every time i click the sign i get the “This is not a sign” error. Does anyone have any idea why this happens? Here is my code:

@Subscribe
public void onSignClicked(PlayerInteractBlockEvent event) {
    Location block = event.getBlock();
    Optional<String> error = SignProcess.isSingWarpValid(block);
    if(error.isPresent()) {
        event.getUser().sendMessage(Texts.of(TextColors.RED, TextStyles.BOLD, "Error: ", TextStyles.RESET, error.get()));
        return;
    }
    String warpName = Texts.toPlain(block.getTileEntity().get().getData(SignData.class).get().getLine(1));
    plugin.getGame().getCommandDispatcher().process(event.getUser(), "warp " + warpName);
}

More code:

public static Optional<String> isSingWarpValid(Location block) {
    if(!block.getTileEntity().isPresent()) {
        return Optional.of("That is not a tile entity.");
    }
    TileEntity tileEntity = block.getTileEntity().get();
    if(!tileEntity.equals(TileEntityTypes.SIGN)) {
        return Optional.of("This is not a sign.");
    }
    if(!tileEntity.getData(SignData.class).isPresent()) {
       return Optional.of("There is no text on the sign.");
    }
    SignData data = tileEntity.getData(SignData.class).get();
    if(!Texts.toPlain(data.getLine(0)).equals("[WARP]")) {
        return Optional.of("This is not a warp sign.");
    }
    if(data.getLine(0).getColor().equals(TextColors.RED)) {
        return Optional.of("The sign is an error sign.");
    }
    if(!WarpManager.getWarpByName(Texts.toPlain(data.getLine(1))).isPresent()) {
        return Optional.of("Warp not found.");
    }
    return Optional.absent();
}

Here is the screenshot:

Ooops. Sorry. I just realised why it’s not working. I’m comparing TileEntity with TileEntityType instead of comparing TileEntityType with TileEntityType.

Sorry for the inconvenience of an unused post. Won’t happen again.

1 Like

It’s all good, you have created a resource for anyone having the same issue in the future :slight_smile:

3 Likes