diff options
| author | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-03-03 15:10:22 +0000 |
|---|---|---|
| committer | LMBishop <13875753+LMBishop@users.noreply.github.com> | 2022-03-03 15:10:22 +0000 |
| commit | f22ddb547d24edec70fcee33fa27de3d68265843 (patch) | |
| tree | 171a9c239c4e551a572b226d280de57fcd6e14fb | |
| parent | e5d62e7e1565ad42bee191997883a23445fa3cfd (diff) | |
Add UI button customisation (closes #158, closes #319)
4 files changed, 33 insertions, 5 deletions
diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/QuestQMenu.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/QuestQMenu.java index 1387cd44..08106122 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/QuestQMenu.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/QuestQMenu.java @@ -37,6 +37,9 @@ public class QuestQMenu implements QMenu { private final String categoryName; private final int pageSize = 45; private final QPlayer owner; + private final ClickType startClickType; + private final ClickType trackClickType; + private final ClickType cancelClickType; private int maxElement = 0; private int backButtonLocation = -1; @@ -51,6 +54,10 @@ public class QuestQMenu implements QMenu { this.owner = owner; this.categoryName = categoryName; this.superMenu = superMenu; + + this.startClickType = MenuUtils.getClickType(config, "options.gui-actions.start-quest"); + this.trackClickType = MenuUtils.getClickType(config, "options.gui-actions.track-quest"); + this.cancelClickType = MenuUtils.getClickType(config, "options.gui-actions.cancel-quest"); } public void populate(List<Quest> quests) { @@ -220,16 +227,16 @@ public class QuestQMenu implements QMenu { if (menuElement instanceof QuestMenuElement) { QuestMenuElement questMenuElement = (QuestMenuElement) menuElement; Quest quest = plugin.getQuestManager().getQuestById(questMenuElement.getQuestId()); - if (event.getClick() == ClickType.LEFT) { + if (event.getClick() == startClickType) { if (config.getBoolean("options.quest-autostart") || quest.isAutoStartEnabled()) return false; if (owner.startQuest(quest) == QuestStartResult.QUEST_SUCCESS) { event.getWhoClicked().closeInventory(); //TODO Option to keep the menu open } return true; - } else if (event.getClick() == ClickType.MIDDLE) { + } else if (event.getClick() == trackClickType) { MenuUtils.handleMiddleClick(plugin, this, quest, Bukkit.getPlayer(owner.getPlayerUUID()), controller); return true; - } else if (event.getClick() == ClickType.RIGHT) { + } else if (event.getClick() == cancelClickType) { MenuUtils.handleRightClick(plugin, this, quest, Bukkit.getPlayer(owner.getPlayerUUID()), controller); return true; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/StartedQMenu.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/StartedQMenu.java index 66ef4744..05edd77a 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/StartedQMenu.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/menu/StartedQMenu.java @@ -28,6 +28,8 @@ public class StartedQMenu implements QMenu { private final HashMap<Integer, String> slotsToQuestIds = new HashMap<>(); private final int pageSize = 45; private final QPlayer owner; + private final ClickType trackClickType; + private final ClickType cancelClickType; private int pagePrevLocation = -1; private int pageNextLocation = -1; @@ -37,6 +39,9 @@ public class StartedQMenu implements QMenu { this.plugin = plugin; this.config = (BukkitQuestsConfig) plugin.getQuestsConfig(); this.owner = owner; + + this.trackClickType = MenuUtils.getClickType(config, "options.gui-actions.track-quest"); + this.cancelClickType = MenuUtils.getClickType(config, "options.gui-actions.cancel-quest"); } public void populate(List<QuestSortWrapper> quests) { @@ -164,10 +169,10 @@ public class StartedQMenu implements QMenu { // repeat from above String questid = slotsToQuestIds.get(event.getSlot() + (((currentPage) - 1) * pageSize)); Quest quest = plugin.getQuestManager().getQuestById(questid); - if (event.getClick() == ClickType.MIDDLE && config.getBoolean("options.allow-quest-track")) { + if (event.getClick() == trackClickType) { MenuUtils.handleMiddleClick(plugin, this, quest, Bukkit.getPlayer(owner.getPlayerUUID()), controller); return true; - } else if (event.getClick() == ClickType.RIGHT) { + } else if (event.getClick() == cancelClickType) { MenuUtils.handleRightClick(plugin, this, quest, Bukkit.getPlayer(owner.getPlayerUUID()), controller); return true; } diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/MenuUtils.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/MenuUtils.java index 230d596c..9db292a0 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/MenuUtils.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/MenuUtils.java @@ -1,12 +1,14 @@ package com.leonardobishop.quests.bukkit.util; import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; +import com.leonardobishop.quests.bukkit.config.BukkitQuestsConfig; import com.leonardobishop.quests.bukkit.menu.CancelQMenu; import com.leonardobishop.quests.bukkit.menu.MenuController; import com.leonardobishop.quests.bukkit.menu.QMenu; import com.leonardobishop.quests.common.quest.Quest; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -79,4 +81,13 @@ public class MenuUtils { } } + public static ClickType getClickType(BukkitQuestsConfig config, String path) { + String value = config.getString(path); + try { + return ClickType.valueOf(value); + } catch (IllegalArgumentException ignored) { + return null; + } + } + } diff --git a/bukkit/src/main/resources/resources/bukkit/config.yml b/bukkit/src/main/resources/resources/bukkit/config.yml index 1c6301b7..d4c7101a 100644 --- a/bukkit/src/main/resources/resources/bukkit/config.yml +++ b/bukkit/src/main/resources/resources/bukkit/config.yml @@ -191,6 +191,11 @@ options: gui-use-placeholderapi: false # Truncate quest requirements when there are multiple requirements to prevent enormous display items gui-truncate-requirements: true + # Set the action buttons for the GUI + gui-actions: + start-quest: LEFT + track-quest: MIDDLE + cancel-quest: RIGHT # Make it so players do not have to start quest themselves quest-autostart: false # Automatically track quests on start, and stop tracking on completion |
