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 all 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 @@ -13,6 +13,10 @@
import com.eternalcode.core.injector.annotations.Bean;
import com.eternalcode.core.injector.annotations.component.ConfigurationFile;
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.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();
}
}
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();
}
}
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}");
Copy link
Member

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

Copy link
Member

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

}
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}");
}
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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.eternalcode.core.configuration.contextual.ConfigItem;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.signeditor.messages.SignEditorMessages;
import com.eternalcode.core.feature.warp.WarpInventoryItem;
import com.eternalcode.multification.notice.Notice;
import org.bukkit.Material;
Expand Down Expand Up @@ -481,4 +482,6 @@ interface JailSection {
Notice jailCannotUseCommand();
}


SignEditorMessages signEditor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.eternalcode.core.configuration.contextual.ConfigItem;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.signeditor.messages.PLSignEditorMessages;
import com.eternalcode.core.feature.signeditor.messages.SignEditorMessages;
import com.eternalcode.core.feature.warp.WarpInventoryItem;
import com.eternalcode.core.translation.AbstractTranslation;
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
Expand Down Expand Up @@ -931,4 +933,7 @@ 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 PLSignEditorMessages signEditor = new PLSignEditorMessages();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.eternalcode.core.configuration.contextual.ConfigItem;
import com.eternalcode.core.feature.language.Language;
import com.eternalcode.core.feature.signeditor.messages.PLSignEditorMessages;
import com.eternalcode.core.feature.warp.WarpInventoryItem;
import com.eternalcode.core.translation.AbstractTranslation;
import com.eternalcode.multification.bukkit.notice.BukkitNotice;
Expand Down Expand Up @@ -953,4 +954,7 @@ 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 PLSignEditorMessages signEditor = new PLSignEditorMessages();
}
Loading