diff --git a/README.md b/README.md index 45637d936..0e2266f3e 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ For Maven projects use: For Gradle projects use: ```kts -compileOnly("com.eternalcode:eternalcore-api:1.5.1") +compileOnly("com.eternalcode:eternalcore-api:1.5.2") ``` For Maven projects use: @@ -88,7 +88,7 @@ For Maven projects use: com.eternalcode eternalcore-api - 1.5.1 + 1.5.2 provided ``` diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index f6d9f963c..576e95508 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -18,7 +18,7 @@ object Versions { const val CDN_CONFIGS = "1.14.6" const val MARIA_DB = "3.5.1" - const val POSTGRESQL = "42.7.4" + const val POSTGRESQL = "42.7.5" const val H2 = "2.3.232" const val ORMLITE = "6.1" const val HIKARI_CP = "6.2.1" @@ -37,7 +37,7 @@ object Versions { const val BSTATS = "3.1.0" - const val CAFFEINE = "3.1.8" + const val CAFFEINE = "3.2.0" const val SPOTIFY_COMPLETABLE_FUTURES = "0.3.6" diff --git a/buildSrc/src/main/kotlin/eternalcode-java.gradle.kts b/buildSrc/src/main/kotlin/eternalcode-java.gradle.kts index 7d4f051bd..355a326fd 100644 --- a/buildSrc/src/main/kotlin/eternalcode-java.gradle.kts +++ b/buildSrc/src/main/kotlin/eternalcode-java.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "com.eternalcode" -version = "1.5.1" +version = "1.5.2" checkstyle { toolVersion = "10.21.1" diff --git a/buildSrc/src/main/kotlin/eternalcore-publish.gradle.kts b/buildSrc/src/main/kotlin/eternalcore-publish.gradle.kts index 40008ce36..326ce38d8 100644 --- a/buildSrc/src/main/kotlin/eternalcore-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/eternalcore-publish.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "com.eternalcode" -version = "1.5.1" +version = "1.5.2" java { withSourcesJar() diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/butcher/ButcherEntityRemoveEvent.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/butcher/ButcherEntityRemoveEvent.java new file mode 100644 index 000000000..7fb661f75 --- /dev/null +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/butcher/ButcherEntityRemoveEvent.java @@ -0,0 +1,41 @@ +package com.eternalcode.core.feature.butcher; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class ButcherEntityRemoveEvent extends Event implements Cancellable { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private boolean cancelled; + private final Entity entity; + + public ButcherEntityRemoveEvent(Entity entity) { + this.entity = entity; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + public Entity getEntity() { + return entity; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/Language.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/Language.java similarity index 69% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/language/Language.java rename to eternalcore-api/src/main/java/com/eternalcode/core/feature/language/Language.java index 40a92dadf..175dcd9c8 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/Language.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/Language.java @@ -1,10 +1,11 @@ package com.eternalcode.core.feature.language; -import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; import java.util.Locale; import java.util.Objects; +import java.util.Set; public class Language { @@ -13,19 +14,19 @@ public class Language { public static final Language DEFAULT = Language.fromLocale(Locale.ROOT); private final String lang; - private final List aliases; + private final Set aliases; public Language(String lang, List aliases) { this.lang = lang; - this.aliases = new ArrayList<>(aliases); + this.aliases = new LinkedHashSet<>(aliases); } public String getLang() { return this.lang; } - public List getAliases() { - return Collections.unmodifiableList(this.aliases); + public Set getAliases() { + return Collections.unmodifiableSet(this.aliases); } public boolean isEquals(Language other) { @@ -33,15 +34,17 @@ public boolean isEquals(Language other) { return true; } - for (String alias : this.aliases) { - if (alias.equals(other.lang)) { - return true; - } + if (this.lang.startsWith(other.lang) || other.lang.startsWith(this.lang)) { + return true; + } - for (String otherAlias : other.aliases) { - if (alias.equals(otherAlias)) { - return true; - } + if (this.aliases.contains(other.lang)) { + return true; + } + + for (String otherAlias : other.aliases) { + if (this.aliases.contains(otherAlias)) { + return true; } } @@ -71,7 +74,7 @@ public static Language fromLocale(Locale locale) { } public Locale toLocale() { - return new Locale(this.lang); + return Locale.of(this.lang); } } diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageProvider.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageProvider.java new file mode 100644 index 000000000..d3e54b5c5 --- /dev/null +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageProvider.java @@ -0,0 +1,9 @@ +package com.eternalcode.core.feature.language; + +import java.util.UUID; + +public interface LanguageProvider { + + Language getDefaultLanguage(UUID player); + +} diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageService.java index c4f9e52c2..689bbcefe 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageService.java @@ -1,11 +1,20 @@ package com.eternalcode.core.feature.language; -import java.util.Locale; -import org.bukkit.entity.Player; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; public interface LanguageService { - Locale getPlayerLanguage(Player player); + void setDefaultProvider(LanguageProvider defaultProvider); + + LanguageProvider getDefaultProvider(); + + CompletableFuture getLanguage(UUID playerUniqueId); + + Language getLanguageNow(UUID playerUniqueId); + + CompletableFuture setLanguage(UUID playerUniqueId, Language language); + + CompletableFuture setDefaultLanguage(UUID playerUniqueId); - void setPlayerLanguage(Player player, Locale locale); } diff --git a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java index 62aedd920..759178fd0 100644 --- a/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java +++ b/eternalcore-api/src/main/java/com/eternalcode/core/feature/warp/WarpService.java @@ -1,10 +1,10 @@ package com.eternalcode.core.feature.warp; import org.bukkit.Location; +import org.jetbrains.annotations.ApiStatus.Experimental; import java.util.Collection; import java.util.Optional; -import org.jetbrains.annotations.ApiStatus.Experimental; public interface WarpService { @@ -18,7 +18,7 @@ public interface WarpService { @Experimental Warp removePermissions(String warp, String... permissions); - boolean isExist(String name); + boolean exists(String name); Optional findWarp(String name); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/AbstractViewerArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/AbstractViewerArgument.java index 1bb38eb28..d25f49079 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/AbstractViewerArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/AbstractViewerArgument.java @@ -1,30 +1,31 @@ package com.eternalcode.core.bridge.litecommand.argument; +import com.eternalcode.core.feature.language.Language; 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; import dev.rollczi.litecommands.argument.resolver.ArgumentResolver; import dev.rollczi.litecommands.invocation.Invocation; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; public abstract class AbstractViewerArgument extends ArgumentResolver { - protected final ViewerService viewerService; protected final TranslationManager translationManager; - protected AbstractViewerArgument(ViewerService viewerService, TranslationManager translationManager) { - this.viewerService = viewerService; + protected AbstractViewerArgument(TranslationManager translationManager) { this.translationManager = translationManager; } @Override protected ParseResult parse(Invocation invocation, Argument context, String argument) { - Viewer viewer = this.viewerService.any(invocation.sender()); - Translation translation = this.translationManager.getMessages(viewer.getLanguage()); + if (invocation.sender() instanceof Player player) { + Translation translation = this.translationManager.getMessages(player.getUniqueId()); + return this.parse(invocation, argument, translation); + } + Translation translation = this.translationManager.getMessages(Language.DEFAULT); return this.parse(invocation, argument, translation); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/EnchantmentArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/EnchantmentArgument.java index 86d753e1f..0c230c4da 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/EnchantmentArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/EnchantmentArgument.java @@ -4,7 +4,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -21,8 +20,8 @@ class EnchantmentArgument extends AbstractViewerArgument { @Inject - EnchantmentArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + EnchantmentArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/GameModeArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/GameModeArgument.java index fe522a6a2..42d5ae476 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/GameModeArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/GameModeArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -23,8 +22,8 @@ class GameModeArgument extends AbstractViewerArgument { private final GameModeArgumentSettings gameModeArgumentSettings; @Inject - GameModeArgument(ViewerService viewerService, TranslationManager translationManager, GameModeArgumentSettings gameModeArgumentSettings) { - super(viewerService, translationManager); + GameModeArgument(TranslationManager translationManager, GameModeArgumentSettings gameModeArgumentSettings) { + super(translationManager); this.gameModeArgumentSettings = gameModeArgumentSettings; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/NoticeTypeArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/NoticeTypeArgument.java index 0371a6423..359774de0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/NoticeTypeArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/NoticeTypeArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.notice.NoticeTextType; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -19,8 +18,8 @@ class NoticeTypeArgument extends AbstractViewerArgument { @Inject - NoticeTypeArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + NoticeTypeArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java index 45f052ffd..3760173d4 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/PlayerArgument.java @@ -7,7 +7,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -25,12 +24,11 @@ public class PlayerArgument extends AbstractViewerArgument { @Inject public PlayerArgument( - ViewerService viewerService, TranslationManager translationManager, Server server, VanishService vanishService ) { - super(viewerService, translationManager); + super(translationManager); this.server = server; this.vanishService = vanishService; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/UserArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/UserArgument.java index ead59db6e..1c74a2ba3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/UserArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/bridge/litecommand/argument/UserArgument.java @@ -6,7 +6,6 @@ import com.eternalcode.core.translation.TranslationManager; import com.eternalcode.core.user.User; import com.eternalcode.core.user.UserManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -23,8 +22,8 @@ class UserArgument extends AbstractViewerArgument { private final UserManager userManager; @Inject - UserArgument(ViewerService viewerService, TranslationManager translationManager, Server server, UserManager userManager) { - super(viewerService, translationManager); + UserArgument(TranslationManager translationManager, Server server, UserManager userManager) { + super(translationManager); this.server = server; this.userManager = userManager; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java index aa45fa011..97e9e46c7 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/LocationsConfiguration.java @@ -22,7 +22,7 @@ public class LocationsConfiguration implements ReloadableConfig { public Position spawn = EMPTY_POSITION; @Description("# Warps now are stored in warps.yml. This is deprecated.") - @Deprecated + @Deprecated(since = "1.5.1", forRemoval = true) public Map warps = new HashMap<>(); @Description("# This is jail location, for your own safety, please don't touch it.") diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java index 30be682dd..b58bbdcdc 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/configuration/implementation/PluginConfiguration.java @@ -4,14 +4,15 @@ import com.eternalcode.core.database.DatabaseType; import com.eternalcode.core.feature.afk.AfkSettings; import com.eternalcode.core.feature.automessage.AutoMessageSettings; +import com.eternalcode.core.feature.catboy.CatBoySettings; import com.eternalcode.core.feature.chat.ChatSettings; import com.eternalcode.core.feature.helpop.HelpOpSettings; import com.eternalcode.core.feature.jail.JailSettings; import com.eternalcode.core.feature.randomteleport.RandomTeleportSettingsImpl; import com.eternalcode.core.feature.spawn.SpawnSettings; +import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; import com.eternalcode.core.injector.annotations.Bean; import com.eternalcode.core.injector.annotations.component.ConfigurationFile; -import com.eternalcode.core.feature.teleportrequest.TeleportRequestSettings; import net.dzikoysk.cdn.entity.Contextual; import net.dzikoysk.cdn.entity.Description; import net.dzikoysk.cdn.entity.Exclude; @@ -342,9 +343,12 @@ public static class Warp { @Description("# Warp inventory auto add new warps") public boolean autoAddNewWarps = true; + @Description("# Should item slots be recalculated after warp deletion") + public boolean recalculateWarpSlots = false; + @Description({"# Options below allow you to customize item representing warp added to GUI, ", "# you can change almost everything inside langueage files, after the warp has been added to the inventory."}) - public String itemNamePrefix = "&8» &6Warp: &f"; + public String itemNamePrefix = "&8» &6Warp: &f"; public String itemLore = "&7Click to teleport!"; @@ -421,6 +425,24 @@ public Set allowedCommands() { } } + @Bean + @Description({ " ", "# 4fun Section" }) + FunSection fun = new FunSection(); + + @Contextual + public static class FunSection implements CatBoySettings { + @Description({ + "# Speed of player walk speed while using /catboy feature", + "# Default minecraft walk speed is 0.2" + }) + public float catboyWalkSpeed = 0.4F; + + @Override + public float getCatboyWalkSpeed() { + return this.catboyWalkSpeed; + } + } + @Override public Resource resource(File folder) { return Source.of(folder, "config.yml"); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkKickController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkKickController.java index e472a0c9c..ffd047e56 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkKickController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkKickController.java @@ -60,7 +60,7 @@ void onAfkSwitch(AfkSwitchEvent event) { } User user = this.userManager.getOrCreate(playerUUID, player.getName()); - Translation translation = this.translationManager.getMessages(user); + Translation translation = this.translationManager.getMessages(user.getUniqueId()); Component component = this.miniMessage.deserialize(translation.afk().afkKickReason()); player.kickPlayer(legacySection().serialize(component)); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AftPlaceholderSetup.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AftPlaceholderSetup.java index c01fc695a..d5f167fb4 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AftPlaceholderSetup.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AftPlaceholderSetup.java @@ -9,7 +9,6 @@ import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; import com.eternalcode.core.util.DurationUtil; -import com.eternalcode.core.viewer.ViewerService; import java.time.Duration; import java.time.Instant; import java.util.Optional; @@ -18,12 +17,10 @@ class AftPlaceholderSetup { private final TranslationManager translationManager; - private final ViewerService viewerService; @Inject - AftPlaceholderSetup(TranslationManager translationManager, ViewerService viewerService) { + AftPlaceholderSetup(TranslationManager translationManager) { this.translationManager = translationManager; - this.viewerService = viewerService; } @Subscribe(EternalInitializeEvent.class) @@ -34,7 +31,7 @@ void setUpPlaceholders(PlaceholderRegistry placeholderRegistry, AfkService afkSe placeholderRegistry.registerPlaceholder(PlaceholderReplacer.of( "afk_formatted", player -> { - Translation messages = this.translationManager.getMessages(this.viewerService.player(player.getUniqueId())); + Translation messages = this.translationManager.getMessages(player.getUniqueId()); return afkService.isAfk(player.getUniqueId()) ? messages.afk().afkEnabledPlaceholder() : messages.afk().afkDisabledPlaceholder(); })); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherArgument.java similarity index 89% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherArgument.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherArgument.java index fd07a13a2..d32a11b46 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherArgument.java @@ -1,15 +1,15 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; import com.eternalcode.core.bridge.litecommand.argument.AbstractViewerArgument; import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.lite.LiteArgument; +import com.eternalcode.core.viewer.ViewerService; import com.eternalcode.multification.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.Viewer; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -25,12 +25,14 @@ class ButcherArgument extends AbstractViewerArgument { static final String KEY = "chunks"; private final PluginConfiguration pluginConfiguration; private final NoticeService noticeService; + private final ViewerService viewerService; @Inject - ButcherArgument(ViewerService viewerService, TranslationManager translationManager, PluginConfiguration pluginConfiguration, NoticeService noticeService) { - super(viewerService, translationManager); + ButcherArgument(TranslationManager translationManager, PluginConfiguration pluginConfiguration, NoticeService noticeService, ViewerService viewerService) { + super(translationManager); this.pluginConfiguration = pluginConfiguration; this.noticeService = noticeService; + this.viewerService = viewerService; } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherCommand.java similarity index 86% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherCommand.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherCommand.java index 0e64ff1f4..997837031 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/ButcherCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/ButcherCommand.java @@ -1,7 +1,7 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; import com.eternalcode.annotations.scan.command.DescriptionDocs; -import com.eternalcode.core.configuration.implementation.PluginConfiguration; +import com.eternalcode.core.event.EventCaller; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.notice.NoticeService; import dev.rollczi.litecommands.annotations.argument.Arg; @@ -25,10 +25,12 @@ class ButcherCommand { private final NoticeService noticeService; + private final EventCaller eventCaller; @Inject - ButcherCommand(NoticeService noticeService, PluginConfiguration pluginConfiguration) { + ButcherCommand(NoticeService noticeService, EventCaller eventCaller) { this.noticeService = noticeService; + this.eventCaller = eventCaller; } @Execute @@ -51,16 +53,21 @@ void execute(@Context Player player, @Arg(ButcherArgument.KEY) int chunks, @Arg( private void killMobs(Player player, int chunksNumber, MobFilter mobFilter) { Collection chunks = this.getChunksNearPlayer(player, chunksNumber); - int killedMobs = 0; for (Chunk chunk : chunks) { for (Entity entity : chunk.getEntities()) { - if (!mobFilter.filterMob(entity)) { continue; } + ButcherEntityRemoveEvent event = new ButcherEntityRemoveEvent(entity); + this.eventCaller.callEvent(event); + + if (event.isCancelled()) { + continue; + } + entity.remove(); killedMobs++; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntity.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntity.java similarity index 95% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntity.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntity.java index 5d437e92b..18689cca2 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntity.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntity.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; import com.eternalcode.core.util.EntityUtil; import org.bukkit.entity.Animals; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntityArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntityArgument.java similarity index 90% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntityArgument.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntityArgument.java index 05889cf5d..ef4228ebb 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobEntityArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobEntityArgument.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; import com.eternalcode.core.bridge.litecommand.argument.AbstractViewerArgument; import com.eternalcode.core.injector.annotations.Inject; @@ -6,7 +6,6 @@ import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; import com.eternalcode.core.util.EntityUtil; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -23,8 +22,8 @@ class MobEntityArgument extends AbstractViewerArgument { static final String KEY = "mobType"; @Inject - MobEntityArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + MobEntityArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobFilter.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobFilter.java similarity index 69% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobFilter.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobFilter.java index 21a5c60aa..53f0bc76c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobFilter.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobFilter.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; import org.bukkit.entity.Entity; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobType.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobType.java similarity index 91% rename from eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobType.java rename to eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobType.java index 1bc4ac2b7..1952d29c3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/mob/MobType.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/butcher/MobType.java @@ -1,4 +1,4 @@ -package com.eternalcode.core.feature.essentials.mob; +package com.eternalcode.core.feature.butcher; enum MobType { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoyEntityService.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoyEntityService.java new file mode 100644 index 000000000..70c5a627e --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoyEntityService.java @@ -0,0 +1,40 @@ +package com.eternalcode.core.feature.catboy; + +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Service; +import org.bukkit.NamespacedKey; +import org.bukkit.entity.Cat; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.persistence.PersistentDataContainer; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.Plugin; + +@Service +class CatBoyEntityService { + + private final NamespacedKey catboyNamespacedKey; + + @Inject + CatBoyEntityService(Plugin plugin) { + this.catboyNamespacedKey = new NamespacedKey(plugin, "catboy"); + } + + Cat createCatboyEntity(Player player, Cat.Type type) { + Cat cat = (Cat) player.getWorld().spawnEntity(player.getLocation(), EntityType.CAT); + cat.setInvulnerable(true); + cat.setOwner(player); + cat.setAI(false); + cat.setCatType(type); + + PersistentDataContainer persistentDataContainer = cat.getPersistentDataContainer(); + persistentDataContainer.set(catboyNamespacedKey, PersistentDataType.BOOLEAN, true); + + return cat; + } + + boolean isCatboy(Cat cat) { + return cat.getPersistentDataContainer().has(catboyNamespacedKey, PersistentDataType.BOOLEAN); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoySettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoySettings.java new file mode 100644 index 000000000..d11434300 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatBoySettings.java @@ -0,0 +1,7 @@ +package com.eternalcode.core.feature.catboy; + +public interface CatBoySettings { + + float getCatboyWalkSpeed(); + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyController.java index 253922a27..776aa418a 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyController.java @@ -1,9 +1,15 @@ package com.eternalcode.core.feature.catboy; import com.eternalcode.commons.scheduler.Scheduler; +import com.eternalcode.core.feature.butcher.ButcherEntityRemoveEvent; import com.eternalcode.core.feature.teleport.event.EternalTeleportEvent; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Controller; +import com.eternalcode.core.publish.Subscribe; +import com.eternalcode.core.publish.event.EternalShutdownEvent; +import java.time.Duration; +import java.util.Optional; +import org.bukkit.Server; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.entity.Cat; @@ -15,21 +21,27 @@ import org.bukkit.event.entity.EntityDismountEvent; import org.bukkit.event.player.PlayerQuitEvent; -import java.time.Duration; -import java.util.Optional; - @Controller class CatboyController implements Listener { private static final Duration TICK = Duration.ofMillis(50L); private final CatboyService catboyService; + private final CatBoyEntityService catBoyEntityService; private final Scheduler scheduler; + private final Server server; @Inject - CatboyController(CatboyService catboyService, Scheduler scheduler) { + CatboyController( + CatboyService catboyService, + CatBoyEntityService catBoyEntityService, + Scheduler scheduler, + Server server + ) { this.catboyService = catboyService; + this.catBoyEntityService = catBoyEntityService; this.scheduler = scheduler; + this.server = server; } @EventHandler @@ -60,7 +72,9 @@ void onTeleport(EternalTeleportEvent event) { Catboy catboy = optionalCatboy.get(); this.catboyService.unmarkAsCatboy(event.getPlayer()); - this.scheduler.runLater(() -> this.catboyService.markAsCatboy(event.getPlayer(), catboy.selectedType()), TICK); + this.scheduler.runLater( + () -> this.catboyService.markAsCatboy(event.getPlayer(), catboy.selectedType()), + TICK); } } @@ -85,4 +99,25 @@ void onHit(EntityDamageByEntityEvent event) { } } + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + void onEntityRemoveFromWorld(ButcherEntityRemoveEvent event) { + if (!(event.getEntity() instanceof Cat cat)) { + return; + } + + if (this.catBoyEntityService.isCatboy(cat)) { + event.setCancelled(true); + } + } + + @Subscribe + void onServerShutdown(EternalShutdownEvent event) { + for (Player onlinePlayer : this.server.getOnlinePlayers()) { + boolean catboy = this.catboyService.isCatboy(onlinePlayer.getUniqueId()); + + if (catboy) { + this.catboyService.unmarkAsCatboy(onlinePlayer); + } + } + } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyServiceImpl.java index 92c6dcdb8..bbe9a0cf8 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/catboy/CatboyServiceImpl.java @@ -5,26 +5,34 @@ import com.eternalcode.core.feature.catboy.event.CatboySwitchEvent; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; -import org.bukkit.entity.Cat; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; - import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Optional; import java.util.UUID; +import org.bukkit.entity.Cat; +import org.bukkit.entity.Player; @Service class CatboyServiceImpl implements CatboyService { + private static final float DEFAULT_WALK_SPEED = 0.2F; private final Map catboys = new HashMap<>(); private final EventCaller eventCaller; + private final CatBoyEntityService catBoyEntityService; + private final CatBoySettings catBoySettings; + @Inject - CatboyServiceImpl(EventCaller eventCaller) { + CatboyServiceImpl( + EventCaller eventCaller, + CatBoyEntityService catBoyEntityService, + CatBoySettings catBoySettings + ) { this.eventCaller = eventCaller; + this.catBoyEntityService = catBoyEntityService; + this.catBoySettings = catBoySettings; } @Override @@ -32,13 +40,9 @@ public void markAsCatboy(Player player, Cat.Type type) { Catboy catboy = new Catboy(player.getUniqueId(), type); this.catboys.put(player.getUniqueId(), catboy); - Cat entity = (Cat) player.getWorld().spawnEntity(player.getLocation(), EntityType.CAT); - entity.setInvulnerable(true); - entity.setOwner(player); - entity.setCatType(type); - - player.addPassenger(entity); - player.setWalkSpeed(0.4F); + Cat cat = this.catBoyEntityService.createCatboyEntity(player, type); + player.addPassenger(cat); + player.setWalkSpeed(this.catBoySettings.getCatboyWalkSpeed()); this.eventCaller.callEvent(new CatboySwitchEvent(player, true)); } @@ -48,7 +52,7 @@ public void unmarkAsCatboy(Player player) { this.catboys.remove(player.getUniqueId()); player.getPassengers().forEach(entity -> entity.remove()); player.getPassengers().clear(); - player.setWalkSpeed(0.2F); + player.setWalkSpeed(DEFAULT_WALK_SPEED); this.eventCaller.callEvent(new CatboySwitchEvent(player, false)); } @@ -90,5 +94,4 @@ public Optional getCatboy(UUID uuid) { public Collection getCatboys() { return Collections.unmodifiableCollection(this.catboys.values()); } - } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/container/DisposalCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/container/DisposalCommand.java index 9163e6621..f2d917565 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/container/DisposalCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/container/DisposalCommand.java @@ -2,11 +2,9 @@ import com.eternalcode.annotations.scan.command.DescriptionDocs; import com.eternalcode.core.injector.annotations.Inject; -import com.eternalcode.core.feature.language.Language; import com.eternalcode.core.notice.NoticeService; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.user.UserManager; import com.eternalcode.commons.adventure.AdventureUtil; import dev.rollczi.litecommands.annotations.context.Context; import dev.rollczi.litecommands.annotations.execute.Execute; @@ -24,14 +22,12 @@ class DisposalCommand { private final NoticeService noticeService; private final MiniMessage miniMessage; private final TranslationManager translationManager; - private final UserManager userManager; private final Server server; @Inject - DisposalCommand(MiniMessage miniMessage, TranslationManager translationManager, UserManager userManager, Server server, NoticeService noticeService) { + DisposalCommand(MiniMessage miniMessage, TranslationManager translationManager, Server server, NoticeService noticeService) { this.miniMessage = miniMessage; this.translationManager = translationManager; - this.userManager = userManager; this.server = server; this.noticeService = noticeService; } @@ -39,11 +35,7 @@ class DisposalCommand { @Execute @DescriptionDocs(description = "Opens a disposal") void execute(@Context Player player) { - Language language = this.userManager.getUser(player.getUniqueId()) - .map(user -> user.getSettings().getLanguage()) - .orElse(Language.DEFAULT); - - Translation translation = this.translationManager.getMessages(language); + Translation translation = this.translationManager.getMessages(player.getUniqueId()); Component component = this.miniMessage.deserialize(translation.inventory().disposalTitle()); String serialize = AdventureUtil.SECTION_SERIALIZER.serialize(component); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/enchant/EnchantArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/enchant/EnchantArgument.java index 290e4567a..b5dd51bae 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/enchant/EnchantArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/enchant/EnchantArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -22,8 +21,8 @@ public class EnchantArgument extends AbstractViewerArgument { public static final String KEY = "enchant-level"; @Inject - public EnchantArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + public EnchantArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveArgument.java index fbfe160a2..98c8b9c3c 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/give/GiveArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -22,8 +21,8 @@ class GiveArgument extends AbstractViewerArgument { static final String KEY = "item-amount"; @Inject - public GiveArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + public GiveArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreArgument.java index df14a7fb2..b561307da 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/item/lore/ItemLoreArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -22,8 +21,8 @@ class ItemLoreArgument extends AbstractViewerArgument { static final String KEY = "item-lore"; @Inject - public ItemLoreArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + public ItemLoreArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedArgument.java index e049f5a34..44dc65353 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -21,8 +20,8 @@ class SpeedArgument extends AbstractViewerArgument { static final String KEY = "speed"; @Inject - SpeedArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + SpeedArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedTypeArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedTypeArgument.java index 81e72ee8e..d924305ac 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedTypeArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/speed/SpeedTypeArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -19,8 +18,8 @@ class SpeedTypeArgument extends AbstractViewerArgument { @Inject - SpeedTypeArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + SpeedTypeArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/time/TimeArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/time/TimeArgument.java index 310a5e71d..ba4c96168 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/time/TimeArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/essentials/time/TimeArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -22,8 +21,8 @@ class TimeArgument extends AbstractViewerArgument { static final String KEY = "time"; @Inject - public TimeArgument(ViewerService viewerService, TranslationManager translationManager) { - super(viewerService, translationManager); + public TimeArgument(TranslationManager translationManager) { + super(translationManager); } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/fullserverbypass/FullServerBypassController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/fullserverbypass/FullServerBypassController.java index 6a8bc4032..fdcd5a252 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/fullserverbypass/FullServerBypassController.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/fullserverbypass/FullServerBypassController.java @@ -47,14 +47,14 @@ void onLogin(PlayerLoginEvent event) { return; } - String serverFullMessage = this.extractServerFullMessage(player); + String serverFullMessage = this.getServerFullMessage(player); Component serverFullMessageComponent = this.miniMessage.deserialize(serverFullMessage); event.disallow(PlayerLoginEvent.Result.KICK_FULL, AdventureUtil.SECTION_SERIALIZER.serialize(serverFullMessageComponent)); } } - private String extractServerFullMessage(Player player) { + private String getServerFullMessage(Player player) { Optional userOption = this.userManager.getUser(player.getUniqueId()); if (userOption.isEmpty()) { @@ -66,7 +66,7 @@ private String extractServerFullMessage(Player player) { User user = userOption.get(); return Joiner.on("\n") - .join(this.translationManager.getMessages(user).player().fullServerSlots()) + .join(this.translationManager.getMessages(user.getUniqueId()).player().fullServerSlots()) .toString(); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomePlaceholderSetup.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomePlaceholderSetup.java index 599f11999..f4d695763 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomePlaceholderSetup.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomePlaceholderSetup.java @@ -1,6 +1,5 @@ package com.eternalcode.core.feature.home; -import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Controller; import com.eternalcode.core.placeholder.PlaceholderRegistry; @@ -9,8 +8,6 @@ import com.eternalcode.core.publish.event.EternalInitializeEvent; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.user.User; -import com.eternalcode.core.user.UserManager; import java.util.Collection; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -20,21 +17,12 @@ class HomePlaceholderSetup { private final HomeService homeService; - private final UserManager userManager; private final TranslationManager translationManager; - private final PluginConfiguration pluginConfiguration; @Inject - HomePlaceholderSetup( - HomeService homeService, - UserManager userManager, - TranslationManager translationManager, - PluginConfiguration pluginConfiguration - ) { + HomePlaceholderSetup(HomeService homeService, TranslationManager translationManager) { this.homeService = homeService; - this.userManager = userManager; this.translationManager = translationManager; - this.pluginConfiguration = pluginConfiguration; } @Subscribe(EternalInitializeEvent.class) @@ -66,10 +54,7 @@ static String homesLeft(int homesLimit, int amountOfHomes) { private String ownedHomes(Player targetPlayer) { Collection homes = this.homeService.getHomes(targetPlayer.getUniqueId()); - - User user = this.userManager.getOrCreate(targetPlayer.getUniqueId(), targetPlayer.getName()); - - Translation translation = this.translationManager.getMessages(user); + Translation translation = this.translationManager.getMessages(targetPlayer.getUniqueId()); if (homes.isEmpty()) { return translation.home().noHomesOwnedPlaceholder(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/HomeArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/HomeArgument.java index 2a95bdb6d..e8a4d52fd 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/HomeArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/home/command/HomeArgument.java @@ -26,6 +26,7 @@ class HomeArgument extends AbstractViewerArgument { private final HomeService homeService; private final NoticeService noticeService; + private final ViewerService viewerService; @Inject HomeArgument( @@ -34,9 +35,10 @@ class HomeArgument extends AbstractViewerArgument { HomeService homeService, NoticeService noticeService ) { - super(viewerService, translationManager); + super(translationManager); this.homeService = homeService; this.noticeService = noticeService; + this.viewerService = viewerService; } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/BukkitLanguageProvider.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/BukkitLanguageProvider.java new file mode 100644 index 000000000..dbfcb1d63 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/BukkitLanguageProvider.java @@ -0,0 +1,48 @@ +package com.eternalcode.core.feature.language; + +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Service; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Locale; +import java.util.UUID; +import org.bukkit.Server; +import org.bukkit.entity.Player; + +@Service +class BukkitLanguageProvider implements LanguageProvider { + + private static Method LOCALE_METHOD; + + private final Server server; + + @Inject + BukkitLanguageProvider(Server server) { + this.server = server; + } + + @Override + public Language getDefaultLanguage(UUID player) { + Player serverPlayer = server.getPlayer(player); + + if (serverPlayer == null) { + return Language.DEFAULT; + } + + return Language.fromLocale(getLocale(serverPlayer)); + } + + private Locale getLocale(Player player) { + try { + // Someday, when we use Paper API, we can remove this + if (LOCALE_METHOD == null) { + LOCALE_METHOD = Player.class.getMethod("locale"); + } + return (Locale) LOCALE_METHOD.invoke(player); + } + catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException exception) { + return Locale.of(player.getLocale()); + } + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageCommand.java index cbf6418ea..cd5699898 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageCommand.java @@ -22,8 +22,8 @@ class LanguageCommand { @Execute @DescriptionDocs(description = "Open language inventory") - void execute(@Context Player player, @Context User user) { - this.languageInventory.open(player, user.getLanguage()); + void execute(@Context Player player) { + this.languageInventory.open(player); } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageInventory.java index 1ba3ca5fb..ab98774b3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageInventory.java @@ -2,6 +2,7 @@ import com.eternalcode.annotations.scan.feature.FeatureDocs; import com.eternalcode.commons.adventure.AdventureUtil; +import com.eternalcode.commons.scheduler.Scheduler; import com.eternalcode.core.configuration.contextual.ConfigItem; import com.eternalcode.core.feature.language.config.LanguageConfiguration; import com.eternalcode.core.injector.annotations.Inject; @@ -10,8 +11,6 @@ import com.eternalcode.core.notice.NoticeService; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.user.User; -import com.eternalcode.core.user.UserManager; import dev.triumphteam.gui.builder.item.BaseItemBuilder; import dev.triumphteam.gui.builder.item.ItemBuilder; import dev.triumphteam.gui.guis.Gui; @@ -23,7 +22,6 @@ import org.bukkit.entity.Player; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; @FeatureDocs( @@ -36,21 +34,41 @@ class LanguageInventory { private final LanguageConfiguration languageConfiguration; private final TranslationManager translationManager; private final NoticeService noticeService; - private final UserManager userManager; private final Server server; + private final Scheduler scheduler; private final MiniMessage miniMessage; + private final LanguageService languageService; @Inject - LanguageInventory(LanguageConfiguration languageConfiguration, TranslationManager translationManager, NoticeService noticeService, UserManager userManager, Server server, MiniMessage miniMessage) { + LanguageInventory( + LanguageConfiguration languageConfiguration, + TranslationManager translationManager, + NoticeService noticeService, + Server server, + Scheduler scheduler, + MiniMessage miniMessage, + LanguageService languageService + ) { this.languageConfiguration = languageConfiguration; this.translationManager = translationManager; this.noticeService = noticeService; - this.userManager = userManager; this.server = server; + this.scheduler = scheduler; this.miniMessage = miniMessage; + this.languageService = languageService; } - void open(Player player, Language language) { + void open(Player player) { + this.languageService.getLanguage(player.getUniqueId()).whenComplete((language, throwable) -> { + if (language == null) { + language = Language.DEFAULT; + } + + this.open(player, language); + }); + } + + private void open(Player player, Language language) { LanguageConfiguration.LanguageSelector languageSelector = this.languageConfiguration.languageSelector; Translation translation = this.translationManager.getMessages(language); Translation.LanguageSection languageSection = translation.language(); @@ -61,18 +79,10 @@ void open(Player player, Language language) { .disableAllInteractions() .create(); - Optional userOption = this.userManager.getUser(player.getUniqueId()); - - if (userOption.isEmpty()) { - return; - } - - User user = userOption.get(); - if (languageSelector.border.fill) { ItemBuilder borderItem = ItemBuilder.from(languageSelector.border.material); - if (!languageSelector.border.name.equals("")) { + if (!languageSelector.border.name.isEmpty()) { borderItem.name(AdventureUtil.resetItalic(this.miniMessage.deserialize(languageSelector.border.name))); } @@ -94,11 +104,11 @@ void open(Player player, Language language) { } for (LanguageConfigItem languageConfigItem : languageSelector.languageConfigItemMap) { - BaseItemBuilder baseItemBuilder = this.createItem(languageConfigItem); + BaseItemBuilder baseItemBuilder = this.createItem(languageConfigItem); GuiItem guiItem = baseItemBuilder.asGuiItem(); guiItem.setAction(event -> { - user.getSettings().setLanguage(languageConfigItem.language); + languageService.setLanguage(player.getUniqueId(), languageConfigItem.language); player.closeInventory(); @@ -112,7 +122,7 @@ void open(Player player, Language language) { } for (ConfigItem item : languageSection.decorationItems()) { - BaseItemBuilder baseItemBuilder = this.createItem(item); + BaseItemBuilder baseItemBuilder = this.createItem(item); GuiItem guiItem = baseItemBuilder.asGuiItem(); guiItem.setAction(event -> { @@ -130,10 +140,10 @@ void open(Player player, Language language) { gui.setItem(item.slot(), guiItem); } - gui.open(player); + scheduler.run(() -> gui.open(player)); } - private BaseItemBuilder createItem(ConfigItem item) { + private BaseItemBuilder createItem(ConfigItem item) { Component name = AdventureUtil.resetItalic(this.miniMessage.deserialize(item.name())); List lore = item.lore() .stream() diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageLoadController.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageLoadController.java new file mode 100644 index 000000000..0808063a0 --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageLoadController.java @@ -0,0 +1,31 @@ +package com.eternalcode.core.feature.language; + +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Controller; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +@Controller +class LanguageLoadController implements Listener { + + private final LanguageServiceImpl languageService; + + @Inject + LanguageLoadController(LanguageServiceImpl languageService) { + this.languageService = languageService; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + void onJoin(AsyncPlayerPreLoginEvent event) { + this.languageService.loadLanguage(event.getUniqueId()); + } + + @EventHandler + void onQuit(PlayerQuitEvent event) { + this.languageService.unloadLanguage(event.getPlayer().getUniqueId()); + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepository.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepository.java new file mode 100644 index 000000000..efc9054dd --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepository.java @@ -0,0 +1,15 @@ +package com.eternalcode.core.feature.language; + +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +interface LanguageRepository { + + CompletableFuture> findLanguage(UUID player); + + CompletableFuture saveLanguage(UUID player, Language language); + + CompletableFuture deleteLanguage(UUID player); + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepositoryImpl.java new file mode 100644 index 000000000..d7b2947bc --- /dev/null +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepositoryImpl.java @@ -0,0 +1,65 @@ +package com.eternalcode.core.feature.language; + +import com.eternalcode.commons.scheduler.Scheduler; +import com.eternalcode.core.database.DatabaseManager; +import com.eternalcode.core.database.wrapper.AbstractRepositoryOrmLite; +import com.eternalcode.core.injector.annotations.Inject; +import com.eternalcode.core.injector.annotations.component.Repository; +import com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; +import com.j256.ormlite.table.TableUtils; +import java.sql.SQLException; +import java.util.Locale; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; + +@Repository +class LanguageRepositoryImpl extends AbstractRepositoryOrmLite implements LanguageRepository { + + @Inject + LanguageRepositoryImpl(DatabaseManager databaseManager, Scheduler scheduler) throws SQLException { + super(databaseManager, scheduler); + TableUtils.createTableIfNotExists(databaseManager.connectionSource(), LanguageTable.class); + } + + @Override + public CompletableFuture> findLanguage(UUID player) { + return selectSafe(LanguageTable.class, player) + .thenApply(optional -> optional.map(table -> table.toLanguage())); + } + + @Override + public CompletableFuture saveLanguage(UUID player, Language language) { + return save(LanguageTable.class, new LanguageTable(player, language)) + .thenApply(status -> null); + } + + @Override + public CompletableFuture deleteLanguage(UUID player) { + return deleteById(LanguageTable.class, player) + .thenApply(result -> null); + } + + @DatabaseTable(tableName = "eternal_core_languages") + private static class LanguageTable { + + @DatabaseField(columnName = "id", id = true) + private UUID player; + + @DatabaseField + private String language; + + LanguageTable() {} + + LanguageTable(UUID player, Language language) { + this.player = player; + this.language = language.getLang(); + } + + Language toLanguage() { + return Language.fromLocale(Locale.of(language)); + } + } + +} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageServiceImpl.java index 0e7fa3ecf..d7ea3b6a6 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageServiceImpl.java @@ -2,38 +2,79 @@ import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; -import com.eternalcode.core.user.User; -import com.eternalcode.core.user.UserManager; -import java.util.Locale; -import java.util.Optional; -import org.bukkit.entity.Player; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; @Service -public class LanguageServiceImpl implements LanguageService { +class LanguageServiceImpl implements LanguageService { - private final UserManager userManager; + private final LanguageRepository languageRepository; + private final Map cachedLanguages = new ConcurrentHashMap<>(); + private LanguageProvider defaultProvider; @Inject - public LanguageServiceImpl(UserManager userManager) { - this.userManager = userManager; + LanguageServiceImpl(LanguageRepository languageRepository, LanguageProvider defaultProvider) { + this.languageRepository = languageRepository; + this.defaultProvider = defaultProvider; } @Override - public Locale getPlayerLanguage(Player player) { - Optional user = this.userManager.getUser(player.getUniqueId()); + public void setDefaultProvider(LanguageProvider defaultProvider) { + this.defaultProvider = defaultProvider; + } - if (user.isPresent()) { - Language language = user.get().getLanguage(); - return language.toLocale(); + @Override + public LanguageProvider getDefaultProvider() { + return defaultProvider; + } + + @Override + public Language getLanguageNow(UUID playerUniqueId) { + Language language = cachedLanguages.get(playerUniqueId); + if (language != null) { + return language; } - return Language.DEFAULT.toLocale(); + return defaultProvider.getDefaultLanguage(playerUniqueId); } @Override - public void setPlayerLanguage(Player player, Locale locale) { - Optional user = this.userManager.getUser(player.getUniqueId()); + public CompletableFuture getLanguage(UUID playerUniqueId) { + Language language = cachedLanguages.get(playerUniqueId); + if (language != null) { + return CompletableFuture.completedFuture(language); + } - user.ifPresent(value -> value.getSettings().setLanguage(Language.fromLocale(locale))); + return this.languageRepository.findLanguage(playerUniqueId) + .thenApply(optional -> optional.orElseGet(() -> this.defaultProvider.getDefaultLanguage(playerUniqueId))); } + + @Override + public CompletableFuture setLanguage(UUID playerUniqueId, Language language) { + if (language.equals(Language.DEFAULT)) { + return setDefaultLanguage(playerUniqueId); + } + + cachedLanguages.put(playerUniqueId, language); + return languageRepository.saveLanguage(playerUniqueId, language); + } + + @Override + public CompletableFuture setDefaultLanguage(UUID playerUniqueId) { + cachedLanguages.remove(playerUniqueId); + return languageRepository.deleteLanguage(playerUniqueId); + } + + CompletableFuture loadLanguage(UUID playerUniqueId) { + return languageRepository.findLanguage(playerUniqueId) + .thenAccept(language -> language.ifPresent(lang -> cachedLanguages.put(playerUniqueId, lang))); + } + + CompletableFuture unloadLanguage(UUID playerUniqueId) { + return languageRepository.findLanguage(playerUniqueId) + .thenAccept(language -> cachedLanguages.remove(playerUniqueId)); + } + } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageSettings.java deleted file mode 100644 index fafb60aa0..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageSettings.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.eternalcode.core.feature.language; - -public interface LanguageSettings { - - Language getLanguage(); - - void setLanguage(Language language); - - LanguageSettings DEFAULT = new LanguageSettings() { - @Override - public Language getLanguage() { - return Language.DEFAULT; - } - - @Override - public void setLanguage(Language language) {} - }; - -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/config/LanguageConfiguration.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/config/LanguageConfiguration.java index 4bbbbbbb2..f7f7a8e36 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/config/LanguageConfiguration.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/language/config/LanguageConfiguration.java @@ -67,8 +67,8 @@ public enum FillType { false, 20, Collections.emptyList(), - Language.EN) - ) + Language.EN + )) .add(new LanguageConfigItem( "&c&lAuto", Collections.singletonList("&7▪ Kliknij, aby pobierać język z ustawień klienta!"), @@ -77,8 +77,8 @@ public enum FillType { false, 22, Collections.emptyList(), - Language.DEFAULT) - ) + Language.DEFAULT + )) .add(new LanguageConfigItem( "&c&lPolish", Collections.singletonList("&7▪ Kliknij aby zmienić język!"), @@ -87,8 +87,8 @@ public enum FillType { false, 24, Collections.emptyList(), - Language.PL) - ) + Language.PL + )) .build(); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java index 381aecf0d..b83b93407 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java @@ -169,6 +169,7 @@ public Duration cooldown() { } @Override + @Deprecated(since = "1.5.0", forRemoval = true) public boolean migrate() { boolean migrated = false; if (randomTeleportDelay != null) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/RequesterArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/RequesterArgument.java index b3aee061f..368378d5e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/RequesterArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/teleportrequest/RequesterArgument.java @@ -5,7 +5,6 @@ import com.eternalcode.core.injector.annotations.lite.LiteArgument; import com.eternalcode.core.translation.Translation; import com.eternalcode.core.translation.TranslationManager; -import com.eternalcode.core.viewer.ViewerService; import dev.rollczi.litecommands.argument.Argument; import dev.rollczi.litecommands.argument.parser.ParseResult; import dev.rollczi.litecommands.invocation.Invocation; @@ -27,8 +26,8 @@ class RequesterArgument extends AbstractViewerArgument { private final Server server; @Inject - RequesterArgument(TeleportRequestService requestService, TranslationManager translationManager, ViewerService viewerService, Server server) { - super(viewerService, translationManager); + RequesterArgument(TeleportRequestService requestService, TranslationManager translationManager, Server server) { + super(translationManager); this.requestService = requestService; this.server = server; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java index fad84b34d..35dca19b6 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java @@ -5,6 +5,7 @@ import com.eternalcode.core.configuration.contextual.ConfigItem; import com.eternalcode.core.configuration.implementation.PluginConfiguration; import com.eternalcode.core.feature.language.Language; +import com.eternalcode.core.feature.language.LanguageService; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import com.eternalcode.core.translation.AbstractTranslation; @@ -21,7 +22,9 @@ import org.bukkit.Server; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Optional; @@ -37,6 +40,7 @@ public class WarpInventory { private static final int GUI_ROW_SIZE_WITH_BORDER = 7; private final TranslationManager translationManager; + private final LanguageService languageService; private final WarpService warpService; private final Server server; private final MiniMessage miniMessage; @@ -47,6 +51,7 @@ public class WarpInventory { @Inject WarpInventory( TranslationManager translationManager, + LanguageService languageService, WarpService warpService, Server server, MiniMessage miniMessage, @@ -55,6 +60,7 @@ public class WarpInventory { PluginConfiguration config ) { this.translationManager = translationManager; + this.languageService = languageService; this.warpService = warpService; this.server = server; this.miniMessage = miniMessage; @@ -63,9 +69,15 @@ public class WarpInventory { this.config = config; } - public void openInventory(Player player, Language language) { - this.createInventory(player, language) - .open(player); + public void openInventory(Player player) { + this.languageService.getLanguage(player.getUniqueId()).whenComplete((language, throwable) -> { + if (language == null) { + language = Language.DEFAULT; + } + + this.createInventory(player, language) + .open(player); + }); } private Gui createInventory(Player player, Language language) { @@ -205,7 +217,7 @@ private BaseItemBuilder createItem(ConfigItem item) { } public void addWarp(Warp warp) { - if (!this.warpService.isExist(warp.getName())) { + if (!this.warpService.exists(warp.getName())) { return; } @@ -251,7 +263,7 @@ public void removeWarp(String warpName) { return; } - if (!this.warpService.isExist(warpName)) { + if (!this.warpService.exists(warpName)) { return; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java index 5011d6564..a969cacf9 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpServiceImpl.java @@ -5,6 +5,8 @@ import com.eternalcode.core.feature.warp.repository.WarpRepository; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; +import org.bukkit.Location; + import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -13,7 +15,6 @@ import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; -import org.bukkit.Location; @FeatureDocs( name = "Warp System", @@ -90,7 +91,7 @@ private Warp modifyPermissions(String warpName, Consumer> modifier) } @Override - public boolean isExist(String name) { + public boolean exists(String name) { return this.warps.containsKey(name); } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java index d266bd9a0..0fb497a29 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/DelWarpCommand.java @@ -37,7 +37,7 @@ void remove(@Context Player player, @Arg Warp warp) { } private void removeWarp(Player player, String name) { - if (!this.warpService.isExist(name)) { + if (!this.warpService.exists(name)) { this.noticeService.create() .player(player.getUniqueId()) .notice(translation -> translation.warp().notExist()) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java index 1bf3171d7..92de010e5 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/SetWarpCommand.java @@ -44,7 +44,7 @@ void add(@Context Player player, @Arg String warpName) { } private void createWarp(Player player, String warp, UUID uniqueId) { - if (this.warpService.isExist(warp)) { + if (this.warpService.exists(warp)) { this.noticeService.create() .player(uniqueId) .notice(translation -> translation.warp().warpAlreadyExists()) diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java index 51fe1f3fd..cfedaa0df 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpArgument.java @@ -10,7 +10,6 @@ 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; import dev.rollczi.litecommands.invocation.Invocation; @@ -30,10 +29,9 @@ class WarpArgument extends AbstractViewerArgument { WarpArgument( WarpService warpService, TranslationManager translationManager, - ViewerService viewerService, NoticeService noticeService ) { - super(viewerService, translationManager); + super(translationManager); this.warpService = warpService; this.noticeService = noticeService; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java index 2b1e052d2..1c53f7236 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/command/WarpCommand.java @@ -44,7 +44,7 @@ class WarpCommand { @Execute(name = "warp") @DescriptionDocs(description = "Open warp inventory, optionally you can disable this feature in config, if feature is disabled eternalcore will show all available warps") - void warp(@Context Player player, @Context User user) { + void warp(@Context Player player) { if (!this.config.warp.inventoryEnabled) { List list = this.warpService.getWarps().stream().map(Warp::getName).toList(); @@ -66,7 +66,7 @@ void warp(@Context Player player, @Context User user) { return; } - this.warpInventory.openInventory(player, user.getLanguage()); + this.warpInventory.openInventory(player); } @Execute(name = "warp") diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java index d3f19b7a4..3a5317433 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/repository/WarpRepositoryImpl.java @@ -109,7 +109,7 @@ private CompletableFuture transactionalSupply(Function warps = new HashMap<>(this.warpConfig.warps); T result = editor.apply(warps); - this.warpConfig.warps.putAll(warps); + this.warpConfig.warps = warps; this.configurationManager.save(this.warpConfig); return result; } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/notice/NoticeService.java b/eternalcore-core/src/main/java/com/eternalcode/core/notice/NoticeService.java index 59efcd330..69ecdb76e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/notice/NoticeService.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/notice/NoticeService.java @@ -1,6 +1,8 @@ package com.eternalcode.core.notice; import com.eternalcode.commons.scheduler.Scheduler; +import com.eternalcode.core.feature.language.Language; +import com.eternalcode.core.feature.language.LanguageService; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import com.eternalcode.core.placeholder.PlaceholderRegistry; @@ -38,6 +40,7 @@ public class NoticeService extends Multification { private final MiniMessage miniMessage; private final NoticeResolverRegistry noticeRegistry; + private final LanguageService languageService; @Inject public NoticeService( @@ -48,7 +51,8 @@ public NoticeService( TranslationManager translationManager, PlaceholderRegistry registry, MiniMessage miniMessage, - NoticeResolverRegistry noticeRegistry + NoticeResolverRegistry noticeRegistry, + LanguageService languageService ) { this.userManager = userManager; this.scheduler = scheduler; @@ -58,6 +62,7 @@ public NoticeService( this.registry = registry; this.miniMessage = miniMessage; this.noticeRegistry = noticeRegistry; + this.languageService = languageService; } @Override @@ -83,7 +88,13 @@ public NoticeService( @Override public @NotNull LocaleProvider localeProvider() { - return viewer -> viewer.getLanguage().toLocale(); + return viewer -> { + if (viewer.isConsole()) { + return Language.DEFAULT.toLocale(); + } + + return languageService.getLanguageNow(viewer.getUniqueId()).toLocale(); + }; } @Override diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManager.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManager.java index de480d0d2..64988ebe9 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManager.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManager.java @@ -2,12 +2,13 @@ import com.eternalcode.annotations.scan.feature.FeatureDocs; import com.eternalcode.core.feature.language.Language; -import com.eternalcode.core.feature.language.LanguageSettings; +import com.eternalcode.core.feature.language.LanguageService; import com.eternalcode.core.user.User; import com.eternalcode.core.viewer.Viewer; import com.eternalcode.multification.translation.TranslationProvider; import java.util.Collections; import java.util.Set; +import java.util.UUID; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -21,10 +22,13 @@ ) public class TranslationManager implements TranslationProvider { + private final LanguageService languageService; + private final Map translatedMessages = new HashMap<>(); private Translation defaultTranslation; - TranslationManager(Translation defaultTranslation) { + TranslationManager(LanguageService languageService, Translation defaultTranslation) { + this.languageService = languageService; this.defaultTranslation = defaultTranslation; } @@ -32,6 +36,10 @@ public void loadLanguage(Language language, Translation translated) { this.translatedMessages.put(language, translated); } + public Translation getMessages(UUID uniqueId) { + return getMessages(this.languageService.getLanguageNow(uniqueId)); + } + public Translation getMessages(Language language) { Translation translation = this.translatedMessages.get(language); @@ -48,13 +56,6 @@ public Translation getMessages(Language language) { return this.defaultTranslation; } - public Translation getMessages(User user) { - LanguageSettings settings = user.getSettings(); - Language language = settings.getLanguage(); - - return this.getMessages(language); - } - public Translation getDefaultMessages() { return this.defaultTranslation; } @@ -63,10 +64,6 @@ public void setDefaultMessages(Translation defaultTranslation) { this.defaultTranslation = defaultTranslation; } - public Translation getMessages(Viewer viewer) { - return this.getMessages(viewer.getLanguage()); - } - @NotNull @Override public Translation provide(Locale locale) { @@ -74,8 +71,7 @@ public Translation provide(Locale locale) { } public Set getAvailableLanguages() { - return Collections.unmodifiableSet( - this.translatedMessages.keySet() - ); + return Collections.unmodifiableSet(this.translatedMessages.keySet()); } + } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManagerSetup.java b/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManagerSetup.java index aa1e51182..7d6e9fba1 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManagerSetup.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManagerSetup.java @@ -1,6 +1,7 @@ package com.eternalcode.core.translation; import com.eternalcode.core.configuration.ConfigurationManager; +import com.eternalcode.core.feature.language.LanguageService; import com.eternalcode.core.injector.annotations.Bean; import com.eternalcode.core.injector.annotations.component.Setup; import com.eternalcode.core.feature.language.config.LanguageConfiguration; @@ -12,7 +13,11 @@ class TranslationManagerSetup { @Bean - TranslationManager translationManager(ConfigurationManager configurationManager, LanguageConfiguration languageConfiguration) { + TranslationManager translationManager( + ConfigurationManager configurationManager, + LanguageService languageService, + LanguageConfiguration languageConfiguration + ) { List usedMessagesList = PandaStream.of(languageConfiguration.languages) .map(TranslationFactory::create) .toList(); @@ -21,7 +26,7 @@ TranslationManager translationManager(ConfigurationManager configurationManager, .find(usedMessages -> usedMessages.getLanguage().equals(languageConfiguration.defaultLanguage)) .orThrow(() -> new RuntimeException("Default language not found!")); - TranslationManager translationManager = new TranslationManager(defaultTranslation); + TranslationManager translationManager = new TranslationManager(languageService, defaultTranslation); for (ReloadableTranslation message : usedMessagesList) { configurationManager.load(message); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/User.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/User.java index ad5affee7..0536b877a 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/User.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/user/User.java @@ -1,6 +1,5 @@ package com.eternalcode.core.user; -import com.eternalcode.core.feature.language.Language; import com.eternalcode.core.viewer.Viewer; import java.util.Objects; @@ -8,7 +7,6 @@ public class User implements Viewer { - private UserSettings userSettings = new UserSettingsImpl(() -> this.userClientSettings); private UserClientSettings userClientSettings = UserClientSettings.NONE; private final String name; @@ -29,11 +27,6 @@ public UUID getUniqueId() { return this.uuid; } - @Override - public Language getLanguage() { - return this.userSettings.getLanguage(); - } - @Override public boolean isConsole() { return false; @@ -47,14 +40,6 @@ public void setClientSettings(UserClientSettings userClientSettings) { this.userClientSettings = userClientSettings; } - public UserSettings getSettings() { - return this.userSettings; - } - - public void setSettings(UserSettings userSettings) { - this.userSettings = userSettings; - } - @Override public boolean equals(Object o) { if (this == o) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientBukkitSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientBukkitSettings.java index ce82852d1..088e4698e 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientBukkitSettings.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientBukkitSettings.java @@ -20,6 +20,11 @@ class UserClientBukkitSettings implements UserClientSettings { this.playerReference = new WeakReference<>(server.getPlayer(uuid)); } + @Override + public boolean isOnline() { + return this.getPlayer().isPresent(); + } + private Option getPlayer() { Player player = this.playerReference.get(); @@ -37,17 +42,4 @@ private Option getPlayer() { return Option.of(player); } - private Player getPlayerOrThrow() { - return this.getPlayer().orThrow(() -> new IllegalStateException("Player is offline")); - } - - @Override - public Locale getLocate() { - return new Locale(this.getPlayerOrThrow().getLocale()); - } - - @Override - public boolean isOnline() { - return this.getPlayer().isPresent(); - } } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientNoneSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientNoneSettings.java index 77701c398..62fdb60a0 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientNoneSettings.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientNoneSettings.java @@ -1,14 +1,7 @@ package com.eternalcode.core.user; -import java.util.Locale; - class UserClientNoneSettings implements UserClientSettings { - @Override - public Locale getLocate() { - return Locale.ENGLISH; - } - @Override public boolean isOnline() { return false; diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientSettings.java index 6607e126a..7a0012bf3 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientSettings.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserClientSettings.java @@ -1,11 +1,7 @@ package com.eternalcode.core.user; -import java.util.Locale; - public interface UserClientSettings { - Locale getLocate(); - UserClientSettings NONE = new UserClientNoneSettings(); boolean isOnline(); diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettings.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettings.java deleted file mode 100644 index c1c39d5b2..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettings.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.eternalcode.core.user; - -import com.eternalcode.core.feature.language.Language; -import com.eternalcode.core.feature.language.LanguageSettings; - -public interface UserSettings extends LanguageSettings { - - @Override - Language getLanguage(); - - @Override - void setLanguage(Language language); - -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettingsImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettingsImpl.java deleted file mode 100644 index 38574c4ec..000000000 --- a/eternalcore-core/src/main/java/com/eternalcode/core/user/UserSettingsImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.eternalcode.core.user; - -import com.eternalcode.core.feature.language.Language; - -import java.util.function.Supplier; - -class UserSettingsImpl implements UserSettings { - - private final Supplier clientSettings; - private Language language = Language.DEFAULT; - - public UserSettingsImpl(Supplier clientSettings) { - this.clientSettings = clientSettings; - } - - @Override - public Language getLanguage() { - return this.language != Language.DEFAULT - ? this.language - : Language.fromLocale(this.clientSettings.get().getLocate()); - } - - @Override - public void setLanguage(Language language) { - this.language = language; - } - -} diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerImpl.java b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerImpl.java index 6941e48da..535cf8c2f 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerImpl.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerImpl.java @@ -1,37 +1,28 @@ package com.eternalcode.core.viewer; -import com.eternalcode.core.feature.language.Language; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.UUID; -import java.util.function.Supplier; class BukkitViewerImpl implements Viewer { - private static final BukkitViewerImpl CONSOLE = new BukkitViewerImpl(UUID.nameUUIDFromBytes("CONSOLE".getBytes()), true, Language.DEFAULT); + private static final BukkitViewerImpl CONSOLE = new BukkitViewerImpl(UUID.nameUUIDFromBytes("CONSOLE".getBytes()), true); private final UUID uuid; private final boolean console; - private final Supplier language; - - private BukkitViewerImpl(UUID uuid, boolean console, Language language) { - this(uuid, console, () -> language); - } - - private BukkitViewerImpl(UUID uuid, boolean console, Supplier language) { + private BukkitViewerImpl(UUID uuid, boolean console) { this.uuid = uuid; this.console = console; - this.language = language; } - public static BukkitViewerImpl console() { + static BukkitViewerImpl console() { return CONSOLE; } - public static BukkitViewerImpl player(UUID uuid, Language language) { - return new BukkitViewerImpl(uuid, false, language); + static BukkitViewerImpl player(UUID uuid) { + return new BukkitViewerImpl(uuid, false); } @Override @@ -59,9 +50,4 @@ public String getName() { return player.getName(); } - @Override - public Language getLanguage() { - return this.language.get(); - } - } diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerProvider.java b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerProvider.java index 1720c3455..45acecd12 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerProvider.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/BukkitViewerProvider.java @@ -1,6 +1,5 @@ package com.eternalcode.core.viewer; -import com.eternalcode.core.feature.language.Language; import com.eternalcode.core.injector.annotations.Inject; import com.eternalcode.core.injector.annotations.component.Service; import com.eternalcode.core.user.User; @@ -61,12 +60,12 @@ public Viewer console() { public Viewer player(UUID uuid) { return this.userManager.getUser(uuid) .map(Viewer.class::cast) - .orElseGet(() -> BukkitViewerImpl.player(uuid, Language.DEFAULT)); + .orElseGet(() -> BukkitViewerImpl.player(uuid)); } @Override public Viewer user(User user) { - return BukkitViewerImpl.player(user.getUniqueId(), user.getSettings().getLanguage()); + return BukkitViewerImpl.player(user.getUniqueId()); } public Viewer sender(CommandSender commandSender) { @@ -82,7 +81,7 @@ public Viewer any(Object any) { return userOption.get(); } - return BukkitViewerImpl.player(player.getUniqueId(), Language.DEFAULT); + return BukkitViewerImpl.player(player.getUniqueId()); } if (any instanceof ConsoleCommandSender || any instanceof RemoteConsoleCommandSender || any instanceof BlockCommandSender) { diff --git a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/Viewer.java b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/Viewer.java index b04d344be..14506e29b 100644 --- a/eternalcore-core/src/main/java/com/eternalcode/core/viewer/Viewer.java +++ b/eternalcore-core/src/main/java/com/eternalcode/core/viewer/Viewer.java @@ -1,15 +1,11 @@ package com.eternalcode.core.viewer; -import com.eternalcode.core.feature.language.Language; - import java.util.UUID; public interface Viewer { UUID getUniqueId(); - Language getLanguage(); - boolean isConsole(); String getName(); diff --git a/eternalcore-core/src/test/java/com/eternalcode/core/test/MockServer.java b/eternalcore-core/src/test/java/com/eternalcode/core/test/MockServer.java index d60003c01..4bd6764e3 100644 --- a/eternalcore-core/src/test/java/com/eternalcode/core/test/MockServer.java +++ b/eternalcore-core/src/test/java/com/eternalcode/core/test/MockServer.java @@ -62,13 +62,13 @@ public void quitPlayer(Player player) { } public void kickPlayer(Player player) { - this.onlinePlayers.remove(player.getUniqueId()); - PlayerKickEvent event = new PlayerKickEvent(player, "Player " + player.getName() + " has been kicked!", "Kicked!"); for (Consumer kickListener : this.kickListeners) { kickListener.accept(event); } + + this.quitPlayer(player); } public void listenJoin(Consumer joinListener) { diff --git a/eternalcore-core/src/test/java/com/eternalcode/core/test/MockViewer.java b/eternalcore-core/src/test/java/com/eternalcode/core/test/MockViewer.java index bbba9cc8e..c25eef78c 100644 --- a/eternalcore-core/src/test/java/com/eternalcode/core/test/MockViewer.java +++ b/eternalcore-core/src/test/java/com/eternalcode/core/test/MockViewer.java @@ -30,11 +30,6 @@ public UUID getUniqueId() { return this.uuid; } - @Override - public Language getLanguage() { - return Language.EN; - } - @Override public String getName() { return this.name;