progress on translation system

This commit is contained in:
alexcrea 2026-08-16 07:26:08 +02:00
parent 19eccb5a08
commit 0ffe7c70f9
Signed by: alexcrea
GPG key ID: E59DF23EE2A2266C
16 changed files with 69 additions and 30 deletions

View file

@ -11,6 +11,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.MetricsUtil; import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.Arrays; import java.util.Arrays;
@ -33,7 +34,7 @@ public class ConfirmActionGui extends AbstractAskGui {
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
@ -47,7 +48,7 @@ public class ConfirmActionGui extends AbstractAskGui {
} }
if (!success) { if (!success) {
event.getWhoClicked().sendMessage("§cAction could not be completed. "); MsgUI.INSTANCE.getCONFIRM_ACTION_FAILED().send(player);
} }
backOnConfirm.show(player); backOnConfirm.show(player);

View file

@ -12,6 +12,7 @@ import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.MaterialUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil;
import java.util.Arrays; import java.util.Arrays;
@ -36,7 +37,7 @@ public class SelectItemTypeGui extends AbstractAskGui {
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }

View file

@ -10,6 +10,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui; import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@ -52,13 +53,12 @@ public abstract class MappedElementListConfigGui<T, S> extends ElementListConfig
// check permission // check permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
player.closeInventory(); player.closeInventory();
player.sendMessage("§eWrite the " + genericDisplayedName() + " name you want to create in the chat.\n" + MsgUI.INSTANCE.getELEMENT_LIST_INSTRUCTION_NEW().send(player, genericDisplayedName());
"§eOr write §ccancel §eto go back to " + genericDisplayedName() + " config menu");
CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player)); CustomAnvil.Companion.getChatListener().setListenedCallback(player, prepareCreateItemConsumer(player));

View file

@ -8,6 +8,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui; import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.LazyValue; import xyz.alexcrea.cuanvil.util.LazyValue;
import java.util.Locale; import java.util.Locale;
@ -69,13 +70,13 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
// check permission // check permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
message = message.toLowerCase(Locale.ROOT); message = message.toLowerCase(Locale.ROOT);
if ("cancel".equalsIgnoreCase(message)) { if ("cancel".equalsIgnoreCase(message)) {
player.sendMessage(genericDisplayedName() + " creation cancelled..."); MsgUI.INSTANCE.getELEMENT_LIST_CANCELLED_NEW().send(player, genericDisplayedName());
show(player); show(player);
return; return;
} }
@ -86,7 +87,7 @@ public abstract class MappedGuiListConfigGui<T, S extends MappedGuiListConfigGui
// Not the most efficient on large number of conflict, but it should not run often. // Not the most efficient on large number of conflict, but it should not run often.
for (T generic : getDisplayableInstanceOfGeneric()) { for (T generic : getDisplayableInstanceOfGeneric()) {
if (generic.toString().equalsIgnoreCase(message)) { if (generic.toString().equalsIgnoreCase(message)) {
player.sendMessage("§cPlease enter a " + genericDisplayedName() + " name that do not already exist..."); MsgUI.INSTANCE.getELEMENT_LIST_DUPLICATED_NEW().send(player, genericDisplayedName());
// wait next message. // wait next message.
CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get()); CustomAnvil.Companion.getChatListener().setListenedCallback(player, selfRef.get());
return; return;

View file

@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.list.elements.ElementMappedToListGui;
import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.DoubleSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MaterialUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil;
@ -70,11 +71,11 @@ public class UnitRepairElementListGui extends SettingGuiListConfigGui<Namespaced
NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack); NamespacedKey type = MaterialUtil.INSTANCE.getCustomType(itemStack);
if (!(meta instanceof Damageable)) { if (!(meta instanceof Damageable)) {
player.sendMessage("§cThis item can't be damaged, so it can't be repaired."); MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW().send(player);
return; return;
} }
if (type.equals(this.parentMaterial)) { if (type.equals(this.parentMaterial)) {
player.sendMessage("§cItem can't repair something of the same type."); MsgUI.INSTANCE.getUNIT_REPAIR_ELEMENT_SAME_TYPE_NEW().send(player);
return; return;
} }

View file

@ -23,6 +23,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.MaterialSelectSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.*; import java.util.*;
@ -113,7 +114,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
// Do not allow to open inventory if player do not have edit configuration permission // Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
// test if group is used & cancel & warn user if so // test if group is used & cancel & warn user if so

View file

@ -18,6 +18,7 @@ import xyz.alexcrea.cuanvil.gui.config.list.MappedElementListConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant; import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import xyz.alexcrea.cuanvil.util.CasedStringUtil; import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MaterialUtil; import xyz.alexcrea.cuanvil.util.MaterialUtil;
@ -156,7 +157,7 @@ public class MaterialSelectSettingGui extends MappedElementListConfigGui<Namespa
// Do not allow to save configuration if player do not have edit configuration permission // Do not allow to save configuration if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
if(testCantSave()) return; if(testCantSave()) return;

View file

@ -16,6 +16,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.config.WorkPenaltyType; import xyz.alexcrea.cuanvil.config.WorkPenaltyType;
import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui; import xyz.alexcrea.cuanvil.gui.config.global.BasicConfigGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions; import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumMap; import java.util.EnumMap;
@ -73,7 +74,7 @@ public class WorkPenaltyTypeSettingGui extends AbstractSettingGui {
// Do not allow to open inventory if player do not have edit configuration permission // Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(GuiGlobalActions.NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
new WorkPenaltyTypeSettingGui(parent).show(player); new WorkPenaltyTypeSettingGui(parent).show(player);

View file

@ -7,6 +7,7 @@ import org.bukkit.event.inventory.InventoryClickEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui; import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui; import xyz.alexcrea.cuanvil.gui.config.settings.SettingGui;
import xyz.alexcrea.cuanvil.lang.MsgUI;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -17,8 +18,6 @@ import java.util.function.Consumer;
*/ */
public class GuiGlobalActions { public class GuiGlobalActions {
public static final String NO_EDIT_PERM = "§cYou do not have permission to edit the config";
/** /**
* A Consumer that should be used if the item goal is to do nothing on click. * A Consumer that should be used if the item goal is to do nothing on click.
*/ */
@ -44,7 +43,7 @@ public class GuiGlobalActions {
// Do not allow to open inventory if player do not have edit configuration permission // Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
try { try {
@ -102,7 +101,7 @@ public class GuiGlobalActions {
// Do not allow to open inventory if player do not have edit configuration permission // Do not allow to open inventory if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }
goal.show(player); goal.show(player);
@ -127,7 +126,7 @@ public class GuiGlobalActions {
// Do not allow to save configuration if player do not have edit configuration permission // Do not allow to save configuration if player do not have edit configuration permission
if (!player.hasPermission(CustomAnvil.editConfigPermission)) { if (!player.hasPermission(CustomAnvil.editConfigPermission)) {
player.closeInventory(); player.closeInventory();
player.sendMessage(NO_EDIT_PERM); MsgUI.INSTANCE.getSHARED_CONFIG_NO_EDIT_PERM().send(player);
return; return;
} }

View file

@ -7,7 +7,6 @@ import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter import org.bukkit.command.TabCompleter
import xyz.alexcrea.cuanvil.lang.MsgCommand import xyz.alexcrea.cuanvil.lang.MsgCommand
import xyz.alexcrea.cuanvil.util.MetricsUtil
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter { class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {

View file

@ -10,9 +10,9 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
import xyz.alexcrea.cuanvil.lang.Message import xyz.alexcrea.cuanvil.lang.Message
import xyz.alexcrea.cuanvil.lang.MsgCommand import xyz.alexcrea.cuanvil.lang.MsgCommand
import xyz.alexcrea.cuanvil.lang.MsgUI
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
@ -35,7 +35,7 @@ class EditConfigExecutor : CASubCommand {
if(sender !is HumanEntity) return false if(sender !is HumanEntity) return false
if(!allowed(sender)) { if(!allowed(sender)) {
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM) MsgUI.SHARED_CONFIG_NO_EDIT_PERM.send(sender)
return false return false
} }
if(PlatformUtil.isFolia) { if(PlatformUtil.isFolia) {

View file

@ -28,6 +28,7 @@ import xyz.alexcrea.cuanvil.dependency.scheduler.FoliaScheduler
import xyz.alexcrea.cuanvil.dependency.scheduler.TaskScheduler import xyz.alexcrea.cuanvil.dependency.scheduler.TaskScheduler
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.componentLore
import xyz.alexcrea.cuanvil.lang.MsgWarning
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT_SLOT
import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError import xyz.alexcrea.cuanvil.util.MetricsUtil.trackError
import java.lang.IllegalStateException import java.lang.IllegalStateException
@ -158,18 +159,14 @@ object DependencyManager {
} }
private fun logException(target: CommandSender, e: Exception) { private fun logException(target: CommandSender, e: Exception) {
CustomAnvil.instance.logger.log( CustomAnvil.logError(
Level.SEVERE,
"Error while trying to handle custom anvil supported plugin: ", "Error while trying to handle custom anvil supported plugin: ",
e e
) )
trackError(e) trackError(e)
// Finally, warn the player // Finally, warn the player
target.sendMessage( MsgWarning.DEPENDENCY_GENERIC_EXCEPTION.send(target)
"[" + ChatColor.YELLOW.toString() + "CustomAnvil" + ChatColor.WHITE.toString() + "] " +
ChatColor.RED.toString() + "Error while handling the anvil."
)
} }
private fun logExceptionAndClear(view: AnvilView, e: Exception) { private fun logExceptionAndClear(view: AnvilView, e: Exception) {

View file

@ -144,4 +144,4 @@ class ErrorMessage(key: String, vararg params: String) : Message("error.$key", *
} }
class CommandMessage(key: String, vararg params: String) : Message("command.$key", *params) class CommandMessage(key: String, vararg params: String) : Message("command.$key", *params)
class UIMessage(key: String, vararg params: String) : Message("ui.$key", *params) class UIMessage(key: String, vararg params: String) : Message("config-ui.$key", *params)

View file

@ -1,6 +1,21 @@
package xyz.alexcrea.cuanvil.lang package xyz.alexcrea.cuanvil.lang
import xyz.alexcrea.cuanvil.lang.UIMessage as Message
object MsgUI { object MsgUI {
val SHARED_CONFIG_NO_EDIT_PERM = Message("shared.no-permission")
val CONFIRM_ACTION_FAILED = Message("confirm-action.fail")
val ELEMENT_LIST_INSTRUCTION_NEW = Message("element-list.instruction-new", "type")
val ELEMENT_LIST_CANCELLED_NEW = Message("element-list.cancelled-new", "type")
val ELEMENT_LIST_DUPLICATED_NEW = Message("element-list.duplicated-new", "type")
val UNIT_REPAIR_ELEMENT_TITLE = Message("unit-repair.element.title")
val UNIT_REPAIR_ELEMENT_DESCRIPTION = Message("unit-repair.element.description")
val UNIT_REPAIR_ELEMENT_CANNOT_REPAIR_NEW = Message("unit-repair.element.cannot-damage-new")
val UNIT_REPAIR_ELEMENT_SAME_TYPE_NEW = Message("unit-repair.element.same-type-new")
} }

View file

@ -15,4 +15,6 @@ object MsgWarning {
val LOAD_LEGACY_SPIGOT = Message("load.legacy.spigot") val LOAD_LEGACY_SPIGOT = Message("load.legacy.spigot")
val LOAD_LEGACY_SPIGOT_OLD = Message("load.legacy.spigot-old") val LOAD_LEGACY_SPIGOT_OLD = Message("load.legacy.spigot-old")
val DEPENDENCY_GENERIC_EXCEPTION = Message("config-ui.shared.no-permission")
} }

View file

@ -89,4 +89,24 @@ command:
start: "<yellow>Reloading config..." start: "<yellow>Reloading config..."
success: "<green>Config reloaded !" success: "<green>Config reloaded !"
fail: "<red>Config was not able to be reloaded..." fail: "<red>Config was not able to be reloaded..."
hard-fail: "<red>Hard fail, plugin disabled" hard-fail: "<red>Hard fail, plugin disabled"
config-ui:
shared:
no-permission: "<red>You do not have permission to edit the config"
confirm-action:
fail: "<red>Action could not be completed."
element-list:
instruction-new:
1: "<yellow>Write the %type name you want to create in the chat."
2: "<yellow>Or write <red>cancel <yellow>to go back to %type config menu"
cancelled-new: "%type creation cancelled..."
duplicated-new: "<red>Please enter a %type name that do not already exist..."
unit-repair:
element:
title: "Select item to be repaired."
description:
1: "<gray>Click here with an item to set the item"
2: "<gray>You like to be repaired by %name"
cannot-damage-new: "<red>This item can't be damaged, so it can't be repaired."
same-type-new: "<red>Item can't repair something of the same type."