EternalCore icon indicating copy to clipboard operation
EternalCore copied to clipboard

Sign editor (/sign setline <index> <text> command)

Open vLuckyyy opened this issue 11 months ago • 1 comments

vLuckyyy avatar Jan 11 '25 20:01 vLuckyyy

@Command(name = "signedit setline")
@Permission("signedit.setline")
public class SignEditCommand implements MiniMessageHolder {

    private final NoticeService noticeService;
    private final SignConfig signConfig;

    public SignEditCommand(NoticeService noticeService, SignConfig signConfig) {
        this.noticeService = noticeService;
        this.signConfig = signConfig;
    }

    @Execute
    void execute(@Context Player player, @Arg Integer index, @Join String text) {
        Block targetBlock = player.getTargetBlockExact(5);
        if (targetBlock == null || !(targetBlock.getState() instanceof Sign sign)) {
            this.noticeService.create()
                .player(player.getUniqueId())
                .notice(this.signConfig.noSignFound)
                .send();
            return;
        }

        SignSide frontSide = sign.getSide(Side.FRONT);
        if (index < 0 || index >= frontSide.lines().size()) {
            this.noticeService.create()
                .player(player.getUniqueId())
                .notice(this.signConfig.invalidIndex)
                .send();
            return;
        }

        frontSide.line(index, MINI_MESSAGE.deserialize(text));
        sign.update();

        this.noticeService.create()
            .player(player.getUniqueId())
            .notice(this.signConfig.lineSet)
            .send();
    }
}

vLuckyyy avatar Jan 11 '25 20:01 vLuckyyy