Getting sign lines

Hi,

I just started learning sponge plugin developing, and im trying to get the lines of a sign from a player interact event.
I got this piece of code:

public class SignClickListener {

    @Listener
    public void onPlayerInteract(InteractBlockEvent event, @First Player player) {
        Optional<SignData> sign = event.getTargetBlock().getOrCreate(SignData.class);
    }
}

but i get “inference variable T has incompatible bounds” error
if someone could provide a snippet i would be very thankful

Thanks for helping

You need to retrieve the SignData from the TileEntity at the Location, not from the BlockState.

It should be something like this:

Optional<SignData> signData = event.getTargetBlock().getLocation().get().getTileEntity().flatMap(t -> t.getOrCreate(SignData.class))

signData will be present if the TileEntity exists, and getOrCreate returns a present Optional (which it always should for a Sign TE).

1 Like

Thanks, just what i needed :slight_smile: