feat(language): reworked messages and formatting
This commit is contained in:
parent
5197fefdaf
commit
0ef5766004
71 changed files with 670 additions and 522 deletions
|
@ -12,8 +12,8 @@ import xyz.ineanto.nicko.config.Configuration;
|
|||
import xyz.ineanto.nicko.config.ConfigurationManager;
|
||||
import xyz.ineanto.nicko.event.PlayerJoinListener;
|
||||
import xyz.ineanto.nicko.event.PlayerQuitListener;
|
||||
import xyz.ineanto.nicko.i18n.CustomLocale;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.CustomLanguage;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.migration.ConfigurationMigrator;
|
||||
import xyz.ineanto.nicko.migration.CustomLocaleMigrator;
|
||||
import xyz.ineanto.nicko.mojang.MojangAPI;
|
||||
|
@ -28,8 +28,8 @@ import xyz.xenondevs.invui.item.impl.SimpleItem;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class NickoBukkit extends JavaPlugin {
|
||||
private static NickoBukkit plugin;
|
||||
public class Nicko extends JavaPlugin {
|
||||
private static Nicko plugin;
|
||||
|
||||
private final boolean unitTesting;
|
||||
|
||||
|
@ -37,19 +37,19 @@ public class NickoBukkit extends JavaPlugin {
|
|||
private PlayerDataStore dataStore;
|
||||
private ConfigurationManager configurationManager;
|
||||
private Configuration configuration;
|
||||
private CustomLocale customLocale;
|
||||
private CustomLanguage customLanguage;
|
||||
private PlayerNameStore nameStore;
|
||||
private RandomNameFetcher nameFetcher;
|
||||
private Metrics metrics;
|
||||
|
||||
public NickoBukkit() {
|
||||
public Nicko() {
|
||||
this.unitTesting = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by MockBukkit
|
||||
*/
|
||||
protected NickoBukkit(Configuration configuration) {
|
||||
protected Nicko(Configuration configuration) {
|
||||
this.unitTesting = true;
|
||||
this.configuration = configuration;
|
||||
getLogger().info("Unit Testing Mode enabled.");
|
||||
|
@ -107,9 +107,9 @@ public class NickoBukkit extends JavaPlugin {
|
|||
|
||||
if (configuration.isCustomLocale()) {
|
||||
try {
|
||||
CustomLocale.dumpIntoFile(Locale.ENGLISH);
|
||||
customLocale = new CustomLocale();
|
||||
new CustomLocaleMigrator(this, customLocale).migrate();
|
||||
CustomLanguage.dumpIntoFile(Language.ENGLISH);
|
||||
customLanguage = new CustomLanguage();
|
||||
new CustomLocaleMigrator(this, customLanguage).migrate();
|
||||
getLogger().info("Successfully loaded the custom locale.");
|
||||
} catch (IOException e) {
|
||||
getLogger().severe("Failed to load the custom locale!");
|
||||
|
@ -155,7 +155,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
getLogger().info("Nicko (Bukkit) has been disabled.");
|
||||
}
|
||||
|
||||
public static NickoBukkit getInstance() {
|
||||
public static Nicko getInstance() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
return mojangAPI;
|
||||
}
|
||||
|
||||
public CustomLocale getCustomLocale() {
|
||||
return customLocale;
|
||||
public CustomLanguage getCustomLocale() {
|
||||
return customLanguage;
|
||||
}
|
||||
}
|
|
@ -7,12 +7,12 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.event.custom.PlayerDisguiseEvent;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.mojang.MojangUtils;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
|
@ -24,13 +24,13 @@ import java.util.Optional;
|
|||
public class AnvilManager {
|
||||
private final Player player;
|
||||
private final AppearanceManager appearanceManager;
|
||||
private final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore();
|
||||
private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||
private final NickoProfile profile;
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public AnvilManager(Player player) {
|
||||
this.player = player;
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
|
||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
||||
this.profile = optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||
|
@ -51,7 +51,7 @@ public class AnvilManager {
|
|||
|
||||
private AnvilGUI.Builder getNameThenSkinAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.plugin(Nicko.getInstance())
|
||||
.itemLeft(getLeftItem(false))
|
||||
.interactableSlots(AnvilGUI.Slot.OUTPUT)
|
||||
.onClick((slot, snapshot) -> {
|
||||
|
@ -71,7 +71,7 @@ public class AnvilManager {
|
|||
|
||||
private AnvilGUI.Builder getNameAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.plugin(Nicko.getInstance())
|
||||
.itemLeft(getLeftItem(false))
|
||||
.interactableSlots(AnvilGUI.Slot.OUTPUT)
|
||||
.onClick((slot, snapshot) -> {
|
||||
|
@ -91,7 +91,7 @@ public class AnvilManager {
|
|||
|
||||
private AnvilGUI.Builder getSkinAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.plugin(Nicko.getInstance())
|
||||
.itemLeft(getLeftItem(true))
|
||||
.interactableSlots(AnvilGUI.Slot.OUTPUT)
|
||||
.onClick((slot, snapshot) -> {
|
||||
|
@ -116,13 +116,13 @@ public class AnvilManager {
|
|||
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(skinChange, false);
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.OK, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Set.OK, true));
|
||||
} else {
|
||||
player.sendMessage(
|
||||
i18n.translate(
|
||||
I18NDict.Event.Appearance.Set.ERROR,
|
||||
playerLanguage.translate(
|
||||
LanguageKey.Event.Appearance.Set.ERROR,
|
||||
true,
|
||||
i18n.translate(actionResult.getErrorKey(), false)
|
||||
playerLanguage.translate(actionResult.getErrorKey(), false)
|
||||
));
|
||||
}
|
||||
return Collections.singletonList(AnvilGUI.ResponseAction.close());
|
||||
|
@ -134,9 +134,9 @@ public class AnvilManager {
|
|||
|
||||
if (meta != null) {
|
||||
if (skin) {
|
||||
meta.displayName(Component.text(i18n.translate(I18NDict.GUI.NEW_SKIN, false)));
|
||||
meta.displayName(Component.text(playerLanguage.translate(LanguageKey.GUI.NEW_SKIN, false)));
|
||||
} else {
|
||||
meta.displayName(Component.text(i18n.translate(I18NDict.GUI.NEW_NAME, false)));
|
||||
meta.displayName(Component.text(playerLanguage.translate(LanguageKey.GUI.NEW_NAME, false)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.mojang.MojangAPI;
|
||||
import xyz.ineanto.nicko.mojang.MojangSkin;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
|
@ -24,7 +24,7 @@ import java.util.Optional;
|
|||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class AppearanceManager {
|
||||
private final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
private final Nicko instance = Nicko.getInstance();
|
||||
private final PlayerDataStore dataStore = instance.getDataStore();
|
||||
private final PlayerNameStore nameStore = instance.getNameStore();
|
||||
|
||||
|
@ -105,7 +105,7 @@ public class AppearanceManager {
|
|||
if (skinChange) {
|
||||
Optional<MojangSkin> skin;
|
||||
try {
|
||||
final MojangAPI mojangAPI = NickoBukkit.getInstance().getMojangAPI();
|
||||
final MojangAPI mojangAPI = Nicko.getInstance().getMojangAPI();
|
||||
final Optional<String> uuid = mojangAPI.getUUID(profile.getSkin());
|
||||
if (uuid.isPresent()) {
|
||||
skin = reset ? mojangAPI.getSkinWithoutCaching(uuid.get()) : mojangAPI.getSkin(uuid.get());
|
||||
|
@ -116,18 +116,18 @@ public class AppearanceManager {
|
|||
properties.put("textures", new WrappedSignedProperty("textures", skinResult.value(), skinResult.signature()));
|
||||
} else {
|
||||
reset();
|
||||
return ActionResult.error(I18NDict.Error.MOJANG_SKIN);
|
||||
return ActionResult.error(LanguageKey.Error.MOJANG_SKIN);
|
||||
}
|
||||
} else {
|
||||
reset();
|
||||
return ActionResult.error(I18NDict.Error.MOJANG_NAME);
|
||||
return ActionResult.error(LanguageKey.Error.MOJANG_NAME);
|
||||
}
|
||||
return ActionResult.ok();
|
||||
} catch (ExecutionException e) {
|
||||
return ActionResult.error(I18NDict.Error.CACHE);
|
||||
return ActionResult.error(LanguageKey.Error.CACHE);
|
||||
} catch (IOException e) {
|
||||
reset();
|
||||
return ActionResult.error(I18NDict.Error.MOJANG_NAME);
|
||||
return ActionResult.error(LanguageKey.Error.MOJANG_NAME);
|
||||
} catch (InterruptedException e) {
|
||||
return ActionResult.error("Unknown error");
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.ineanto.nicko.appearance.random;
|
||||
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
@ -12,9 +12,9 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
|
||||
public class RandomNameFetcher {
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko instance;
|
||||
|
||||
public RandomNameFetcher(NickoBukkit instance) {
|
||||
public RandomNameFetcher(Nicko instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import org.bukkit.command.CommandSender;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.ineanto.nicko.gui.HomeGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
|
||||
public class NickoCommand implements CommandExecutor {
|
||||
@Override
|
||||
|
@ -16,8 +16,8 @@ public class NickoCommand implements CommandExecutor {
|
|||
if (player.isOp() || player.hasPermission("nicko.use") || player.hasPermission("nicko.*")) {
|
||||
new HomeGUI(player).open();
|
||||
} else {
|
||||
final I18N i18N = new I18N(player);
|
||||
player.sendMessage(i18N.translate(I18NDict.Error.PERMISSION, true));
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Error.PERMISSION, true));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -4,11 +4,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||
import xyz.ineanto.nicko.version.Version;
|
||||
|
||||
public class Configuration {
|
||||
public static final Version VERSION = new Version(1, 0, 8);
|
||||
public static final Version VERSION = new Version(1, 0, 9);
|
||||
public static final Configuration DEFAULT = new Configuration(VERSION.toString(),
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"§6Nicko §8§l| §r",
|
||||
false);
|
||||
|
||||
private final transient Version versionObject;
|
||||
|
@ -19,21 +18,17 @@ public class Configuration {
|
|||
private final SQLDataSourceConfiguration sqlConfiguration;
|
||||
@JsonProperty("redis")
|
||||
private final DataSourceConfiguration redisConfiguration;
|
||||
@JsonProperty("prefix")
|
||||
private final String prefix;
|
||||
@JsonProperty("customLocale")
|
||||
private final Boolean customLocale;
|
||||
|
||||
public Configuration(@JsonProperty("version") String version,
|
||||
@JsonProperty("sql") SQLDataSourceConfiguration sqlConfiguration,
|
||||
@JsonProperty("redis") DataSourceConfiguration redisConfiguration,
|
||||
@JsonProperty("prefix") String prefix,
|
||||
@JsonProperty("customLocale") Boolean customLocale) {
|
||||
this.version = version;
|
||||
this.versionObject = Version.fromString(version);
|
||||
this.sqlConfiguration = sqlConfiguration;
|
||||
this.redisConfiguration = redisConfiguration;
|
||||
this.prefix = prefix;
|
||||
this.customLocale = customLocale;
|
||||
}
|
||||
|
||||
|
@ -53,10 +48,6 @@ public class Configuration {
|
|||
return redisConfiguration;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public Boolean isCustomLocale() {
|
||||
return customLocale;
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@ import java.nio.file.StandardCopyOption;
|
|||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ConfigurationManager {
|
||||
private final Logger logger = Logger.getLogger("ConfigurationManager");
|
||||
private final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
||||
private final File file;
|
||||
private final File backupFile;
|
||||
|
@ -40,7 +38,6 @@ public class ConfigurationManager {
|
|||
try {
|
||||
final InputStream input = getClass().getResourceAsStream("/config.yml");
|
||||
if (input != null) {
|
||||
logger.info("Saved default configuration as config.yml");
|
||||
Files.createDirectories(file.getParentFile().toPath());
|
||||
Files.createFile(file.toPath());
|
||||
Files.copy(input, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
|
|
|
@ -6,13 +6,13 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUIData;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.ineanto.nicko.storage.name.PlayerNameStore;
|
||||
|
@ -30,8 +30,8 @@ public class PlayerJoinListener implements Listener {
|
|||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
final I18N i18n = new I18N(player);
|
||||
final Nicko instance = Nicko.getInstance();
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
final PlayerNameStore nameStore = instance.getNameStore();
|
||||
final PlayerDataStore dataStore = instance.getDataStore();
|
||||
nameStore.storeName(player);
|
||||
|
@ -52,12 +52,11 @@ public class PlayerJoinListener implements Listener {
|
|||
final boolean needsASkinChange = profile.getSkin() != null && !profile.getSkin().equals(player.getName());
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(needsASkinChange, false);
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Restore.OK, true));
|
||||
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Appearance.Restore.OK));
|
||||
} else {
|
||||
player.sendMessage(
|
||||
i18n.translate(I18NDict.Event.Appearance.Restore.ERROR,
|
||||
true,
|
||||
i18n.translate(actionResult.getErrorKey(), false)
|
||||
playerLanguage.translateWithOops(LanguageKey.Event.Appearance.Restore.ERROR,
|
||||
playerLanguage.translate(actionResult.getErrorKey(), false)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUIData;
|
||||
|
@ -21,9 +21,9 @@ public class PlayerQuitListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
final ActionResult result = NickoBukkit.getInstance().getDataStore().saveData(player);
|
||||
final ActionResult result = Nicko.getInstance().getDataStore().saveData(player);
|
||||
if (result.isError()) {
|
||||
NickoBukkit.getInstance().getLogger().warning("Failed to save data for " + player.getName());
|
||||
Nicko.getInstance().getLogger().warning("Failed to save data for " + player.getName());
|
||||
}
|
||||
|
||||
// This is a dirty way to do it but could be worse tbh
|
||||
|
|
|
@ -5,8 +5,8 @@ import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
|||
import xyz.ineanto.nicko.gui.items.admin.ManageCacheItem;
|
||||
import xyz.ineanto.nicko.gui.items.admin.ManagePlayerItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
@ -17,22 +17,22 @@ public class AdminGUI {
|
|||
private final String title;
|
||||
|
||||
public AdminGUI(Player player) {
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.ADMIN, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.ADMIN, false);
|
||||
|
||||
final HomeGUI parent = new HomeGUI(player);
|
||||
final GoBackItem backItem = new GoBackItem(player);
|
||||
final ManagePlayerItem managePlayerItem = new ManagePlayerItem(i18n, player);
|
||||
final ManagePlayerItem managePlayerItem = new ManagePlayerItem(playerLanguage, player);
|
||||
|
||||
this.gui = Gui.normal()
|
||||
.setStructure(
|
||||
"# # # # # # # # #",
|
||||
"# # # S C X # # #",
|
||||
"# # # S C U # # #",
|
||||
"B # # # # # # # #"
|
||||
)
|
||||
.addIngredient('S', new ManageCacheItem(i18n))
|
||||
.addIngredient('S', new ManageCacheItem(playerLanguage))
|
||||
.addIngredient('C', managePlayerItem.get())
|
||||
.addIngredient('U', new SimpleItem(ItemDefaults.getUnavailableItem(i18n)))
|
||||
.addIngredient('U', new SimpleItem(ItemDefaults.getUnavailableItem(playerLanguage)))
|
||||
.addIngredient('B', backItem.get(parent.getGUI(), parent.getTitle()))
|
||||
.build();
|
||||
this.player = player;
|
||||
|
|
|
@ -5,8 +5,8 @@ import xyz.ineanto.nicko.gui.items.admin.cache.CacheStatisticsItem;
|
|||
import xyz.ineanto.nicko.gui.items.admin.cache.InvalidateCacheItem;
|
||||
import xyz.ineanto.nicko.gui.items.admin.cache.InvalidateSkinItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
|
@ -16,8 +16,8 @@ public class CacheManagementGUI {
|
|||
private final String title;
|
||||
|
||||
public CacheManagementGUI(Player player) {
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.CACHE, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.CACHE, false);
|
||||
|
||||
final AdminGUI parent = new AdminGUI(player);
|
||||
final GoBackItem backItem = new GoBackItem(player);
|
||||
|
|
|
@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
|
|||
import xyz.ineanto.nicko.gui.items.common.choice.CancelItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.choice.ChoiceCallback;
|
||||
import xyz.ineanto.nicko.gui.items.common.choice.ConfirmItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
|
@ -18,11 +18,11 @@ public class ChoiceGUI {
|
|||
private final String title;
|
||||
|
||||
public ChoiceGUI(Player player, ChoiceCallback callback) {
|
||||
final I18N i18n = new I18N(player);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
final ConfirmItem confirmItem = new ConfirmItem(player, callback);
|
||||
final CancelItem cancelItem = new CancelItem(player, callback);
|
||||
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.CONFIRM, false);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.CONFIRM, false);
|
||||
this.gui = Gui.normal()
|
||||
.setStructure(
|
||||
"@ @ @ @ % & & & &",
|
||||
|
@ -31,7 +31,7 @@ public class ChoiceGUI {
|
|||
)
|
||||
.addIngredient('@', confirmItem.get())
|
||||
.addIngredient('&', cancelItem.get())
|
||||
.addIngredient('I', new SimpleItem(i18n.translateItem(new ItemBuilder(Material.PAPER), I18NDict.GUI.Choice.CHOOSE)))
|
||||
.addIngredient('I', new SimpleItem(playerLanguage.translateItem(new ItemBuilder(Material.PAPER), LanguageKey.GUI.Choice.CHOOSE)))
|
||||
.build();
|
||||
this.player = player;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ import xyz.ineanto.nicko.gui.items.appearance.ChangeBothItem;
|
|||
import xyz.ineanto.nicko.gui.items.appearance.ChangeNameItem;
|
||||
import xyz.ineanto.nicko.gui.items.appearance.ChangeSkinItem;
|
||||
import xyz.ineanto.nicko.gui.items.home.*;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
|
@ -25,8 +25,8 @@ public class HomeGUI {
|
|||
dynamicStructure[2] = dynamicStructure[2].replace("A", "#");
|
||||
}
|
||||
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.HOME, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.HOME, false);
|
||||
|
||||
final ExitItem exitItem = new ExitItem(player);
|
||||
final ResetItem resetItem = new ResetItem(player);
|
||||
|
|
|
@ -2,14 +2,14 @@ package xyz.ineanto.nicko.gui;
|
|||
|
||||
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.ScrollUpItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.mojang.MojangSkin;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
import xyz.xenondevs.invui.item.Item;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.gui.items.admin.cache.CacheEntryItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.ScrollDownItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -27,22 +27,22 @@ public class InvalidateSkinGUI {
|
|||
private final String title;
|
||||
|
||||
public InvalidateSkinGUI(Player player) {
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.INVALIDATE_SKIN, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.INVALIDATE_SKIN, false);
|
||||
|
||||
final ConcurrentMap<String, Optional<MojangSkin>> skins = NickoBukkit.getInstance().getMojangAPI().getSkinCache().asMap();
|
||||
final ConcurrentMap<String, Optional<MojangSkin>> skins = Nicko.getInstance().getMojangAPI().getSkinCache().asMap();
|
||||
final List<String> loadedSkins = skins.entrySet().stream()
|
||||
.filter(entry -> entry.getValue().isPresent())
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
final List<Item> items = loadedSkins.stream()
|
||||
.map(uuid -> new CacheEntryItem(i18n, uuid))
|
||||
.map(uuid -> new CacheEntryItem(playerLanguage, uuid))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final CacheManagementGUI parent = new CacheManagementGUI(player);
|
||||
final ScrollUpItem scrollUpItem = new ScrollUpItem(i18n);
|
||||
final ScrollDownItem scrollDownItem = new ScrollDownItem(i18n);
|
||||
final ScrollUpItem scrollUpItem = new ScrollUpItem(playerLanguage);
|
||||
final ScrollDownItem scrollDownItem = new ScrollDownItem(playerLanguage);
|
||||
final GoBackItem backItem = new GoBackItem(player);
|
||||
|
||||
gui = ScrollGui.items(guiItemBuilder -> {
|
||||
|
|
|
@ -7,8 +7,8 @@ import xyz.ineanto.nicko.gui.items.admin.check.PlayerInformationItem;
|
|||
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.ScrollDownItem;
|
||||
import xyz.ineanto.nicko.gui.items.common.ScrollUpItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.gui.structure.Markers;
|
||||
|
@ -26,20 +26,20 @@ public class PlayerCheckGUI {
|
|||
private final String title;
|
||||
|
||||
public PlayerCheckGUI(Player player, Collection<? extends Player> players) {
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.CHECK, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.CHECK, false);
|
||||
|
||||
final List<Item> items = players.stream()
|
||||
.map(Entity::getUniqueId)
|
||||
.map(Bukkit::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.map(mappedPlayer -> new PlayerInformationItem(i18n, mappedPlayer))
|
||||
.map(mappedPlayer -> new PlayerInformationItem(playerLanguage, mappedPlayer))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final AdminGUI parent = new AdminGUI(player);
|
||||
final GoBackItem backItem = new GoBackItem(player);
|
||||
final ScrollUpItem scrollUpItem = new ScrollUpItem(i18n);
|
||||
final ScrollDownItem scrollDownItem = new ScrollDownItem(i18n);
|
||||
final ScrollUpItem scrollUpItem = new ScrollUpItem(playerLanguage);
|
||||
final ScrollDownItem scrollDownItem = new ScrollDownItem(playerLanguage);
|
||||
|
||||
gui = ScrollGui.items(guiItemBuilder -> {
|
||||
guiItemBuilder.setStructure(
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.bukkit.entity.Player;
|
|||
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.ineanto.nicko.gui.items.settings.LanguageCyclingItem;
|
||||
import xyz.ineanto.nicko.gui.items.settings.RandomSkinCyclingItem;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
|
@ -21,8 +21,8 @@ public class SettingsGUI {
|
|||
"B # # # # # # # #"
|
||||
};
|
||||
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translate(I18NDict.GUI.Titles.SETTINGS, false);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.SETTINGS, false);
|
||||
|
||||
final HomeGUI parent = new HomeGUI(player);
|
||||
final LanguageCyclingItem languageItem = new LanguageCyclingItem(player);
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package xyz.ineanto.nicko.gui.items;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.AbstractItemBuilder;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||
|
||||
public class ItemDefaults {
|
||||
public static AbstractItemBuilder<?> getErrorSkullItem(I18N i18n, String key, Object... args) {
|
||||
public static AbstractItemBuilder<?> getErrorSkullItem(PlayerLanguage playerLanguage, String key, Object... args) {
|
||||
// "Missing Value" (Valve's signature missing texture) Texture Value
|
||||
final SkullBuilder.HeadTexture headTexture = new SkullBuilder.HeadTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjNmZTU5YjJhMWQyYmYzMjcwNDA2OGVmYzg2MGM3NWY5MjEyYzIzMTBiNDNkMDdjNGJiYTRiNGViMjM0ZTY4NCJ9fX0=");
|
||||
final SkullBuilder builder = new SkullBuilder(headTexture);
|
||||
return i18n.translateItem(builder, key, args);
|
||||
return playerLanguage.translateItem(builder, key, args);
|
||||
}
|
||||
|
||||
public static AbstractItemBuilder<?> getUnavailableItem(I18N i18n) {
|
||||
public static AbstractItemBuilder<?> getUnavailableItem(PlayerLanguage playerLanguage) {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.RED_TERRACOTTA);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.UNAVAILABLE);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.UNAVAILABLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.gui.CacheManagementGUI;
|
||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AsyncItem;
|
||||
|
@ -19,18 +19,18 @@ import xyz.xenondevs.invui.util.MojangApiUtils;
|
|||
import java.io.IOException;
|
||||
|
||||
public class ManageCacheItem extends AsyncItem {
|
||||
public ManageCacheItem(I18N i18n) {
|
||||
public ManageCacheItem(PlayerLanguage playerLanguage) {
|
||||
super(new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.PAINTING);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.LOADING);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.LOADING);
|
||||
}, (click -> true)).getItemProvider(),
|
||||
() -> {
|
||||
try {
|
||||
final SkullBuilder builder = new SkullBuilder("Notch");
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.MANAGE_CACHE);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Admin.MANAGE_CACHE);
|
||||
} catch (MojangApiUtils.MojangApiException | IOException e) {
|
||||
NickoBukkit.getInstance().getLogger().warning("Unable to get Head texture for Notch! (GUI/ManageCache)");
|
||||
return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Admin.MANAGE_CACHE);
|
||||
Nicko.getInstance().getLogger().warning("Unable to get Head texture for Notch! (GUI/ManageCache)");
|
||||
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Admin.MANAGE_CACHE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,24 +4,24 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ManagePlayerItem {
|
||||
private final Player player;
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public ManagePlayerItem(I18N i18n, Player player) {
|
||||
this.i18n = i18n;
|
||||
public ManagePlayerItem(PlayerLanguage playerLanguage, Player player) {
|
||||
this.playerLanguage = playerLanguage;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.WRITABLE_BOOK);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.MANAGE_PLAYER);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Admin.MANAGE_PLAYER);
|
||||
}, click -> {
|
||||
new PlayerCheckGUI(player, Bukkit.getOnlinePlayers()).open();
|
||||
return true;
|
||||
|
|
|
@ -6,13 +6,13 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.gui.ChoiceGUI;
|
||||
import xyz.ineanto.nicko.gui.InvalidateSkinGUI;
|
||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||
import xyz.ineanto.nicko.gui.items.common.choice.ChoiceCallback;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.mojang.MojangAPI;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||
|
@ -25,22 +25,22 @@ import java.util.UUID;
|
|||
public class CacheEntryItem extends AsyncItem {
|
||||
private final String name;
|
||||
private final String uuid;
|
||||
private final MojangAPI mojangAPI = NickoBukkit.getInstance().getMojangAPI();
|
||||
private final MojangAPI mojangAPI = Nicko.getInstance().getMojangAPI();
|
||||
|
||||
public CacheEntryItem(I18N i18n, String uuid) {
|
||||
public CacheEntryItem(PlayerLanguage playerLanguage, String uuid) {
|
||||
super(new ItemBuilder(Material.PAINTING)
|
||||
.setDisplayName(
|
||||
Component.text(i18n.translate(I18NDict.GUI.LOADING, false)).content()
|
||||
Component.text(playerLanguage.translate(LanguageKey.GUI.LOADING, false)).content()
|
||||
),
|
||||
() -> {
|
||||
final String dashedUuid = uuid.replaceAll("(.{8})(.{4})(.{4})(.{4})(.+)", "$1-$2-$3-$4-$5");
|
||||
final UUID uuidObject = UUID.fromString(dashedUuid);
|
||||
try {
|
||||
final SkullBuilder skull = new SkullBuilder(uuidObject);
|
||||
return i18n.translateItem(skull, I18NDict.GUI.Admin.Cache.ENTRY, NickoBukkit.getInstance().getMojangAPI().getUUIDName(uuid));
|
||||
return playerLanguage.translateItem(skull, LanguageKey.GUI.Admin.Cache.ENTRY, Nicko.getInstance().getMojangAPI().getUUIDName(uuid));
|
||||
} catch (MojangApiUtils.MojangApiException | IOException e) {
|
||||
NickoBukkit.getInstance().getLogger().warning("Unable to get Head texture for specified UUID (" + uuid + ")! (GUI/Cache/Entry)");
|
||||
return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Admin.Cache.ENTRY, NickoBukkit.getInstance().getMojangAPI().getUUIDName(uuid));
|
||||
Nicko.getInstance().getLogger().warning("Unable to get Head texture for specified UUID (" + uuid + ")! (GUI/Cache/Entry)");
|
||||
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Admin.Cache.ENTRY, Nicko.getInstance().getMojangAPI().getUUIDName(uuid));
|
||||
}
|
||||
});
|
||||
this.uuid = uuid;
|
||||
|
@ -54,8 +54,8 @@ public class CacheEntryItem extends AsyncItem {
|
|||
new ChoiceGUI(player, new ChoiceCallback() {
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
final I18N i18n = new I18N(player);
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Admin.Cache.INVALIDATE_ENTRY, true, name));
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Admin.Cache.INVALIDATE_ENTRY, name));
|
||||
mojangAPI.eraseFromCache(uuid);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@ import com.google.common.cache.CacheStats;
|
|||
import com.google.common.cache.LoadingCache;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.mojang.MojangSkin;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
@ -14,19 +14,19 @@ import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
|||
import java.util.Optional;
|
||||
|
||||
public class CacheStatisticsItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public CacheStatisticsItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.BOOK);
|
||||
final LoadingCache<String, Optional<MojangSkin>> cache = NickoBukkit.getInstance().getMojangAPI().getSkinCache();
|
||||
final LoadingCache<String, Optional<MojangSkin>> cache = Nicko.getInstance().getMojangAPI().getSkinCache();
|
||||
final CacheStats stats = cache.stats();
|
||||
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.Cache.STATISTICS,
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Admin.Cache.STATISTICS,
|
||||
stats.requestCount(),
|
||||
Math.round(cache.size())
|
||||
);
|
||||
|
|
|
@ -3,32 +3,32 @@ package xyz.ineanto.nicko.gui.items.admin.cache;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class InvalidateCacheItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public InvalidateCacheItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.TNT);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.Cache.INVALIDATE_CACHE);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Admin.Cache.INVALIDATE_CACHE);
|
||||
}, (click) -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
click.getEvent().getView().close();
|
||||
|
||||
final Player player = click.getPlayer();
|
||||
final I18N i18n = new I18N(player);
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Admin.Cache.INVALIDATE_CACHE, true));
|
||||
NickoBukkit.getInstance().getMojangAPI().getSkinCache().invalidateAll();
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
|
||||
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Admin.Cache.INVALIDATE_CACHE));
|
||||
Nicko.getInstance().getMojangAPI().getSkinCache().invalidateAll();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -4,22 +4,22 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.gui.InvalidateSkinGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class InvalidateSkinItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public InvalidateSkinItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.PAPER);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Admin.Cache.INVALIDATE_SKIN);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Admin.Cache.INVALIDATE_SKIN);
|
||||
}, (click) -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
|
|
|
@ -6,14 +6,14 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.gui.ChoiceGUI;
|
||||
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
|
||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||
import xyz.ineanto.nicko.gui.items.common.choice.ChoiceCallback;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.xenondevs.invui.item.builder.AbstractItemBuilder;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
|
@ -28,20 +28,20 @@ import java.util.Optional;
|
|||
public class PlayerInformationItem extends AsyncItem {
|
||||
private final Player target;
|
||||
private final NickoProfile profile;
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public PlayerInformationItem(I18N i18n, Player target) {
|
||||
public PlayerInformationItem(PlayerLanguage playerLanguage, Player target) {
|
||||
super(new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.PAINTING);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.LOADING);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.LOADING);
|
||||
}, (click -> true)).getItemProvider(), () -> {
|
||||
try {
|
||||
final SkullBuilder skull = new SkullBuilder(target.getUniqueId());
|
||||
final Optional<NickoProfile> optionalProfile = NickoBukkit.getInstance().getDataStore().getData(target.getUniqueId());
|
||||
final Optional<NickoProfile> optionalProfile = Nicko.getInstance().getDataStore().getData(target.getUniqueId());
|
||||
|
||||
if (optionalProfile.isPresent()) {
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
final AbstractItemBuilder<?> headItem = i18n.translateItem(skull, I18NDict.GUI.Admin.CHECK,
|
||||
final AbstractItemBuilder<?> headItem = playerLanguage.translateItem(skull, LanguageKey.GUI.Admin.CHECK,
|
||||
target.getName(),
|
||||
(profile.hasData() ? "<green>✔</green>" : "<red>❌</red>"),
|
||||
(profile.getName() == null ? "<grey>N/A<grey>" : profile.getName()),
|
||||
|
@ -56,16 +56,16 @@ public class PlayerInformationItem extends AsyncItem {
|
|||
return headItem;
|
||||
}
|
||||
} catch (MojangApiUtils.MojangApiException | IOException e) {
|
||||
NickoBukkit.getInstance().getLogger().severe("Unable to get head for specified UUID ( " + target.getUniqueId() + ")! (GUI/PlayerCheck)");
|
||||
Nicko.getInstance().getLogger().severe("Unable to get head for specified UUID ( " + target.getUniqueId() + ")! (GUI/PlayerCheck)");
|
||||
}
|
||||
|
||||
return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Admin.CHECK,
|
||||
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Admin.CHECK,
|
||||
"§c§l?!?", "§7N/A", "§7N/A", "§7N/A"
|
||||
);
|
||||
});
|
||||
this.i18n = i18n;
|
||||
this.playerLanguage = playerLanguage;
|
||||
this.target = target;
|
||||
this.profile = NickoBukkit.getInstance().getDataStore().getData(target.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
this.profile = Nicko.getInstance().getDataStore().getData(target.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,7 +78,7 @@ public class PlayerInformationItem extends AsyncItem {
|
|||
public void onConfirm() {
|
||||
final AppearanceManager appearanceManager = new AppearanceManager(target);
|
||||
appearanceManager.reset();
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Admin.Check.REMOVE_SKIN, true, target.getName()));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Admin.Check.REMOVE_SKIN, true, target.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,22 +4,22 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.anvil.AnvilManager;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ChangeBothItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public ChangeBothItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.TOTEM_OF_UNDYING);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.CHANGE_BOTH);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.CHANGE_BOTH);
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
|
|
|
@ -4,22 +4,22 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.anvil.AnvilManager;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ChangeNameItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public ChangeNameItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.NAME_TAG);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.CHANGE_NAME);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.CHANGE_NAME);
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
|
|
|
@ -2,11 +2,11 @@ package xyz.ineanto.nicko.gui.items.appearance;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.anvil.AnvilManager;
|
||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
import xyz.xenondevs.invui.util.MojangApiUtils;
|
||||
|
@ -14,11 +14,11 @@ import xyz.xenondevs.invui.util.MojangApiUtils;
|
|||
import java.io.IOException;
|
||||
|
||||
public class ChangeSkinItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
private final Player player;
|
||||
|
||||
public ChangeSkinItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
|
@ -26,10 +26,10 @@ public class ChangeSkinItem {
|
|||
return new SuppliedItem(() -> {
|
||||
try {
|
||||
final SkullBuilder builder = new SkullBuilder(player.getName());
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.CHANGE_SKIN);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.CHANGE_SKIN);
|
||||
} catch (MojangApiUtils.MojangApiException | IOException e) {
|
||||
NickoBukkit.getInstance().getLogger().warning("Unable to get Head texture for specified player (" + player.getName() + ")! (GUI/Home)");
|
||||
return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Home.CHANGE_SKIN);
|
||||
Nicko.getInstance().getLogger().warning("Unable to get Head texture for specified player (" + player.getName() + ")! (GUI/Home)");
|
||||
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Home.CHANGE_SKIN);
|
||||
}
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
|
|
|
@ -2,24 +2,24 @@ package xyz.ineanto.nicko.gui.items.common;
|
|||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
public class GoBackItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public GoBackItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get(Gui gui, String parentTitle) {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.ARROW);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.GO_BACK);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.GO_BACK);
|
||||
}, click -> {
|
||||
click.getEvent().getView().close();
|
||||
Window.single().setGui(gui).setTitle(parentTitle).open(click.getPlayer());
|
||||
|
|
|
@ -4,26 +4,26 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Translation;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem;
|
||||
|
||||
public class ScrollDownItem extends ScrollItem {
|
||||
final I18N i18n;
|
||||
final PlayerLanguage playerLanguage;
|
||||
|
||||
public ScrollDownItem(I18N i18n) {
|
||||
public ScrollDownItem(PlayerLanguage playerLanguage) {
|
||||
super(1);
|
||||
this.i18n = i18n;
|
||||
this.playerLanguage = playerLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(ScrollGui gui) {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
|
||||
final Translation translation = i18n.translateAndReplace(I18NDict.GUI.SCROLL_DOWN);
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.SCROLL_DOWN);
|
||||
builder.setDisplayName(Component.text(translation.name()).content());
|
||||
if (!gui.canScroll(1)) {
|
||||
// Lore serialization
|
||||
|
|
|
@ -4,26 +4,26 @@ import net.kyori.adventure.text.Component;
|
|||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Material;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Translation;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
import xyz.xenondevs.invui.gui.ScrollGui;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem;
|
||||
|
||||
public class ScrollUpItem extends ScrollItem {
|
||||
final I18N i18n;
|
||||
final PlayerLanguage playerLanguage;
|
||||
|
||||
public ScrollUpItem(I18N i18n) {
|
||||
public ScrollUpItem(PlayerLanguage playerLanguage) {
|
||||
super(-1);
|
||||
this.i18n = i18n;
|
||||
this.playerLanguage = playerLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemProvider getItemProvider(ScrollGui gui) {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
|
||||
final Translation translation = i18n.translateAndReplace(I18NDict.GUI.SCROLL_UP);
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.SCROLL_UP);
|
||||
builder.setDisplayName(Component.text(translation.name()).content());
|
||||
if (!gui.canScroll(-1)) {
|
||||
// Lore serialization
|
||||
|
|
|
@ -2,24 +2,24 @@ package xyz.ineanto.nicko.gui.items.common.choice;
|
|||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class CancelItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
private final ChoiceCallback callback;
|
||||
|
||||
public CancelItem(Player player, ChoiceCallback callback) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Choice.CANCEL);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Choice.CANCEL);
|
||||
}, click -> {
|
||||
click.getEvent().getView().close();
|
||||
callback.onCancel();
|
||||
|
|
|
@ -2,24 +2,24 @@ package xyz.ineanto.nicko.gui.items.common.choice;
|
|||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ConfirmItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
private final ChoiceCallback callback;
|
||||
|
||||
public ConfirmItem(Player player, ChoiceCallback callback) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Choice.CONFIRM);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Choice.CONFIRM);
|
||||
}, click -> {
|
||||
click.getEvent().getView().close();
|
||||
callback.onConfirm();
|
||||
|
|
|
@ -4,22 +4,22 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.gui.AdminGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class AdminAccessItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public AdminAccessItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.COMMAND_BLOCK_MINECART);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.ADMIN);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.ADMIN);
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
|
|
|
@ -3,22 +3,22 @@ package xyz.ineanto.nicko.gui.items.home;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ExitItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public ExitItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.OAK_DOOR);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.EXIT);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.EXIT);
|
||||
}, click -> {
|
||||
click.getEvent().getView().close();
|
||||
final ClickType clickType = click.getClickType();
|
||||
|
|
|
@ -2,11 +2,11 @@ package xyz.ineanto.nicko.gui.items.home;
|
|||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
@ -14,19 +14,19 @@ import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
|||
import java.util.Optional;
|
||||
|
||||
public class RandomSkinItem {
|
||||
private final I18N i18n;
|
||||
private final NickoBukkit instance;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
private final Nicko instance;
|
||||
|
||||
public RandomSkinItem(Player player) {
|
||||
this.instance = NickoBukkit.getInstance();
|
||||
this.i18n = new I18N(player);
|
||||
this.instance = Nicko.getInstance();
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final SkullBuilder.HeadTexture texture = new SkullBuilder.HeadTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzgzMTEzOGMyMDYxMWQzMDJjNDIzZmEzMjM3MWE3NDNkMTc0MzdhMTg5NzNjMzUxOTczNDQ3MGE3YWJiNCJ9fX0=");
|
||||
final SkullBuilder builder = new SkullBuilder(texture);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.RANDOM_SKIN);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.RANDOM_SKIN);
|
||||
}, (event) -> {
|
||||
final Player player = event.getPlayer();
|
||||
final ClickType clickType = event.getClickType();
|
||||
|
@ -42,12 +42,12 @@ public class RandomSkinItem {
|
|||
final AppearanceManager appearanceManager = new AppearanceManager(player);
|
||||
final ActionResult result = appearanceManager.updatePlayer(true, false);
|
||||
if (!result.isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Set.OK, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Set.OK, true));
|
||||
} else {
|
||||
player.sendMessage(i18n.translate(
|
||||
I18NDict.Event.Appearance.Set.ERROR,
|
||||
player.sendMessage(playerLanguage.translate(
|
||||
LanguageKey.Event.Appearance.Set.ERROR,
|
||||
true,
|
||||
i18n.translate(result.getErrorKey(), false)
|
||||
playerLanguage.translate(result.getErrorKey(), false)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
@ -13,16 +13,16 @@ import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
|||
import java.util.Optional;
|
||||
|
||||
public class ResetItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public ResetItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.TNT);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.RESET);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.RESET);
|
||||
}, (event) -> {
|
||||
final Player player = event.getPlayer();
|
||||
final ClickType clickType = event.getClickType();
|
||||
|
@ -30,16 +30,16 @@ public class ResetItem {
|
|||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(player);
|
||||
optionalProfile.ifPresent(profile -> {
|
||||
if (!profile.hasData()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Remove.MISSING, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Remove.MISSING, true));
|
||||
event.getEvent().getView().close();
|
||||
return;
|
||||
}
|
||||
|
||||
final AppearanceManager appearanceManager = new AppearanceManager(player);
|
||||
if (!appearanceManager.reset().isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Remove.OK, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Remove.OK, true));
|
||||
} else {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Appearance.Remove.ERROR, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Appearance.Remove.ERROR, true));
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
|
|
@ -4,22 +4,22 @@ import org.bukkit.Material;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.gui.SettingsGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class SettingsAccessItem {
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public SettingsAccessItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.COMPARATOR);
|
||||
return i18n.translateItem(builder, I18NDict.GUI.Home.SETTINGS);
|
||||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.SETTINGS);
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
|
|
|
@ -6,12 +6,12 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.gui.SettingsGUI;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Translation;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
|
@ -28,26 +28,26 @@ import java.util.Optional;
|
|||
public class LanguageCyclingItem {
|
||||
private final Player player;
|
||||
private final ItemProvider[] providers;
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public LanguageCyclingItem(Player player) {
|
||||
this.player = player;
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.providers = getItems();
|
||||
}
|
||||
|
||||
public AbstractItem get() {
|
||||
final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore();
|
||||
final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||
final Optional<NickoProfile> profile = dataStore.getData(player.getUniqueId());
|
||||
if (profile.isPresent()) {
|
||||
final NickoProfile nickoProfile = profile.get();
|
||||
int localeOrdinal = nickoProfile.getLocale().ordinal();
|
||||
return CycleItem.withStateChangeHandler((observer, integer) -> {
|
||||
observer.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.707107f); // 0.707107 ~= C
|
||||
nickoProfile.setLocale(Locale.values()[integer]);
|
||||
nickoProfile.setLocale(Language.values()[integer]);
|
||||
player.getOpenInventory().close();
|
||||
if (dataStore.updateCache(player.getUniqueId(), nickoProfile).isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Settings.ERROR, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Settings.ERROR, true));
|
||||
} else {
|
||||
new SettingsGUI(player).open();
|
||||
}
|
||||
|
@ -57,14 +57,14 @@ public class LanguageCyclingItem {
|
|||
return new SimpleItem(ItemProvider.EMPTY);
|
||||
}
|
||||
|
||||
private ItemProvider generateItem(Locale locale, List<Locale> locales) {
|
||||
private ItemProvider generateItem(Language language, List<Language> languages) {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.OAK_SIGN);
|
||||
final Translation translation = i18n.translateAndReplace(I18NDict.GUI.Settings.LANGUAGE);
|
||||
final Translation cyclingChoicesTranslation = i18n.translateAndReplace(I18NDict.GUI.Settings.CYCLING_CHOICES);
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.LANGUAGE);
|
||||
final Translation cyclingChoicesTranslation = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.CYCLING_CHOICES);
|
||||
|
||||
builder.setDisplayName(Component.text(translation.name()).content());
|
||||
for (Locale value : locales) {
|
||||
if (locale != value) {
|
||||
for (Language value : languages) {
|
||||
if (language != value) {
|
||||
builder.addLoreLines("§7> " + value.getName());
|
||||
} else {
|
||||
builder.addLoreLines("§6§l> §f" + value.getName());
|
||||
|
@ -80,13 +80,13 @@ public class LanguageCyclingItem {
|
|||
}
|
||||
|
||||
private ItemProvider[] getItems() {
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
final Nicko instance = Nicko.getInstance();
|
||||
final ArrayList<ItemProvider> items = new ArrayList<>();
|
||||
final ArrayList<Locale> localesToGenerate = new ArrayList<>();
|
||||
final ArrayList<Language> localesToGenerate = new ArrayList<>();
|
||||
|
||||
Collections.addAll(localesToGenerate, Locale.values());
|
||||
Collections.addAll(localesToGenerate, Language.values());
|
||||
if (!instance.getNickoConfig().isCustomLocale()) {
|
||||
localesToGenerate.remove(Locale.CUSTOM);
|
||||
localesToGenerate.remove(Language.CUSTOM);
|
||||
}
|
||||
localesToGenerate.forEach(locale -> items.add(generateItem(locale, localesToGenerate)));
|
||||
return items.toArray(new ItemProvider[]{});
|
||||
|
|
|
@ -5,10 +5,10 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Translation;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.xenondevs.invui.item.ItemProvider;
|
||||
|
@ -22,11 +22,11 @@ import java.util.Optional;
|
|||
public class RandomSkinCyclingItem {
|
||||
private final Player player;
|
||||
private final ItemProvider[] providers;
|
||||
private final I18N i18n;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
|
||||
public RandomSkinCyclingItem(Player player) {
|
||||
this.player = player;
|
||||
this.i18n = new I18N(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.providers = new ItemProvider[]{
|
||||
getItemProviderForValue(true),
|
||||
getItemProviderForValue(false)
|
||||
|
@ -34,7 +34,7 @@ public class RandomSkinCyclingItem {
|
|||
}
|
||||
|
||||
public AbstractItem get() {
|
||||
final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore();
|
||||
final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||
final Optional<NickoProfile> profile = dataStore.getData(player.getUniqueId());
|
||||
if (profile.isPresent()) {
|
||||
final NickoProfile nickoProfile = profile.get();
|
||||
|
@ -43,7 +43,7 @@ public class RandomSkinCyclingItem {
|
|||
observer.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.707107f); // 0.707107 ~= C
|
||||
nickoProfile.setRandomSkin(integer != 1);
|
||||
if (dataStore.updateCache(player.getUniqueId(), nickoProfile).isError()) {
|
||||
player.sendMessage(i18n.translate(I18NDict.Event.Settings.ERROR, true));
|
||||
player.sendMessage(playerLanguage.translate(LanguageKey.Event.Settings.ERROR, true));
|
||||
player.getOpenInventory().close();
|
||||
}
|
||||
}, localeOrdinal, providers);
|
||||
|
@ -55,12 +55,12 @@ public class RandomSkinCyclingItem {
|
|||
private ItemProvider getItemProviderForValue(boolean enabled) {
|
||||
final SkullBuilder.HeadTexture texture = new SkullBuilder.HeadTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzgzMTEzOGMyMDYxMWQzMDJjNDIzZmEzMjM3MWE3NDNkMTc0MzdhMTg5NzNjMzUxOTczNDQ3MGE3YWJiNCJ9fX0=");
|
||||
final SkullBuilder builder = new SkullBuilder(texture);
|
||||
final Translation randomSkinTranslation = i18n.translateAndReplace(I18NDict.GUI.Settings.RANDOM_SKIN);
|
||||
final Translation toggleableTranslation = i18n.translateAndReplace(I18NDict.GUI.Settings.TOGGLEABLE_BUTTON,
|
||||
final Translation randomSkinTranslation = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.RANDOM_SKIN);
|
||||
final Translation toggleableTranslation = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.TOGGLEABLE_BUTTON,
|
||||
(enabled ? "§7>§c" : "§6§l>§c§l"),
|
||||
(enabled ? "§6§l>§a§l" : "§7>§a")
|
||||
);
|
||||
final Translation cyclingChoicesTranslation = i18n.translateAndReplace(I18NDict.GUI.Settings.CYCLING_CHOICES);
|
||||
final Translation cyclingChoicesTranslation = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.CYCLING_CHOICES);
|
||||
|
||||
builder.setDisplayName(randomSkinTranslation.name());
|
||||
toggleableTranslation.lore().forEach(builder::addLoreLines);
|
||||
|
|
|
@ -1,40 +1,41 @@
|
|||
package xyz.ineanto.nicko.i18n;
|
||||
package xyz.ineanto.nicko.language;
|
||||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.version.Version;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class CustomLocale {
|
||||
private static final Logger logger = Logger.getLogger("CustomLocale");
|
||||
private static final File directory = new File(NickoBukkit.getInstance().getDataFolder(), "/locale/");
|
||||
public class CustomLanguage {
|
||||
private static final File directory = new File(Nicko.getInstance().getDataFolder(), "/locale/");
|
||||
private static final File file = new File(directory, "locale.yml");
|
||||
|
||||
private final String version;
|
||||
private final Version versionObject;
|
||||
private final YamlConfig yamlFile;
|
||||
|
||||
public CustomLocale() throws IOException {
|
||||
public CustomLanguage() throws IOException {
|
||||
this.yamlFile = new YamlConfig(new FileInputStream(file));
|
||||
this.version = yamlFile.getString("version");
|
||||
this.versionObject = Version.fromString(version);
|
||||
}
|
||||
|
||||
public static void dumpIntoFile(Locale locale) throws IOException {
|
||||
if (locale == Locale.CUSTOM) return;
|
||||
public static void dumpIntoFile(Language language) throws IOException {
|
||||
if (language == Language.CUSTOM) return;
|
||||
if (file.exists()) return;
|
||||
if (!directory.exists()) directory.mkdirs();
|
||||
|
||||
final String localeFileName = locale.getCode() + ".yml";
|
||||
final String localeFileName = language.getCode() + ".yml";
|
||||
try {
|
||||
final InputStream resource = NickoBukkit.getInstance().getResource(localeFileName);
|
||||
final InputStream resource = Nicko.getInstance().getResource(localeFileName);
|
||||
Files.copy(resource, file.toPath());
|
||||
resource.close();
|
||||
} catch (IOException e) {
|
||||
logger.severe("Unable to dump Locale: " + locale.getCode() + "!");
|
||||
Nicko.getInstance().getLogger().severe("Unable to dump Locale: " + language.getCode() + "!");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +1,26 @@
|
|||
package xyz.ineanto.nicko.i18n;
|
||||
package xyz.ineanto.nicko.language;
|
||||
|
||||
import xyz.ineanto.nicko.version.Version;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public enum Locale implements Serializable {
|
||||
public enum Language implements Serializable {
|
||||
ENGLISH("en", "English"),
|
||||
FRENCH("fr", "Français"),
|
||||
CUSTOM("cm", "Server Custom");
|
||||
|
||||
public static final Version VERSION = new Version(1, 1, 3);
|
||||
public static final Version VERSION = new Version(1, 1, 4);
|
||||
|
||||
private final String code;
|
||||
private transient final String name;
|
||||
|
||||
Locale(String code, String name) {
|
||||
Language(String code, String name) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public static Locale fromCode(String code) {
|
||||
for (Locale value : values()) {
|
||||
public static Language fromCode(String code) {
|
||||
for (Language value : values()) {
|
||||
if (code.equals(value.code)) return value;
|
||||
}
|
||||
return ENGLISH;
|
|
@ -1,6 +1,10 @@
|
|||
package xyz.ineanto.nicko.i18n;
|
||||
package xyz.ineanto.nicko.language;
|
||||
|
||||
public class LanguageKey {
|
||||
public static final String PREFIX = "prefix";
|
||||
public static final String WHOOSH = "whoosh";
|
||||
public static final String OOPS = "oops";
|
||||
|
||||
public class I18NDict {
|
||||
public static class Error {
|
||||
public static final String ERROR_KEY = "error.";
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
package xyz.ineanto.nicko.i18n;
|
||||
package xyz.ineanto.nicko.language;
|
||||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.xenondevs.invui.item.builder.AbstractItemBuilder;
|
||||
|
||||
|
@ -16,22 +16,22 @@ import java.util.logging.Logger;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class I18N {
|
||||
public class PlayerLanguage {
|
||||
private final MessageFormat formatter = new MessageFormat("");
|
||||
private final Logger logger = Logger.getLogger("I18N");
|
||||
private final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
private final Nicko instance = Nicko.getInstance();
|
||||
private final Pattern replacementPattern = Pattern.compile("(?ms)\\{\\d+}");
|
||||
private final YamlConfig yamlConfig;
|
||||
private final Locale playerLocale;
|
||||
private final Language playerLanguage;
|
||||
|
||||
public I18N(Player player) {
|
||||
public PlayerLanguage(Player player) {
|
||||
final Optional<NickoProfile> optionalProfile = NickoProfile.get(player);
|
||||
this.playerLocale = optionalProfile.map(NickoProfile::getLocale).orElse(Locale.ENGLISH);
|
||||
this.playerLanguage = optionalProfile.map(NickoProfile::getLocale).orElse(Language.ENGLISH);
|
||||
this.yamlConfig = getYamlConfig();
|
||||
}
|
||||
|
||||
public I18N(Locale locale) {
|
||||
this.playerLocale = locale;
|
||||
public PlayerLanguage(Language language) {
|
||||
this.playerLanguage = language;
|
||||
this.yamlConfig = getYamlConfig();
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class I18N {
|
|||
final ArrayList<String> lore = readList(loreKey);
|
||||
|
||||
if (name == null && lore == null) {
|
||||
logger.warning(nameKey + " doesn't exists! Is your language file outdated?");
|
||||
Nicko.getInstance().getLogger().warning(nameKey + " doesn't exists! Is your language file outdated?");
|
||||
return new Translation(nameKey, new ArrayList<>(List.of(loreKey)));
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class I18N {
|
|||
|
||||
// If it does, replace the content with the args at position replacementIndex
|
||||
if (replacementIndex < args.length && args[replacementIndex] != null) {
|
||||
// Replace with the corresponding varargs index
|
||||
// Replace it with the corresponding varargs index
|
||||
toTranslate.set(lineIndex, currentLine.replace("{" + replacementIndex + "}", args[replacementIndex].toString()));
|
||||
replacementIndex++;
|
||||
}
|
||||
|
@ -115,11 +115,34 @@ public class I18N {
|
|||
|
||||
public String translate(String key, boolean prefix, Object... arguments) {
|
||||
final String translation = readString(key);
|
||||
|
||||
try {
|
||||
formatter.applyPattern(translation);
|
||||
return (prefix ? instance.getNickoConfig().getPrefix() : "") + formatter.format(arguments);
|
||||
return (prefix ? getPrefix() + " " : "") + formatter.format(arguments);
|
||||
} catch (Exception e) {
|
||||
return (prefix ? instance.getNickoConfig().getPrefix() : "") + key;
|
||||
return (prefix ? getPrefix() + " " : "") + key;
|
||||
}
|
||||
}
|
||||
|
||||
public String translateWithWhoosh(String key, Object... arguments) {
|
||||
final String translation = readStringWithMiniMessage(key);
|
||||
|
||||
try {
|
||||
formatter.applyPattern(translation);
|
||||
return getWhoosh() + " " + formatter.format(arguments);
|
||||
} catch (Exception e) {
|
||||
return getWhoosh() + " " + key;
|
||||
}
|
||||
}
|
||||
|
||||
public String translateWithOops(String key, Object... arguments) {
|
||||
final String translation = readStringWithMiniMessage(key);
|
||||
|
||||
try {
|
||||
formatter.applyPattern(translation);
|
||||
return getOops() + " " + formatter.format(arguments);
|
||||
} catch (Exception e) {
|
||||
return getOops() + " " + key;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,15 +150,31 @@ public class I18N {
|
|||
return yamlConfig.getString(key);
|
||||
}
|
||||
|
||||
private String readStringWithMiniMessage(String key) {
|
||||
return LegacyComponentSerializer.legacySection().serialize(MiniMessage.miniMessage().deserialize(readString(key)));
|
||||
}
|
||||
|
||||
private ArrayList<String> readList(String key) {
|
||||
return yamlConfig.getStringList(key);
|
||||
}
|
||||
|
||||
private String getPrefix() {
|
||||
return readStringWithMiniMessage(LanguageKey.PREFIX);
|
||||
}
|
||||
|
||||
private String getWhoosh() {
|
||||
return readStringWithMiniMessage(LanguageKey.WHOOSH);
|
||||
}
|
||||
|
||||
private String getOops() {
|
||||
return readStringWithMiniMessage(LanguageKey.OOPS);
|
||||
}
|
||||
|
||||
private YamlConfig getYamlConfig() {
|
||||
if (playerLocale == Locale.CUSTOM) {
|
||||
if (playerLanguage == Language.CUSTOM) {
|
||||
return instance.getCustomLocale().getYamlFile();
|
||||
} else {
|
||||
final InputStream resource = instance.getResource(playerLocale.getCode() + ".yml");
|
||||
final InputStream resource = instance.getResource(playerLanguage.getCode() + ".yml");
|
||||
return new YamlConfig(resource);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package xyz.ineanto.nicko.i18n;
|
||||
package xyz.ineanto.nicko.language;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package xyz.ineanto.nicko.migration;
|
||||
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.ConfigurationManager;
|
||||
|
||||
|
@ -9,9 +9,9 @@ import java.nio.file.Files;
|
|||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class ConfigurationMigrator implements Migrator {
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko instance;
|
||||
|
||||
public ConfigurationMigrator(NickoBukkit instance) {
|
||||
public ConfigurationMigrator(Nicko instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,12 @@ public class ConfigurationMigrator implements Migrator {
|
|||
instance.getLogger().info("Migrating configuration file to match the current version...");
|
||||
try {
|
||||
Files.copy(configurationManager.getFile().toPath(), configurationManager.getBackupFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
configurationManager.saveDefaultConfig();
|
||||
if (configurationManager.getFile().delete()) {
|
||||
configurationManager.saveDefaultConfig();
|
||||
instance.getLogger().info("Successfully migrated your configuration file!");
|
||||
} else {
|
||||
instance.getLogger().severe("Failed to migrate your configuration!");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().severe("Failed to migrate your configuration!");
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package xyz.ineanto.nicko.migration;
|
||||
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.CustomLocale;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.CustomLanguage;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -12,31 +12,33 @@ import java.time.ZoneId;
|
|||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class CustomLocaleMigrator implements Migrator {
|
||||
private final NickoBukkit instance;
|
||||
private final CustomLocale customLocale;
|
||||
private final Nicko instance;
|
||||
private final CustomLanguage customLanguage;
|
||||
|
||||
public CustomLocaleMigrator(NickoBukkit instance, CustomLocale customLocale) {
|
||||
public CustomLocaleMigrator(Nicko instance, CustomLanguage customLanguage) {
|
||||
this.instance = instance;
|
||||
this.customLocale = customLocale;
|
||||
this.customLanguage = customLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate() {
|
||||
// Migrate custom locale (1.1.0-RC1)
|
||||
if (customLocale.getVersionObject() == null
|
||||
|| customLocale.getVersion().isEmpty()
|
||||
|| customLocale.getVersionObject().compareTo(Locale.VERSION) != 0) {
|
||||
instance.getLogger().info("Migrating the custom locale (" + customLocale.getVersion() + ") to match the current version (" + Locale.VERSION + ")...");
|
||||
if (customLanguage.getVersionObject() == null
|
||||
|| customLanguage.getVersion().isEmpty()
|
||||
|| customLanguage.getVersionObject().compareTo(Language.VERSION) != 0) {
|
||||
instance.getLogger().info("Migrating the custom locale (" + customLanguage.getVersion() + ") to match the current version (" + Language.VERSION + ")...");
|
||||
|
||||
final String date = Instant.now().atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("dd-MM-yyyy"));
|
||||
final File backupFile = new File(customLocale.getDirectory(), "locale-" + date + ".yml");
|
||||
final File backupFile = new File(customLanguage.getDirectory(), "locale-" + date + ".yml");
|
||||
|
||||
try {
|
||||
Files.copy(customLocale.getFile().toPath(), backupFile.toPath());
|
||||
if (customLocale.getFile().delete()) {
|
||||
CustomLocale.dumpIntoFile(Locale.ENGLISH);
|
||||
Files.copy(customLanguage.getFile().toPath(), backupFile.toPath());
|
||||
if (customLanguage.getFile().delete()) {
|
||||
CustomLanguage.dumpIntoFile(Language.ENGLISH);
|
||||
instance.getLogger().info("Successfully migrated the custom locale.");
|
||||
} else {
|
||||
instance.getLogger().severe("Failed to migrate the custom locale!");
|
||||
}
|
||||
instance.getLogger().info("Successfully migrated the custom locale.");
|
||||
} catch (IOException e) {
|
||||
instance.getLogger().severe("Failed to migrate the custom locale!");
|
||||
}
|
||||
|
|
|
@ -4,16 +4,16 @@ import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class NickoExpansion extends PlaceholderExpansion {
|
||||
|
||||
private final NickoBukkit instance;
|
||||
private final Nicko instance;
|
||||
|
||||
public NickoExpansion(NickoBukkit instance) {
|
||||
public NickoExpansion(Nicko instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,26 +1,26 @@
|
|||
package xyz.ineanto.nicko.profile;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NickoProfile implements Cloneable {
|
||||
public static final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore();
|
||||
public static final NickoProfile EMPTY_PROFILE = new NickoProfile(null, null, Locale.ENGLISH, true);
|
||||
public static final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||
public static final NickoProfile EMPTY_PROFILE = new NickoProfile(null, null, Language.ENGLISH, true);
|
||||
|
||||
private String name;
|
||||
private String skin;
|
||||
private Locale locale;
|
||||
private Language language;
|
||||
private boolean randomSkin;
|
||||
|
||||
public NickoProfile(String name, String skin, Locale locale, boolean randomSkin) {
|
||||
public NickoProfile(String name, String skin, Language language, boolean randomSkin) {
|
||||
this.name = name;
|
||||
this.skin = skin;
|
||||
this.locale = locale;
|
||||
this.language = language;
|
||||
this.randomSkin = randomSkin;
|
||||
}
|
||||
|
||||
|
@ -52,12 +52,12 @@ public class NickoProfile implements Cloneable {
|
|||
this.skin = skin;
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return locale;
|
||||
public Language getLocale() {
|
||||
return language;
|
||||
}
|
||||
|
||||
public void setLocale(Locale locale) {
|
||||
this.locale = locale;
|
||||
public void setLocale(Language language) {
|
||||
this.language = language;
|
||||
}
|
||||
|
||||
public boolean isRandomSkin() {
|
||||
|
@ -73,7 +73,7 @@ public class NickoProfile implements Cloneable {
|
|||
return "NickoProfile{" +
|
||||
"name='" + name + '\'' +
|
||||
", skin='" + skin + '\'' +
|
||||
", locale=" + locale +
|
||||
", locale=" + language +
|
||||
", randomSkin=" + randomSkin +
|
||||
'}';
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package xyz.ineanto.nicko.storage;
|
|||
import org.bukkit.entity.Player;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.mojang.MojangAPI;
|
||||
import xyz.ineanto.nicko.mojang.MojangUtils;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
|
@ -34,7 +34,7 @@ public class PlayerDataStore {
|
|||
|
||||
public ActionResult updateCache(UUID uuid, NickoProfile profile) {
|
||||
if (storage.isError() || cache.isError()) {
|
||||
return ActionResult.error(I18NDict.Error.CACHE);
|
||||
return ActionResult.error(LanguageKey.Error.CACHE);
|
||||
}
|
||||
|
||||
getCache().cache(uuid, profile);
|
||||
|
|
|
@ -2,7 +2,7 @@ package xyz.ineanto.nicko.storage.json;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.Storage;
|
||||
|
@ -16,7 +16,7 @@ import java.util.logging.Logger;
|
|||
public class JSONStorage extends Storage {
|
||||
private final Logger logger = Logger.getLogger("JSONStorage");
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().setPrettyPrinting().create();
|
||||
private final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
private final File directory = new File(Nicko.getInstance().getDataFolder() + "/players/");
|
||||
|
||||
private JSONStorageProvider provider;
|
||||
|
||||
|
@ -54,14 +54,14 @@ public class JSONStorage extends Storage {
|
|||
|
||||
@Override
|
||||
public boolean isStored(UUID uuid) {
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
final File directory = new File(Nicko.getInstance().getDataFolder() + "/players/");
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
return file.exists();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<NickoProfile> retrieve(UUID uuid) {
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
final File directory = new File(Nicko.getInstance().getDataFolder() + "/players/");
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
try (FileReader fileReader = new FileReader(file)) {
|
||||
try (BufferedReader reader = new BufferedReader(fileReader)) {
|
||||
|
@ -75,7 +75,7 @@ public class JSONStorage extends Storage {
|
|||
|
||||
@Override
|
||||
public ActionResult delete(UUID uuid) {
|
||||
final File directory = new File(NickoBukkit.getInstance().getDataFolder() + "/players/");
|
||||
final File directory = new File(Nicko.getInstance().getDataFolder() + "/players/");
|
||||
final File file = new File(directory, uuid.toString() + ".json");
|
||||
if (file.delete() || !file.exists()) {
|
||||
return ActionResult.ok();
|
||||
|
|
|
@ -2,7 +2,7 @@ package xyz.ineanto.nicko.storage.mariadb;
|
|||
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.Storage;
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class MariaDBStorage extends Storage {
|
|||
bungeecord = resultSet.getBoolean("bungeecord");
|
||||
}
|
||||
|
||||
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
||||
final NickoProfile profile = new NickoProfile(name, skin, Language.fromCode(locale), bungeecord);
|
||||
return Optional.of(profile);
|
||||
} catch (SQLException e) {
|
||||
logger.warning("Couldn't fetch profile: " + e.getMessage());
|
||||
|
|
|
@ -2,7 +2,7 @@ package xyz.ineanto.nicko.storage.mysql;
|
|||
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.Storage;
|
||||
|
||||
|
@ -91,7 +91,7 @@ public class MySQLStorage extends Storage {
|
|||
bungeecord = resultSet.getBoolean("bungeecord");
|
||||
}
|
||||
|
||||
final NickoProfile profile = new NickoProfile(name, skin, Locale.fromCode(locale), bungeecord);
|
||||
final NickoProfile profile = new NickoProfile(name, skin, Language.fromCode(locale), bungeecord);
|
||||
return Optional.of(profile);
|
||||
} catch (SQLException e) {
|
||||
logger.warning("Couldn't fetch profile: " + e.getMessage());
|
||||
|
|
|
@ -6,7 +6,7 @@ import redis.clients.jedis.Jedis;
|
|||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.Cache;
|
||||
import xyz.ineanto.nicko.storage.CacheProvider;
|
||||
|
@ -40,7 +40,7 @@ public class RedisCache extends Cache {
|
|||
jedis.set("nicko:" + uuid.toString(), gson.toJson(profile));
|
||||
return ActionResult.ok();
|
||||
} catch (JedisException exception) {
|
||||
return ActionResult.error(I18NDict.Error.CACHE);
|
||||
return ActionResult.error(LanguageKey.Error.CACHE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class RedisCache extends Cache {
|
|||
jedis.del("nicko:" + uuid.toString());
|
||||
return ActionResult.ok();
|
||||
} catch (JedisException exception) {
|
||||
return ActionResult.error(I18NDict.Error.CACHE);
|
||||
return ActionResult.error(LanguageKey.Error.CACHE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import com.comphenix.protocol.PacketType;
|
|||
import com.comphenix.protocol.events.InternalStructure;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||
|
@ -54,24 +52,23 @@ public class WrapperPlayServerRespawn extends AbstractPacket {
|
|||
// 1.20.5 to 1.21.1
|
||||
|
||||
// why is life so hard?
|
||||
// Get the key from that class
|
||||
final MinecraftKey key = MinecraftKey.fromHandle(
|
||||
Accessors.getFieldAccessor(
|
||||
TYPE.getPacketClass(),
|
||||
MinecraftReflection.getResourceKey(),
|
||||
true
|
||||
)
|
||||
.get(spawnInfoStructure));
|
||||
/**final Class<?> commonPlayerInfoClazz = MinecraftReflection.getMinecraftClass("network.protocol.game.CommonPlayerSpawnInfo");
|
||||
Object commonSpawnData = Accessors.getFieldAccessor(TYPE.getPacketClass(), commonPlayerInfoClazz, true).getField().get(TYPE.getPacketClass());
|
||||
final MinecraftKey key = MinecraftKey.fromHandle(
|
||||
Accessors.getFieldAccessor(
|
||||
commonPlayerInfoClazz,
|
||||
MinecraftReflection.getResourceKey(),
|
||||
true
|
||||
)
|
||||
.get(spawnInfoStructure));
|
||||
|
||||
// Set the key
|
||||
Accessors.getFieldAccessor(
|
||||
spawnInfoStructure.getClass(),
|
||||
MinecraftReflection.getResourceKey(),
|
||||
true
|
||||
)
|
||||
.set(spawnInfoStructure, key);
|
||||
|
||||
handle.getStructures().writeSafely(0, spawnInfoStructure);
|
||||
// Set the key
|
||||
Accessors.getFieldAccessor(
|
||||
commonPlayerInfoClazz,
|
||||
MinecraftReflection.getResourceKey(),
|
||||
true
|
||||
)
|
||||
.set(commonSpawnData, key);*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# Nicko ${version} - Config:
|
||||
|
||||
# Specifies the configuration version, don't change.
|
||||
version: "1.0.8"
|
||||
version: "1.0.9"
|
||||
|
||||
############
|
||||
# LANGUAGE #
|
||||
############
|
||||
|
||||
# Nicko's messages prefix.
|
||||
# Accepted values: any string
|
||||
prefix: "§6Nicko §8§l| §r"
|
||||
#
|
||||
# Language
|
||||
#
|
||||
|
||||
# Nicko will copy the English locale as "lang.yml"
|
||||
# and will use the translations in that file when "Server Custom"
|
||||
|
@ -17,11 +13,10 @@ prefix: "§6Nicko §8§l| §r"
|
|||
# Accepted values: false (Disabled), true (Enabled)
|
||||
customLocale: false
|
||||
|
||||
###########
|
||||
# STORAGE #
|
||||
###########
|
||||
#
|
||||
# Storage
|
||||
#
|
||||
|
||||
# This configuration section manages SQL.
|
||||
sql:
|
||||
# Indicates wherever the data will be stored locally
|
||||
# inside a .json file or in an SQL database.
|
||||
|
@ -44,7 +39,7 @@ sql:
|
|||
# Accepted values: any string
|
||||
password: "password"
|
||||
|
||||
# This configuration section manages Redis (BungeeCord support).
|
||||
# This configuration section manages Redis (enabled BungeeCord support).
|
||||
# It is used to transfer data between multiple servers.
|
||||
redis:
|
||||
# Indicates wherever the data will be stored through
|
||||
|
|
|
@ -3,43 +3,47 @@
|
|||
# Specifies the configuration version, don't change.
|
||||
version: "1.1.4"
|
||||
|
||||
prefix: "<b><gradient:#01a97c:#8ffd54>NICKO</gradient></b>"
|
||||
whoosh: "<b><gradient:#01a97c:#8ffd54>WHOOSH!</gradient></b>"
|
||||
oops: "<b><color:#ff4640>OOPS!</color></b>"
|
||||
|
||||
error:
|
||||
permission: "§cYou do not have the required permission."
|
||||
invalid_username: "§cThis is not a valid Minecraft username."
|
||||
mojang_name: "There is no Minecraft account with this name."
|
||||
mojang_skin: "This Minecraft account has no skin."
|
||||
cache: "Unable to get skin from the cache."
|
||||
permission: "<gray>You're missing the permission to do that.<gray>"
|
||||
invalid_username: "<gray>This is an invalid Minecraft username.<gray>"
|
||||
mojang_name: "<gray>There's is not Minecraft account with this username.<gray>"
|
||||
mojang_skin: "<gray>This Minecraft account has no skin.<gray>"
|
||||
cache: "<gray>Unable to get data from the cache.<gray>"
|
||||
|
||||
event:
|
||||
settings:
|
||||
error: "§cUnable to update your settings. §7§o({0})"
|
||||
error: "<gray>Wasn't able to update your settings! ({0})</gray>"
|
||||
appearance:
|
||||
set:
|
||||
error: "§cUnable to apply your disguise. §7§o({0})"
|
||||
ok: "§fDisguise applied."
|
||||
error: "<gray>Wasn't able to apply your disguise! ({0})</gray>"
|
||||
ok: "<gray>You're now disguised.</gray>"
|
||||
restore:
|
||||
error: "§cUnable to apply your previous disguise back. §7§o({0})"
|
||||
ok: "§aYour previous active disguise has been applied."
|
||||
error: "<gray>Wasn't able to apply the previous disguise! ({0})</gray>"
|
||||
ok: "<gray>Disguise restored from last time.<gray>"
|
||||
remove:
|
||||
error: "§cUnable to remove your disguise. It will be reset on your next login."
|
||||
missing: "§cYou are not under a disguise."
|
||||
ok: "§fDisguise removed."
|
||||
error: "<gray>Wasn't able to remove your disguise!.</gray>"
|
||||
missing: "<gray>You're not currently disguised.</gray>"
|
||||
ok: "<gray>Undisguised successfully.</gray>"
|
||||
admin:
|
||||
cache:
|
||||
invalidate_cache: "§fComplete cache invalidated."
|
||||
invalidate_entry: "§6{0} §fhas been invalidated."
|
||||
invalidate_cache: "<gray>Cache purged.</gray>"
|
||||
invalidate_entry: "<gray>{0} was purged.</gray>"
|
||||
check:
|
||||
remove_skin: "§fSkin removed from player."
|
||||
remove_skin: "<gray>Skin removed from player.</gray>"
|
||||
|
||||
gui:
|
||||
title:
|
||||
home: "Nicko - Home"
|
||||
settings: "Nicko > Settings"
|
||||
admin: "Nicko > Administration"
|
||||
check: "Nicko > Admin... > Check"
|
||||
confirm: "... > Confirm action"
|
||||
cache: "Nicko > Admin... > Cache"
|
||||
invalidate_skin: "... > Cache > Invalidate"
|
||||
settings: "Settings"
|
||||
admin: "Administration"
|
||||
check: "Player Management"
|
||||
confirm: "Are you sure?"
|
||||
cache: "Cache Management"
|
||||
invalidate_skin: "Purge cache..."
|
||||
|
||||
exit:
|
||||
name: "Exit"
|
||||
|
@ -52,7 +56,7 @@ gui:
|
|||
error:
|
||||
name: "Error!"
|
||||
lore:
|
||||
- "<gray>The item texture failed to load, but it might still work.</gray>"
|
||||
- "<gray>The item failed to load, but it might still work.</gray>"
|
||||
loading:
|
||||
name: "<gray><i>Loading...</i></gray>"
|
||||
choice:
|
||||
|
|
|
@ -3,43 +3,47 @@
|
|||
# Précise la version de la configuration, ne pas changer.
|
||||
version: "1.1.4"
|
||||
|
||||
prefix: "<b><gradient:#01a97c:#8ffd54>NICKO</gradient></b>"
|
||||
whoosh: "<b><gradient:#01a97c:#8ffd54>WHOOSH!</gradient></b>"
|
||||
oops: "<b><color:#ff4640>OOPS!</color></b>"
|
||||
|
||||
error:
|
||||
permission: "§cVous ne possédez pas la permission."
|
||||
invalid_username: "§cLe pseudo n'est pas un pseudo Minecraft valide."
|
||||
mojang_name: "Compte Minecraft inexistant"
|
||||
mojang_skin: "Skin Minecraft invalide"
|
||||
cache: "Erreur du cache"
|
||||
permission: "<gray>Vous n'avez pas la permission de faire cela.<gray>"
|
||||
invalid_username: "<gray>Nom d'utilisateur Minecraft invalide.<gray>"
|
||||
mojang_name: "<gray>Aucun compte Minecraft associé à ce nom d'utilisateur.<gray>"
|
||||
mojang_skin: "<gray>Ce compte Minecraft n'a pas de skin.<gray>"
|
||||
cache: "<gray>Impossible de récupérer les données depuis le cache.<gray>"
|
||||
|
||||
event:
|
||||
settings:
|
||||
error: "§cImpossible de mettre à jour vos paramètres. §7§o({0})"
|
||||
error: "<gray>Impossible de mettre à jour vos paramètres ! ({0})</gray>"
|
||||
appearance:
|
||||
set:
|
||||
error: "§cImpossible d''appliquer votre déguisement. §7§o({0})"
|
||||
ok: "§fDéguisement appliqué."
|
||||
error: "<gray>Impossible d''appliquer votre déguisement ! ({0})</gray>"
|
||||
ok: "<gray>Déguisement appliqué avec succès.</gray>"
|
||||
restore:
|
||||
error: "§cImpossible d''appliquer votre précédent déguisement. §7§o({0})"
|
||||
ok: "§aVotre précédent déguisement a été appliqué."
|
||||
error: "<gray>Impossible d''appliquer le précédent déguisement ! ({0})</gray>"
|
||||
ok: "<gray>Votre précédent déguisement a été appliqué.<gray>"
|
||||
remove:
|
||||
error: "§cImpossible de retirer votre déguisement. Il sera réinitialisé à votre prochaine reconnexion."
|
||||
missing: "§cVous n''avez pas de déguisement."
|
||||
ok: "§fDéguisement retiré."
|
||||
error: "<gray>Impossible de retirer votre déguisement.</gray>"
|
||||
missing: "<gray>Vous n''avez pas de déguisement.</gray>"
|
||||
ok: "<gray>Déguisement retiré.</gray>"
|
||||
admin:
|
||||
cache:
|
||||
invalidate_cache: "§fCache complet invalidé."
|
||||
invalidate_entry: "§6{0} §fa été invalidé."
|
||||
invalidate_cache: "<gray>Cache complet invalidé.</gray>"
|
||||
invalidate_entry: "<gray>{0} a été invalidé.</gray>"
|
||||
check:
|
||||
remove_skin: "§fSkin retiré du joueur."
|
||||
remove_skin: "<gray>Déguisement retiré au joueur.</gray>"
|
||||
|
||||
gui:
|
||||
title:
|
||||
home: "Nicko - Accueil"
|
||||
settings: "Nicko > Paramètres"
|
||||
admin: "Nicko > Administration"
|
||||
check: "Nicko > Admin... > Vérification"
|
||||
confirm: "... > Confirmer l''action"
|
||||
cache: "Nicko > Admin... > Cache"
|
||||
invalidate_skin: "... > Cache > Invalider"
|
||||
settings: "Paramètres"
|
||||
admin: "Administration"
|
||||
check: "Gestion des Joueurs"
|
||||
confirm: "Êtes-vous sûr ?"
|
||||
cache: "Gestion du Cache"
|
||||
invalidate_skin: "Purge du cache..."
|
||||
|
||||
exit:
|
||||
name: "Quitter"
|
||||
|
@ -50,7 +54,7 @@ gui:
|
|||
lore:
|
||||
- "<gray><i>Ce boutton est désactivé.</i></gray>"
|
||||
error:
|
||||
name: "Erreur!"
|
||||
name: "Erreur !"
|
||||
lore:
|
||||
- "<gray>La texture de l'objet n'a pas chargé</gray>"
|
||||
- "<gray>correctement mais il fonctionne encore.</gray>"
|
||||
|
@ -121,10 +125,10 @@ gui:
|
|||
- "Nb. de skin dans le cache: <aqua>{1}</aqua>"
|
||||
- "<dark_gray><i>Le cache est vidé toutes les 24 heures.</i></dark_gray>"
|
||||
invalidate_cache:
|
||||
name: "Invalider le cache"
|
||||
name: "Purger le cache"
|
||||
lore:
|
||||
- "<red><i>DÉCONSEILLÉ</i></red>"
|
||||
- "<gray>Invalide l'entièreté du cache des skin.</gray>"
|
||||
- "<gray>Purge l'entièreté du cache des skin.</gray>"
|
||||
- "<gray>Ne retire pas les déguisements des joueurs.</gray>"
|
||||
invalidate_skin:
|
||||
name: "Invalider un skin..."
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
name: Nicko
|
||||
main: xyz.ineanto.nicko.NickoBukkit
|
||||
main: xyz.ineanto.nicko.Nicko
|
||||
version: ${version}
|
||||
author: Ineanto
|
||||
description: "The feature packed, next generation disguise plugin for Minecraft."
|
||||
|
|
|
@ -5,19 +5,19 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class NickoPluginTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.random.RandomNameFetcher;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.mojang.MojangUtils;
|
||||
|
@ -13,13 +13,13 @@ import xyz.ineanto.nicko.mojang.MojangUtils;
|
|||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class RandomNameTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -5,19 +5,19 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class ConfigurationTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
MockBukkit.mock();
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -5,7 +5,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
|
||||
|
@ -16,17 +16,13 @@ public class ConfigurationVersionTest {
|
|||
public static void setup() {
|
||||
MockBukkit.mock();
|
||||
final Configuration configuration = Configuration.DEFAULT;
|
||||
MockBukkit.load(NickoBukkit.class, configuration);
|
||||
MockBukkit.load(Nicko.class, configuration);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Compare configuration version")
|
||||
public void compareConfigurationVersion() {
|
||||
final Configuration configuration = new Configuration(Configuration.VERSION.toString(),
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"",
|
||||
false);
|
||||
final Configuration configuration = Configuration.DEFAULT;
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), 0);
|
||||
}
|
||||
|
||||
|
@ -36,7 +32,6 @@ public class ConfigurationVersionTest {
|
|||
final Configuration configuration = new Configuration("24.1.0",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"",
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), 1);
|
||||
}
|
||||
|
@ -47,7 +42,6 @@ public class ConfigurationVersionTest {
|
|||
final Configuration configuration = new Configuration("0.23.3",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"",
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), -1);
|
||||
}
|
||||
|
@ -58,7 +52,6 @@ public class ConfigurationVersionTest {
|
|||
final Configuration configuration = new Configuration(null,
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"",
|
||||
false);
|
||||
assertEquals(configuration.getVersionObject().compareTo(Configuration.VERSION), -1);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,12 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Translation;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
import xyz.ineanto.nicko.language.Translation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -22,14 +22,14 @@ public class ItemTranslationTest {
|
|||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
MockBukkit.load(NickoBukkit.class, config);
|
||||
MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Translate Item Without Lore")
|
||||
public void translateItemTranslationWithoutLore() {
|
||||
final I18N i18n = new I18N(Locale.FRENCH);
|
||||
final Translation translation = i18n.translateAndReplace(I18NDict.GUI.GO_BACK);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.GO_BACK);
|
||||
assertTrue(translation.lore().isEmpty());
|
||||
assertEquals(translation.name(), "Retour");
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ public class ItemTranslationTest {
|
|||
@Test
|
||||
@DisplayName("Translate Item")
|
||||
public void translateItemLore() {
|
||||
final I18N i18n = new I18N(Locale.FRENCH);
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
|
||||
final Translation test = i18n.translateAndReplace(I18NDict.GUI.Settings.TOGGLEABLE_BUTTON, "EST", "EST");
|
||||
final Translation test = playerLanguage.translateAndReplace(LanguageKey.GUI.Settings.TOGGLEABLE_BUTTON, "EST", "EST");
|
||||
test.lore().forEach(System.out::println);
|
||||
|
||||
final Translation translation = i18n.translateAndReplace(I18NDict.GUI.Admin.Cache.STATISTICS, "1", "1");
|
||||
final Translation translation = playerLanguage.translateAndReplace(LanguageKey.GUI.Admin.Cache.STATISTICS, "1", "1");
|
||||
assertFalse(translation.lore().isEmpty());
|
||||
assertEquals("Nombre de requêtes: <aqua>1</aqua>", translation.lore().get(0));
|
||||
assertEquals("Nb. de skin dans le cache: <aqua>1</aqua>", translation.lore().get(1));
|
||||
|
|
|
@ -5,11 +5,11 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.i18n.I18N;
|
||||
import xyz.ineanto.nicko.i18n.I18NDict;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.language.PlayerLanguage;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
@ -18,14 +18,14 @@ public class TranslationTest {
|
|||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
MockBukkit.mock();
|
||||
MockBukkit.load(NickoBukkit.class, config);
|
||||
MockBukkit.load(Nicko.class, config);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Translate Line With Replacement")
|
||||
public void translateItemTranslationWithoutLore() {
|
||||
final I18N i18n = new I18N(Locale.FRENCH);
|
||||
final String translation = i18n.translate(I18NDict.Event.Settings.ERROR, false, "Test");
|
||||
final PlayerLanguage playerLanguage = new PlayerLanguage(Language.FRENCH);
|
||||
final String translation = playerLanguage.translate(LanguageKey.Event.Settings.ERROR, false, "Test");
|
||||
assertEquals("§cImpossible de mettre à jour vos paramètres. §7§o(Test)", translation);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,22 @@ import be.seeseemelk.mockbukkit.MockBukkit;
|
|||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
import xyz.ineanto.nicko.i18n.CustomLocale;
|
||||
import xyz.ineanto.nicko.language.CustomLanguage;
|
||||
import xyz.ineanto.nicko.migration.CustomLocaleMigrator;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class MigrationTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
|
||||
private static File folder;
|
||||
private static File localeFile;
|
||||
|
@ -27,9 +30,8 @@ public class MigrationTest {
|
|||
final Configuration configuration = new Configuration(Configuration.VERSION.toString(),
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"§6Nicko §8§l| §r",
|
||||
true);
|
||||
plugin = MockBukkit.load(NickoBukkit.class, configuration);
|
||||
plugin = MockBukkit.load(Nicko.class, configuration);
|
||||
folder = new File(plugin.getDataFolder(), "/locale/");
|
||||
localeFile = new File(folder, "locale.yml");
|
||||
folder.mkdirs();
|
||||
|
@ -40,26 +42,26 @@ public class MigrationTest {
|
|||
public void testLanguageFileMigration() throws IOException {
|
||||
final String content = """
|
||||
# Nicko - Language File:
|
||||
|
||||
|
||||
# hello I'm the invalid version
|
||||
version: "1.0.0"
|
||||
""";
|
||||
""";
|
||||
|
||||
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(localeFile));
|
||||
outputStream.write(content.getBytes(StandardCharsets.UTF_8));
|
||||
outputStream.flush();
|
||||
|
||||
// Get wrong locale
|
||||
final CustomLocale customLocaleBeforeMigration = new CustomLocale();
|
||||
assertEquals(customLocaleBeforeMigration.getVersion(), "1.0.0");
|
||||
final CustomLanguage customLanguageBeforeMigration = new CustomLanguage();
|
||||
assertEquals(customLanguageBeforeMigration.getVersion(), "1.0.0");
|
||||
|
||||
// Migrate the wrong locale to the correct one
|
||||
final CustomLocaleMigrator localeMigrator = new CustomLocaleMigrator(plugin, customLocaleBeforeMigration);
|
||||
final CustomLocaleMigrator localeMigrator = new CustomLocaleMigrator(plugin, customLanguageBeforeMigration);
|
||||
localeMigrator.migrate();
|
||||
|
||||
// Get the migrated locale
|
||||
final CustomLocale customLocaleMigrated = new CustomLocale();
|
||||
assertEquals(customLocaleMigrated.getVersion(), "1.1.0");
|
||||
final CustomLanguage customLanguageMigrated = new CustomLanguage();
|
||||
assertEquals(customLanguageMigrated.getVersion(), "1.1.0");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.junit.jupiter.api.AfterAll;
|
|||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
|
||||
|
@ -16,14 +16,14 @@ import java.util.Optional;
|
|||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class MapCacheTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
private static PlayerMock player;
|
||||
|
||||
@BeforeAll
|
||||
public static void setup() {
|
||||
final Configuration config = Configuration.DEFAULT;
|
||||
final ServerMock server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
player = server.addPlayer();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import be.seeseemelk.mockbukkit.MockBukkit;
|
|||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||
import org.junit.jupiter.api.*;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DataSourceConfiguration;
|
||||
|
@ -19,7 +19,7 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class RedisCacheTest {
|
||||
private static NickoBukkit plugin;
|
||||
private static Nicko plugin;
|
||||
private static PlayerMock player;
|
||||
|
||||
@BeforeAll
|
||||
|
@ -28,10 +28,9 @@ public class RedisCacheTest {
|
|||
"",
|
||||
DefaultDataSources.SQL_EMPTY,
|
||||
new DataSourceConfiguration(true, "127.0.0.1", 6379, "", ""),
|
||||
"",
|
||||
false);
|
||||
final ServerMock server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
plugin = MockBukkit.load(Nicko.class, config);
|
||||
player = server.addPlayer();
|
||||
assertInstanceOf(RedisCacheProvider.class, plugin.getDataStore().getCache().getProvider());
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ package xyz.ineanto.nicko.test.storage;
|
|||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import org.junit.jupiter.api.*;
|
||||
import xyz.ineanto.nicko.NickoBukkit;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.config.Configuration;
|
||||
import xyz.ineanto.nicko.config.DefaultDataSources;
|
||||
import xyz.ineanto.nicko.config.SQLDataSourceConfiguration;
|
||||
import xyz.ineanto.nicko.i18n.Locale;
|
||||
import xyz.ineanto.nicko.language.Language;
|
||||
import xyz.ineanto.nicko.profile.NickoProfile;
|
||||
import xyz.ineanto.nicko.storage.PlayerDataStore;
|
||||
import xyz.ineanto.nicko.storage.mariadb.MariaDBStorageProvider;
|
||||
|
@ -28,12 +28,11 @@ public class SQLStorageTest {
|
|||
"",
|
||||
new SQLDataSourceConfiguration(true, "127.0.0.1", 3306, "root", "12345", true),
|
||||
DefaultDataSources.REDIS_EMPTY,
|
||||
"",
|
||||
false);
|
||||
|
||||
MockBukkit.mock();
|
||||
|
||||
final NickoBukkit plugin = MockBukkit.load(NickoBukkit.class, config);
|
||||
final Nicko plugin = MockBukkit.load(Nicko.class, config);
|
||||
dataStore = plugin.getDataStore();
|
||||
uuid = UUID.randomUUID();
|
||||
assertInstanceOf(MariaDBStorageProvider.class, dataStore.getStorage().getProvider());
|
||||
|
@ -64,12 +63,12 @@ public class SQLStorageTest {
|
|||
final NickoProfile profile = optionalProfile.get();
|
||||
assertNull(profile.getName());
|
||||
assertNull(profile.getSkin());
|
||||
assertEquals(profile.getLocale(), Locale.ENGLISH);
|
||||
assertEquals(profile.getLocale(), Language.ENGLISH);
|
||||
assertTrue(profile.isRandomSkin());
|
||||
|
||||
profile.setName("Notch");
|
||||
profile.setSkin("Notch");
|
||||
profile.setLocale(Locale.FRENCH);
|
||||
profile.setLocale(Language.FRENCH);
|
||||
profile.setRandomSkin(false);
|
||||
|
||||
final ActionResult result = dataStore.getStorage().store(uuid, profile);
|
||||
|
@ -86,7 +85,7 @@ public class SQLStorageTest {
|
|||
final NickoProfile updatedProfile = optionalProfile.get();
|
||||
assertEquals(updatedProfile.getName(), "Notch");
|
||||
assertEquals(updatedProfile.getSkin(), "Notch");
|
||||
assertEquals(updatedProfile.getLocale(), Locale.FRENCH);
|
||||
assertEquals(updatedProfile.getLocale(), Language.FRENCH);
|
||||
assertFalse(updatedProfile.isRandomSkin());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue