9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-19 15:09:19 +00:00

feat: add usage for PlayerMenuCloseEvent, closes #158

This commit is contained in:
LoJoSho
2025-01-23 13:58:51 -06:00
parent f5fac4e048
commit 79687a22fc
2 changed files with 16 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package com.hibiscusmc.hmccosmetics.api.events;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.jetbrains.annotations.NotNull;
/**
@@ -10,9 +11,19 @@ import org.jetbrains.annotations.NotNull;
*/
public class PlayerMenuCloseEvent extends PlayerMenuEvent {
private static final HandlerList HANDLER_LIST = new HandlerList();
private final InventoryCloseEvent.Reason reason;
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu, @NotNull InventoryCloseEvent.Reason reason) {
super(who, menu);
this.reason = reason;
}
/**
* Gets the {@link InventoryCloseEvent.Reason} why the menu was closed.
* @return The reason why the menu was closed.
*/
public InventoryCloseEvent.Reason getReason() {
return reason;
}
@Override

View File

@@ -1,6 +1,7 @@
package com.hibiscusmc.hmccosmetics.gui;
import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuCloseEvent;
import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent;
import com.hibiscusmc.hmccosmetics.config.Settings;
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
@@ -169,6 +170,9 @@ public class Menu {
});
gui.setCloseGuiAction(event -> {
PlayerMenuCloseEvent closeEvent = new PlayerMenuCloseEvent(user, this, event.getReason());
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> Bukkit.getPluginManager().callEvent(closeEvent));
if (taskid.get() != -1) Bukkit.getScheduler().cancelTask(taskid.get());
});