From ba83b7e3eb12dbfe4eae08493a07c3eec2e5dff6 Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 3 Feb 2022 12:37:44 +0200 Subject: [PATCH] Implement ACTION defining by ACTION TYPE This change implements a new way how to define actions via a custom panel template. Previously there were 2 options how to define an action: - by click-type - as an array list This adds the third type: by action type. It means that now developers could code that action is the main key for defining what happens when button is clicked: ``` actions: visit: click-type: LEFT tooltip: Tooltip text for left click action ``` --- .../api/panels/reader/TemplateReader.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/java/world/bentobox/bentobox/api/panels/reader/TemplateReader.java b/src/main/java/world/bentobox/bentobox/api/panels/reader/TemplateReader.java index 1f0a866fb..d98d501ad 100644 --- a/src/main/java/world/bentobox/bentobox/api/panels/reader/TemplateReader.java +++ b/src/main/java/world/bentobox/bentobox/api/panels/reader/TemplateReader.java @@ -360,6 +360,24 @@ else if (section.isString(FALLBACK) && reusableItemMap != null) itemRecord.addAction(actionData); } } + else + { + ConfigurationSection actionDataSection = actionSection.getConfigurationSection(actionKey); + + if (actionDataSection != null && actionDataSection.contains("click-type")) + { + clickType = Enums.getIfPresent(ClickType.class, + actionDataSection.getString("click-type", "UNKNOWN").toUpperCase()). + or(ClickType.UNKNOWN); + + ItemTemplateRecord.ActionRecords actionData = + new ItemTemplateRecord.ActionRecords(clickType, + actionKey, + actionDataSection.getString("content"), + actionDataSection.getString("tooltip")); + itemRecord.addAction(actionData); + } + } }); } }