From 80b2dd2747d53b8e190edee414598e3edde56995 Mon Sep 17 00:00:00 2001 From: TheMode Date: Wed, 2 Jun 2021 09:25:08 +0200 Subject: [PATCH] Make InventoryEvent an interface --- .../minestom/server/event/InventoryEvent.java | 23 ------------------- .../event/inventory/InventoryClickEvent.java | 13 ++++++++--- .../event/inventory/InventoryCloseEvent.java | 13 ++++++++--- .../event/inventory/InventoryOpenEvent.java | 8 ++++--- .../inventory/InventoryPreClickEvent.java | 13 ++++++++--- .../server/event/trait/InventoryEvent.java | 15 ++++++++++++ 6 files changed, 50 insertions(+), 35 deletions(-) delete mode 100644 src/main/java/net/minestom/server/event/InventoryEvent.java create mode 100644 src/main/java/net/minestom/server/event/trait/InventoryEvent.java diff --git a/src/main/java/net/minestom/server/event/InventoryEvent.java b/src/main/java/net/minestom/server/event/InventoryEvent.java deleted file mode 100644 index 58d4db57c..000000000 --- a/src/main/java/net/minestom/server/event/InventoryEvent.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.minestom.server.event; - -import net.minestom.server.inventory.Inventory; -import org.jetbrains.annotations.Nullable; - -public class InventoryEvent implements Event { - - protected Inventory inventory; - - public InventoryEvent(@Nullable Inventory inventory) { - this.inventory = inventory; - } - - /** - * Gets the inventory. - * - * @return the inventory, null if this is a player's inventory - */ - @Nullable - public Inventory getInventory() { - return inventory; - } -} \ No newline at end of file diff --git a/src/main/java/net/minestom/server/event/inventory/InventoryClickEvent.java b/src/main/java/net/minestom/server/event/inventory/InventoryClickEvent.java index b7e9a89bb..c7ce5381b 100644 --- a/src/main/java/net/minestom/server/event/inventory/InventoryClickEvent.java +++ b/src/main/java/net/minestom/server/event/inventory/InventoryClickEvent.java @@ -1,7 +1,8 @@ package net.minestom.server.event.inventory; import net.minestom.server.entity.Player; -import net.minestom.server.event.InventoryEvent; +import net.minestom.server.event.trait.InventoryEvent; +import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.click.ClickType; import net.minestom.server.item.ItemStack; @@ -12,8 +13,9 @@ import org.jetbrains.annotations.Nullable; * Called after {@link InventoryPreClickEvent}, this event cannot be cancelled and items related to the click * are already moved. */ -public class InventoryClickEvent extends InventoryEvent { +public class InventoryClickEvent implements InventoryEvent, PlayerEvent { + private final Inventory inventory; private final Player player; private final int slot; private final ClickType clickType; @@ -23,7 +25,7 @@ public class InventoryClickEvent extends InventoryEvent { public InventoryClickEvent(@Nullable Inventory inventory, @NotNull Player player, int slot, @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { - super(inventory); + this.inventory = inventory; this.player = player; this.slot = slot; this.clickType = clickType; @@ -79,4 +81,9 @@ public class InventoryClickEvent extends InventoryEvent { public ItemStack getCursorItem() { return cursorItem; } + + @Override + public @Nullable Inventory getInventory() { + return inventory; + } } diff --git a/src/main/java/net/minestom/server/event/inventory/InventoryCloseEvent.java b/src/main/java/net/minestom/server/event/inventory/InventoryCloseEvent.java index 881d64e07..ec6579799 100644 --- a/src/main/java/net/minestom/server/event/inventory/InventoryCloseEvent.java +++ b/src/main/java/net/minestom/server/event/inventory/InventoryCloseEvent.java @@ -1,7 +1,8 @@ package net.minestom.server.event.inventory; import net.minestom.server.entity.Player; -import net.minestom.server.event.InventoryEvent; +import net.minestom.server.event.trait.InventoryEvent; +import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.inventory.Inventory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,13 +10,14 @@ import org.jetbrains.annotations.Nullable; /** * Called when an {@link Inventory} is closed by a player. */ -public class InventoryCloseEvent extends InventoryEvent { +public class InventoryCloseEvent implements InventoryEvent, PlayerEvent { + private final Inventory inventory; private final Player player; private Inventory newInventory; public InventoryCloseEvent(@Nullable Inventory inventory, @NotNull Player player) { - super(inventory); + this.inventory = inventory; this.player = player; } @@ -47,4 +49,9 @@ public class InventoryCloseEvent extends InventoryEvent { public void setNewInventory(@Nullable Inventory newInventory) { this.newInventory = newInventory; } + + @Override + public @Nullable Inventory getInventory() { + return inventory; + } } diff --git a/src/main/java/net/minestom/server/event/inventory/InventoryOpenEvent.java b/src/main/java/net/minestom/server/event/inventory/InventoryOpenEvent.java index 6b02eb717..d73682243 100644 --- a/src/main/java/net/minestom/server/event/inventory/InventoryOpenEvent.java +++ b/src/main/java/net/minestom/server/event/inventory/InventoryOpenEvent.java @@ -2,7 +2,8 @@ package net.minestom.server.event.inventory; import net.minestom.server.entity.Player; import net.minestom.server.event.CancellableEvent; -import net.minestom.server.event.InventoryEvent; +import net.minestom.server.event.trait.InventoryEvent; +import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.inventory.Inventory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -12,14 +13,15 @@ import org.jetbrains.annotations.Nullable; *

* Executed by {@link Player#openInventory(Inventory)}. */ -public class InventoryOpenEvent extends InventoryEvent implements CancellableEvent { +public class InventoryOpenEvent implements InventoryEvent, PlayerEvent, CancellableEvent { + private Inventory inventory; private final Player player; private boolean cancelled; public InventoryOpenEvent(@Nullable Inventory inventory, @NotNull Player player) { - super(inventory); + this.inventory = inventory; this.player = player; } diff --git a/src/main/java/net/minestom/server/event/inventory/InventoryPreClickEvent.java b/src/main/java/net/minestom/server/event/inventory/InventoryPreClickEvent.java index ca4733b38..cf483e8bc 100644 --- a/src/main/java/net/minestom/server/event/inventory/InventoryPreClickEvent.java +++ b/src/main/java/net/minestom/server/event/inventory/InventoryPreClickEvent.java @@ -2,7 +2,8 @@ package net.minestom.server.event.inventory; import net.minestom.server.entity.Player; import net.minestom.server.event.CancellableEvent; -import net.minestom.server.event.InventoryEvent; +import net.minestom.server.event.trait.InventoryEvent; +import net.minestom.server.event.trait.PlayerEvent; import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.click.ClickType; import net.minestom.server.item.ItemStack; @@ -12,8 +13,9 @@ import org.jetbrains.annotations.Nullable; /** * Called before {@link InventoryClickEvent}, used to potentially cancel the click. */ -public class InventoryPreClickEvent extends InventoryEvent implements CancellableEvent { +public class InventoryPreClickEvent implements InventoryEvent, PlayerEvent, CancellableEvent { + private final Inventory inventory; private final Player player; private final int slot; private final ClickType clickType; @@ -26,7 +28,7 @@ public class InventoryPreClickEvent extends InventoryEvent implements Cancellabl @NotNull Player player, int slot, @NotNull ClickType clickType, @NotNull ItemStack clicked, @NotNull ItemStack cursor) { - super(inventory); + this.inventory = inventory; this.player = player; this.slot = slot; this.clickType = clickType; @@ -110,4 +112,9 @@ public class InventoryPreClickEvent extends InventoryEvent implements Cancellabl public void setCancelled(boolean cancel) { this.cancelled = cancel; } + + @Override + public @Nullable Inventory getInventory() { + return inventory; + } } diff --git a/src/main/java/net/minestom/server/event/trait/InventoryEvent.java b/src/main/java/net/minestom/server/event/trait/InventoryEvent.java new file mode 100644 index 000000000..d102f5d20 --- /dev/null +++ b/src/main/java/net/minestom/server/event/trait/InventoryEvent.java @@ -0,0 +1,15 @@ +package net.minestom.server.event.trait; + +import net.minestom.server.event.Event; +import net.minestom.server.inventory.Inventory; +import org.jetbrains.annotations.Nullable; + +public interface InventoryEvent extends Event { + + /** + * Gets the inventory. + * + * @return the inventory, null if this is a player's inventory + */ + @Nullable Inventory getInventory(); +} \ No newline at end of file