Skip to content

Commit

Permalink
uuid passing
Browse files Browse the repository at this point in the history
  • Loading branch information
tim03we committed Dec 16, 2024
1 parent 8708006 commit 2db70b3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
13 changes: 7 additions & 6 deletions src/main/java/ovis/futureplots/commands/SubCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@ public boolean hasPermission(Player player) {
return this.permissions == null || this.permissions.stream().anyMatch(player::hasPermission);
}

protected String translate(CommandSender sender, TranslationKey key, Object... replacements) {
return translate(sender, key.getKey(), replacements);
}

protected String translate(CommandSender sender, String key, Object... replacements) {
if(sender instanceof Player) {
return new LanguageManager(((Player) sender).getLoginChainData().getLanguageCode()).message(key, replacements);
Player player = (Player) sender;
return new LanguageManager(player.getLoginChainData().getLanguageCode()).message(player.getUniqueId(), key, replacements);
}
return new LanguageManager(FuturePlots.getSettings().getDefaultLanguage()).message(key, replacements);
}

protected String translate(CommandSender sender, TranslationKey key, Object... replacements) {
return translate(sender, key.getKey(), replacements);
return new LanguageManager(FuturePlots.getSettings().getDefaultLanguage()).message(null, key, replacements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
* @author Tim tim03we, Ovis Development (2024)
Expand Down Expand Up @@ -74,7 +75,7 @@ public void init() {
}

@Override
public String message(String locale, String key, Object... replacements) {
public String message(UUID uuid, String locale, String key, Object... replacements) {
String message = messages.getOrDefault(locale, new HashMap<>()).getOrDefault(key, "null");
if (replacements == null)
return message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import ovis.futureplots.components.util.language.handler.MainHandler;
import ovis.futureplots.components.util.language.TranslationKey;

import java.util.UUID;

/**
* @author Tim tim03we, Ovis Development (2024)
*/
Expand All @@ -46,14 +48,28 @@ public LanguageManager(String locale) {
this.locale = locale;
}

/*
*
* The UUID only has a use for custom handlers to customize the player language
*
*/

public String message(TranslationKey translationKey, Object... replacements) {
return message(translationKey.getKey(), replacements);
return message(null, translationKey.getKey(), replacements);
}

public String message(String key, Object... replacements) {
return message(null, key, replacements);
}

public String message(UUID uuid, TranslationKey translationKey, Object... replacements) {
return message(uuid, translationKey.getKey(), replacements);
}

public String message(UUID uuid, String key, Object... replacements) {
if(FuturePlots.getSettings().isDefaultLangEnabled()) {
this.locale = FuturePlots.getSettings().getDefaultLanguage();
}
return handler.message(this.locale, key, replacements);
return handler.message(uuid, this.locale, key, replacements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@

package ovis.futureplots.components.util.language.provider;

import javax.annotation.Nullable;
import java.util.UUID;

/**
* @author Tim tim03we, Ovis Development (2024)
*/
public interface LanguageProvider {

void init();

String message(String locale, String key, Object... replacements);
String message(@Nullable UUID uuid, String locale, String key, Object... replacements);
}

0 comments on commit 2db70b3

Please sign in to comment.