Skip to content

Commit

Permalink
#1036: Add API for InventoryView derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
Miles Holder authored and md-5 committed Jul 27, 2024
1 parent 1fe2c75 commit b3c2b83
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/bukkit/entity/HumanEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ public interface HumanEntity extends LivingEntity, AnimalTamer, InventoryHolder
* @param prop The property.
* @param value The value to set the property to.
* @return True if the property was successfully set.
* @deprecated use {@link InventoryView} and its children.
*/
@Deprecated(forRemoval = true, since = "1.21")
public boolean setWindowProperty(@NotNull InventoryView.Property prop, int value);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryEvent;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.view.EnchantmentView;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -23,7 +23,7 @@ public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellab
private boolean cancelled;
private final Player enchanter;

public PrepareItemEnchantEvent(@NotNull final Player enchanter, @NotNull InventoryView view, @NotNull final Block table, @NotNull final ItemStack item, @NotNull final EnchantmentOffer[] offers, final int bonus) {
public PrepareItemEnchantEvent(@NotNull final Player enchanter, @NotNull EnchantmentView view, @NotNull final Block table, @NotNull final ItemStack item, @NotNull final EnchantmentOffer[] offers, final int bonus) {
super(view);
this.enchanter = enchanter;
this.table = table;
Expand Down Expand Up @@ -100,6 +100,12 @@ public int getEnchantmentBonus() {
return bonus;
}

@NotNull
@Override
public EnchantmentView getView() {
return (EnchantmentView) super.getView();
}

@Override
public boolean isCancelled() {
return cancelled;
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/bukkit/event/inventory/PrepareAnvilEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.bukkit.event.HandlerList;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.view.AnvilView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -14,7 +14,7 @@ public class PrepareAnvilEvent extends PrepareInventoryResultEvent {

private static final HandlerList handlers = new HandlerList();

public PrepareAnvilEvent(@NotNull InventoryView inventory, @Nullable ItemStack result) {
public PrepareAnvilEvent(@NotNull AnvilView inventory, @Nullable ItemStack result) {
super(inventory, result);
}

Expand All @@ -24,6 +24,12 @@ public AnvilInventory getInventory() {
return (AnvilInventory) super.getInventory();
}

@NotNull
@Override
public AnvilView getView() {
return (AnvilView) super.getView();
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/org/bukkit/event/inventory/TradeSelectEvent.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.bukkit.event.inventory;

import org.bukkit.event.HandlerList;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.Merchant;
import org.bukkit.inventory.MerchantInventory;
import org.bukkit.inventory.view.MerchantView;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -19,7 +19,7 @@ public class TradeSelectEvent extends InventoryInteractEvent {
//
private final int index;

public TradeSelectEvent(@NotNull InventoryView transaction, int newIndex) {
public TradeSelectEvent(@NotNull MerchantView transaction, int newIndex) {
super(transaction);
this.index = newIndex;
}
Expand Down Expand Up @@ -49,6 +49,12 @@ public Merchant getMerchant() {
return getInventory().getMerchant();
}

@NotNull
@Override
public MerchantView getView() {
return (MerchantView) super.getView();
}

@NotNull
@Override
public HandlerList getHandlers() {
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/bukkit/inventory/AnvilInventory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bukkit.inventory;

import org.bukkit.inventory.view.AnvilView;
import org.jetbrains.annotations.Nullable;

/**
Expand All @@ -12,36 +13,46 @@ public interface AnvilInventory extends Inventory {
* the default item name.
*
* @return the rename text
* @deprecated use {@link AnvilView#getRenameText()}.
*/
@Deprecated(forRemoval = true, since = "1.21")
@Nullable
String getRenameText();

/**
* Get the item cost (in amount) to complete the current repair.
*
* @return the amount
* @deprecated use {@link AnvilView#getRepairItemCost()}.
*/
@Deprecated(forRemoval = true, since = "1.21")
int getRepairCostAmount();

/**
* Set the item cost (in amount) to complete the current repair.
*
* @param amount the amount
* @deprecated use {@link AnvilView#setRepairItemCost(int)}.
*/
@Deprecated(forRemoval = true, since = "1.21")
void setRepairCostAmount(int amount);

/**
* Get the experience cost (in levels) to complete the current repair.
*
* @return the experience cost
* @deprecated use {@link AnvilView#getRepairCost()}.
*/
@Deprecated(forRemoval = true, since = "1.21")
int getRepairCost();

/**
* Set the experience cost (in levels) to complete the current repair.
*
* @param levels the experience cost
* @deprecated use {@link AnvilView#setRepairCost(int)}.
*/
@Deprecated(forRemoval = true, since = "1.21")
void setRepairCost(int levels);

/**
Expand All @@ -53,14 +64,18 @@ public interface AnvilInventory extends Inventory {
* maximum repair cost.
*
* @return the maximum experience cost
* @deprecated use {@link AnvilView#getMaximumRepairCost()}.
*/
@Deprecated(forRemoval = true, since = "1.21")
int getMaximumRepairCost();

/**
* Set the maximum experience cost (in levels) to be allowed by the current
* repair. The default value set by vanilla Minecraft is 40.
*
* @param levels the maximum experience cost
* @deprecated use {@link AnvilView#setMaximumRepairCost(int)}.
*/
@Deprecated(forRemoval = true, since = "1.21")
void setMaximumRepairCost(int levels);
}
2 changes: 2 additions & 0 deletions src/main/java/org/bukkit/inventory/InventoryView.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public interface InventoryView {
public static final int OUTSIDE = -999;
/**
* Represents various extra properties of certain inventory windows.
* @deprecated use {@link InventoryView} and its children
*/
@Deprecated(forRemoval = true, since = "1.21")
public enum Property {
/**
* The progress of the down-pointing arrow in a brewing inventory.
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/org/bukkit/inventory/view/AnvilView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.bukkit.inventory.view;

import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.Nullable;

/**
* An instance of {@link InventoryView} which provides extra methods related to
* anvil view data.
*/
public interface AnvilView extends InventoryView {

/**
* Gets the rename text specified within the anvil's text field.
*
* @return The text within the anvil's text field if an item is present
* otherwise null
*/
@Nullable
String getRenameText();

/**
* Gets the amount of items needed to repair.
*
* @return The amount of materials required to repair the item
*/
int getRepairItemCountCost();

/**
* Gets the experience cost needed to repair.
*
* @return The repair cost in experience
*/
int getRepairCost();

/**
* Gets the maximum repair cost needed to repair.
*
* @return The maximum repair cost in experience
*/
int getMaximumRepairCost();

/**
* Sets the amount of repair materials required to repair the item.
*
* @param amount the amount of repair materials
*/
void setRepairItemCountCost(int amount);

/**
* Sets the repair cost in experience.
*
* @param cost the experience cost to repair
*/
void setRepairCost(int cost);

/**
* Sets maximum repair cost in experience.
*
* @param levels the levels to set
*/
void setMaximumRepairCost(int levels);
}
84 changes: 84 additions & 0 deletions src/main/java/org/bukkit/inventory/view/BeaconView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.bukkit.inventory.view;

import org.bukkit.inventory.InventoryView;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.Nullable;

/**
* An instance of {@link InventoryView} which provides extra methods related to
* beacon view data.
*/
public interface BeaconView extends InventoryView {

/**
* Gets the tier of the beacon
* <p>
* Beacon tier is deduced by the height of the pyramid the beacon is
* standing on. The level of the beacon is 0 unless the beacon is activated.
*
* @return The tier of the beacon
*/
int getTier();

/**
* Gets the primary effect of the beacon.
* <p>
* If the beacon level is high enough where the primary effect can be
* upgraded to level two, e.g. Speed 2. Instead of
* {@link #getSecondaryEffect()} being null it {@link #getSecondaryEffect()}
* returns the same {@link PotionEffectType} as this method.
*
* @return The primary effect enabled on the beacon
*/
@Nullable
PotionEffectType getPrimaryEffect();

/**
* Gets the secondary effect of the beacon.
* <p>
* If the beacon level is high enough where the primary effect can be
* upgraded to level two, e.g. Speed 2. The secondary effect will return the
* same effect as {@link #getPrimaryEffect()}.
*
* @return The secondary effect enabled on the beacon
*/
@Nullable
PotionEffectType getSecondaryEffect();

/**
* Sets the primary effect of the beacon, or null to clear
* <p>
* The {@link PotionEffectType} provided must be one that is already within
* the beacon as a valid option.
* <ol>
* <li>{@link PotionEffectType#SPEED}
* <li>{@link PotionEffectType#HASTE}
* <li>{@link PotionEffectType#RESISTANCE}
* <li>{@link PotionEffectType#JUMP_BOOST}
* <li>{@link PotionEffectType#STRENGTH}
* <li>{@link PotionEffectType#REGENERATION}
* </ol>
*
* @param effect desired primary effect
*/
void setPrimaryEffect(@Nullable final PotionEffectType effect);

/**
* Sets the secondary effect on this beacon, or null to clear. Note that
* tier must be &gt;= 4 for this effect to be active.
* <p>
* The {@link PotionEffectType} provided must be one that is already within
* the beacon as a valid option.
* <ol>
* <li>{@link PotionEffectType#SPEED}
* <li>{@link PotionEffectType#HASTE}
* <li>{@link PotionEffectType#RESISTANCE}
* <li>{@link PotionEffectType#JUMP_BOOST}
* <li>{@link PotionEffectType#STRENGTH}
* <li>{@link PotionEffectType#REGENERATION}
* </ol>
*
* @param effect the desired secondary effect
*/
void setSecondaryEffect(@Nullable final PotionEffectType effect);
}
42 changes: 42 additions & 0 deletions src/main/java/org/bukkit/inventory/view/BrewingStandView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.bukkit.inventory.view;

import org.bukkit.inventory.InventoryView;

/**
* An instance of {@link InventoryView} which provides extra methods related to
* brewing stand view data.
*/
public interface BrewingStandView extends InventoryView {

/**
* Gets the fuel level of this brewing stand.
* <p>
* The default maximum fuel level in minecraft is 20.
*
* @return The amount of fuel level left
*/
int getFuelLevel();

/**
* Gets the amount of brewing ticks left.
*
* @return The amount of ticks left for the brewing task
*/
int getBrewingTicks();

/**
* Sets the fuel level left.
*
* @param level the level of the fuel, which is no less than 0
* @throws IllegalArgumentException if the level is less than 0
*/
void setFuelLevel(final int level) throws IllegalArgumentException;

/**
* Sets the brewing ticks left.
*
* @param ticks the ticks left, which is no less than 0
* @throws IllegalArgumentException if the ticks are less than 0
*/
void setBrewingTicks(final int ticks) throws IllegalArgumentException;
}
Loading

0 comments on commit b3c2b83

Please sign in to comment.