blob: 19e67a70895965c3f4e49985f1892419197c3cd2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package org.bukkit.event.inventory;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.Cancellable;
import org.bukkit.inventory.InventoryView;
/**
* An abstract base class for events that describe an interaction between a
* HumanEntity and the contents of an Inventory.
*/
public abstract class InventoryInteractEvent extends InventoryEvent implements Cancellable {
private Result result = Result.DEFAULT;
public InventoryInteractEvent(InventoryView transaction) {
super(transaction);
}
/**
* Gets the player who performed the click.
*
* @return The clicking player.
*/
public HumanEntity getWhoClicked() {
return getView().getPlayer();
}
/**
* Sets the result of this event. This will change whether or not this
* event is considered cancelled.
*
* @see #isCancelled()
* @param newResult the new {@link org.bukkit.event.Event.Result} for this event
*/
public void setResult(Result newResult) {
result = newResult;
}
/**
* Gets the {@link org.bukkit.event.Event.Result} of this event. The Result describes the
* behavior that will be applied to the inventory in relation to this
* event.
*
* @return the Result of this event.
*/
public Result getResult() {
return result;
}
/**
* Gets whether or not this event is cancelled. This is based off of the
* Result value returned by {@link #getResult()}. Result.ALLOW and
* Result.DEFAULT will result in a returned value of false, but
* Result.DENY will result in a returned value of true.
* <p>
* {@inheritDoc}
*
* @return whether the event is cancelled
*/
public boolean isCancelled() {
return getResult() == Result.DENY;
}
/**
* Proxy method to {@link #setResult(Event.Result)} for the Cancellable
* interface. {@link #setResult(Event.Result)} is preferred, as it allows
* you to specify the Result beyond Result.DENY and Result.ALLOW.
* <p>
* {@inheritDoc}
*
* @param toCancel result becomes DENY if true, ALLOW if false
*/
public void setCancelled(boolean toCancel) {
setResult(toCancel ? Result.DENY : Result.ALLOW);
}
}
|