Skip to content

Commit

Permalink
Follow mr. @Rollczi review. v2
Browse files Browse the repository at this point in the history
  • Loading branch information
vLuckyyy committed Jan 12, 2025
1 parent 95f8ed3 commit 60b4c11
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.eternalcode.core.feature.warp.command.permission.argument;

import com.eternalcode.core.configuration.implementation.PluginConfiguration;
import com.eternalcode.core.feature.warp.Warp;
import com.eternalcode.core.feature.warp.WarpService;
import com.eternalcode.core.injector.annotations.Inject;
Expand All @@ -26,21 +25,16 @@ public class WarpPermissionMultiArgumentResolver
implements MultipleArgumentResolver<CommandSender, WarpPermissionEntry> {

private static final String WARP_PLACEHOLDER_PREFIX = "{WARP}";
private static final String PERMISSION_PLACEHOLDER_PREFIX = "{PERMISSION}";

private final PluginConfiguration config;
private final WarpService warpService;
private final NoticeService noticeService;
private final ViewerService viewerService;

@Inject
public WarpPermissionMultiArgumentResolver(
PluginConfiguration config,
WarpService warpService,
NoticeService noticeService,
ViewerService viewerService
) {
this.config = config;
this.warpService = warpService;
this.noticeService = noticeService;
this.viewerService = viewerService;
Expand All @@ -56,7 +50,7 @@ public ParseResult<WarpPermissionEntry> parse(

if (!rawInput.hasNext()) {
return ParseResult.failure(this.noticeService.create()
.notice(translation -> translation.warp().missingWarpName())
.notice(translation -> translation.warp().missingWarpArgument())
.viewer(viewer)
);
}
Expand All @@ -74,26 +68,13 @@ public ParseResult<WarpPermissionEntry> parse(
}

if (!rawInput.hasNext()) {
Collection<String> permissions = warp.get().getPermissions();

if (permissions.isEmpty()) {
return ParseResult.failure(this.noticeService.create()
.notice(translation -> translation.warp().noPermissionAssigned())
.placeholder(WARP_PLACEHOLDER_PREFIX, warpName)
.viewer(viewer)
);
}

return ParseResult.failure(this.noticeService.create()
.notice(translation -> translation.warp().listPermission())
.placeholder(WARP_PLACEHOLDER_PREFIX, warpName)
.placeholder(PERMISSION_PLACEHOLDER_PREFIX, String.join(this.config.format.separator, permissions))
.notice(translation -> translation.warp().missingPermissionArgument())
.viewer(viewer)
);
}

String permission = rawInput.next();

return ParseResult.success(new WarpPermissionEntry(warp.get(), permission));
}

Expand All @@ -120,7 +101,7 @@ public SuggestionResult suggest(
}

if (index == 2) {
String warpName = current.multilevelList().get(0);
String warpName = current.multilevelList().getFirst();
Optional<Warp> warpOptional = this.warpService.findWarp(warpName);

if (warpOptional.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ interface WarpSection {
Notice permissionDoesNotExist();
Notice permissionAlreadyExist();
Notice noPermissionsProvided();
Notice noPermissionAssigned();
Notice missingWarpName();
Notice listPermission();
Notice missingWarpArgument();
Notice missingPermissionArgument();

WarpInventorySection warpInventory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ public static class ENWarpSection implements WarpSection {
public Notice permissionDoesNotExist = Notice.chat("<red>✘ <dark_red>Permission <red>{PERMISSION} <dark_red>doesn't exist!");
public Notice permissionAlreadyExist = Notice.chat("<red>✘ <dark_red>Permission <red>{PERMISSION} <dark_red>already exists!");
public Notice noPermissionAssigned = Notice.chat("<red>✘ <red>There are no permissions assigned to this warp!");
public Notice missingWarpName = Notice.chat("<red>✘ <dark_red>You must provide a warp name!");
public Notice listPermission = Notice.chat("<green>► <white>Permissions for warp <green>{WARP}<white>: <green>{PERMISSIONS}");
public Notice missingWarpArgument = Notice.chat("<red>✘ <dark_red>You must provide a warp name!");
public Notice missingPermissionArgument = Notice.chat("<red>✘ <dark_red>You must provide a permission!");

@Description({" ", "# {WARPS} - List of warps (separated by commas)"})
public Notice available = Notice.chat("<green>► <white>Available warps: <green>{WARPS}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ public static class PLWarpSection implements WarpSection {
public Notice permissionDoesNotExist = Notice.chat("<red>✘ <red>Podane uprawnienie nie istnieje ({PERMISSION})!");
public Notice permissionAlreadyExist = Notice.chat("<red>✘ <red>Podane uprawnienie już istnieje ({PERMISSION})!");
public Notice noPermissionAssigned = Notice.chat("<red>✘ <red>Ten warp nie ma przypisanych żadnych permisji");
public Notice missingWarpName = Notice.chat("<red>✘ <dark_red>Musisz podać nazwę warpu!");
public Notice listPermission = Notice.chat("<green>► <white>Lista uprawnień dla warpa <green>{WARP}<white>: <green>{PERMISSIONS}!");
public Notice missingWarpArgument = Notice.chat("<red>✘ <dark_red>Musisz podać nazwę warpu!");
public Notice missingPermissionArgument = Notice.chat("<red>✘ <dark_red>Musisz podać uprawnienie!");

@Description({" ", "# {WARPS} - Lista dostępnych warpów"})
public Notice available = Notice.chat("<green>► <white>Dostepne warpy: <green>{WARPS}!");
Expand Down

0 comments on commit 60b4c11

Please sign in to comment.