fix/feat/refactor: yes
This commit is contained in:
parent
a674edc187
commit
51d6f0f6af
14 changed files with 68 additions and 85 deletions
|
@ -34,16 +34,21 @@
|
|||
<includes>
|
||||
<include>net.wesjd:anvilgui</include>
|
||||
<include>de.studiocode.invui:*</include>
|
||||
<include>com.github.jsixface:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>net.wesjd.anvilgui</pattern>
|
||||
<shadedPattern>net.artelnatif.anvilgui</shadedPattern>
|
||||
<shadedPattern>net.artelnatif.libs.anvilgui</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.studiocode.invui</pattern>
|
||||
<shadedPattern>net.artelnatif.invui</shadedPattern>
|
||||
<shadedPattern>net.artelnatif.libs.invui</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.jsixface</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.yaml</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<minimizeJar>false</minimizeJar>
|
||||
|
|
|
@ -105,7 +105,12 @@
|
|||
<artifactId>mariadb-java-client</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- YAML Reader -->
|
||||
<dependency>
|
||||
<groupId>com.github.jsixface</groupId>
|
||||
<artifactId>yamlconfig</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -130,16 +135,21 @@
|
|||
<includes>
|
||||
<include>net.wesjd:anvilgui</include>
|
||||
<include>de.studiocode.invui:*</include>
|
||||
<include>com.github.jsixface:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>net.wesjd.anvilgui</pattern>
|
||||
<shadedPattern>net.artelnatif.anvilgui</shadedPattern>
|
||||
<shadedPattern>net.artelnatif.libs.anvilgui</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>de.studiocode.invui</pattern>
|
||||
<shadedPattern>net.artelnatif.invui</shadedPattern>
|
||||
<shadedPattern>net.artelnatif.libs.invui</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github.jsixface</pattern>
|
||||
<shadedPattern>net.artelnatif.libs.yaml</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<!-- Prevents breaking AnvilGUI's VersionWrapper. -->
|
||||
|
|
|
@ -107,9 +107,7 @@ public class NickoBukkit extends JavaPlugin {
|
|||
localeFileManager = new LocaleFileManager();
|
||||
if (config.isCustomLocale()) {
|
||||
if (localeFileManager.dumpFromLocale(Locale.ENGLISH)) {
|
||||
if (localeFileManager.loadValues()) {
|
||||
getLogger().info("Successfully loaded custom language file.");
|
||||
}
|
||||
getLogger().info("Successfully loaded custom language file.");
|
||||
} else {
|
||||
getLogger().warning("Failed to load custom language file!");
|
||||
}
|
||||
|
|
|
@ -60,9 +60,9 @@ public class AnvilManager {
|
|||
appearanceManager.setName(response);
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(false);
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_SUCCESS));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.SUCCESS));
|
||||
} else {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
||||
}
|
||||
return AnvilGUI.Response.close();
|
||||
}
|
||||
|
@ -81,9 +81,9 @@ public class AnvilManager {
|
|||
appearanceManager.setSkin(response);
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(true);
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_SUCCESS));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.SUCCESS));
|
||||
} else {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.DISGUISE_FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Disguise.FAIL, I18N.translateWithoutPrefix(player, actionResult.getErrorMessage())));
|
||||
}
|
||||
return AnvilGUI.Response.close();
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ public class PlayerJoinListener implements Listener {
|
|||
if (appearanceManager.hasData()) {
|
||||
final ActionResult actionResult = appearanceManager.updatePlayer(appearanceManager.needsASkinChange());
|
||||
if (!actionResult.isError()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.PREVIOUS_SKIN_APPLIED));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.PreviousSkin.SUCCESS));
|
||||
} else {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.PREVIOUS_SKIN_APPLY_FAIL, I18N.translate(player, actionResult.getErrorMessage())));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.PreviousSkin.FAIL, I18N.translate(player, actionResult.getErrorMessage())));
|
||||
}
|
||||
}
|
||||
}, 20L);
|
||||
|
|
|
@ -5,7 +5,6 @@ import de.studiocode.invui.gui.builder.GUIBuilder;
|
|||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.gui.structure.Structure;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.items.admin.ReloadLanguageFileItem;
|
||||
import net.artelnatif.nicko.gui.items.common.BackItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -15,12 +14,11 @@ public class AdminPanelGUI {
|
|||
|
||||
public AdminPanelGUI(Player player) {
|
||||
final Structure structure = new Structure("# # # # # # # # #",
|
||||
"# % % P U L % % #",
|
||||
"# % % P U # % % #",
|
||||
"B # # # # # # # #");
|
||||
structure.addIngredient('B', new BackItem(new MainGUI(player).getGUI()));
|
||||
this.gui = new GUIBuilder<>(GUIType.NORMAL)
|
||||
.setStructure(structure)
|
||||
.addIngredient('L', new ReloadLanguageFileItem())
|
||||
.build();
|
||||
this.player = player;
|
||||
}
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
package net.artelnatif.nicko.gui.items.admin;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ReloadLanguageFileItem extends BaseItem {
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
return new ItemBuilder(Material.BOOK)
|
||||
.addEnchantment(Enchantment.DAMAGE_ALL, 1, false)
|
||||
.addItemFlags(ItemFlag.HIDE_ENCHANTS)
|
||||
.setDisplayName("§fReload Language File");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
event.getView().close();
|
||||
final boolean success = NickoBukkit.getInstance().getLocaleFileManager().loadValues();
|
||||
if (success) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Plugin.CUSTOM_LANGUAGE_RELOAD_SUCCESS));
|
||||
} else {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Plugin.CUSTOM_LANGUAGE_RELOAD_FAIL));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,15 +27,15 @@ public class ResetItem extends BaseItem {
|
|||
final AppearanceManager appearanceManager = AppearanceManager.get(player);
|
||||
|
||||
if (!appearanceManager.hasData()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_NOTACTIVE));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Undisguise.NONE));
|
||||
event.getView().close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!appearanceManager.reset().isError()) {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_SUCCESS));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Undisguise.SUCCESS));
|
||||
} else {
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.UNDISGUISE_FAIL));
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Undisguise.FAIL));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,21 @@ public class LanguageCyclingItem {
|
|||
getItemProviderForLocale(Locale.CUSTOM),
|
||||
};
|
||||
|
||||
private final ItemProvider[] providersNoCustom = new ItemProvider[]{
|
||||
getItemProviderForLocale(Locale.ENGLISH),
|
||||
getItemProviderForLocale(Locale.FRENCH)
|
||||
};
|
||||
|
||||
public BaseItem get(Player player) {
|
||||
Optional<NickoProfile> profile = NickoBukkit.getInstance().getDataStore().getData(player.getUniqueId());
|
||||
final NickoBukkit instance = NickoBukkit.getInstance();
|
||||
Optional<NickoProfile> profile = instance.getDataStore().getData(player.getUniqueId());
|
||||
if (profile.isPresent()) {
|
||||
final NickoProfile nickoProfile = profile.get();
|
||||
int localeOrdinal = nickoProfile.getLocale().ordinal();
|
||||
return CycleItem.withStateChangeHandler((observer, integer) -> {
|
||||
nickoProfile.setLocale(Locale.values()[integer]);
|
||||
observer.playSound(player, Sound.UI_BUTTON_CLICK, 1f, 0.707107f); // 0.707107 ~= C
|
||||
}, localeOrdinal, providers);
|
||||
}, localeOrdinal, instance.getNickoConfig().isCustomLocale() ? providers : providersNoCustom);
|
||||
}
|
||||
|
||||
return new SimpleItem(ItemProvider.EMPTY);
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.disguise.NickoProfile;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
|
||||
public class I18N {
|
||||
|
@ -51,10 +52,11 @@ public class I18N {
|
|||
final Locale locale = getLocale(player);
|
||||
String translation;
|
||||
if (locale == Locale.CUSTOM) {
|
||||
translation = instance.getLocaleFileManager().getFromFile(key.key());
|
||||
translation = instance.getLocaleFileManager().get(key.key());
|
||||
} else {
|
||||
final HashMap<String, String> values = yaml.load(instance.getResource(locale.getCode() + ".yml"));
|
||||
translation = values.getOrDefault(key.key(), key.key());
|
||||
final InputStream resource = instance.getResource(locale.getCode() + ".yml");
|
||||
final YamlConfig yamlConfig = YamlConfig.load(resource);
|
||||
translation = yamlConfig.getString(key.key());
|
||||
}
|
||||
|
||||
return translation;
|
||||
|
|
|
@ -2,13 +2,21 @@ package net.artelnatif.nicko.i18n;
|
|||
|
||||
public record I18NDict(String key) {
|
||||
public static class Event {
|
||||
public static final I18NDict UNDISGUISE_SUCCESS = new I18NDict("event.undisguise.success");
|
||||
public static final I18NDict UNDISGUISE_FAIL = new I18NDict("event.undisguise.fail");
|
||||
public static final I18NDict UNDISGUISE_NOTACTIVE = new I18NDict("event.undisguise.notactive");
|
||||
public static final I18NDict DISGUISE_SUCCESS = new I18NDict("event.disguise.success");
|
||||
public static final I18NDict DISGUISE_FAIL = new I18NDict("event.disguise.fail");
|
||||
public static final I18NDict PREVIOUS_SKIN_APPLIED = new I18NDict("event.previous_skin_applied.success");
|
||||
public static final I18NDict PREVIOUS_SKIN_APPLY_FAIL = new I18NDict("event.previous_skin_applied.fail");
|
||||
public static class Disguise {
|
||||
public static final I18NDict SUCCESS = new I18NDict("event.disguise.success");
|
||||
public static final I18NDict FAIL = new I18NDict("event.disguise.fail");
|
||||
}
|
||||
|
||||
public static class Undisguise {
|
||||
public static final I18NDict SUCCESS = new I18NDict("event.undisguise.success");
|
||||
public static final I18NDict FAIL = new I18NDict("event.undisguise.fail");
|
||||
public static final I18NDict NONE = new I18NDict("event.undisguise.none");
|
||||
}
|
||||
|
||||
public static class PreviousSkin {
|
||||
public static final I18NDict SUCCESS = new I18NDict("event.previous_skin_applied.success");
|
||||
public static final I18NDict FAIL = new I18NDict("event.previous_skin_applied.fail");
|
||||
}
|
||||
}
|
||||
|
||||
public static class Plugin {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.artelnatif.nicko.i18n;
|
||||
|
||||
import com.github.jsixface.YamlConfig;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
|
@ -11,23 +12,16 @@ public class LocaleFileManager {
|
|||
private final File folder = new File(NickoBukkit.getInstance().getDataFolder() + "/lang/");
|
||||
private final File file = new File(folder, "lang.yml");
|
||||
|
||||
private HashMap<String, String> data = new HashMap<>();
|
||||
|
||||
public boolean loadValues() {
|
||||
if (!file.exists()) return true;
|
||||
public String get(String key) {
|
||||
if (!file.exists()) return key;
|
||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file))) {
|
||||
data = yaml.load(inputStream);
|
||||
return true;
|
||||
final YamlConfig yamlConfig = YamlConfig.load(inputStream);
|
||||
return yamlConfig.getString(key);
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public String getFromFile(String key) {
|
||||
if (!file.exists() || data.isEmpty()) return key;
|
||||
return data.get(key);
|
||||
}
|
||||
|
||||
public boolean dumpFromLocale(Locale locale) {
|
||||
if (locale == Locale.CUSTOM) return true;
|
||||
if (file.exists()) return true;
|
||||
|
|
|
@ -17,5 +17,5 @@ event:
|
|||
success: "§aYour previous active disguise has been applied back."
|
||||
undisguise:
|
||||
fail: "§cUnable to remove your disguise. It will be set back to default on your next login. Sorry!"
|
||||
notactive: "§cYou do not have an active disguise."
|
||||
none: "§cYou do not have an active disguise."
|
||||
success: "§aDisguise removed."
|
|
@ -17,5 +17,5 @@ event:
|
|||
success: "§aVotre précédent déguisement a été réappliqué."
|
||||
undisguise:
|
||||
fail: "§cImpossible de retier votre déguisement. Il sera remis par défaut à votre prochaine reconnexion. Désolé !"
|
||||
notactive: "§cVous n'avez pas de déguisement."
|
||||
none: "§cVous n'avez pas de déguisement."
|
||||
success: "§aDéguisement retiré."
|
Loading…
Reference in a new issue