Skip to content

Commit

Permalink
Merge branch 'master' into fix-butcher-catboy-add-config
Browse files Browse the repository at this point in the history
# Conflicts:
#	eternalcore-api/src/main/java/com/eternalcode/core/feature/language/LanguageService.java
#	eternalcore-core/src/main/java/com/eternalcode/core/feature/home/HomePlaceholderSetup.java
#	eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageInventory.java
#	eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageRepositoryImpl.java
#	eternalcore-core/src/main/java/com/eternalcode/core/feature/language/LanguageServiceImpl.java
#	eternalcore-core/src/main/java/com/eternalcode/core/notice/NoticeService.java
#	eternalcore-core/src/main/java/com/eternalcode/core/translation/TranslationManagerSetup.java
  • Loading branch information
Rollczi committed Jan 17, 2025
2 parents 2f6a790 + 8936fa3 commit 0495cf6
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public interface LanguageService {

LanguageProvider getDefaultProvider();

CompletableFuture<Language> getLanguage(UUID player);
CompletableFuture<Language> getLanguage(UUID playerUniqueId);

Language getLanguageNow(UUID player);
Language getLanguageNow(UUID playerUniqueId);

CompletableFuture<Void> setLanguage(UUID player, Language language);
CompletableFuture<Void> setLanguage(UUID playerUniqueId, Language language);

CompletableFuture<Void> setDefaultLanguage(UUID player);
CompletableFuture<Void> setDefaultLanguage(UUID playerUniqueId);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -66,10 +54,7 @@ static String homesLeft(int homesLimit, int amountOfHomes) {

private String ownedHomes(Player targetPlayer) {
Collection<Home> homes = this.homeService.getHomes(targetPlayer.getUniqueId());

User user = this.userManager.getOrCreate(targetPlayer.getUniqueId(), targetPlayer.getName());

Translation translation = this.translationManager.getMessages(user.getUniqueId());
Translation translation = this.translationManager.getMessages(targetPlayer.getUniqueId());

if (homes.isEmpty()) {
return translation.home().noHomesOwnedPlaceholder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ class LanguageInventory {
private final LanguageService languageService;

@Inject
LanguageInventory(LanguageConfiguration languageConfiguration, TranslationManager translationManager, NoticeService noticeService, Server server, Scheduler scheduler, MiniMessage miniMessage, LanguageService languageService) {
LanguageInventory(
LanguageConfiguration languageConfiguration,
TranslationManager translationManager,
NoticeService noticeService,
Server server,
Scheduler scheduler,
MiniMessage miniMessage,
LanguageService languageService
) {
this.languageConfiguration = languageConfiguration;
this.translationManager = translationManager;
this.noticeService = noticeService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static class LanguageTable {
this.language = language.getLang();
}

public Language toLanguage() {
Language toLanguage() {
return Language.fromLocale(Locale.of(language));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,50 @@ public LanguageProvider getDefaultProvider() {
}

@Override
public Language getLanguageNow(UUID player) {
Language language = cachedLanguages.get(player);
public Language getLanguageNow(UUID playerUniqueId) {
Language language = cachedLanguages.get(playerUniqueId);
if (language != null) {
return language;
}

return defaultProvider.getDefaultLanguage(player);
return defaultProvider.getDefaultLanguage(playerUniqueId);
}

@Override
public CompletableFuture<Language> getLanguage(UUID player) {
Language language = cachedLanguages.get(player);
public CompletableFuture<Language> getLanguage(UUID playerUniqueId) {
Language language = cachedLanguages.get(playerUniqueId);
if (language != null) {
return CompletableFuture.completedFuture(language);
}

return this.languageRepository.findLanguage(player)
.thenApply(optional -> optional.orElseGet(() -> this.defaultProvider.getDefaultLanguage(player)));
return this.languageRepository.findLanguage(playerUniqueId)
.thenApply(optional -> optional.orElseGet(() -> this.defaultProvider.getDefaultLanguage(playerUniqueId)));
}

@Override
public CompletableFuture<Void> setLanguage(UUID player, Language language) {
public CompletableFuture<Void> setLanguage(UUID playerUniqueId, Language language) {
if (language.equals(Language.DEFAULT)) {
return setDefaultLanguage(player);
return setDefaultLanguage(playerUniqueId);
}

cachedLanguages.put(player, language);
return languageRepository.saveLanguage(player, language);
cachedLanguages.put(playerUniqueId, language);
return languageRepository.saveLanguage(playerUniqueId, language);
}

@Override
public CompletableFuture<Void> setDefaultLanguage(UUID player) {
cachedLanguages.remove(player);
return languageRepository.deleteLanguage(player);
public CompletableFuture<Void> setDefaultLanguage(UUID playerUniqueId) {
cachedLanguages.remove(playerUniqueId);
return languageRepository.deleteLanguage(playerUniqueId);
}

CompletableFuture<Void> loadLanguage(UUID uniqueId) {
return languageRepository.findLanguage(uniqueId)
.thenAccept(language -> language.ifPresent(lang -> cachedLanguages.put(uniqueId, lang)));
CompletableFuture<Void> loadLanguage(UUID playerUniqueId) {
return languageRepository.findLanguage(playerUniqueId)
.thenAccept(language -> language.ifPresent(lang -> cachedLanguages.put(playerUniqueId, lang)));
}

CompletableFuture<Void> unloadLanguage(UUID uniqueId) {
return languageRepository.findLanguage(uniqueId)
.thenAccept(language -> cachedLanguages.remove(uniqueId));
CompletableFuture<Void> unloadLanguage(UUID playerUniqueId) {
return languageRepository.findLanguage(playerUniqueId)
.thenAccept(language -> cachedLanguages.remove(playerUniqueId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public NoticeService(
TranslationManager translationManager,
PlaceholderRegistry registry,
MiniMessage miniMessage,
NoticeResolverRegistry noticeRegistry, LanguageService languageService
NoticeResolverRegistry noticeRegistry,
LanguageService languageService
) {
this.userManager = userManager;
this.scheduler = scheduler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
class TranslationManagerSetup {

@Bean
TranslationManager translationManager(ConfigurationManager configurationManager, LanguageService languageService, LanguageConfiguration languageConfiguration) {
TranslationManager translationManager(
ConfigurationManager configurationManager,
LanguageService languageService,
LanguageConfiguration languageConfiguration
) {
List<AbstractTranslation> usedMessagesList = PandaStream.of(languageConfiguration.languages)
.map(TranslationFactory::create)
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlayerKickEvent> kickListener : this.kickListeners) {
kickListener.accept(event);
}

this.quitPlayer(player);
}

public void listenJoin(Consumer<PlayerJoinEvent> joinListener) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public UUID getUniqueId() {
return this.uuid;
}

@Override
public Language getLanguage() {
return Language.EN;
}

@Override
public String getName() {
return this.name;
Expand Down

0 comments on commit 0495cf6

Please sign in to comment.