forked from Slimefun/Slimefun4
-
-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathAsyncMachineOperationStartEvent.java
More file actions
96 lines (84 loc) · 2.86 KB
/
Copy pathAsyncMachineOperationStartEvent.java
File metadata and controls
96 lines (84 loc) · 2.86 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
86
87
88
89
90
91
92
93
94
95
96
package io.github.thebusybiscuit.slimefun4.api.events;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation;
import io.github.thebusybiscuit.slimefun4.core.machines.MachineProcessor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
/**
* This {@link Event} is fired whenever an {@link MachineProcessor} wants to start a {@link MachineOperation} when invoking any of the {@link MachineProcessor#startOperation} method
* The event is cancellable, if the event is cancelled, the operation will not be added to the operation map and {@link MachineProcessor#startOperation} will return false
*
* @author m1919810
*
*/
public class AsyncMachineOperationStartEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final BlockPosition position;
private final MachineProcessor<?> machineProcessor;
private final MachineOperation machineOperation;
private boolean cancel;
public <T extends MachineOperation> AsyncMachineOperationStartEvent(
BlockPosition pos, MachineProcessor<T> processor, T operation) {
super(!Bukkit.isPrimaryThread());
this.position = pos;
this.machineProcessor = processor;
this.machineOperation = operation;
}
/**
* This returns the {@link BlockPosition} of the machine.
*
* @return The {@link BlockPosition} of the machine
*/
@Nonnull
public BlockPosition getPosition() {
return position;
}
/**
* The {@link MachineProcessor} instance of the machine.
*
* @return The {@link MachineProcessor} instance of the machine
*/
@Nullable public MachineProcessor<?> getProcessor() {
return machineProcessor;
}
/**
* This returns the used {@link MachineOperation} in the process.
*
* @return The {@link MachineOperation} of the process
*/
@Nullable public MachineOperation getOperation() {
return machineOperation;
}
@Nonnull
public static HandlerList getHandlerList() {
return handlers;
}
@Nonnull
@Override
public HandlerList getHandlers() {
return getHandlerList();
}
/**
* This returns whether the event is cancelled
*
* @return cancel flag
*/
@Override
public boolean isCancelled() {
return this.cancel;
}
/**
* This sets the cancel flag of the event
* If the event is cancelled, the operation will not be added to the operation map and {@link MachineProcessor#startOperation} will return false
*
* @param b new flag
*/
@Override
public void setCancelled(boolean b) {
this.cancel = b;
}
}