-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
igoyek
wants to merge
6
commits into
master
Choose a base branch
from
feature/sign-command-editor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+178
−0
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bb017c8
primary implementation (to be fixed)
igoyek aa76ccb
Update command name
igoyek 2c16d2b
Merge branch 'master' into feature/sign-command-editor
vLuckyyy e3fe988
Refactor messages, add compatibility for non-side-based sing's
vLuckyyy 45a19e7
Use Block#getTargetBlockExact
vLuckyyy c6fcdfd
Fix index placeholder.
vLuckyyy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...nalcore-core/src/main/java/com/eternalcode/core/feature/signeditor/SignEditorCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.eternalcode.core.feature.signeditor; | ||
|
||
import com.eternalcode.core.compatibility.Compatibility; | ||
import com.eternalcode.core.compatibility.Version; | ||
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.entity.Player; | ||
|
||
@Command(name = "signeditor") | ||
@Permission("eternalcode.signeditor") | ||
@Compatibility(to = @Version(minor = 19, patch = 4)) | ||
public class SignEditorCommand { | ||
|
||
private final NoticeService noticeService; | ||
private final MiniMessage miniMessage; | ||
|
||
public SignEditorCommand(NoticeService noticeService, MiniMessage miniMessage) { | ||
this.noticeService = noticeService; | ||
this.miniMessage = miniMessage; | ||
} | ||
|
||
@Execute(name = "setline") | ||
void execute(@Context Player player, @Arg int index, @Join String text) { | ||
Block targetBlock = player.getTargetBlockExact(5); | ||
|
||
if (!(targetBlock.getState() instanceof Sign sign)) { | ||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.signEditor().noSignFound()) | ||
.send(); | ||
return; | ||
} | ||
|
||
if (index < 0 || index >= sign.getLines().length) { | ||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.signEditor().invalidIndex()) | ||
.send(); | ||
return; | ||
} | ||
|
||
sign.setLine(index, this.miniMessage.deserialize(text).toString()); | ||
sign.update(); | ||
|
||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.placeholder("{INDEX}", String.valueOf(index)) | ||
.placeholder("{TEXT}", text) | ||
.notice(translation -> translation.signEditor().lineSet()) | ||
.send(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ore-core/src/main/java/com/eternalcode/core/feature/signeditor/SignSideEditorCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.eternalcode.core.feature.signeditor; | ||
|
||
import com.eternalcode.core.compatibility.Compatibility; | ||
import com.eternalcode.core.compatibility.Version; | ||
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 = "signeditor") | ||
@Permission("eternalcode.signeditor") | ||
@Compatibility(from = @Version(minor = 20, patch = 0)) | ||
public class SignSideEditorCommand { | ||
|
||
private final NoticeService noticeService; | ||
private final MiniMessage miniMessage; | ||
|
||
public SignSideEditorCommand(NoticeService noticeService, MiniMessage miniMessage) { | ||
this.noticeService = noticeService; | ||
this.miniMessage = miniMessage; | ||
} | ||
|
||
@Execute(name = "setline") | ||
void execute(@Context Player player, @Arg Side side, @Arg int index, @Join String text) { | ||
Block targetBlock = player.getTargetBlockExact(5); | ||
|
||
if (!(targetBlock.getState() instanceof Sign sign)) { | ||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.signEditor().noSignFound()) | ||
.send(); | ||
return; | ||
} | ||
|
||
SignSide signSide = sign.getSide(side); | ||
if (index < 0 || index >= signSide.getLines().length) { | ||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.notice(translation -> translation.signEditor().invalidIndex()) | ||
.send(); | ||
return; | ||
} | ||
|
||
signSide.setLine(index, this.miniMessage.deserialize(text).toString()); | ||
sign.update(); | ||
|
||
this.noticeService.create() | ||
.player(player.getUniqueId()) | ||
.placeholder("{INDEX}", String.valueOf(index)) | ||
.placeholder("{TEXT}", text) | ||
.notice(translation -> translation.signEditor().lineSet()) | ||
.send(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/main/java/com/eternalcode/core/feature/signeditor/messages/ENSignEditorMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.eternalcode.core.feature.signeditor.messages; | ||
|
||
import com.eternalcode.multification.notice.Notice; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import net.dzikoysk.cdn.entity.Contextual; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Contextual | ||
public class ENSignEditorMessages implements SignEditorMessages { | ||
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Sign not found, please look at the sign!"); | ||
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>Invalid index!"); | ||
public Notice lineSet = Notice.chat("<green>► <white>Line <green>{INDEX} <white>set to <green>{TEXT}"); | ||
} |
15 changes: 15 additions & 0 deletions
15
.../src/main/java/com/eternalcode/core/feature/signeditor/messages/PLSignEditorMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.eternalcode.core.feature.signeditor.messages; | ||
|
||
import com.eternalcode.multification.notice.Notice; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import net.dzikoysk.cdn.entity.Contextual; | ||
|
||
@Getter | ||
@Accessors(fluent = true) | ||
@Contextual | ||
public class PLSignEditorMessages implements SignEditorMessages{ | ||
public Notice noSignFound = Notice.chat("<red>✘ <dark_red>Nie odnaleziono tabliczki, proszę spojrzeć na tabliczkę!"); | ||
public Notice invalidIndex = Notice.chat("<red>✘ <dark_red>Nieprawidłowy indeks!"); | ||
public Notice lineSet = Notice.chat("<green>► <white>Ustawiono linię <green>{INDEX} <white>na <green>{TEXT}"); | ||
} |
9 changes: 9 additions & 0 deletions
9
...re/src/main/java/com/eternalcode/core/feature/signeditor/messages/SignEditorMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.eternalcode.core.feature.signeditor.messages; | ||
|
||
import com.eternalcode.multification.notice.Notice; | ||
|
||
public interface SignEditorMessages { | ||
Notice noSignFound(); | ||
Notice invalidIndex(); | ||
Notice lineSet(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove formatting for text if the text added to sign should be formatted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that formatting used to set text to ex. Bold could overlap with formatting of message so the text in Notice would be bold and green instead of just bold