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