Commits

Senmori authored and md_5 committed 78ce389df2c
SPIGOT-1505: PlayerItemMendEvent
No tags

src/main/java/org/bukkit/event/player/PlayerItemMendEvent.java

Added
1 +package org.bukkit.event.player;
2 +
3 +import org.bukkit.entity.ExperienceOrb;
4 +import org.bukkit.entity.Player;
5 +import org.bukkit.event.Cancellable;
6 +import org.bukkit.event.HandlerList;
7 +import org.bukkit.inventory.ItemStack;
8 +
9 +/**
10 + * Represents when a player has an item repaired via the Mending enchantment.
11 + * <br>
12 + * This event is fired directly before the {@link PlayerExpChangeEvent}, and the
13 + * results of this event directly affect the {@link PlayerExpChangeEvent}.
14 + */
15 +public class PlayerItemMendEvent extends PlayerEvent implements Cancellable {
16 +
17 + private static final HandlerList handlers = new HandlerList();
18 + //
19 + private final ItemStack item;
20 + private final ExperienceOrb experienceOrb;
21 + private int repairAmount;
22 + private boolean cancelled;
23 +
24 + public PlayerItemMendEvent(Player who, ItemStack item, ExperienceOrb experienceOrb, int repairAmount) {
25 + super(who);
26 + this.item = item;
27 + this.experienceOrb = experienceOrb;
28 + this.repairAmount = repairAmount;
29 + }
30 +
31 + /**
32 + * Get the {@link ItemStack} to be repaired.
33 + *
34 + * This is not necessarily the item the player is holding.
35 + *
36 + * @return the item to be repaired
37 + */
38 + public ItemStack getItem() {
39 + return item;
40 + }
41 +
42 + /**
43 + * Get the experience orb triggering the event.
44 + *
45 + * @return the experience orb
46 + */
47 + public ExperienceOrb getExperienceOrb() {
48 + return experienceOrb;
49 + }
50 +
51 + /**
52 + * Get the amount the item is to be repaired.
53 + *
54 + * The default value is twice the value of the consumed experience orb
55 + * or the remaining damage left on the item, whichever is smaller.
56 + *
57 + * @return how much damage will be repaired by the experience orb
58 + */
59 + public int getRepairAmount() {
60 + return repairAmount;
61 + }
62 +
63 + /**
64 + * Set the amount the item will be repaired.
65 + *
66 + * Half of this value will be subtracted from the experience orb which initiated this event.
67 + *
68 + * @param amount how much damage will be repaired on the item
69 + */
70 + public void setRepairAmount(int amount) {
71 + this.repairAmount = amount;
72 + }
73 +
74 + @Override
75 + public boolean isCancelled() {
76 + return cancelled;
77 + }
78 +
79 + @Override
80 + public void setCancelled(boolean cancelled) {
81 + this.cancelled = cancelled;
82 + }
83 +
84 + @Override
85 + public HandlerList getHandlers() {
86 + return handlers;
87 + }
88 +
89 + public static HandlerList getHandlerList() {
90 + return handlers;
91 + }
92 +}

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut