Skip to content

Commit

Permalink
Fix warp placeholder handling in warp-related messages
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Jan 11, 2025
1 parent 5ea9344 commit 07c1118
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ private void removeWarp(Player player, String name) {
if (!this.warpService.warpExists(name)) {
this.noticeService.create()
.player(player.getUniqueId())
.placeholder("{WARP}", name)
.notice(translation -> translation.warp().notExist())
.placeholder("{WARP}", name)
.send();

return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ private void createWarp(Player player, String warp, UUID uniqueId) {
if (this.warpService.warpExists(warp)) {
this.noticeService.create()
.player(uniqueId)
.placeholder("{WARP}", warp)
.notice(translation -> translation.warp().warpAlreadyExists())
.placeholder("{WARP}", warp)
.send();

return;
Expand All @@ -62,9 +62,7 @@ private void createWarp(Player player, String warp, UUID uniqueId) {
.send();

if (this.config.warp.autoAddNewWarps) {

if (this.warpService.getNamesOfWarps().size() <= MAX_WARPS_IN_GUI) {

this.warpInventory.addWarp(createdWarp);

this.noticeService.create()
Expand All @@ -80,7 +78,6 @@ private void createWarp(Player player, String warp, UUID uniqueId) {
.notice(translation -> translation.warp().itemLimit())
.placeholder("{LIMIT}", String.valueOf(MAX_WARPS_IN_GUI))
.send();

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import com.eternalcode.core.feature.warp.WarpService;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.lite.LiteArgument;
import com.eternalcode.core.notice.EternalCoreBroadcast;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.Viewer;
import com.eternalcode.core.viewer.ViewerService;
import dev.rollczi.litecommands.argument.Argument;
import dev.rollczi.litecommands.argument.parser.ParseResult;
Expand All @@ -20,19 +23,33 @@
class WarpArgument extends AbstractViewerArgument<Warp> {

private final WarpService warpService;
private final NoticeService noticeService;

@Inject
WarpArgument(WarpService warpService, TranslationManager translationManager, ViewerService viewerService) {
WarpArgument(
WarpService warpService,
TranslationManager translationManager,
ViewerService viewerService,
NoticeService noticeService
) {
super(viewerService, translationManager);
this.warpService = warpService;
this.noticeService = noticeService;
}

@Override
public ParseResult<Warp> parse(Invocation<CommandSender> invocation, String argument, Translation translation) {
Optional<Warp> warpOption = this.warpService.findWarp(argument);

return warpOption.map(ParseResult::success)
.orElseGet(() -> ParseResult.failure(translation.warp().notExist()));
.orElseGet(() -> {
EternalCoreBroadcast<Viewer, Translation, ?> warpNotExistNotice = this.noticeService.create()
.sender(invocation.sender())
.notice(translation.warp().notExist())
.placeholder("{WARP}", argument);

return ParseResult.failure(warpNotExistNotice);
});
}

@Override
Expand Down

0 comments on commit 07c1118

Please sign in to comment.