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

Remove useless annotations and change name #581

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,35 +1,68 @@
package com.eternalcode.core.feature.home;

import com.eternalcode.core.litecommand.argument.AbstractViewerArgument;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.injector.annotations.lite.LiteArgument;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.litecommand.argument.AbstractViewerBroadcastArgument;
import com.eternalcode.core.notice.NoticeBroadcast;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.ViewerProvider;
import com.eternalcode.core.viewer.Viewer;
import com.eternalcode.core.viewer.ViewerProvider;
import dev.rollczi.litecommands.argument.ArgumentName;
import dev.rollczi.litecommands.command.LiteInvocation;
import dev.rollczi.litecommands.suggestion.Suggestion;
import panda.std.Option;
import panda.std.Result;

import java.util.List;
import java.util.UUID;

@LiteArgument(type = Home.class)
@ArgumentName("name")
class HomeArgument extends AbstractViewerArgument<Home> {
class HomeArgument extends AbstractViewerBroadcastArgument<Home> {

private final HomeManager homeManager;
private final NoticeService noticeService;

@Inject
HomeArgument(ViewerProvider viewerProvider, TranslationManager translationManager, HomeManager homeManager) {
HomeArgument(ViewerProvider viewerProvider, TranslationManager translationManager, HomeManager homeManager, NoticeService noticeService) {
super(viewerProvider, translationManager);
this.homeManager = homeManager;
this.noticeService = noticeService;
}

@Override
public Result<Home, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Home, NoticeBroadcast> parse(LiteInvocation invocation, String argument, Translation translation) {
Viewer viewer = this.viewerProvider.any(invocation.sender().getHandle());
UUID uniqueId = viewer.getUniqueId();

Option<Home> home = this.homeManager.getHome(uniqueId, argument);

if (home.isPresent()) {
return Result.ok(home.get());
}

String homes = String.join(", ",
this.homeManager.getHomes(uniqueId).stream()
.map(Home::getName)
.toList());

return this.homeManager.getHome(viewer.getUniqueId(), argument)
.toResult(translation.home().notExist());
NoticeBroadcast notice = this.noticeService.create()
.notice(translate -> translate.home().homeList())
.placeholder("{HOMES}", homes)
.viewer(viewer);

return Result.error(notice);
}

@Override
public List<Suggestion> suggest(LiteInvocation invocation) {
Viewer viewer = this.viewerProvider.any(invocation.sender().getHandle());

return this.homeManager.getHomes(viewer.getUniqueId()).stream()
.map(Home::getName)
.map(Suggestion::of)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.eternalcode.core.feature.home;

import com.eternalcode.annotations.scan.command.DescriptionDocs;
import com.eternalcode.core.feature.teleport.TeleportService;
import com.eternalcode.core.feature.teleport.TeleportTaskService;
import com.eternalcode.core.injector.annotations.Inject;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.shared.PositionAdapter;
import com.eternalcode.core.feature.teleport.TeleportService;
import com.eternalcode.core.feature.teleport.TeleportTaskService;
import dev.rollczi.litecommands.argument.Arg;
import dev.rollczi.litecommands.command.amount.Required;
import dev.rollczi.litecommands.command.execute.Execute;
Expand Down Expand Up @@ -40,9 +40,15 @@ void execute(Player player) {
Collection<Home> playerHomes = this.homeManager.getHomes(player.getUniqueId());

if (playerHomes.size() != 1) {
String homes = String.join(", ",
this.homeManager.getHomes(player.getUniqueId()).stream()
.map(Home::getName)
.toList());

this.noticeService.create()
.player(player.getUniqueId())
.notice(translation -> translation.home().enterName())
.notice(translation -> translation.home().homeList())
.placeholder("{HOMES}", homes)
.send();
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.eternalcode.core.litecommand.argument;

import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.notice.NoticeBroadcast;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.ViewerProvider;
import com.eternalcode.core.viewer.Viewer;
import com.eternalcode.core.viewer.ViewerProvider;
import dev.rollczi.litecommands.argument.simple.OneArgument;
import dev.rollczi.litecommands.command.LiteInvocation;
import panda.std.Result;
Expand All @@ -28,5 +29,4 @@ public final Result<T, Notice> parse(LiteInvocation invocation, String argument)
}

public abstract Result<T, Notice> parse(LiteInvocation invocation, String argument, Translation translation);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.eternalcode.core.litecommand.argument;

import com.eternalcode.core.notice.NoticeBroadcast;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.Viewer;
import com.eternalcode.core.viewer.ViewerProvider;
import dev.rollczi.litecommands.argument.simple.OneArgument;
import dev.rollczi.litecommands.command.LiteInvocation;
import panda.std.Result;

public abstract class AbstractViewerBroadcastArgument<T> implements OneArgument<T> {

protected final ViewerProvider viewerProvider;
protected final TranslationManager translationManager;

protected AbstractViewerBroadcastArgument(ViewerProvider viewerProvider, TranslationManager translationManager) {
this.viewerProvider = viewerProvider;
this.translationManager = translationManager;
}

@Override
public final Result<T, NoticeBroadcast> parse(LiteInvocation invocation, String argument) {
Viewer viewer = this.viewerProvider.any(invocation.sender().getHandle());
Translation translation = this.translationManager.getMessages(viewer.getLanguage());

return this.parse(invocation, argument, translation);
}

public abstract Result<T, NoticeBroadcast> parse(LiteInvocation invocation, String argument, Translation translation);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.eternalcode.core.litecommand.handler;

import com.eternalcode.core.injector.annotations.lite.LiteHandler;
import com.eternalcode.core.notice.NoticeBroadcast;
import dev.rollczi.litecommands.command.LiteInvocation;
import dev.rollczi.litecommands.handle.Handler;
import org.bukkit.command.CommandSender;

@LiteHandler(NoticeBroadcast.class)
public class NoticeBroadcastHandler implements Handler<CommandSender, NoticeBroadcast> {

@Override
public void handle(CommandSender sender, LiteInvocation invocation, NoticeBroadcast value) {
value.send();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ interface DecorationItemsSection {
HomeSection home();

interface HomeSection {
Notice enterName();
Notice notExist();
Notice homeList();
Notice create();
Notice delete();
Notice limit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,8 @@ public static class ENDecorationItemsSection implements DecorationItemsSection {
@Getter
@Contextual
public static class ENHomeSection implements HomeSection {
public Notice enterName = Notice.chat("<red>► <dark_red>Enter the name of the home!");
public Notice notExist = Notice.chat("<red>► <dark_red>This home doesn't exist");
@Description("# {HOMES} - List of homes (separated by commas)")
public Notice homeList = Notice.chat("<green>► <white>Available homes: <green>{HOMES}");

@Description({ " ", "# {HOME} - Home name" })
public Notice create = Notice.chat("<green>► <white>Home <green>{HOME} <white>has been created.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ public static class PLDecorationItemsSection implements DecorationItemsSection {
@Getter
@Contextual
public static class PLHomeSection implements HomeSection {
public Notice enterName = Notice.chat("<red>► <dark_red>Podaj nazwę domu!");
public Notice notExist = Notice.chat("<red>► <dark_red>Nie ma takiego domu!");
@Description({ " ", "# {HOMES} - Lista domów" })
public Notice homeList = Notice.chat("<green>► <white>Lista domów: <green>{HOMES}!");

@Description({ " ", "# {HOME} - Nazwa domu" })
public Notice create = Notice.chat("<green>► <white>Stworzono dom o nazwie <green>{HOME}<white>!");
Expand Down