Skip to content

Commit 93811f8

Browse files
igoyekvLuckyyyRollczi
committed
GH-886 Sign editor (/sign setline <index> <text> command) (#895)
* primary implementation (to be fixed) Took 1 hour 0 minutes * Update command name Took 11 minutes * Refactor messages, add compatibility for non-side-based sing's * Use Block#getTargetBlockExact * Fix index placeholder. * followed all instructions followed all instructions fixed all (i think) issues and critical errors now its working :), tested Took 32 minutes * Update eternalcore-core/src/main/java/com/eternalcode/core/feature/signeditor/SignEditorCommand.java * Fix for 1.19.4 compatibility Took 7 minutes * Fix jar build Took 34 minutes * Code review --------- Co-authored-by: Martin Sulikowski <[email protected]> Co-authored-by: Norbert Dejlich <[email protected]>
1 parent 37e390a commit 93811f8

File tree

8 files changed

+201
-3
lines changed

8 files changed

+201
-3
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.eternalcode.core.feature.signeditor;
2+
3+
import com.eternalcode.commons.adventure.AdventureUtil;
4+
import com.eternalcode.core.compatibility.Compatibility;
5+
import com.eternalcode.core.compatibility.Version;
6+
import com.eternalcode.core.injector.annotations.Inject;
7+
import com.eternalcode.core.notice.NoticeService;
8+
import dev.rollczi.litecommands.annotations.argument.Arg;
9+
import dev.rollczi.litecommands.annotations.command.Command;
10+
import dev.rollczi.litecommands.annotations.context.Context;
11+
import dev.rollczi.litecommands.annotations.execute.Execute;
12+
import dev.rollczi.litecommands.annotations.join.Join;
13+
import dev.rollczi.litecommands.annotations.permission.Permission;
14+
import net.kyori.adventure.text.minimessage.MiniMessage;
15+
import org.bukkit.block.Block;
16+
import org.bukkit.block.Sign;
17+
import org.bukkit.entity.Player;
18+
19+
@Command(name = "signedit")
20+
@Permission("eternalcode.signedit")
21+
@Compatibility(to = @Version(minor = 19, patch = 4))
22+
public class SignEditorCommand {
23+
24+
private final NoticeService noticeService;
25+
private final MiniMessage miniMessage;
26+
27+
@Inject
28+
public SignEditorCommand(NoticeService noticeService, MiniMessage miniMessage) {
29+
this.noticeService = noticeService;
30+
this.miniMessage = miniMessage;
31+
}
32+
33+
@Execute(name = "set")
34+
void execute(@Context Player player, @Arg int line, @Join String text) {
35+
Block targetBlock = player.getTargetBlockExact(5);
36+
37+
if (targetBlock == null) {
38+
return;
39+
}
40+
41+
if (!(targetBlock.getState() instanceof Sign sign)) {
42+
this.noticeService.create()
43+
.player(player.getUniqueId())
44+
.notice(translation -> translation.signEditor().noSignFound())
45+
.send();
46+
return;
47+
}
48+
49+
if (line < 1 || line >= sign.getLines().length) {
50+
this.noticeService.create()
51+
.player(player.getUniqueId())
52+
.placeholder("{LINE}", String.valueOf(line))
53+
.notice(translation -> translation.signEditor().invalidIndex())
54+
.send();
55+
56+
return;
57+
}
58+
59+
sign.setLine(line - 1, AdventureUtil.SECTION_SERIALIZER.serialize(this.miniMessage.deserialize(text)));
60+
sign.update();
61+
62+
this.noticeService.create()
63+
.player(player.getUniqueId())
64+
.placeholder("{LINE}", String.valueOf(line))
65+
.placeholder("{TEXT}", text)
66+
.notice(translation -> translation.signEditor().lineSet())
67+
.send();
68+
}
69+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.eternalcode.core.feature.signeditor;
2+
3+
import com.eternalcode.commons.adventure.AdventureUtil;
4+
import com.eternalcode.core.compatibility.Compatibility;
5+
import com.eternalcode.core.compatibility.Version;
6+
import com.eternalcode.core.injector.annotations.Inject;
7+
import com.eternalcode.core.notice.NoticeService;
8+
import dev.rollczi.litecommands.annotations.argument.Arg;
9+
import dev.rollczi.litecommands.annotations.command.Command;
10+
import dev.rollczi.litecommands.annotations.context.Context;
11+
import dev.rollczi.litecommands.annotations.execute.Execute;
12+
import dev.rollczi.litecommands.annotations.join.Join;
13+
import dev.rollczi.litecommands.annotations.permission.Permission;
14+
import net.kyori.adventure.text.minimessage.MiniMessage;
15+
import org.bukkit.block.Block;
16+
import org.bukkit.block.Sign;
17+
import org.bukkit.block.sign.Side;
18+
import org.bukkit.block.sign.SignSide;
19+
import org.bukkit.entity.Player;
20+
21+
@Command(name = "signedit")
22+
@Permission("eternalcode.signedit")
23+
@Compatibility(from = @Version(minor = 20, patch = 0))
24+
public class SignSideEditorCommand {
25+
26+
private final NoticeService noticeService;
27+
private final MiniMessage miniMessage;
28+
29+
@Inject
30+
public SignSideEditorCommand(NoticeService noticeService, MiniMessage miniMessage) {
31+
this.noticeService = noticeService;
32+
this.miniMessage = miniMessage;
33+
}
34+
35+
@Execute(name = "set")
36+
void execute(@Context Player player, @Arg Side side, @Arg int line, @Join String text) {
37+
Block targetBlock = player.getTargetBlockExact(5);
38+
39+
if (targetBlock == null) {
40+
return;
41+
}
42+
43+
if (!(targetBlock.getState() instanceof Sign sign)) {
44+
this.noticeService.create()
45+
.player(player.getUniqueId())
46+
.notice(translation -> translation.signEditor().noSignFound())
47+
.send();
48+
49+
return;
50+
}
51+
52+
SignSide signSide = sign.getSide(side);
53+
if (line < 1 || line > signSide.getLines().length) {
54+
this.noticeService.create()
55+
.player(player.getUniqueId())
56+
.placeholder("{LINE}", String.valueOf(line))
57+
.notice(translation -> translation.signEditor().invalidIndex())
58+
.send();
59+
return;
60+
}
61+
62+
signSide.setLine(line - 1, AdventureUtil.SECTION_SERIALIZER.serialize(this.miniMessage.deserialize(text)));
63+
sign.update();
64+
65+
this.noticeService.create()
66+
.player(player.getUniqueId())
67+
.placeholder("{LINE}", String.valueOf(line))
68+
.placeholder("{TEXT}", text)
69+
.notice(translation -> translation.signEditor().lineSet())
70+
.send();
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.eternalcode.core.feature.signeditor.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
import lombok.Getter;
5+
import lombok.experimental.Accessors;
6+
import net.dzikoysk.cdn.entity.Contextual;
7+
8+
@Getter
9+
@Accessors(fluent = true)
10+
@Contextual
11+
public class ENSignEditorMessages implements SignEditorMessages {
12+
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Look at the sign to edit it!");
13+
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>The value {LINE} is invalid! <red>Please select a number between 1 and 4!");
14+
public Notice lineSet = Notice.chat("<green>► <white>Line <green>{LINE} <white>set to <green>{TEXT}");
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.eternalcode.core.feature.signeditor.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
import lombok.Getter;
5+
import lombok.experimental.Accessors;
6+
import net.dzikoysk.cdn.entity.Contextual;
7+
8+
@Getter
9+
@Accessors(fluent = true)
10+
@Contextual
11+
public class PLSignEditorMessages implements SignEditorMessages {
12+
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Spójrz na tabliczkę, aby ją edytować!");
13+
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>Wartość {LINE} jest nieprawidłowa! <red>Wybierz numer od 1 do 4!");
14+
public Notice lineSet = Notice.chat("<green>► <white>Zmieniono linię <green>{LINE}</green> na <green>{TEXT}");
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.eternalcode.core.feature.signeditor.messages;
2+
3+
import com.eternalcode.multification.notice.Notice;
4+
5+
public interface SignEditorMessages {
6+
Notice noSignFound();
7+
Notice invalidIndex();
8+
Notice lineSet();
9+
}

eternalcore-core/src/main/java/com/eternalcode/core/translation/Translation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.eternalcode.core.feature.randomteleport.messages.RandomTeleportMessages;
1515
import com.eternalcode.core.feature.seen.messages.SeenMessages;
1616
import com.eternalcode.core.feature.setslot.messages.SetSlotMessages;
17+
import com.eternalcode.core.feature.signeditor.messages.SignEditorMessages;
1718
import com.eternalcode.core.feature.spawn.messages.SpawnMessages;
1819
import com.eternalcode.core.feature.sudo.messages.SudoMessages;
1920
import com.eternalcode.core.feature.teleportrequest.messages.TeleportRequestMessages;
@@ -222,6 +223,8 @@ interface ContainerSection {
222223
PlayerSection player();
223224
//Seen section
224225
SeenMessages seen();
226+
// sign editor section
227+
SignEditorMessages signEditor();
225228
// spawn section
226229
SpawnMessages spawn();
227230
// set slot section

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/ENTranslation.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import com.eternalcode.core.feature.adminchat.messages.ENAdminChatMessages;
66
import com.eternalcode.core.feature.afk.messages.ENAfkMessages;
77
import com.eternalcode.core.feature.automessage.messages.ENAutoMessageMessages;
8-
import com.eternalcode.core.feature.itemedit.messages.ENItemEditMessages;
98
import com.eternalcode.core.feature.helpop.messages.ENHelpOpMessages;
109
import com.eternalcode.core.feature.home.messages.ENHomeMessages;
10+
import com.eternalcode.core.feature.itemedit.messages.ENItemEditMessages;
1111
import com.eternalcode.core.feature.jail.messages.ENJailMessages;
1212
import com.eternalcode.core.feature.language.Language;
13-
import com.eternalcode.core.feature.seen.messages.ENSeenMessages;
14-
import com.eternalcode.core.feature.setslot.messages.ENSetSlotMessages;
1513
import com.eternalcode.core.feature.privatechat.messages.ENPrivateMessages;
1614
import com.eternalcode.core.feature.randomteleport.messages.ENRandomTeleportMessages;
15+
import com.eternalcode.core.feature.seen.messages.ENSeenMessages;
16+
import com.eternalcode.core.feature.setslot.messages.ENSetSlotMessages;
17+
import com.eternalcode.core.feature.signeditor.messages.ENSignEditorMessages;
1718
import com.eternalcode.core.feature.spawn.messages.ENSpawnMessages;
1819
import com.eternalcode.core.feature.sudo.messages.ENSudoMessages;
1920
import com.eternalcode.core.feature.teleportrequest.messages.ENTeleportRequestMessages;
@@ -119,6 +120,12 @@ public class ENTranslation extends AbstractTranslation {
119120
@Description("# This section is responsible for all messages related to item editing.")
120121
public ENItemEditMessages itemEdit = new ENItemEditMessages();
121122

123+
@Description({
124+
" ",
125+
"# This section is responsible for the messages of the /signeditor command",
126+
})
127+
public ENSignEditorMessages signEditor = new ENSignEditorMessages();
128+
122129
@Getter
123130
@Contextual
124131
public static class ENFormatSection implements Format {

eternalcore-core/src/main/java/com/eternalcode/core/translation/implementation/PLTranslation.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.eternalcode.core.feature.setslot.messages.PLSetSlotMessages;
1515
import com.eternalcode.core.feature.privatechat.messages.PLPrivateChatMessages;
1616
import com.eternalcode.core.feature.randomteleport.messages.PLRandomTeleportMessages;
17+
import com.eternalcode.core.feature.signeditor.messages.PLSignEditorMessages;
18+
import com.eternalcode.core.feature.signeditor.messages.SignEditorMessages;
1719
import com.eternalcode.core.feature.spawn.messages.PLSpawnMessages;
1820
import com.eternalcode.core.feature.sudo.messages.PLSudoMessages;
1921
import com.eternalcode.core.feature.teleportrequest.messages.PLTeleportRequestMessages;
@@ -116,6 +118,12 @@ public class PLTranslation extends AbstractTranslation {
116118
@Description("# Ta sekcja odpowiada za wiadomości dotyczące edytowanie itemow")
117119
public PLItemEditMessages itemEdit = new PLItemEditMessages();
118120

121+
@Description({
122+
" ",
123+
"# Ta sekcja odpowiada za wiadomości komendy /signeditor"
124+
})
125+
public PLSignEditorMessages signEditor = new PLSignEditorMessages();
126+
119127
@Getter
120128
@Contextual
121129
public static class PLFormatSection implements Format {

0 commit comments

Comments
 (0)