diff --git a/InvSee++_Common/pom.xml b/InvSee++_Common/pom.xml index c26fd24a4..7ea166ff8 100644 --- a/InvSee++_Common/pom.xml +++ b/InvSee++_Common/pom.xml @@ -75,7 +75,7 @@ io.papermc.paper paper-api - 1.20.6-R0.1-SNAPSHOT + 1.21-R0.1-SNAPSHOT provided diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/CreationOptions.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/CreationOptions.java index 29f7d1b55..6abf92bc7 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/CreationOptions.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/CreationOptions.java @@ -6,6 +6,8 @@ import com.janboerman.invsee.spigot.api.template.EnderChestSlot; import com.janboerman.invsee.spigot.api.template.Mirror; import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; + import org.bukkit.Bukkit; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/EnderSpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/EnderSpectatorInventoryView.java index b6e361a66..96da8e385 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/EnderSpectatorInventoryView.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/EnderSpectatorInventoryView.java @@ -1,52 +1,24 @@ -package com.janboerman.invsee.spigot.api; - -import com.janboerman.invsee.spigot.api.template.EnderChestSlot; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.ItemStack; - -/** - * Represents an open window for an {@link EnderSpectatorInventory}. - */ -public abstract class EnderSpectatorInventoryView extends SpectatorInventoryView { - - protected EnderSpectatorInventoryView(CreationOptions creationOptions) { - super(creationOptions); - } - - /** {@inheritDoc} */ - @Override - public abstract EnderSpectatorInventory getTopInventory(); - - /** Sets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using - * {@code getMirror().getSlot(slot).defaultIndex()}. - * @see com.janboerman.invsee.spigot.api.template.Mirror */ - @Override - public void setItem(int slot, ItemStack item) { - if (slot == -999 || slot >= getTopInventory().getSize()) { - super.setItem(slot, item); - } else { - EnderChestSlot ecSlot = getMirror().getSlot(slot); - if (ecSlot != null) super.setItem(ecSlot.defaultIndex(), item); - } - } - - /** Gets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using - * {@code getMirror().getSlot(slot).defaultIndex()}. - * @see com.janboerman.invsee.spigot.api.template.Mirror */ - @Override - public ItemStack getItem(int slot) { - if (slot == -999 || slot >= getTopInventory().getSize()) { - return super.getItem(slot); - } else { - EnderChestSlot ecSlot = getMirror().getSlot(slot); - return ecSlot == null ? null : super.getItem(ecSlot.defaultIndex()); - } - } - - /** {@inheritDoc} */ - @Override - public InventoryType getType() { - return InventoryType.CHEST; - } - -} +package com.janboerman.invsee.spigot.api; + +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; + +import org.bukkit.event.inventory.InventoryType; + +/** + * Represents an open window for an {@link EnderSpectatorInventory}. + */ +public interface EnderSpectatorInventoryView extends SpectatorInventoryView { + + /** {@inheritDoc} */ + @Override + public EnderSpectatorInventory getTopInventory(); + + /** + * Get the inventory type. + * @return the inventory type + */ + public default InventoryType getType() { + return InventoryType.CHEST; + } + +} diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/InvseeAPI.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/InvseeAPI.java index 886069939..0f9a7219b 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/InvseeAPI.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/InvseeAPI.java @@ -15,6 +15,9 @@ import com.janboerman.invsee.spigot.internal.OpenSpectatorsCache; import com.janboerman.invsee.spigot.internal.inventory.ShallowCopy; import com.janboerman.invsee.spigot.internal.inventory.Personal; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; import com.janboerman.invsee.utils.*; import org.bukkit.*; import org.bukkit.entity.*; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/MainSpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/MainSpectatorInventoryView.java index a07fb9c0b..585877f43 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/MainSpectatorInventoryView.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/MainSpectatorInventoryView.java @@ -1,52 +1,21 @@ -package com.janboerman.invsee.spigot.api; - -import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; -import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.ItemStack; - -/** - * Represents an open window for a {@link MainSpectatorInventory}. - */ -public abstract class MainSpectatorInventoryView extends SpectatorInventoryView { - - protected MainSpectatorInventoryView(CreationOptions creationOptions) { - super(creationOptions); - } - - /** {@inheritDoc} */ - @Override - public abstract MainSpectatorInventory getTopInventory(); - - /** Sets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using - * {@code getMirror().getSlot(slot).defaultIndex()}. - * @see com.janboerman.invsee.spigot.api.template.Mirror */ - @Override - public void setItem(int slot, ItemStack item) { - if (0 <= slot && slot < getTopInventory().getSize()) { - PlayerInventorySlot piSlot = getMirror().getSlot(slot); - if (piSlot != null) super.setItem(piSlot.defaultIndex(), item); - } else { - super.setItem(slot, item); - } - } - - /** Gets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using - * {@code getMirror().getSlot(slot).defaultIndex()}. - * @see com.janboerman.invsee.spigot.api.template.Mirror */ - @Override - public ItemStack getItem(int slot) { - if (0 <= slot && slot < getTopInventory().getSize()) { - PlayerInventorySlot piSlot = getMirror().getSlot(slot); - return piSlot == null ? null : super.getItem(piSlot.defaultIndex()); - } else { - return super.getItem(slot); - } - } - - /** {@inheritDoc} */ - @Override - public InventoryType getType() { - return InventoryType.CHEST; - } - -} +package com.janboerman.invsee.spigot.api; + +import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; + +import org.bukkit.event.inventory.InventoryType; + +public interface MainSpectatorInventoryView extends SpectatorInventoryView { + + /** {@inheritDoc} */ + @Override + public MainSpectatorInventory getTopInventory(); + + /** + * Get the inventory type. + * @return the inventory type + */ + public default InventoryType getType() { + return InventoryType.CHEST; + } + +} diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/SpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/SpectatorInventoryView.java index ca4607246..565bb814f 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/SpectatorInventoryView.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/SpectatorInventoryView.java @@ -1,64 +1,53 @@ -package com.janboerman.invsee.spigot.api; - -import com.janboerman.invsee.spigot.api.logging.Difference; -import com.janboerman.invsee.spigot.api.target.Target; -import com.janboerman.invsee.spigot.api.template.Mirror; -import org.bukkit.inventory.InventoryView; - -import javax.annotation.Nullable; -import java.util.Objects; - -/** - * Represents an open window for a {@link SpectatorInventory}. - * @param the inventory's slot type. - */ -public abstract class SpectatorInventoryView extends InventoryView { - - private final CreationOptions creationOptions; - protected Target target; - - protected SpectatorInventoryView(CreationOptions creationOptions) { - this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); - } - - /** {@inheritDoc} */ - @Override - public abstract SpectatorInventory getTopInventory(); - - /** - * Get the difference tracked by this window. - * @return the difference - */ - public abstract @Nullable Difference getTrackedDifference(); - - /** - * Get the options this window was created with. - * @return a copy of the creation options - */ - public CreationOptions getCreationOptions() { - return creationOptions.clone(); - } - - //can't override getTitle because that does not work on 1.12 (the method is final :/) - //can't override title() either because of Adventure Text (because I can't have return type String) - //ooh the burden of supporting multiple versions! - - /** - * Get the mirror the {@link SpectatorInventory} is viewed through. - * @return the mirror - * @see Mirror explanation in the InvSee++ wiki - */ - public Mirror getMirror() { - return creationOptions.getMirror(); - } - - /** - * Get the target of the {@link SpectatorInventory}. - * @return the target - */ - public Target getTarget() { - SpectatorInventory top = getTopInventory(); - return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; - } - -} +package com.janboerman.invsee.spigot.api; + +import javax.annotation.Nullable; + +import com.janboerman.invsee.spigot.api.logging.Difference; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +/** + * Represents an open window for a {@link SpectatorInventory}. + * @param the inventory's slot type. + */ +// cannot extend InventoryView, because this class was not an interface before Bukkit 1.21. +public interface SpectatorInventoryView { + + /** + * Get the top inventory of this view. + * @return the top inventory + */ + public SpectatorInventory getTopInventory(); + + /** + * Get the difference tracked by this window. + * @return the difference + */ + public @Nullable Difference getTrackedDifference(); + + /** + * Get the options this window was created with. + * @return a copy of the creation options + */ + public CreationOptions getCreationOptions(); + + /** + * Get the title of this InventoryView. + * @return the title + */ + public String getTitle(); + + /** + * Get the mirror the {@link SpectatorInventory} is viewed through. + * @return the mirror + * @see Mirror explanation in the InvSee++ wiki + */ + public Mirror getMirror(); + + /** + * Get the target of the {@link SpectatorInventory}. + * @return the target + */ + public Target getTarget(); + +} diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/Title.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/Title.java index 1feaabfe3..a4927ec3c 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/Title.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/Title.java @@ -2,6 +2,7 @@ import com.janboerman.invsee.spigot.api.target.Target; import com.janboerman.invsee.spigot.internal.ConstantTitle; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; import java.util.function.Function; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/Difference.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/Difference.java index 546a9dec5..2d60eb701 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/Difference.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/Difference.java @@ -9,8 +9,10 @@ import java.util.Map; import java.util.Objects; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; + /** - * The Difference of a {@link com.janboerman.invsee.spigot.api.SpectatorInventoryView} is the set of items that were added and removed the {@link com.janboerman.invsee.spigot.api.SpectatorInventory}. + * The Difference of a {@link SpectatorInventoryView} is the set of items that were added and removed the {@link com.janboerman.invsee.spigot.api.SpectatorInventory}. */ public class Difference { diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogGranularity.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogGranularity.java index 5912bd5d2..105a2f08a 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogGranularity.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogGranularity.java @@ -1,5 +1,7 @@ package com.janboerman.invsee.spigot.api.logging; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; + /** * Granularity for logging. */ @@ -7,7 +9,7 @@ public enum LogGranularity { /** Log never. */ LOG_NEVER, - /** Log when the {@link com.janboerman.invsee.spigot.api.SpectatorInventoryView} closes. */ + /** Log when the {@link SpectatorInventoryView} closes. */ LOG_ON_CLOSE, /** Log changes after every change to the {@link com.janboerman.invsee.spigot.api.SpectatorInventory}. */ LOG_EVERY_CHANGE, diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogOptions.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogOptions.java index 8465761d8..d12355949 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogOptions.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/logging/LogOptions.java @@ -12,8 +12,10 @@ import java.util.Objects; import java.util.Set; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; + /** - * Options for logging interactions with {@link com.janboerman.invsee.spigot.api.SpectatorInventoryView}s. + * Options for logging interactions with {@link SpectatorInventoryView}s. * * @see com.janboerman.invsee.spigot.api.CreationOptions */ diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/placeholder/PlaceholderPalette.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/placeholder/PlaceholderPalette.java index 4b6ea6d07..fabeec2f9 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/placeholder/PlaceholderPalette.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/placeholder/PlaceholderPalette.java @@ -1,6 +1,5 @@ package com.janboerman.invsee.spigot.api.placeholder; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; import org.bukkit.inventory.ItemStack; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/response/OpenResponse.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/response/OpenResponse.java index 3c0674007..8e30886d4 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/response/OpenResponse.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/api/response/OpenResponse.java @@ -1,6 +1,6 @@ package com.janboerman.invsee.spigot.api.response; -import com.janboerman.invsee.spigot.api.SpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.SpectatorInventoryView; import java.util.NoSuchElementException; import java.util.Objects; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/InvseePlatform.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/InvseePlatform.java index 5e9268b3b..7d8b7c034 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/InvseePlatform.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/InvseePlatform.java @@ -2,9 +2,9 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Title; import com.janboerman.invsee.spigot.api.logging.LogGranularity; import com.janboerman.invsee.spigot.api.logging.LogOptions; @@ -21,7 +21,6 @@ import org.bukkit.plugin.Plugin; import java.util.Collections; -import java.util.Set; import java.util.UUID; import java.util.concurrent.CompletableFuture; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/placeholder/SimplePlaceholderPalette.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/placeholder/SimplePlaceholderPalette.java index 6e846e8f7..3d5d74f90 100644 --- a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/placeholder/SimplePlaceholderPalette.java +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/placeholder/SimplePlaceholderPalette.java @@ -1,6 +1,5 @@ package com.janboerman.invsee.spigot.internal.placeholder; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.placeholder.PlaceholderGroup; import com.janboerman.invsee.spigot.api.placeholder.PlaceholderPalette; import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/EnderSpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/EnderSpectatorInventoryView.java new file mode 100644 index 000000000..ecb630290 --- /dev/null +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/EnderSpectatorInventoryView.java @@ -0,0 +1,54 @@ +package com.janboerman.invsee.spigot.internal.view; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.ItemStack; + +/** + * Represents an open window for an {@link EnderSpectatorInventory}. + */ +public abstract class EnderSpectatorInventoryView extends SpectatorInventoryView { + + protected EnderSpectatorInventoryView(CreationOptions creationOptions) { + super(creationOptions); + } + + /** {@inheritDoc} */ + @Override + public abstract EnderSpectatorInventory getTopInventory(); + + /** Sets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using + * {@code getMirror().getSlot(slot).defaultIndex()}. + * @see com.janboerman.invsee.spigot.api.template.Mirror */ + @Override + public void setItem(int slot, ItemStack item) { + if (slot == -999 || slot >= getTopInventory().getSize()) { + super.setItem(slot, item); + } else { + EnderChestSlot ecSlot = getMirror().getSlot(slot); + if (ecSlot != null) super.setItem(ecSlot.defaultIndex(), item); + } + } + + /** Gets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using + * {@code getMirror().getSlot(slot).defaultIndex()}. + * @see com.janboerman.invsee.spigot.api.template.Mirror */ + @Override + public ItemStack getItem(int slot) { + if (slot == -999 || slot >= getTopInventory().getSize()) { + return super.getItem(slot); + } else { + EnderChestSlot ecSlot = getMirror().getSlot(slot); + return ecSlot == null ? null : super.getItem(ecSlot.defaultIndex()); + } + } + + /** {@inheritDoc} */ + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + +} diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/MainSpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/MainSpectatorInventoryView.java new file mode 100644 index 000000000..836baaa9d --- /dev/null +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/MainSpectatorInventoryView.java @@ -0,0 +1,54 @@ +package com.janboerman.invsee.spigot.internal.view; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.MainSpectatorInventory; +import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.ItemStack; + +/** + * Represents an open window for a {@link MainSpectatorInventory}. + */ +public abstract class MainSpectatorInventoryView extends SpectatorInventoryView { + + protected MainSpectatorInventoryView(CreationOptions creationOptions) { + super(creationOptions); + } + + /** {@inheritDoc} */ + @Override + public abstract MainSpectatorInventory getTopInventory(); + + /** Sets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using + * {@code getMirror().getSlot(slot).defaultIndex()}. + * @see com.janboerman.invsee.spigot.api.template.Mirror */ + @Override + public void setItem(int slot, ItemStack item) { + if (0 <= slot && slot < getTopInventory().getSize()) { + PlayerInventorySlot piSlot = getMirror().getSlot(slot); + if (piSlot != null) super.setItem(piSlot.defaultIndex(), item); + } else { + super.setItem(slot, item); + } + } + + /** Gets the item in the desired slot of the InventoryView. If the slot is in the top inventory, then the inventory slot will be computed using + * {@code getMirror().getSlot(slot).defaultIndex()}. + * @see com.janboerman.invsee.spigot.api.template.Mirror */ + @Override + public ItemStack getItem(int slot) { + if (0 <= slot && slot < getTopInventory().getSize()) { + PlayerInventorySlot piSlot = getMirror().getSlot(slot); + return piSlot == null ? null : super.getItem(piSlot.defaultIndex()); + } else { + return super.getItem(slot); + } + } + + /** {@inheritDoc} */ + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + +} diff --git a/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/SpectatorInventoryView.java b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/SpectatorInventoryView.java new file mode 100644 index 000000000..0db92dae1 --- /dev/null +++ b/InvSee++_Common/src/main/java/com/janboerman/invsee/spigot/internal/view/SpectatorInventoryView.java @@ -0,0 +1,281 @@ +package com.janboerman.invsee.spigot.internal.view; + +import com.google.common.base.Preconditions; +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.SpectatorInventory; +import com.janboerman.invsee.spigot.api.logging.Difference; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +import javax.annotation.Nullable; +import java.util.Objects; + +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * Represents an open window for a {@link SpectatorInventory}. + * @param the inventory's slot type. + */ +public abstract class SpectatorInventoryView implements com.janboerman.invsee.spigot.api.SpectatorInventoryView { + + private final CreationOptions creationOptions; + protected Target target; + + protected SpectatorInventoryView(CreationOptions creationOptions) { + this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); + } + + /** {@inheritDoc} */ + @Override + public abstract SpectatorInventory getTopInventory(); + + /** + * Get the difference tracked by this window. + * @return the difference + */ + public abstract @Nullable Difference getTrackedDifference(); + + /** + * Get the options this window was created with. + * @return a copy of the creation options + */ + public CreationOptions getCreationOptions() { + return creationOptions.clone(); + } + + //can't override getTitle because that does not work on 1.12 (the method is final :/) + //can't override title() either because of Adventure Text (because I can't have return type String) + //ooh the burden of supporting multiple versions! + + /** + * Get the mirror the {@link SpectatorInventory} is viewed through. + * @return the mirror + * @see Mirror explanation in the InvSee++ wiki + */ + public Mirror getMirror() { + return creationOptions.getMirror(); + } + + /** + * Get the target of the {@link SpectatorInventory}. + * @return the target + */ + public Target getTarget() { + SpectatorInventory top = getTopInventory(); + return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; + } + + @Override + public void setItem(final int slot, @org.jetbrains.annotations.Nullable final ItemStack item) { + Inventory inventory = getInventory(slot); + if (inventory != null) { + inventory.setItem(convertSlot(slot), item); + } else if (item != null) { + getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item); + } + } + + @org.jetbrains.annotations.Nullable + @Override + public ItemStack getItem(final int slot) { + Inventory inventory = getInventory(slot); + return (inventory == null) ? null : inventory.getItem(convertSlot(slot)); + } + + @Override + public void setCursor(@org.jetbrains.annotations.Nullable final ItemStack item) { + getPlayer().setItemOnCursor(item); + } + + @org.jetbrains.annotations.Nullable + @Override + public ItemStack getCursor() { + return getPlayer().getItemOnCursor(); + } + + @org.jetbrains.annotations.Nullable + @Override + public Inventory getInventory(final int rawSlot) { + // Slot may be -1 if not properly detected due to client bug + // e.g. dropping an item into part of the enchantment list section of an enchanting table + if (rawSlot == OUTSIDE || rawSlot == -1) { + return null; + } + Preconditions.checkArgument(rawSlot >= 0, "Negative, non outside slot %s", rawSlot); + Preconditions.checkArgument(rawSlot < countSlots(), "Slot %s greater than inventory slot count", rawSlot); + + if (rawSlot < getTopInventory().getSize()) { + return getTopInventory(); + } else { + return getBottomInventory(); + } + } + + @Override + public int convertSlot(final int rawSlot) { + int numInTop = getTopInventory().getSize(); + // Index from the top inventory as having slots from [0,size] + if (rawSlot < numInTop) { + return rawSlot; + } + + // Move down the slot index by the top size + int slot = rawSlot - numInTop; + + // Player crafting slots are indexed differently. The matrix is caught by the first return. + // Creative mode is the same, except that you can't see the crafting slots (but the IDs are still used) + if (getType() == InventoryType.CRAFTING || getType() == InventoryType.CREATIVE) { + /* + * Raw Slots: + * + * 5 1 2 0 + * 6 3 4 + * 7 + * 8 45 + * 9 10 11 12 13 14 15 16 17 + * 18 19 20 21 22 23 24 25 26 + * 27 28 29 30 31 32 33 34 35 + * 36 37 38 39 40 41 42 43 44 + */ + + /* + * Converted Slots: + * + * 39 1 2 0 + * 38 3 4 + * 37 + * 36 40 + * 9 10 11 12 13 14 15 16 17 + * 18 19 20 21 22 23 24 25 26 + * 27 28 29 30 31 32 33 34 35 + * 0 1 2 3 4 5 6 7 8 + */ + + if (slot < 4) { + // Send [5,8] to [39,36] + return 39 - slot; + } else if (slot > 39) { + // Slot lives in the extra slot section + return slot; + } else { + // Reset index so 9 -> 0 + slot -= 4; + } + } + + // 27 = 36 - 9 + if (slot >= 27) { + // Put into hotbar section + slot -= 27; + } else { + // Take out of hotbar section + // 9 = 36 - 27 + slot += 9; + } + + return slot; + } + + @NotNull + @Override + public InventoryType.SlotType getSlotType(final int slot) { + InventoryType.SlotType type = InventoryType.SlotType.CONTAINER; + if (slot >= 0 && slot < this.getTopInventory().getSize()) { + switch (this.getType()) { + case BLAST_FURNACE: + case FURNACE: + case SMOKER: + if (slot == 2) { + type = InventoryType.SlotType.RESULT; + } else if (slot == 1) { + type = InventoryType.SlotType.FUEL; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + case BREWING: + if (slot == 3) { + type = InventoryType.SlotType.FUEL; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + case ENCHANTING: + type = InventoryType.SlotType.CRAFTING; + break; + case WORKBENCH: + case CRAFTING: + if (slot == 0) { + type = InventoryType.SlotType.RESULT; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + case BEACON: + type = InventoryType.SlotType.CRAFTING; + break; + case ANVIL: + case SMITHING: + case CARTOGRAPHY: + case GRINDSTONE: + case MERCHANT: + if (slot == 2) { + type = InventoryType.SlotType.RESULT; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + case STONECUTTER: + if (slot == 1) { + type = InventoryType.SlotType.RESULT; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + case LOOM: + case SMITHING_NEW: + if (slot == 3) { + type = InventoryType.SlotType.RESULT; + } else { + type = InventoryType.SlotType.CRAFTING; + } + break; + default: + // Nothing to do, it's a CONTAINER slot + } + } else { + if (slot < 0) { + type = InventoryType.SlotType.OUTSIDE; + } else if (this.getType() == InventoryType.CRAFTING) { // Also includes creative inventory + if (slot < 9) { + type = InventoryType.SlotType.ARMOR; + } else if (slot > 35) { + type = InventoryType.SlotType.QUICKBAR; + } + } else if (slot >= (this.countSlots() - (9 + 4 + 1))) { // Quickbar, Armor, Offhand + type = InventoryType.SlotType.QUICKBAR; + } + } + return type; + } + + @Override + public void close() { + getPlayer().closeInventory(); + } + + @Override + public int countSlots() { + return getTopInventory().getSize() + getBottomInventory().getSize(); + } + + @Override + public boolean setProperty(@NotNull final InventoryView.Property prop, final int value) { + return getPlayer().setWindowProperty(prop, value); + } + +} diff --git a/InvSee++_PerWorldInventory/src/main/java/com/janboerman/invsee/spigot/perworldinventory/PerWorldInventorySeeApi.java b/InvSee++_PerWorldInventory/src/main/java/com/janboerman/invsee/spigot/perworldinventory/PerWorldInventorySeeApi.java index 0d564a050..34af8be2e 100644 --- a/InvSee++_PerWorldInventory/src/main/java/com/janboerman/invsee/spigot/perworldinventory/PerWorldInventorySeeApi.java +++ b/InvSee++_PerWorldInventory/src/main/java/com/janboerman/invsee/spigot/perworldinventory/PerWorldInventorySeeApi.java @@ -4,10 +4,10 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.InvseeAPI; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.SpectatorInventory; import com.janboerman.invsee.spigot.api.response.NotCreatedReason; import com.janboerman.invsee.spigot.api.response.OpenResponse; diff --git a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/BukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/BukkitInventoryView.java new file mode 100644 index 000000000..eea5dc452 --- /dev/null +++ b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/BukkitInventoryView.java @@ -0,0 +1,38 @@ +package com.janboerman.invsee.spigot.impl_1_20_1_R1; + +import java.util.Objects; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.SpectatorInventory; +import com.janboerman.invsee.spigot.api.SpectatorInventoryView; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +import org.bukkit.inventory.InventoryView; + +abstract class BukkitInventoryView extends InventoryView implements SpectatorInventoryView { + + private final CreationOptions creationOptions; + protected Target target; + + BukkitInventoryView(CreationOptions creationOptions) { + this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); + } + + @Override + public CreationOptions getCreationOptions() { + return creationOptions.clone(); + } + + @Override + public Mirror getMirror() { + return creationOptions.getMirror(); + } + + @Override + public Target getTarget() { + SpectatorInventory top = getTopInventory(); + return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; + } + +} diff --git a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/EnderBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/EnderBukkitInventoryView.java index 53456ac02..3ce825303 100644 --- a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/EnderBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/EnderBukkitInventoryView.java @@ -1,18 +1,20 @@ package com.janboerman.invsee.spigot.impl_1_20_1_R1; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class EnderBukkitInventoryView extends EnderSpectatorInventoryView { +class EnderBukkitInventoryView extends BukkitInventoryView { final EnderNmsContainer nms; @@ -36,6 +38,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/InvseeImpl.java b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/InvseeImpl.java index 310427ffe..f00ddf24e 100644 --- a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/InvseeImpl.java +++ b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/InvseeImpl.java @@ -2,9 +2,9 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Scheduler; import com.janboerman.invsee.spigot.api.SpectatorInventory; import com.janboerman.invsee.spigot.api.event.SpectatorInventorySaveEvent; diff --git a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/MainBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/MainBukkitInventoryView.java index 942a50986..23bafc4f2 100644 --- a/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/MainBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_1_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_20_1_R1/MainBukkitInventoryView.java @@ -1,18 +1,19 @@ package com.janboerman.invsee.spigot.impl_1_20_1_R1; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class MainBukkitInventoryView extends MainSpectatorInventoryView { +class MainBukkitInventoryView extends BukkitInventoryView { final MainNmsContainer nms; @@ -36,6 +37,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/BukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/BukkitInventoryView.java new file mode 100644 index 000000000..f8962674d --- /dev/null +++ b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/BukkitInventoryView.java @@ -0,0 +1,38 @@ +package com.janboerman.invsee.spigot.impl_1_20_4_R3; + +import java.util.Objects; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.SpectatorInventory; +import com.janboerman.invsee.spigot.api.SpectatorInventoryView; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +import org.bukkit.inventory.InventoryView; + +abstract class BukkitInventoryView extends InventoryView implements SpectatorInventoryView { + + private final CreationOptions creationOptions; + protected Target target; + + BukkitInventoryView(CreationOptions creationOptions) { + this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); + } + + @Override + public CreationOptions getCreationOptions() { + return creationOptions.clone(); + } + + @Override + public Mirror getMirror() { + return creationOptions.getMirror(); + } + + @Override + public Target getTarget() { + SpectatorInventory top = getTopInventory(); + return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; + } + +} diff --git a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/EnderBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/EnderBukkitInventoryView.java index 53113c18d..8320c8696 100644 --- a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/EnderBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/EnderBukkitInventoryView.java @@ -1,18 +1,20 @@ package com.janboerman.invsee.spigot.impl_1_20_4_R3; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class EnderBukkitInventoryView extends EnderSpectatorInventoryView { +class EnderBukkitInventoryView extends BukkitInventoryView { final EnderNmsContainer nms; @@ -36,6 +38,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/InvseeImpl.java b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/InvseeImpl.java index 848159a1f..7de7a7f92 100644 --- a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/InvseeImpl.java +++ b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/InvseeImpl.java @@ -2,9 +2,9 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Scheduler; import com.janboerman.invsee.spigot.api.SpectatorInventory; import com.janboerman.invsee.spigot.api.event.SpectatorInventorySaveEvent; diff --git a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/MainBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/MainBukkitInventoryView.java index fb4e51a4e..1f190d575 100644 --- a/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/MainBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_4_R3/src/main/java/com/janboerman/invsee/spigot/impl_1_20_4_R3/MainBukkitInventoryView.java @@ -1,18 +1,19 @@ package com.janboerman.invsee.spigot.impl_1_20_4_R3; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class MainBukkitInventoryView extends MainSpectatorInventoryView { +class MainBukkitInventoryView extends BukkitInventoryView { final MainNmsContainer nms; @@ -36,6 +37,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/BukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/BukkitInventoryView.java new file mode 100644 index 000000000..388fb9717 --- /dev/null +++ b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/BukkitInventoryView.java @@ -0,0 +1,38 @@ +package com.janboerman.invsee.spigot.impl_1_20_6_R4; + +import java.util.Objects; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.SpectatorInventory; +import com.janboerman.invsee.spigot.api.SpectatorInventoryView; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +import org.bukkit.inventory.InventoryView; + +abstract class BukkitInventoryView extends InventoryView implements SpectatorInventoryView { + + private final CreationOptions creationOptions; + protected Target target; + + BukkitInventoryView(CreationOptions creationOptions) { + this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); + } + + @Override + public CreationOptions getCreationOptions() { + return creationOptions.clone(); + } + + @Override + public Mirror getMirror() { + return creationOptions.getMirror(); + } + + @Override + public Target getTarget() { + SpectatorInventory top = getTopInventory(); + return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; + } + +} diff --git a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/EnderBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/EnderBukkitInventoryView.java index 9731e3e2b..b866aae61 100644 --- a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/EnderBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/EnderBukkitInventoryView.java @@ -1,18 +1,19 @@ package com.janboerman.invsee.spigot.impl_1_20_6_R4; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class EnderBukkitInventoryView extends EnderSpectatorInventoryView { +class EnderBukkitInventoryView extends BukkitInventoryView { final EnderNmsContainer nms; @@ -36,6 +37,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/InvseeImpl.java b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/InvseeImpl.java index 20f948668..900d80d60 100644 --- a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/InvseeImpl.java +++ b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/InvseeImpl.java @@ -2,9 +2,9 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Scheduler; import com.janboerman.invsee.spigot.api.SpectatorInventory; import com.janboerman.invsee.spigot.api.event.SpectatorInventorySaveEvent; @@ -30,7 +30,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.inventory.PlayerEnderChestContainer; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.storage.PlayerDataStorage; @@ -39,7 +38,6 @@ import org.bukkit.craftbukkit.v1_20_R4.CraftWorld; import org.bukkit.craftbukkit.v1_20_R4.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_20_R4.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R4.util.CraftChatMessage; import org.bukkit.entity.HumanEntity; diff --git a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/MainBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/MainBukkitInventoryView.java index a634436a9..d9ac896f7 100644 --- a/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/MainBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_20_6_R4/src/main/java/com/janboerman/invsee/spigot/impl_1_20_6_R4/MainBukkitInventoryView.java @@ -1,18 +1,19 @@ package com.janboerman.invsee.spigot.impl_1_20_6_R4; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_20_R4.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; +import org.bukkit.event.inventory.InventoryType; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class MainBukkitInventoryView extends MainSpectatorInventoryView { +class MainBukkitInventoryView extends BukkitInventoryView { final MainNmsContainer nms; @@ -36,6 +37,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/BukkitInventoryView.java b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/BukkitInventoryView.java new file mode 100644 index 000000000..3ba381ce3 --- /dev/null +++ b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/BukkitInventoryView.java @@ -0,0 +1,109 @@ +package com.janboerman.invsee.spigot.impl_1_21_R1; + +import java.util.Objects; + +import com.google.common.base.Preconditions; + +import com.janboerman.invsee.spigot.api.CreationOptions; +import com.janboerman.invsee.spigot.api.SpectatorInventory; +import com.janboerman.invsee.spigot.api.SpectatorInventoryView; +import com.janboerman.invsee.spigot.api.target.Target; +import com.janboerman.invsee.spigot.api.template.Mirror; + +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; + +abstract class BukkitInventoryView implements SpectatorInventoryView, InventoryView { + + private final CreationOptions creationOptions; + protected Target target; + + BukkitInventoryView(CreationOptions creationOptions) { + this.creationOptions = Objects.requireNonNull(creationOptions, "creation options cannot be null"); + } + + @Override + public void setCursor(ItemStack itemStack) { + getPlayer().setItemOnCursor(itemStack); + } + + @Override + public ItemStack getCursor() { + return getPlayer().getItemOnCursor(); + } + + @Override + public Inventory getInventory(int rawSlot) { + if (rawSlot == InventoryView.OUTSIDE || rawSlot == -1) { + return null; + } else { + Preconditions.checkArgument(rawSlot >= 0, "Negative, non outside slot %s", rawSlot); + Preconditions.checkArgument(rawSlot < this.countSlots(), "Slot %s greater than inventory slot count", rawSlot); + return rawSlot < this.getTopInventory().getSize() ? this.getTopInventory() : this.getBottomInventory(); + } + } + + @Override + public int convertSlot(int rawSlot) { + int topSize = getTopInventory().getSize(); + if (rawSlot < topSize) { + return rawSlot; + } else { + int slot = rawSlot - topSize; + if (slot >= 27) { + slot -= 27; + } else { + slot += 9; + } + return slot; + } + } + + @Override + public InventoryType.SlotType getSlotType(int slot) { + if (slot < 0) { + return InventoryType.SlotType.OUTSIDE; + } else { + int slotCount = countSlots(); + if (slotCount - 9 <= slot && slot < slotCount) { + return InventoryType.SlotType.QUICKBAR; + } else { + return InventoryType.SlotType.CONTAINER; + } + } + } + + @Override + public void close() { + getPlayer().closeInventory(); + } + + @Override + public int countSlots() { + return getTopInventory().getSize() + getBottomInventory().getStorageContents().length; + } + + @Override + public boolean setProperty(Property property, int value) { + return getPlayer().setWindowProperty(property, value); + } + + @Override + public CreationOptions getCreationOptions() { + return creationOptions.clone(); + } + + @Override + public Mirror getMirror() { + return creationOptions.getMirror(); + } + + @Override + public Target getTarget() { + SpectatorInventory top = getTopInventory(); + return target == null ? target = Target.byGameProfile(top.getSpectatedPlayerId(), top.getSpectatedPlayerName()) : target; + } + +} diff --git a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/EnderBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/EnderBukkitInventoryView.java index 342c1faa3..916a8d327 100644 --- a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/EnderBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/EnderBukkitInventoryView.java @@ -1,22 +1,21 @@ package com.janboerman.invsee.spigot.impl_1_21_R1; -import com.google.common.base.Preconditions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; +import com.janboerman.invsee.spigot.api.template.EnderChestSlot; + import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; import org.bukkit.event.inventory.InventoryType; -import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; import javax.annotation.Nullable; -class EnderBukkitInventoryView extends EnderSpectatorInventoryView { +class EnderBukkitInventoryView extends BukkitInventoryView implements EnderSpectatorInventoryView { final EnderNmsContainer nms; @@ -40,6 +39,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); @@ -81,75 +85,10 @@ public ItemStack getItem(int slot) { } } - @Override - public void setCursor(ItemStack itemStack) { - getPlayer().setItemOnCursor(itemStack); - } - - @Override - public ItemStack getCursor() { - return getPlayer().getItemOnCursor(); - } - - @Override - public Inventory getInventory(int rawSlot) { - if (rawSlot == InventoryView.OUTSIDE || rawSlot == -1) { - return null; - } else { - Preconditions.checkArgument(rawSlot >= 0, "Negative, non outside slot %s", rawSlot); - Preconditions.checkArgument(rawSlot < this.countSlots(), "Slot %s greater than inventory slot count", rawSlot); - return rawSlot < this.getTopInventory().getSize() ? this.getTopInventory() : this.getBottomInventory(); - } - } - - @Override - public int convertSlot(int rawSlot) { - int topSize = getTopInventory().getSize(); - if (rawSlot < topSize) { - return rawSlot; - } else { - int slot = rawSlot - topSize; - if (slot >= 27) { - slot -= 27; - } else { - slot += 9; - } - return slot; - } - } - - @Override - public InventoryType.SlotType getSlotType(int slot) { - if (slot < 0) { - return InventoryType.SlotType.OUTSIDE; - } else { - int slotCount = countSlots(); - if (slotCount - 9 <= slot && slot < slotCount) { - return InventoryType.SlotType.QUICKBAR; - } else { - return InventoryType.SlotType.CONTAINER; - } - } - } - - @Override - public void close() { - getPlayer().closeInventory(); - } - - @Override - public int countSlots() { - return getTopInventory().getSize() + getBottomInventory().getStorageContents().length; - } - - @Override - public boolean setProperty(Property property, int value) { - return getPlayer().setWindowProperty(property, value); - } - @Override public @Nullable Difference getTrackedDifference() { DifferenceTracker tracker = nms.tracker; return tracker == null ? null : tracker.getDifference(); } + } diff --git a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/InvseeImpl.java b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/InvseeImpl.java index 54e4e6954..d768fbd0b 100644 --- a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/InvseeImpl.java +++ b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/InvseeImpl.java @@ -2,9 +2,9 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Scheduler; import com.janboerman.invsee.spigot.api.SpectatorInventory; import com.janboerman.invsee.spigot.api.event.SpectatorInventorySaveEvent; @@ -38,7 +38,6 @@ import org.bukkit.craftbukkit.v1_21_R1.CraftWorld; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftHumanEntity; import org.bukkit.craftbukkit.v1_21_R1.entity.CraftPlayer; -import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventory; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_21_R1.util.CraftChatMessage; import org.bukkit.entity.HumanEntity; diff --git a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/MainBukkitInventoryView.java b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/MainBukkitInventoryView.java index 23918fa86..75a759dcf 100644 --- a/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/MainBukkitInventoryView.java +++ b/InvSee++_Platforms/Impl_1_21_R1/src/main/java/com/janboerman/invsee/spigot/impl_1_21_R1/MainBukkitInventoryView.java @@ -5,6 +5,8 @@ import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.logging.Difference; import com.janboerman.invsee.spigot.api.logging.DifferenceTracker; +import com.janboerman.invsee.spigot.api.template.PlayerInventorySlot; + import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftInventoryView; import org.bukkit.craftbukkit.v1_21_R1.inventory.CraftItemStack; import org.bukkit.entity.HumanEntity; @@ -16,7 +18,7 @@ import javax.annotation.Nullable; -class MainBukkitInventoryView extends MainSpectatorInventoryView implements InventoryView { +class MainBukkitInventoryView extends BukkitInventoryView implements MainSpectatorInventoryView { final MainNmsContainer nms; @@ -40,6 +42,11 @@ public HumanEntity getPlayer() { return nms.player.getBukkitEntity(); } + @Override + public InventoryType getType() { + return InventoryType.CHEST; + } + @Override public String getTitle() { return nms.title(); diff --git a/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/EnderseeCommandExecutor.java b/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/EnderseeCommandExecutor.java index 58c0164b8..4ef5985af 100644 --- a/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/EnderseeCommandExecutor.java +++ b/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/EnderseeCommandExecutor.java @@ -2,7 +2,7 @@ import com.janboerman.invsee.spigot.api.CreationOptions; import com.janboerman.invsee.spigot.api.EnderSpectatorInventory; -import com.janboerman.invsee.spigot.api.EnderSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.EnderSpectatorInventoryView; import com.janboerman.invsee.spigot.api.Exempt; import com.janboerman.invsee.spigot.api.InvseeAPI; import com.janboerman.invsee.spigot.api.response.ImplementationFault; diff --git a/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/InvseeCommandExecutor.java b/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/InvseeCommandExecutor.java index 6a17cb92f..220111060 100644 --- a/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/InvseeCommandExecutor.java +++ b/InvSee++_Plugin/src/main/java/com/janboerman/invsee/spigot/InvseeCommandExecutor.java @@ -4,7 +4,7 @@ import com.janboerman.invsee.spigot.api.Exempt; import com.janboerman.invsee.spigot.api.InvseeAPI; import com.janboerman.invsee.spigot.api.MainSpectatorInventory; -import com.janboerman.invsee.spigot.api.MainSpectatorInventoryView; +import com.janboerman.invsee.spigot.internal.view.MainSpectatorInventoryView; import com.janboerman.invsee.spigot.api.response.*; import com.janboerman.invsee.spigot.api.target.Target; /*