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

refactor: abstraction of menu related events

This commit is contained in:
Craftinators
2023-03-15 08:05:15 -04:00
parent 2b4e570172
commit 1ccb35ad62
3 changed files with 31 additions and 28 deletions

View File

@@ -9,24 +9,12 @@ import org.jetbrains.annotations.NotNull;
/**
* Called when a menu is closed by a player
*/
public class PlayerMenuCloseEvent extends CosmeticUserEvent implements Cancellable {
public class PlayerMenuCloseEvent extends PlayerMenuEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final Menu menu;
public PlayerMenuCloseEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
super(who);
this.menu = menu;
}
/**
* Gets the {@link Menu} that the player closed
*
* @return The {@link Menu} which is being closed by the player
*/
@NotNull
public Menu getMenu() {
return menu;
super(who, menu);
}
@Override

View File

@@ -0,0 +1,27 @@
package com.hibiscusmc.hmccosmetics.api;
import com.hibiscusmc.hmccosmetics.gui.Menu;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import org.jetbrains.annotations.NotNull;
/**
* Represents a menu related event
*/
public abstract class PlayerMenuEvent extends PlayerCosmeticEvent {
protected Menu menu;
public PlayerMenuEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
super(who);
this.menu = menu;
}
/**
* Gets the {@link Menu} involved with this event
*
* @return The {@link Menu} which is involved with the event
*/
@NotNull
public final Menu getMenu() {
return menu;
}
}

View File

@@ -9,24 +9,12 @@ import org.jetbrains.annotations.NotNull;
/**
* Called when a menu is opened by a player
*/
public class PlayerMenuOpenEvent extends CosmeticUserEvent implements Cancellable {
public class PlayerMenuOpenEvent extends PlayerMenuEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private final Menu menu;
public PlayerMenuOpenEvent(@NotNull CosmeticUser who, @NotNull Menu menu) {
super(who);
this.menu = menu;
}
/**
* Gets the {@link Menu} that the player opened
*
* @return The {@link Menu} which is being opened by the player
*/
@NotNull
public Menu getMenu() {
return menu;
super(who, menu);
}
@Override