-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new locale provider PLAYER_CHOICE allow player to set individuall…
…y their language by using command
- Loading branch information
Showing
15 changed files
with
239 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/main/java/pl/teksusik/customskins/i18n/locale/FixedLocaleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/pl/teksusik/customskins/i18n/locale/LocaleProviderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package pl.teksusik.customskins.i18n.locale; | ||
|
||
public enum LocaleProviderType { | ||
PLAYER, FIXED; | ||
PLAYER_CHOICE, PLAYER, FIXED; | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/pl/teksusik/customskins/i18n/locale/PlayerChoiceLocaleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package pl.teksusik.customskins.i18n.locale; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.name.Named; | ||
import eu.okaeri.i18n.locale.LocaleProvider; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.Nullable; | ||
import pl.teksusik.customskins.storage.Storage; | ||
|
||
import java.util.Locale; | ||
import java.util.Optional; | ||
|
||
public class PlayerChoiceLocaleProvider implements LocaleProvider<Player> { | ||
@Inject | ||
private Storage storage; | ||
@Inject | ||
@Named("defaultLocale") | ||
private Locale fallbackLocale; | ||
|
||
@Override | ||
public boolean supports(Class<?> type) { | ||
return Player.class.isAssignableFrom(type); | ||
} | ||
|
||
@Override | ||
public @Nullable Locale getLocale(Player entity) { | ||
Optional<String> preferableLocale = this.storage.findLocale(entity.getUniqueId()); | ||
if (preferableLocale.isEmpty()) { | ||
return this.fallbackLocale; | ||
} | ||
|
||
Locale locale = Locale.forLanguageTag(preferableLocale.get().replace("_", "-")); | ||
if (locale == null) { | ||
return this.fallbackLocale; | ||
} | ||
|
||
return locale; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
src/main/java/pl/teksusik/customskins/i18n/locale/PlayerLocaleProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.