mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-02-21 14:52:05 +01:00
Added language selection using command (as alternative to GUI)
Implements https://github.com/BentoBoxWorld/BentoBox/issues/1411 The IslandLanguageCommand now have tab-completion. Added LocalesManager#isLocaleAvailable(Locale).
This commit is contained in:
parent
360a417a4a
commit
0e3535d0cc
@ -1,10 +1,12 @@
|
|||||||
package world.bentobox.bentobox.api.commands.island;
|
package world.bentobox.bentobox.api.commands.island;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.bentobox.panels.LanguagePanel;
|
import world.bentobox.bentobox.panels.LanguagePanel;
|
||||||
|
import world.bentobox.bentobox.util.Util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
@ -20,11 +22,40 @@ public class IslandLanguageCommand extends CompositeCommand {
|
|||||||
setPermission("island.language");
|
setPermission("island.language");
|
||||||
setOnlyPlayer(true);
|
setOnlyPlayer(true);
|
||||||
setDescription("commands.island.language.description");
|
setDescription("commands.island.language.description");
|
||||||
|
setParametersHelp("commands.island.language.parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(User user, String label, List<String> args) {
|
public boolean execute(User user, String label, List<String> args) {
|
||||||
|
if (args.size() == 1) {
|
||||||
|
// The user provided a language code
|
||||||
|
Locale locale = Locale.forLanguageTag(args.get(0));
|
||||||
|
if (getPlugin().getLocalesManager().isLocaleAvailable(locale)) {
|
||||||
|
// Check if that locale is not already selected
|
||||||
|
if (!user.getLocale().equals(locale)) {
|
||||||
|
getPlugin().getPlayers().setLocale(user.getUniqueId(), locale.toLanguageTag());
|
||||||
|
user.sendMessage("language.edited", "[lang]", locale.toLanguageTag());
|
||||||
|
} else {
|
||||||
|
user.sendMessage("commands.island.language.already-selected");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
user.sendMessage("commands.island.language.not-available");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
LanguagePanel.openPanel(user);
|
LanguagePanel.openPanel(user);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<List<String>> tabComplete(User user, String alias, List<String> args) {
|
||||||
|
List<String> options = new ArrayList<>();
|
||||||
|
String lastArg = !args.isEmpty() ? args.get(args.size()-1) : "";
|
||||||
|
for (Locale locale : getPlugin().getLocalesManager().getAvailableLocales(true)) {
|
||||||
|
options.add(locale.toLanguageTag());
|
||||||
|
}
|
||||||
|
return Optional.of(Util.tabLimit(options, lastArg));
|
||||||
|
}
|
||||||
}
|
}
|
@ -296,6 +296,16 @@ public class LocalesManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns {@code true} if this locale is available, {@code false} otherwise.
|
||||||
|
* @param locale the locale, not null. Consider using {@link Locale#forLanguageTag(String)} if needed.
|
||||||
|
* @return {@code true} if this locale is available, {@code false} otherwise.
|
||||||
|
* @since 1.14.0
|
||||||
|
*/
|
||||||
|
public boolean isLocaleAvailable(@NonNull Locale locale) {
|
||||||
|
return languages.containsKey(locale);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return raw map of system locales to BentoBox locales
|
* @return raw map of system locales to BentoBox locales
|
||||||
*/
|
*/
|
||||||
|
@ -657,6 +657,9 @@ commands:
|
|||||||
description: "display island settings"
|
description: "display island settings"
|
||||||
language:
|
language:
|
||||||
description: "select language"
|
description: "select language"
|
||||||
|
parameters: "[language]"
|
||||||
|
not-available: "&c This language is not available."
|
||||||
|
already-selected: "&c You are already using this language."
|
||||||
expel:
|
expel:
|
||||||
description: "expel a player from your island"
|
description: "expel a player from your island"
|
||||||
parameters: "<player>"
|
parameters: "<player>"
|
||||||
|
Loading…
Reference in New Issue
Block a user