#1487: Add specific getTopInventory methods for InventoryView derivatives

By: Miles Holder <mwholder@proton.me>
This commit is contained in:
CraftBukkit/Spigot 2024-10-06 18:45:12 +11:00
parent d7d206b995
commit adf5fecbbb
12 changed files with 36 additions and 36 deletions

View file

@ -64,7 +64,7 @@
+ return bukkitEntity; + return bukkitEntity;
+ } + }
+ +
+ org.bukkit.craftbukkit.inventory.CraftInventory inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBeacon(this.beacon); + org.bukkit.craftbukkit.inventory.CraftInventoryBeacon inventory = new org.bukkit.craftbukkit.inventory.CraftInventoryBeacon(this.beacon);
+ bukkitEntity = new CraftBeaconView(this.player.player.getBukkitEntity(), inventory, this); + bukkitEntity = new CraftBeaconView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity; + return bukkitEntity;
+ } + }

View file

@ -15,24 +15,24 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public class CraftInventoryView<T extends Container> extends CraftAbstractInventoryView { public class CraftInventoryView<T extends Container, I extends Inventory> extends CraftAbstractInventoryView {
protected final T container; protected final T container;
private final CraftHumanEntity player; private final CraftHumanEntity player;
private final CraftInventory viewing; private final I viewing;
private final String originalTitle; private final String originalTitle;
private String title; private String title;
public CraftInventoryView(HumanEntity player, Inventory viewing, T container) { public CraftInventoryView(HumanEntity player, I viewing, T container) {
// TODO: Should we make sure it really IS a CraftHumanEntity first? And a CraftInventory? // TODO: Should we make sure it really IS a CraftHumanEntity first? And a CraftInventory?
this.player = (CraftHumanEntity) player; this.player = (CraftHumanEntity) player;
this.viewing = (CraftInventory) viewing; this.viewing = viewing;
this.container = container; this.container = container;
this.originalTitle = CraftChatMessage.fromComponent(container.getTitle()); this.originalTitle = CraftChatMessage.fromComponent(container.getTitle());
this.title = originalTitle; this.title = originalTitle;
} }
@Override @Override
public Inventory getTopInventory() { public I getTopInventory() {
return viewing; return viewing;
} }

View file

@ -4,13 +4,13 @@ import net.minecraft.world.inventory.ContainerAnvil;
import org.bukkit.craftbukkit.inventory.CraftInventoryAnvil; import org.bukkit.craftbukkit.inventory.CraftInventoryAnvil;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.view.AnvilView; import org.bukkit.inventory.view.AnvilView;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class CraftAnvilView extends CraftInventoryView<ContainerAnvil> implements AnvilView { public class CraftAnvilView extends CraftInventoryView<ContainerAnvil, AnvilInventory> implements AnvilView {
public CraftAnvilView(final HumanEntity player, final Inventory viewing, final ContainerAnvil container) { public CraftAnvilView(final HumanEntity player, final AnvilInventory viewing, final ContainerAnvil container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -5,14 +5,14 @@ import net.minecraft.world.level.block.entity.TileEntityBeacon;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType; import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.BeaconInventory;
import org.bukkit.inventory.view.BeaconView; import org.bukkit.inventory.view.BeaconView;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
public class CraftBeaconView extends CraftInventoryView<ContainerBeacon> implements BeaconView { public class CraftBeaconView extends CraftInventoryView<ContainerBeacon, BeaconInventory> implements BeaconView {
public CraftBeaconView(final HumanEntity player, final Inventory viewing, final ContainerBeacon container) { public CraftBeaconView(final HumanEntity player, final BeaconInventory viewing, final ContainerBeacon container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -5,12 +5,12 @@ import net.minecraft.world.inventory.ContainerBrewingStand;
import net.minecraft.world.level.block.entity.TileEntityBrewingStand; import net.minecraft.world.level.block.entity.TileEntityBrewingStand;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.BrewerInventory;
import org.bukkit.inventory.view.BrewingStandView; import org.bukkit.inventory.view.BrewingStandView;
public class CraftBrewingStandView extends CraftInventoryView<ContainerBrewingStand> implements BrewingStandView { public class CraftBrewingStandView extends CraftInventoryView<ContainerBrewingStand, BrewerInventory> implements BrewingStandView {
public CraftBrewingStandView(final HumanEntity player, final Inventory viewing, final ContainerBrewingStand container) { public CraftBrewingStandView(final HumanEntity player, final BrewerInventory viewing, final ContainerBrewingStand container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -4,12 +4,12 @@ import com.google.common.base.Preconditions;
import net.minecraft.world.inventory.CrafterMenu; import net.minecraft.world.inventory.CrafterMenu;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.CrafterInventory;
import org.bukkit.inventory.view.CrafterView; import org.bukkit.inventory.view.CrafterView;
public class CraftCrafterView extends CraftInventoryView<CrafterMenu> implements CrafterView { public class CraftCrafterView extends CraftInventoryView<CrafterMenu, CrafterInventory> implements CrafterView {
public CraftCrafterView(final HumanEntity player, final Inventory viewing, final CrafterMenu container) { public CraftCrafterView(final HumanEntity player, final CrafterInventory viewing, final CrafterMenu container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -11,13 +11,13 @@ import org.bukkit.craftbukkit.enchantments.CraftEnchantment;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.enchantments.EnchantmentOffer; import org.bukkit.enchantments.EnchantmentOffer;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.view.EnchantmentView; import org.bukkit.inventory.view.EnchantmentView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftEnchantmentView extends CraftInventoryView<ContainerEnchantTable> implements EnchantmentView { public class CraftEnchantmentView extends CraftInventoryView<ContainerEnchantTable, EnchantingInventory> implements EnchantmentView {
public CraftEnchantmentView(final HumanEntity player, final Inventory viewing, final ContainerEnchantTable container) { public CraftEnchantmentView(final HumanEntity player, final EnchantingInventory viewing, final ContainerEnchantTable container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -4,12 +4,12 @@ import net.minecraft.world.inventory.ContainerFurnace;
import net.minecraft.world.level.block.entity.TileEntityFurnace; import net.minecraft.world.level.block.entity.TileEntityFurnace;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.FurnaceInventory;
import org.bukkit.inventory.view.FurnaceView; import org.bukkit.inventory.view.FurnaceView;
public class CraftFurnaceView extends CraftInventoryView<ContainerFurnace> implements FurnaceView { public class CraftFurnaceView extends CraftInventoryView<ContainerFurnace, FurnaceInventory> implements FurnaceView {
public CraftFurnaceView(final HumanEntity player, final Inventory viewing, final ContainerFurnace container) { public CraftFurnaceView(final HumanEntity player, final FurnaceInventory viewing, final ContainerFurnace container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -5,12 +5,12 @@ import net.minecraft.world.inventory.ContainerLectern;
import net.minecraft.world.level.block.entity.TileEntityLectern; import net.minecraft.world.level.block.entity.TileEntityLectern;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.LecternInventory;
import org.bukkit.inventory.view.LecternView; import org.bukkit.inventory.view.LecternView;
public class CraftLecternView extends CraftInventoryView<ContainerLectern> implements LecternView { public class CraftLecternView extends CraftInventoryView<ContainerLectern, LecternInventory> implements LecternView {
public CraftLecternView(final HumanEntity player, final Inventory viewing, final ContainerLectern container) { public CraftLecternView(final HumanEntity player, final LecternInventory viewing, final ContainerLectern container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -9,12 +9,12 @@ import org.bukkit.block.banner.PatternType;
import org.bukkit.craftbukkit.block.banner.CraftPatternType; import org.bukkit.craftbukkit.block.banner.CraftPatternType;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.LoomInventory;
import org.bukkit.inventory.view.LoomView; import org.bukkit.inventory.view.LoomView;
public class CraftLoomView extends CraftInventoryView<ContainerLoom> implements LoomView { public class CraftLoomView extends CraftInventoryView<ContainerLoom, LoomInventory> implements LoomView {
public CraftLoomView(final HumanEntity player, final Inventory viewing, final ContainerLoom container) { public CraftLoomView(final HumanEntity player, final LoomInventory viewing, final ContainerLoom container) {
super(player, viewing, container); super(player, viewing, container);
} }

View file

@ -4,16 +4,16 @@ import net.minecraft.world.inventory.ContainerMerchant;
import net.minecraft.world.item.trading.IMerchant; import net.minecraft.world.item.trading.IMerchant;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.Merchant; import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantInventory;
import org.bukkit.inventory.view.MerchantView; import org.bukkit.inventory.view.MerchantView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftMerchantView extends CraftInventoryView<ContainerMerchant> implements MerchantView { public class CraftMerchantView extends CraftInventoryView<ContainerMerchant, MerchantInventory> implements MerchantView {
private final IMerchant trader; private final IMerchant trader;
public CraftMerchantView(final HumanEntity player, final Inventory viewing, final ContainerMerchant container, final IMerchant trader) { public CraftMerchantView(final HumanEntity player, final MerchantInventory viewing, final ContainerMerchant container, final IMerchant trader) {
super(player, viewing, container); super(player, viewing, container);
this.trader = trader; this.trader = trader;
} }

View file

@ -7,14 +7,14 @@ import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.RecipeStonecutting; import net.minecraft.world.item.crafting.RecipeStonecutting;
import org.bukkit.craftbukkit.inventory.CraftInventoryView; import org.bukkit.craftbukkit.inventory.CraftInventoryView;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.StonecutterInventory;
import org.bukkit.inventory.StonecuttingRecipe; import org.bukkit.inventory.StonecuttingRecipe;
import org.bukkit.inventory.view.StonecutterView; import org.bukkit.inventory.view.StonecutterView;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftStonecutterView extends CraftInventoryView<ContainerStonecutter> implements StonecutterView { public class CraftStonecutterView extends CraftInventoryView<ContainerStonecutter, StonecutterInventory> implements StonecutterView {
public CraftStonecutterView(final HumanEntity player, final Inventory viewing, final ContainerStonecutter container) { public CraftStonecutterView(final HumanEntity player, final StonecutterInventory viewing, final ContainerStonecutter container) {
super(player, viewing, container); super(player, viewing, container);
} }