Skip to content

Commit 07c1118

Browse files
committed
Fix warp placeholder handling in warp-related messages
1 parent 5ea9344 commit 07c1118

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ private void removeWarp(Player player, String name) {
4040
if (!this.warpService.warpExists(name)) {
4141
this.noticeService.create()
4242
.player(player.getUniqueId())
43-
.placeholder("{WARP}", name)
4443
.notice(translation -> translation.warp().notExist())
44+
.placeholder("{WARP}", name)
4545
.send();
4646

4747
return;

eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ private void createWarp(Player player, String warp, UUID uniqueId) {
4646
if (this.warpService.warpExists(warp)) {
4747
this.noticeService.create()
4848
.player(uniqueId)
49-
.placeholder("{WARP}", warp)
5049
.notice(translation -> translation.warp().warpAlreadyExists())
50+
.placeholder("{WARP}", warp)
5151
.send();
5252

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

6464
if (this.config.warp.autoAddNewWarps) {
65-
6665
if (this.warpService.getNamesOfWarps().size() <= MAX_WARPS_IN_GUI) {
67-
6866
this.warpInventory.addWarp(createdWarp);
6967

7068
this.noticeService.create()
@@ -80,7 +78,6 @@ private void createWarp(Player player, String warp, UUID uniqueId) {
8078
.notice(translation -> translation.warp().itemLimit())
8179
.placeholder("{LIMIT}", String.valueOf(MAX_WARPS_IN_GUI))
8280
.send();
83-
8481
}
8582
}
8683
}

eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import com.eternalcode.core.feature.warp.WarpService;
66
import com.eternalcode.core.injector.annotations.Inject;
77
import com.eternalcode.core.injector.annotations.lite.LiteArgument;
8+
import com.eternalcode.core.notice.EternalCoreBroadcast;
9+
import com.eternalcode.core.notice.NoticeService;
810
import com.eternalcode.core.translation.Translation;
911
import com.eternalcode.core.translation.TranslationManager;
12+
import com.eternalcode.core.viewer.Viewer;
1013
import com.eternalcode.core.viewer.ViewerService;
1114
import dev.rollczi.litecommands.argument.Argument;
1215
import dev.rollczi.litecommands.argument.parser.ParseResult;
@@ -20,19 +23,33 @@
2023
class WarpArgument extends AbstractViewerArgument<Warp> {
2124

2225
private final WarpService warpService;
26+
private final NoticeService noticeService;
2327

2428
@Inject
25-
WarpArgument(WarpService warpService, TranslationManager translationManager, ViewerService viewerService) {
29+
WarpArgument(
30+
WarpService warpService,
31+
TranslationManager translationManager,
32+
ViewerService viewerService,
33+
NoticeService noticeService
34+
) {
2635
super(viewerService, translationManager);
2736
this.warpService = warpService;
37+
this.noticeService = noticeService;
2838
}
2939

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

3444
return warpOption.map(ParseResult::success)
35-
.orElseGet(() -> ParseResult.failure(translation.warp().notExist()));
45+
.orElseGet(() -> {
46+
EternalCoreBroadcast<Viewer, Translation, ?> warpNotExistNotice = this.noticeService.create()
47+
.sender(invocation.sender())
48+
.notice(translation.warp().notExist())
49+
.placeholder("{WARP}", argument);
50+
51+
return ParseResult.failure(warpNotExistNotice);
52+
});
3653
}
3754

3855
@Override

0 commit comments

Comments
 (0)