9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2026-01-01 05:16:39 +00:00

add close icon

This commit is contained in:
XiaoMoMi
2024-11-28 15:49:26 +08:00
parent 9bdfbf7cf1
commit ecd61cf849
2 changed files with 26 additions and 5 deletions

View File

@@ -68,12 +68,13 @@ public class BukkitMarketManager implements MarketManager, Listener {
protected TextValue<Player> title;
protected String[] layout;
protected final HashMap<Character, CustomFishingItem> decorativeIcons;
protected final HashMap<Character, Pair<CustomFishingItem, Action<Player>[]>> decorativeIcons;
protected final ConcurrentHashMap<UUID, MarketGUI> marketGUICache;
protected char itemSlot;
protected char sellSlot;
protected char sellAllSlot;
protected char closeSlot;
protected CustomFishingItem sellIconAllowItem;
protected CustomFishingItem sellIconDenyItem;
@@ -190,7 +191,10 @@ public class BukkitMarketManager implements MarketManager, Listener {
for (Map.Entry<String, Object> entry : decorativeSection.getStringRouteMappedValues(false).entrySet()) {
if (entry.getValue() instanceof Section innerSection) {
char symbol = Objects.requireNonNull(innerSection.getString("symbol")).charAt(0);
decorativeIcons.put(symbol, new SingleItemParser("gui", innerSection, plugin.getConfigManager().getItemFormatFunctions()).getItem());
decorativeIcons.put(symbol, Pair.of(
new SingleItemParser("gui", innerSection, plugin.getConfigManager().getItemFormatFunctions()).getItem(),
plugin.getActionManager().parseActions(innerSection.getSection("action")))
);
}
}
}
@@ -213,8 +217,8 @@ public class BukkitMarketManager implements MarketManager, Listener {
gui.addElement(new MarketGUIElement(itemSlot, new ItemStack(Material.AIR)));
gui.addElement(new MarketDynamicGUIElement(sellSlot, new ItemStack(Material.AIR)));
gui.addElement(new MarketDynamicGUIElement(sellAllSlot, new ItemStack(Material.AIR)));
for (Map.Entry<Character, CustomFishingItem> entry : decorativeIcons.entrySet()) {
gui.addElement(new MarketGUIElement(entry.getKey(), entry.getValue().build(context)));
for (Map.Entry<Character, Pair<CustomFishingItem, Action<Player>[]>> entry : decorativeIcons.entrySet()) {
gui.addElement(new MarketGUIElement(entry.getKey(), entry.getValue().left().build(context)));
}
gui.build().refresh().show();
marketGUICache.put(player.getUniqueId(), gui);
@@ -336,6 +340,12 @@ public class BukkitMarketManager implements MarketManager, Listener {
event.setCancelled(true);
}
Pair<CustomFishingItem, Action<Player>[]> decorativeIcon = this.decorativeIcons.get(element.getSymbol());
if (decorativeIcon != null) {
ActionManager.trigger(gui.context, decorativeIcon.right());
return;
}
if (element.getSymbol() == sellSlot) {
Pair<Integer, Double> pair = getItemsToSell(gui.context, gui.getItemsInGUI());

View File

@@ -206,7 +206,7 @@ mechanics:
earnings-multiplier: 1
# Layout for the market menu
layout:
- 'AAAAAAAAA'
- 'AAAAAAAAC'
- 'AIIIIIIIA'
- 'AIIIIIIIA'
- 'AIIIIIIIA'
@@ -353,6 +353,17 @@ mechanics:
name: ' '
components:
minecraft:hide_tooltip: {}
close-icon:
symbol: 'C'
material: RED_STAINED_GLASS_PANE
display:
name: ' '
components:
minecraft:hide_tooltip: {}
# Add actions on click
action:
action_1:
type: close-inv
# This section is only effective if "override-vanilla" is set to true
# Meaning vanilla mechanics, such as lure enchantment, will no longer apply
# You must configure their effects in CustomFishing instead