diff --git a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/InventoryUpdatedEvent.java b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/InventoryUpdatedEvent.java index d0bd8eb..0e6fb45 100644 --- a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/InventoryUpdatedEvent.java +++ b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/InventoryUpdatedEvent.java @@ -6,12 +6,10 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -// TODO: better solution? - /** * An event that is called after the {@link VirtualInventory} has been updated. */ -public class InventoryUpdatedEvent extends ItemUpdateEvent { +public class InventoryUpdatedEvent extends UpdateEvent { /** * Creates a new {@link ItemUpdateEvent}. diff --git a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/ItemUpdateEvent.java b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/ItemUpdateEvent.java index 46c5cd7..b1e8bd9 100644 --- a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/ItemUpdateEvent.java +++ b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/ItemUpdateEvent.java @@ -11,6 +11,8 @@ import org.jetbrains.annotations.Nullable; */ public class ItemUpdateEvent extends UpdateEvent { + private boolean cancelled; + /** * Creates a new {@link ItemUpdateEvent}. * @@ -29,7 +31,16 @@ public class ItemUpdateEvent extends UpdateEvent { super(virtualInventory, slot, updateReason, previousItemStack, newItemStack); } - private boolean cancelled; + /** + * Change the {@link ItemStack} that will appear in the {@link VirtualInventory} + * to a different one. + * + * @param newItemStack The {@link ItemStack} to appear in the {@link VirtualInventory} + * if the {@link ItemUpdateEvent} is not cancelled. + */ + public void setNewItemStack(@Nullable ItemStack newItemStack) { + this.newItemStack = newItemStack; + } /** * Gets the cancellation state of this event. diff --git a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/UpdateEvent.java b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/UpdateEvent.java index ef1d062..12d6758 100644 --- a/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/UpdateEvent.java +++ b/InvUI/src/main/java/de/studiocode/invui/virtualinventory/event/UpdateEvent.java @@ -9,10 +9,10 @@ import org.jetbrains.annotations.Nullable; abstract class UpdateEvent { private final VirtualInventory virtualInventory; - private final ItemStack previousItemStack; private final UpdateReason updateReason; private final int slot; - private ItemStack newItemStack; + private final ItemStack previousItemStack; + protected ItemStack newItemStack; /** * Creates a new {@link ItemUpdateEvent}. @@ -32,8 +32,8 @@ abstract class UpdateEvent { this.virtualInventory = virtualInventory; this.slot = slot; this.updateReason = updateReason; - this.previousItemStack = previousItemStack; - this.newItemStack = newItemStack; + this.previousItemStack = previousItemStack != null ? previousItemStack.clone() : null; + this.newItemStack = newItemStack != null ? newItemStack.clone() : null; } /** @@ -55,7 +55,7 @@ abstract class UpdateEvent { } /** - * Gets the {@link ItemStack} that was there previously. + * Gets a clone of the {@link ItemStack} that was there previously. * * @return The {@link ItemStack} */ @@ -64,7 +64,7 @@ abstract class UpdateEvent { } /** - * The new {@link ItemStack} that will be there if the event isn't cancelled. + * Gets clone of the new {@link ItemStack} that will be there if the event isn't cancelled. * * @return The new {@link ItemStack} */ @@ -72,17 +72,6 @@ abstract class UpdateEvent { return newItemStack; } - /** - * Change the {@link ItemStack} that will appear in the {@link VirtualInventory} - * to a different one. - * - * @param newItemStack The {@link ItemStack} to appear in the {@link VirtualInventory} - * if the {@link ItemUpdateEvent} is not cancelled. - */ - public void setNewItemStack(@Nullable ItemStack newItemStack) { - this.newItemStack = newItemStack; - } - /** * Gets the slot that is affected. *