13
0
geforkt von Mirrors/Paper

Add EnchantmentOffer to PrepareItemEnchantEvent

By: LukBukkit <luk.bukkit@gmail.com>
Dieser Commit ist enthalten in:
Bukkit/Spigot 2016-11-27 20:48:06 +01:00
Ursprung 1630d4344b
Commit 70550c8dce
2 geänderte Dateien mit 107 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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;
}
}

Datei anzeigen

@ -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;
}