diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/org/bukkit/enchantments/EnchantmentOffer.java | 81 | ||||
-rw-r--r-- | src/main/java/org/bukkit/event/enchantment/PrepareItemEnchantEvent.java | 34 |
2 files changed, 107 insertions, 8 deletions
diff --git a/src/main/java/org/bukkit/enchantments/EnchantmentOffer.java b/src/main/java/org/bukkit/enchantments/EnchantmentOffer.java new file mode 100644 index 00000000..92e4f04f --- /dev/null +++ b/src/main/java/org/bukkit/enchantments/EnchantmentOffer.java @@ -0,0 +1,81 @@ +package org.bukkit.enchantments; + +import org.apache.commons.lang.Validate; + +/** + * A class for the available enchantment offers in the enchantment table. + */ +public class EnchantmentOffer { + + private Enchantment enchantment; + private int enchantmentLevel; + private int cost; + + public EnchantmentOffer(Enchantment enchantment, int enchantmentLevel, int cost) { + this.enchantment = enchantment; + this.enchantmentLevel = enchantmentLevel; + this.cost = cost; + } + + /** + * Get the type of the enchantment. + * + * @return type of enchantment + */ + public Enchantment getEnchantment() { + return enchantment; + } + + /** + * Sets the type of the enchantment. + * + * @param enchantment type of the enchantment + */ + public void setEnchantment(Enchantment enchantment) { + Validate.notNull(enchantment, "The enchantment may not be null!"); + + this.enchantment = enchantment; + } + + /** + * Gets the level of the enchantment. + * + * @return level of the enchantment + */ + public int getEnchantmentLevel() { + return enchantmentLevel; + } + + /** + * Sets the level of the enchantment. + * + * @param enchantmentLevel level of the enchantment + */ + public void setEnchantmentLevel(int enchantmentLevel) { + Validate.isTrue(enchantmentLevel > 0, "The enchantment level must be greater than 0!"); + + this.enchantmentLevel = enchantmentLevel; + } + + /** + * Gets the cost in experience levels the player has to pay to enchant his + * item with this enchantment. + * + * @return cost for this enchantment + */ + public int getCost() { + return cost; + } + + /** + * Sets the cost in experience levels the player has to pay to enchant his + * item with this enchantment + * + * @param cost cost for this enchantment + */ + public void setCost(int cost) { + Validate.isTrue(cost > 0, "The cost must be greater than 0!"); + + this.cost = cost; + } +} diff --git a/src/main/java/org/bukkit/event/enchantment/PrepareItemEnchantEvent.java b/src/main/java/org/bukkit/event/enchantment/PrepareItemEnchantEvent.java index 6c0aa9ff..6995b6e0 100644 --- a/src/main/java/org/bukkit/event/enchantment/PrepareItemEnchantEvent.java +++ b/src/main/java/org/bukkit/event/enchantment/PrepareItemEnchantEvent.java @@ -1,6 +1,7 @@ package org.bukkit.event.enchantment; import org.bukkit.block.Block; +import org.bukkit.enchantments.EnchantmentOffer; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; @@ -16,19 +17,18 @@ public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellab private static final HandlerList handlers = new HandlerList(); private final Block table; private final ItemStack item; - private final int[] levelsOffered; + private final EnchantmentOffer[] offers; private final int bonus; private boolean cancelled; private final Player enchanter; - public PrepareItemEnchantEvent(final Player enchanter, InventoryView view, final Block table, final ItemStack item, final int[] levelsOffered, final int bonus) { + public PrepareItemEnchantEvent(final Player enchanter, InventoryView view, final Block table, final ItemStack item, final EnchantmentOffer[] offers, final int bonus) { super(view); this.enchanter = enchanter; this.table = table; this.item = item; - this.levelsOffered = levelsOffered; + this.offers = offers; this.bonus = bonus; - this.cancelled = false; } /** @@ -50,7 +50,7 @@ public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellab } /** - * Gets the item to be enchanted (can be modified) + * Gets the item to be enchanted. * * @return ItemStack of item */ @@ -59,13 +59,29 @@ public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellab } /** - * Get list of offered exp level costs of the enchantment (modify values - * to change offer) + * Get a list of offered experience level costs of the enchantment. * * @return experience level costs offered + * @deprecated Use {@link #getOffers()} instead of this method */ public int[] getExpLevelCostsOffered() { - return levelsOffered; + int[] levelOffers = new int[offers.length]; + for (int i = 0; i < offers.length; i++) { + levelOffers[i] = offers[i] != null ? offers[i].getCost() : 0; + } + return levelOffers; + } + + /** + * Get a list of available {@link EnchantmentOffer} for the player. You can + * modify the values to change the available offers for the player. An offer + * may be null, if there isn't a enchantment offer at a specific slot. There + * are 3 slots in the enchantment table available to modify. + * + * @return list of available enchantment offers + */ + public EnchantmentOffer[] getOffers() { + return offers; } /** @@ -77,10 +93,12 @@ public class PrepareItemEnchantEvent extends InventoryEvent implements Cancellab return bonus; } + @Override public boolean isCancelled() { return cancelled; } + @Override public void setCancelled(boolean cancel) { this.cancelled = cancel; } |