mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 00:15:56 +02:00
ask gui translatable
This commit is contained in:
parent
1d402b1e76
commit
f373cae100
12 changed files with 54 additions and 37 deletions
|
|
@ -13,12 +13,11 @@ import org.jetbrains.annotations.Nullable;
|
|||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
import xyz.alexcrea.cuanvil.lang.Message;
|
||||
import xyz.alexcrea.cuanvil.lang.MsgError;
|
||||
import xyz.alexcrea.cuanvil.lang.MsgUI;
|
||||
import xyz.alexcrea.cuanvil.util.ComponentUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MetricsUtil;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
|
@ -47,8 +46,7 @@ public class ConfirmActionGui extends AbstractAskGui {
|
|||
try {
|
||||
success = onConfirm.get();
|
||||
} catch (Exception e) {
|
||||
CustomAnvil.instance.getLogger().log(Level.WARNING, "Could not process confirmation supplier.", e); //TODO MESSAGE
|
||||
MetricsUtil.INSTANCE.trackError(e);
|
||||
CustomAnvil.Companion.logError(MsgError.INSTANCE.getCONFIRM_ACTION_GENERIC().unformatted(), e, true, Level.WARNING);
|
||||
success = false;
|
||||
}
|
||||
|
||||
|
|
@ -62,10 +60,11 @@ public class ConfirmActionGui extends AbstractAskGui {
|
|||
// Info item
|
||||
ItemStack infoItem = new ItemStack(Material.PAPER);
|
||||
ItemMeta infoMeta = infoItem.getItemMeta();
|
||||
assert infoMeta != null;
|
||||
|
||||
infoMeta.setDisplayName("§eAre you sure ?"); //TODO MESSAGE
|
||||
ComponentUtil.INSTANCE.setMessageName(infoMeta, MsgUI.INSTANCE.getCONFIRM_ACTION_ARE_YOU_SURE());
|
||||
if(actionDescription != null){
|
||||
ComponentUtil.INSTANCE.applyLore(actionDescription.formatted(), infoMeta);
|
||||
ComponentUtil.INSTANCE.applyLore(actionDescription.formatted(actionParam), infoMeta);
|
||||
}
|
||||
|
||||
infoItem.setItemMeta(infoMeta);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import org.bukkit.entity.HumanEntity;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||
import xyz.alexcrea.cuanvil.lang.Message;
|
||||
|
|
@ -17,7 +16,6 @@ import xyz.alexcrea.cuanvil.lang.MsgUI;
|
|||
import xyz.alexcrea.cuanvil.util.ComponentUtil;
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
|
|
@ -89,8 +87,9 @@ public class SelectItemTypeGui extends AbstractAskGui {
|
|||
@NotNull String param
|
||||
){
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
|
||||
meta.setDisplayName("§ePlace an item here"); //TODO MESSAGE
|
||||
ComponentUtil.INSTANCE.setMessageName(meta, MsgUI.INSTANCE.getSELECT_ITEM_TYPE_PLACE_HERE());
|
||||
ComponentUtil.INSTANCE.applyLore(actionDescription.formatted(param), meta);
|
||||
|
||||
item.setItemMeta(meta);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil;
|
||||
import xyz.alexcrea.cuanvil.group.*;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectGroupContainer;
|
||||
import xyz.alexcrea.cuanvil.gui.config.SelectMaterialContainer;
|
||||
|
|
@ -65,13 +64,9 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
// Delete item
|
||||
ItemStack deleteItem = new ItemStack(Material.RED_TERRACOTTA);
|
||||
ItemMeta deleteMeta = deleteItem.getItemMeta();
|
||||
|
||||
assert deleteMeta != null;
|
||||
PlatformUtil.INSTANCE.setComponentDisplayName(
|
||||
deleteMeta,
|
||||
MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_BUTTON_NAME().formattedConcatenated(),
|
||||
null
|
||||
);
|
||||
|
||||
ComponentUtil.INSTANCE.setMessageName(deleteMeta, MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_BUTTON_NAME());
|
||||
ComponentUtil.INSTANCE.applyLore(
|
||||
MsgUI.INSTANCE.getMATERIAL_GROUP_ELEMENT_DELETE_BUTTON_LORE().formatted(),
|
||||
deleteMeta
|
||||
|
|
@ -88,11 +83,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
ItemMeta selectItemMeta = selectItem.getItemMeta();
|
||||
assert selectItemMeta != null;
|
||||
|
||||
PlatformUtil.INSTANCE.setComponentDisplayName(
|
||||
selectItemMeta,
|
||||
materialSelectionName.formattedConcatenated(name),
|
||||
null
|
||||
);
|
||||
ComponentUtil.INSTANCE.setMessageName(selectItemMeta, materialSelectionName);
|
||||
|
||||
selectItem.setItemMeta(selectItemMeta);
|
||||
this.materialSelection = new GuiItem(selectItem, (event) -> {
|
||||
|
|
@ -109,11 +100,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
|
|||
ItemMeta selectGroupMeta = selectGroup.getItemMeta();
|
||||
assert selectGroupMeta != null;
|
||||
|
||||
PlatformUtil.INSTANCE.setComponentDisplayName(
|
||||
selectGroupMeta,
|
||||
selectGroupName.formattedConcatenated(name),
|
||||
null
|
||||
);
|
||||
ComponentUtil.INSTANCE.setMessageName(selectGroupMeta, selectGroupName);
|
||||
|
||||
selectGroup.setItemMeta(selectGroupMeta);
|
||||
this.groupSelection = new GuiItem(selectGroup, (event) -> {
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ open class CustomAnvil : JavaPlugin() {
|
|||
|
||||
// Load language
|
||||
try {
|
||||
Lang.reload()
|
||||
Lang.loadDefault()
|
||||
} catch (e: Exception) {
|
||||
logError("error occurred loading language file", e)
|
||||
if(tryDirtyStart()) return
|
||||
|
|
|
|||
|
|
@ -23,10 +23,8 @@ import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
|||
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil
|
||||
import xyz.alexcrea.cuanvil.util.ComponentUtil.serializeLegacy
|
||||
import xyz.alexcrea.cuanvil.util.ComponentUtil.serializePlain
|
||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilColorUtil
|
||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilLoreEditUtil
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class ReloadExecutor : CASubCommand {
|
|||
if(!ConfigHolder.reloadAllFromDisk(hardfail)) return false
|
||||
|
||||
// reload language config
|
||||
Lang.reload()
|
||||
if(!Lang.reload()) return false
|
||||
|
||||
// Then update all global gui containing value from config
|
||||
BasicConfigGui.getInstance()?.updateGuiValues()
|
||||
|
|
|
|||
|
|
@ -6,10 +6,26 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
|
|||
|
||||
object Lang {
|
||||
|
||||
private val default = Language(DEFAULT_LANG, false)
|
||||
private var lang = default
|
||||
private lateinit var default: Language
|
||||
private lateinit var lang: Language
|
||||
|
||||
fun reload() {
|
||||
fun loadDefault() {
|
||||
default = Language(DEFAULT_LANG, false)
|
||||
lang = default
|
||||
reload()
|
||||
}
|
||||
|
||||
fun reload(): Boolean {
|
||||
try {
|
||||
unsafeReload()
|
||||
return true
|
||||
} catch(e: Exception) {
|
||||
CustomAnvil.logError("Error loading language $langID", e, false)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
private fun unsafeReload() {
|
||||
val langID = langID
|
||||
if(lang.name == langID && lang != default)
|
||||
lang.reload()
|
||||
|
|
|
|||
|
|
@ -19,8 +19,11 @@ object MsgError {
|
|||
val RELOAD_HARD_FAIL = ErrorMessage("reload.resource.hardfail")
|
||||
|
||||
/*
|
||||
* ----------
|
||||
* Commands
|
||||
* ----------
|
||||
* ----
|
||||
* UI
|
||||
* ----
|
||||
*/
|
||||
val CONFIRM_ACTION_GENERIC = ErrorMessage("confirm-action.generic")
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,9 @@ object MsgUI {
|
|||
val SHARED_TYPED_CONFIG_TITLE = Message("shared.typed-config-title", "type")
|
||||
|
||||
val CONFIRM_ACTION_FAILED = Message("confirm-action.fail")
|
||||
val CONFIRM_ACTION_ARE_YOU_SURE = Message("confirm-action.is-user-sure")
|
||||
|
||||
val SELECT_ITEM_TYPE_PLACE_HERE = Message("select-item-type.place-here")
|
||||
|
||||
val ELEMENT_LIST_INSTRUCTION_NEW = Message("element-list.instruction-new", "type")
|
||||
val ELEMENT_LIST_CANCELLED_NEW = Message("element-list.cancelled-new", "type")
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener.Companion.ANVIL_OUTPUT
|
|||
import xyz.alexcrea.cuanvil.util.ComponentUtil.serializePlain
|
||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilLoreEditUtil
|
||||
import xyz.alexcrea.cuanvil.util.anvil.AnvilXpUtil
|
||||
import xyz.alexcrea.cuanvil.util.config.LoreEditConfigUtil
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import net.kyori.adventure.text.Component
|
|||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.inventory.meta.ItemMeta
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.sendPaperMessage
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.setComponentDisplayName
|
||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.setPaperLore
|
||||
import xyz.alexcrea.cuanvil.lang.Message
|
||||
|
||||
object ComponentUtil {
|
||||
|
||||
|
|
@ -39,4 +41,8 @@ object ComponentUtil {
|
|||
meta.lore = this.map {obj -> obj.serializeLegacy()}
|
||||
}
|
||||
|
||||
fun ItemMeta.setMessageName(message: Message) {
|
||||
this.setComponentDisplayName(message.formattedConcatenated())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,6 +30,9 @@ error:
|
|||
fail: "Resource %path Could not be loaded or reloaded."
|
||||
hard-fail: "Disabling plugin."
|
||||
|
||||
confirm-action:
|
||||
generic: "Could not process confirmation supplier."
|
||||
|
||||
command:
|
||||
shared:
|
||||
no-diag-permission: "<red>You do not have permission to diagnostic this server"
|
||||
|
|
@ -106,6 +109,10 @@ config-ui:
|
|||
|
||||
confirm-action:
|
||||
fail: "<red>Action could not be completed."
|
||||
is-user-sure: "<yellow>Are you sure ?"
|
||||
|
||||
select-item-type:
|
||||
place-here: "<yellow>Place an item here"
|
||||
|
||||
element-list:
|
||||
instruction-new:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue