From 1ccb35ad624996d1cd4f5da0c5c60d02bd8e90fa Mon Sep 17 00:00:00 2001 From: Craftinators Date: Wed, 15 Mar 2023 08:05:15 -0400 Subject: [PATCH] refactor: abstraction of menu related events --- .../api/PlayerMenuCloseEvent.java | 16 ++--------- .../hmccosmetics/api/PlayerMenuEvent.java | 27 +++++++++++++++++++ .../hmccosmetics/api/PlayerMenuOpenEvent.java | 16 ++--------- 3 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuEvent.java diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuCloseEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuCloseEvent.java index 1569f429..cbbbc4de 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuCloseEvent.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuCloseEvent.java @@ -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 diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuEvent.java new file mode 100644 index 00000000..e5b74a2e --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuEvent.java @@ -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; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuOpenEvent.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuOpenEvent.java index cfea3dfc..a31a09d4 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuOpenEvent.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/api/PlayerMenuOpenEvent.java @@ -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