-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemExecuteEvent.java
More file actions
85 lines (70 loc) · 2.33 KB
/
ItemExecuteEvent.java
File metadata and controls
85 lines (70 loc) · 2.33 KB
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
77
78
79
80
81
82
83
84
85
package com.github.pinont.singularitylib.api.event;
import com.github.pinont.singularitylib.api.items.ItemInteraction;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import static com.github.pinont.singularitylib.plugin.CorePlugin.sendDebugMessage;
public class ItemExecuteEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS = new HandlerList();
private final Player player;
private final ItemStack item;
private final ItemInteraction interaction;
private final Action action;
private boolean isCancelled;
public ItemExecuteEvent(PlayerInteractEvent event, ItemStack item, ItemInteraction interaction) {
this.player = event.getPlayer();
this.item = item;
this.interaction = interaction;
this.action = event.getAction();
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
@Override
public boolean callEvent() {
Bukkit.getPluginManager().callEvent(this);
return !isCancelled();
}
public void execute() {
if (callEvent()) {
if (interaction.getAction().contains(getAction())) {
interaction.execute(player);
if (player.getGameMode() != GameMode.CREATIVE) {
item.setAmount(item.getAmount() - interaction.removeItemAmountOnExecute());
}
sendDebugMessage("Executing interaction: " + interaction.getName());
}
}
}
public Player getPlayer() {
return this.player;
}
public ItemStack getItem() {
return this.item;
}
public ItemInteraction getInteraction() {
return this.interaction;
}
public Action getAction() {
return this.action;
}
@Override
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}
@Override
public boolean isCancelled() {
return this.isCancelled;
}
@Override
public void setCancelled(boolean b) {
this.isCancelled = b;
}
}