Skip to content

Commit

Permalink
GH-446 Notice (#446)
Browse files Browse the repository at this point in the history
* Add domain and unit tests for notice.

* Implement serialization to notice composer.

* Implement deserialization to notice composer.

* Fix code style.

* Merge welcome title and subtitle.

* Fix merge conflicts.

* Revert 'fadeIn' refactor typo.

* Revert 'fadeIn' refactor typo.

* 'messages' -> 'text'

* Add comments for new notification system

* follow rollczi's and piotrulla suggestions

* Remove wildcard

* getNoticeFacade -> getNoticeService

* NotificationHandler -> NoticeHandler

* announcer -> broadcaster

* Update CHANGELOGS.md

---------

Co-authored-by: Martin Sulikowski <[email protected]>
  • Loading branch information
Rollczi and vLuckyyy committed Jun 21, 2023
1 parent a15633d commit 1030b6e
Show file tree
Hide file tree
Showing 127 changed files with 2,623 additions and 1,466 deletions.
3 changes: 2 additions & 1 deletion CHANGELOGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
- Add warp system (/warp)
- Add support to PlaceholderAPI
- More advanced /hat command
- Add support to multiple notification type for configs
- Add support to multiple notice type for configs
- Add replay messages for all time-related commands
- Add replay messages for all weather-related commands
- Add home limit per permission
- Add message translation to world and location argument
- Refactor messages config format
3 changes: 3 additions & 0 deletions buildSrc/src/main/kotlin/eternalcode-java-test.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ plugins {
}

dependencies {
testImplementation("dev.rollczi.litecommands:core:2.8.8")
testImplementation("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT")
testImplementation("net.dzikoysk:cdn:1.14.4")
testImplementation("org.panda-lang:expressible-junit:1.3.5")
testImplementation("org.codehaus.groovy:groovy-all:3.0.17")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
testImplementation("org.mockito:mockito-core:5.3.1")
testImplementation("net.kyori:adventure-platform-bukkit:4.3.0")
testImplementation("net.kyori:adventure-platform-facet:4.3.0")
testImplementation("net.kyori:adventure-text-minimessage:4.13.1")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.eternalcode.core.command.contextual.UserContextual;
import com.eternalcode.core.command.contextual.ViewerContextual;
import com.eternalcode.core.command.handler.InvalidUsage;
import com.eternalcode.core.command.handler.NotificationHandler;
import com.eternalcode.core.command.handler.NoticeHandler;
import com.eternalcode.core.command.handler.PermissionMessage;
import com.eternalcode.core.configuration.ConfigurationBackupService;
import com.eternalcode.core.configuration.ConfigurationManager;
Expand Down Expand Up @@ -115,11 +115,9 @@
import com.eternalcode.core.listener.player.PlayerQuitListener;
import com.eternalcode.core.feature.spawn.SpawnRespawnController;
import com.eternalcode.core.listener.sign.SignChangeListener;
import com.eternalcode.core.notification.NoticeService;
import com.eternalcode.core.notification.NoticeType;
import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notification.NotificationAnnouncer;
import com.eternalcode.core.notification.adventure.AdventureNotificationAnnouncer;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.notice.NoticeTextType;
import com.eternalcode.core.placeholder.PlaceholderBukkitRegistryImpl;
import com.eternalcode.core.placeholder.PlaceholderRegistry;
import com.eternalcode.core.scheduler.BukkitSchedulerImpl;
Expand Down Expand Up @@ -185,7 +183,6 @@ class EternalCore implements EternalCoreApi {
/* Adventure */
private final BukkitAudiences audiencesProvider;
private final MiniMessage miniMessage;
private final AdventureNotificationAnnouncer notificationAnnouncer;

/* Configuration */
private final ConfigurationManager configurationManager;
Expand Down Expand Up @@ -233,8 +230,6 @@ public EternalCore(Plugin plugin) {
.postProcessor(new LegacyColorProcessor())
.build();

this.notificationAnnouncer = new AdventureNotificationAnnouncer(this.audiencesProvider, this.miniMessage);

/* Configuration */
ConfigurationBackupService configurationBackupService = new ConfigurationBackupService(plugin.getDataFolder());
this.configurationManager = new ConfigurationManager(configurationBackupService, plugin.getDataFolder());
Expand All @@ -261,7 +256,7 @@ public EternalCore(Plugin plugin) {

this.chatManager = new ChatManager(pluginConfiguration.chat);
this.translationManager = TranslationManager.create(this.configurationManager, languageConfiguration);
this.noticeService = new NoticeService(this.scheduler, this.translationManager, this.viewerProvider, this.notificationAnnouncer, this.placeholderRegistry);
this.noticeService = NoticeService.adventure(this.audiencesProvider, this.miniMessage, this.scheduler, this.viewerProvider, this.translationManager, this.placeholderRegistry);
this.afkService = new AfkService(pluginConfiguration.afk, this.noticeService, this.userManager, this.eventCaller);
this.teleportRequestService = new TeleportRequestService(pluginConfiguration.teleportAsk);

Expand Down Expand Up @@ -306,7 +301,7 @@ public EternalCore(Plugin plugin) {
// Arguments (include optional)
.argument(String.class, StringNicknameArgument.KEY, new StringNicknameArgument(server))
.argument(GameMode.class, new GameModeArgument(this.viewerProvider, this.translationManager, commandConfiguration.argument))
.argument(NoticeType.class, new NoticeTypeArgument(this.viewerProvider, this.translationManager))
.argument(NoticeTextType.class, new NoticeTypeArgument(this.viewerProvider, this.translationManager))
.argument(SpeedType.class, new SpeedTypeArgument(this.viewerProvider, this.translationManager))
.argument(Warp.class, new WarpArgument(this.warpManager, this.translationManager, this.viewerProvider))
.argument(Enchantment.class, new EnchantmentArgument(this.viewerProvider, this.translationManager))
Expand All @@ -330,8 +325,8 @@ public EternalCore(Plugin plugin) {
.contextualBind(User.class, new UserContextual(this.translationManager, this.userManager))

.invalidUsageHandler(new InvalidUsage(this.viewerProvider, this.noticeService))
.permissionHandler(new PermissionMessage(this.viewerProvider, this.audiencesProvider, this.translationManager, this.miniMessage))
.resultHandler(Notification.class, new NotificationHandler(this.viewerProvider, this.noticeService))
.permissionHandler(new PermissionMessage(this.viewerProvider, this.noticeService))
.resultHandler(Notice.class, new NoticeHandler(this.viewerProvider, this.noticeService))

.commandInstance(
new EternalCoreCommand(this.configurationManager, this.miniMessage),
Expand Down Expand Up @@ -573,10 +568,6 @@ public BukkitViewerProvider getViewerProvider() {
return this.viewerProvider;
}

public NotificationAnnouncer getNotificationAnnouncer() {
return this.notificationAnnouncer;
}

public NoticeService getNoticeService() {
return this.noticeService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.eternalcode.annotations.scan.feature.FeatureDocs;
import com.eternalcode.core.configuration.implementation.PluginConfiguration;
import com.eternalcode.core.delay.Delay;
import com.eternalcode.core.notification.NoticeService;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.util.DurationUtil;
import dev.rollczi.litecommands.command.execute.Execute;
import dev.rollczi.litecommands.command.permission.Permission;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.eternalcode.core.afk;

import com.eternalcode.core.event.EventCaller;
import com.eternalcode.core.notification.NoticeService;
import com.eternalcode.core.notice.NoticeService;
import com.eternalcode.core.user.User;
import com.eternalcode.core.user.UserManager;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -20,13 +20,13 @@ protected AbstractViewerArgument(BukkitViewerProvider viewerProvider, Translatio
}

@Override
public final Result<T, Notification> parse(LiteInvocation invocation, String argument) {
public final Result<T, Notice> 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, Notification> parse(LiteInvocation invocation, String argument, Translation translation);
public abstract Result<T, Notice> parse(LiteInvocation invocation, String argument, Translation translation);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.util.DurationUtil;
Expand Down Expand Up @@ -37,7 +37,7 @@ public DurationArgument(BukkitViewerProvider viewerProvider, TranslationManager
}

@Override
public Result<Duration, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Duration, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
return Option.supplyThrowing(DateTimeParseException.class, () -> Duration.parse("PT" + argument))
.toResult(() -> translation.argument().invalidTimeFormat());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -22,7 +22,7 @@ public EnchantmentArgument(BukkitViewerProvider viewerProvider, TranslationManag
}

@Override
public Result<Enchantment, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Enchantment, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
Enchantment enchantment = Enchantment.getByKey(NamespacedKey.minecraft(argument));

if (enchantment == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.feature.essentials.gamemode.GameModeArgumentSettings;
import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -26,7 +26,7 @@ public GameModeArgument(BukkitViewerProvider viewerProvider, TranslationManager
}

@Override
public Result<GameMode, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<GameMode, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
Option<GameMode> gameMode = Option.supplyThrowing(IllegalArgumentException.class, () -> GameMode.valueOf(argument.toUpperCase()));

if (gameMode.isPresent()) {
Expand All @@ -35,7 +35,7 @@ public Result<GameMode, Notification> parse(LiteInvocation invocation, String ar

Optional<GameMode> alias = this.gameModeArgumentSettings.getByAlias(argument);

return alias.<Result<GameMode, Notification>>map(Result::ok)
return alias.<Result<GameMode, Notice>>map(Result::ok)
.orElseGet(() -> Result.error(translation.player().gameModeNotCorrect()));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand Down Expand Up @@ -28,7 +29,7 @@ public LocationArgument(TranslationManager translationManager, BukkitViewerProvi
}

@Override
public Result<Location, String> parseMultilevel(LiteInvocation invocation, String... arguments) {
public Result<Location, Notice> parseMultilevel(LiteInvocation invocation, String... arguments) {
Viewer viewer = this.viewerProvider.any(invocation.sender().getHandle());
Translation translation = this.translationManager.getMessages(viewer);

Expand All @@ -38,7 +39,7 @@ public Result<Location, String> parseMultilevel(LiteInvocation invocation, Strin
double z = Double.parseDouble(arguments[2]);

return new Location(null, x, y, z);
}).mapErr(ex -> translation.argument().youMustGiveWorldName().getMessage());
}).mapErr(ex -> translation.argument().youMustGiveWorldName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.eternalcode.core.feature.essentials.mob.MobEntity;
import com.eternalcode.core.feature.essentials.mob.MobType;
import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.util.EntityUtil;
Expand All @@ -24,7 +24,7 @@ public MobEntityArgument(BukkitViewerProvider viewerProvider, TranslationManager
}

@Override
public Result<MobEntity, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<MobEntity, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
try {
MobType mobType = MobType.valueOf(argument.toUpperCase());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.NoticeType;
import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.NoticeTextType;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -15,24 +15,23 @@
import java.util.List;

@ArgumentName("action")
public class NoticeTypeArgument extends AbstractViewerArgument<NoticeType> {
public class NoticeTypeArgument extends AbstractViewerArgument<NoticeTextType> {

public NoticeTypeArgument(BukkitViewerProvider viewerProvider, TranslationManager translationManager) {
super(viewerProvider, translationManager);
}

@Override
public List<Suggestion> suggest(LiteInvocation invocation) {
return Arrays.stream(NoticeType.values())
.filter(type -> type != NoticeType.DISABLED)
return Arrays.stream(NoticeTextType.values())
.map(notificationType -> notificationType.name().toLowerCase())
.map(Suggestion::of)
.toList();
}

@Override
public Result<NoticeType, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
return Option.supplyThrowing(IllegalArgumentException.class, () -> NoticeType.valueOf(argument.toUpperCase()))
public Result<NoticeTextType, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
return Option.supplyThrowing(IllegalArgumentException.class, () -> NoticeTextType.valueOf(argument.toUpperCase()))
.toResult(() -> translation.argument().noArgument());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -25,7 +25,7 @@ public PlayerArgument(BukkitViewerProvider viewerProvider, TranslationManager tr
}

@Override
public Result<Player, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Player, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
Player player = this.server.getPlayer(argument);

if (player == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.teleport.request.TeleportRequestService;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
Expand Down Expand Up @@ -32,7 +32,7 @@ public RequesterArgument(TeleportRequestService requestService, TranslationManag
}

@Override
public Result<Player, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Player, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
Player target = this.server.getPlayer(argument);

if (!(invocation.sender().getHandle() instanceof Player player)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.viewer.BukkitViewerProvider;
Expand All @@ -26,7 +26,7 @@ public SpeedArgument(BukkitViewerProvider viewerProvider, TranslationManager tra
}

@Override
public Result<Integer, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<Integer, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
return Option.supplyThrowing(NumberFormatException.class, () -> Integer.parseInt(argument))
.filter(SPEED_VALID::valid)
.toResult(() -> translation.player().speedBetweenZeroAndTen());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.feature.essentials.speed.SpeedType;
Expand All @@ -22,7 +22,7 @@ public SpeedTypeArgument(BukkitViewerProvider viewerProvider, TranslationManager
}

@Override
public Result<SpeedType, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<SpeedType, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
return Option.supplyThrowing(IllegalArgumentException.class, () -> SpeedType.valueOf(argument.toUpperCase()))
.toResult(() -> translation.player().speedTypeNotCorrect());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.eternalcode.core.command.argument;

import com.eternalcode.core.notification.Notification;
import com.eternalcode.core.notice.Notice;
import com.eternalcode.core.translation.Translation;
import com.eternalcode.core.translation.TranslationManager;
import com.eternalcode.core.user.User;
Expand Down Expand Up @@ -37,7 +37,7 @@ public List<Suggestion> suggest(LiteInvocation invocation) {
}

@Override
public Result<User, Notification> parse(LiteInvocation invocation, String argument, Translation translation) {
public Result<User, Notice> parse(LiteInvocation invocation, String argument, Translation translation) {
Optional<User> optionalUser = this.userManager.getUser(argument);

if (optionalUser.isPresent()) {
Expand Down
Loading

0 comments on commit 1030b6e

Please sign in to comment.