Solved on sign click

  • After careful consideration and due to limited usage, we’ve made the decision to discontinue the PaperMC forums. Moving forward, we recommend using Hangar for plugin uploads, and for all other community discussions and support, please join us on Discord.

AggerTV

New member
Sep 27, 2023
8
0
1
Hello, I am making a guard plugin, and I want to open a gui if a guard clicks on a designated guard sign.

The current way I am doing it
Java:
public class SignClickListener implements Listener {

    private final IGuardMainMenu guardMainMenu;

    @Inject
    public SignClickListener(IGuardMainMenu guardMainMenu) {
        this.guardMainMenu = guardMainMenu;
    }

    @EventHandler(ignoreCancelled = true)
    public void onSignClick(PlayerInteractEvent event) {
        if (event.getClickedBlock() != null && event.getClickedBlock().getState() instanceof Sign) {
            Sign sign = (Sign) event.getClickedBlock().getState();

            if (sign.getSide(Side.FRONT).lines().contains(text("[Vagt]"))) {
                Player player = event.getPlayer();

                if (!player.hasPermission("vagtplugin.guardsign.open")) {
                    player.sendMessage(text().content("Du har ikke adgang til dette!").color(RED).decorate(ITALIC).build());
                    event.setCancelled(true);
                    return;
                }

                if (event.getAction() == Action.LEFT_CLICK_BLOCK && player.hasPermission("vagtplugin.sign.destroy") && player.isSneaking()) {
                    player.sendMessage(text().content("[VagtPlugin] ").color(YELLOW)
                            .append(text().content("Du har nu fjernet et ").color(GRAY))
                            .append(text().content("vagt-skilt").color(AQUA))
                            .build());
                    return;
                }

                guardMainMenu.open(player);
                event.setCancelled(true);
            }
        }
    }
}

This works, but it wont work if I for example add color codes to the sign, and I am sure that there are better ways of doing it.

So my question is: what is a better way for doing x stuff when clicking on specific signs, like in my case when clicking a guard sign?

Thanks :)