mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 16:41:35 +01:00
Make InventoryEvent an interface
This commit is contained in:
parent
096e1de9b5
commit
80b2dd2747
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,8 @@
|
|||||||
package net.minestom.server.event.inventory;
|
package net.minestom.server.event.inventory;
|
||||||
|
|
||||||
import net.minestom.server.entity.Player;
|
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.Inventory;
|
||||||
import net.minestom.server.inventory.click.ClickType;
|
import net.minestom.server.inventory.click.ClickType;
|
||||||
import net.minestom.server.item.ItemStack;
|
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
|
* Called after {@link InventoryPreClickEvent}, this event cannot be cancelled and items related to the click
|
||||||
* are already moved.
|
* are already moved.
|
||||||
*/
|
*/
|
||||||
public class InventoryClickEvent extends InventoryEvent {
|
public class InventoryClickEvent implements InventoryEvent, PlayerEvent {
|
||||||
|
|
||||||
|
private final Inventory inventory;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final int slot;
|
private final int slot;
|
||||||
private final ClickType clickType;
|
private final ClickType clickType;
|
||||||
@ -23,7 +25,7 @@ public class InventoryClickEvent extends InventoryEvent {
|
|||||||
public InventoryClickEvent(@Nullable Inventory inventory, @NotNull Player player,
|
public InventoryClickEvent(@Nullable Inventory inventory, @NotNull Player player,
|
||||||
int slot, @NotNull ClickType clickType,
|
int slot, @NotNull ClickType clickType,
|
||||||
@NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
@NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
||||||
super(inventory);
|
this.inventory = inventory;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
this.clickType = clickType;
|
this.clickType = clickType;
|
||||||
@ -79,4 +81,9 @@ public class InventoryClickEvent extends InventoryEvent {
|
|||||||
public ItemStack getCursorItem() {
|
public ItemStack getCursorItem() {
|
||||||
return cursorItem;
|
return cursorItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package net.minestom.server.event.inventory;
|
package net.minestom.server.event.inventory;
|
||||||
|
|
||||||
import net.minestom.server.entity.Player;
|
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.Inventory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -9,13 +10,14 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
/**
|
/**
|
||||||
* Called when an {@link Inventory} is closed by a player.
|
* 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 final Player player;
|
||||||
private Inventory newInventory;
|
private Inventory newInventory;
|
||||||
|
|
||||||
public InventoryCloseEvent(@Nullable Inventory inventory, @NotNull Player player) {
|
public InventoryCloseEvent(@Nullable Inventory inventory, @NotNull Player player) {
|
||||||
super(inventory);
|
this.inventory = inventory;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,4 +49,9 @@ public class InventoryCloseEvent extends InventoryEvent {
|
|||||||
public void setNewInventory(@Nullable Inventory newInventory) {
|
public void setNewInventory(@Nullable Inventory newInventory) {
|
||||||
this.newInventory = newInventory;
|
this.newInventory = newInventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,8 @@ package net.minestom.server.event.inventory;
|
|||||||
|
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.CancellableEvent;
|
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.Inventory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -12,14 +13,15 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
* <p>
|
* <p>
|
||||||
* Executed by {@link Player#openInventory(Inventory)}.
|
* 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 final Player player;
|
||||||
|
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public InventoryOpenEvent(@Nullable Inventory inventory, @NotNull Player player) {
|
public InventoryOpenEvent(@Nullable Inventory inventory, @NotNull Player player) {
|
||||||
super(inventory);
|
this.inventory = inventory;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@ package net.minestom.server.event.inventory;
|
|||||||
|
|
||||||
import net.minestom.server.entity.Player;
|
import net.minestom.server.entity.Player;
|
||||||
import net.minestom.server.event.CancellableEvent;
|
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.Inventory;
|
||||||
import net.minestom.server.inventory.click.ClickType;
|
import net.minestom.server.inventory.click.ClickType;
|
||||||
import net.minestom.server.item.ItemStack;
|
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.
|
* 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 Player player;
|
||||||
private final int slot;
|
private final int slot;
|
||||||
private final ClickType clickType;
|
private final ClickType clickType;
|
||||||
@ -26,7 +28,7 @@ public class InventoryPreClickEvent extends InventoryEvent implements Cancellabl
|
|||||||
@NotNull Player player,
|
@NotNull Player player,
|
||||||
int slot, @NotNull ClickType clickType,
|
int slot, @NotNull ClickType clickType,
|
||||||
@NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
@NotNull ItemStack clicked, @NotNull ItemStack cursor) {
|
||||||
super(inventory);
|
this.inventory = inventory;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.slot = slot;
|
this.slot = slot;
|
||||||
this.clickType = clickType;
|
this.clickType = clickType;
|
||||||
@ -110,4 +112,9 @@ public class InventoryPreClickEvent extends InventoryEvent implements Cancellabl
|
|||||||
public void setCancelled(boolean cancel) {
|
public void setCancelled(boolean cancel) {
|
||||||
this.cancelled = cancel;
|
this.cancelled = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable Inventory getInventory() {
|
||||||
|
return inventory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user