|
6 | 6 | import org.bukkit.Material; |
7 | 7 | import org.bukkit.entity.HumanEntity; |
8 | 8 | import org.bukkit.entity.Player; |
| 9 | +import org.bukkit.event.Event; |
9 | 10 | import org.bukkit.event.inventory.InventoryClickEvent; |
10 | 11 | import org.bukkit.event.inventory.InventoryCloseEvent; |
11 | 12 | import org.bukkit.event.inventory.InventoryDragEvent; |
|
17 | 18 |
|
18 | 19 | import java.util.ArrayList; |
19 | 20 | import java.util.HashMap; |
| 21 | +import java.util.HashSet; |
20 | 22 | import java.util.Map; |
21 | 23 | import java.util.Map.Entry; |
| 24 | +import java.util.Set; |
22 | 25 | import java.util.function.Consumer; |
23 | 26 |
|
24 | 27 | public class GUI implements AnyNamed { |
@@ -116,10 +119,10 @@ public void onClose(InventoryCloseEvent e) { |
116 | 119 | if (onClose != null) { |
117 | 120 | SkriptGUI.getGUIManager().setGUI(e, GUI.this); |
118 | 121 | onClose.accept(e); |
119 | | - if (closeCancelled) { |
| 122 | + if (closeCancelled.contains(e)) { |
120 | 123 | Bukkit.getScheduler().runTaskLater(SkriptGUI.getInstance(), () -> { |
121 | 124 | // Reset behavior (it shouldn't persist) |
122 | | - setCloseCancelled(false); |
| 125 | + setCloseCancelled(e, false); |
123 | 126 |
|
124 | 127 | Player closer = (Player) e.getPlayer(); |
125 | 128 | pause(closer); // Avoid calling any open sections |
@@ -153,7 +156,7 @@ public void onClose(InventoryCloseEvent e) { |
153 | 156 | @Nullable |
154 | 157 | private Consumer<InventoryCloseEvent> onClose; |
155 | 158 | // Whether the inventory close event for this event handler is cancelled. |
156 | | - private boolean closeCancelled; |
| 159 | + private final Set<Event> closeCancelled = new HashSet<>(); |
157 | 160 |
|
158 | 161 | @Nullable |
159 | 162 | private String id; |
@@ -500,8 +503,12 @@ public void setOnClose(Consumer<InventoryCloseEvent> onClose) { |
500 | 503 | * Sets whether this GUI's close event should be cancelled. |
501 | 504 | * @param cancel Whether this GUI's close event should be cancelled. |
502 | 505 | */ |
503 | | - public void setCloseCancelled(boolean cancel) { |
504 | | - closeCancelled = cancel; |
| 506 | + public void setCloseCancelled(Event event, boolean cancel) { |
| 507 | + if (cancel) { |
| 508 | + closeCancelled.add(event); |
| 509 | + } else { |
| 510 | + closeCancelled.remove(event); |
| 511 | + } |
505 | 512 | } |
506 | 513 |
|
507 | 514 | /** |
|
0 commit comments