Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-886 Sign editor (/sign setline <index> <text> command) #895

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings;
import java.util.LinkedHashMap;
import java.util.Set;

import com.eternalcode.multification.notice.Notice;
import net.dzikoysk.cdn.entity.Contextual;
import net.dzikoysk.cdn.entity.Description;
import net.dzikoysk.cdn.entity.Exclude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.eternalcode.core.feature.signeditor;

import com.eternalcode.core.notice.NoticeService;
import dev.rollczi.litecommands.annotations.argument.Arg;
import dev.rollczi.litecommands.annotations.command.Command;
import dev.rollczi.litecommands.annotations.context.Context;
import dev.rollczi.litecommands.annotations.execute.Execute;
import dev.rollczi.litecommands.annotations.join.Join;
import dev.rollczi.litecommands.annotations.permission.Permission;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.block.sign.Side;
import org.bukkit.block.sign.SignSide;
import org.bukkit.entity.Player;

@Command(name = "signedit")
@Permission("eternalcode.signedit")
public class SignEditCommand {

private final NoticeService noticeService;
private final MiniMessage miniMessage;

public SignEditCommand(NoticeService noticeService, MiniMessage miniMessage) {
this.noticeService = noticeService;
this.miniMessage = miniMessage;
}

@Execute
void execute(@Context Player player, @Arg Integer index, @Join String text) {
Block targetBlock = player.getTargetBlock(null, 5);

if (!(targetBlock.getState() instanceof Sign sign)) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.signEdit().noSignFound())
.send();
return;
}

SignSide frontSide = sign.getSide(Side.FRONT);
if (index < 0 || index >= frontSide.getLines().length) {
this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.signEdit().invalidIndex())
.send();
return;
}

frontSide.setLine(index, this.miniMessage.deserialize(text).toString());
sign.update();

this.noticeService.create()
.player(player.getUniqueId())
.placeholder("{INDEX}", index.toString())
.placeholder("{TEXT}", text)
.notice(translation -> translation.signEdit().lineSet())
.send();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,12 @@ interface JailSection {
Notice jailCannotUseCommand();
}


SignEditSection signEdit();

interface SignEditSection {
Notice noSignFound();
Notice invalidIndex();
Notice lineSet();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,15 @@ public static class ENJailSection implements JailSection {
@Description({" ", "# {PLAYER} - Player who has been detained", "# {REMAINING_TIME} - Time of detention", "# {DETAINED_BY} - Player who detained the player"})
public Notice jailListPlayerEntry = Notice.chat("<green>► <white>{PLAYER} <gray>(<white>{REMAINING_TIME}<gray>) <white>detained by <green>{DETAINED_BY} <white>!");
}

@Description({ " ", "# Ta sekcja odpowiada za wiadomości dotyczące edycji tabliczek"})
public PLTranslation.SignEditor signEditor = new PLTranslation.SignEditor();

@Getter
@Contextual
public static class SignEditor {
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Sign not found!");
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>Invalid index!");
public Notice lineSet = Notice.chat("<green>► <white>Line <green>{LINE} <white>set to <green>{TEXT}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -941,4 +941,15 @@ public static class PLJailSection implements JailSection {
@Description({" ", "# {PLAYER} - Gracz który jest uwięziony, {DETAINED_BY} - Gracz który uwięził gracza, {REMAINING_TIME} - Czas pozostały do uwolnienia"})
public Notice jailListPlayerEntry = Notice.chat("<green>► <white>Gracz <green>{PLAYER} <white>został uwięziony przez <green>{DETAINED_BY} <white>na czas <green>{REMAINING_TIME} <white>!");
}

@Description({ " ", "# Ta sekcja odpowiada za wiadomości dotyczące edycji tabliczek"})
public SignEditor signEditor = new SignEditor();

@Getter
@Contextual
public static class SignEditor {
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Nie odnaleziono tabliczki!");
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>Nieprawidłowy indeks!");
public Notice lineSet = Notice.chat("<green>► <white>Ustawiono linię <green>{LINE} <white>na <green>{TEXT}");
}
}