mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Made requested changes
This commit is contained in:
parent
7c0b29f866
commit
1d58bca4d3
@ -123,8 +123,6 @@ public class MachineProcessor<T extends MachineOperation> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will actually start the {@link MachineOperation}.
|
* This method will actually start the {@link MachineOperation}.
|
||||||
* We don't need to validate any of these inputs as that is already
|
|
||||||
* covered in our public methods.
|
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param pos
|
||||||
* The {@link BlockPosition} of our machine
|
* The {@link BlockPosition} of our machine
|
||||||
@ -134,7 +132,10 @@ public class MachineProcessor<T extends MachineOperation> {
|
|||||||
* @return Whether the {@link MachineOperation} was successfully started. This will return false if another
|
* @return Whether the {@link MachineOperation} was successfully started. This will return false if another
|
||||||
* {@link MachineOperation} has already been started at that {@link BlockPosition}.
|
* {@link MachineOperation} has already been started at that {@link BlockPosition}.
|
||||||
*/
|
*/
|
||||||
private boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) {
|
public boolean startOperation(@Nonnull BlockPosition pos, @Nonnull T operation) {
|
||||||
|
Validate.notNull(pos, "The BlockPosition must not be null");
|
||||||
|
Validate.notNull(operation, "The machine operation cannot be null");
|
||||||
|
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -185,7 +186,9 @@ public class MachineProcessor<T extends MachineOperation> {
|
|||||||
* @return The current {@link MachineOperation} or null.
|
* @return The current {@link MachineOperation} or null.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
private T getOperation(@Nonnull BlockPosition pos) {
|
public T getOperation(@Nonnull BlockPosition pos) {
|
||||||
|
Validate.notNull(pos, "The BlockPosition must not be null");
|
||||||
|
|
||||||
lock.readLock().lock();
|
lock.readLock().lock();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -227,8 +230,6 @@ public class MachineProcessor<T extends MachineOperation> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This will end the {@link MachineOperation} at the given {@link BlockPosition}.
|
* This will end the {@link MachineOperation} at the given {@link BlockPosition}.
|
||||||
* We don't need to validate our input here as that is already
|
|
||||||
* covered in our public methods.
|
|
||||||
*
|
*
|
||||||
* @param pos
|
* @param pos
|
||||||
* The {@link BlockPosition} at which our machine is located.
|
* The {@link BlockPosition} at which our machine is located.
|
||||||
@ -236,29 +237,33 @@ public class MachineProcessor<T extends MachineOperation> {
|
|||||||
* @return Whether the {@link MachineOperation} was successfully ended. This will return false if there was no
|
* @return Whether the {@link MachineOperation} was successfully ended. This will return false if there was no
|
||||||
* {@link MachineOperation} to begin with.
|
* {@link MachineOperation} to begin with.
|
||||||
*/
|
*/
|
||||||
private boolean endOperation(@Nonnull BlockPosition pos) {
|
public boolean endOperation(@Nonnull BlockPosition pos) {
|
||||||
|
Validate.notNull(pos, "The BlockPosition cannot be null");
|
||||||
|
|
||||||
lock.writeLock().lock();
|
lock.writeLock().lock();
|
||||||
|
|
||||||
|
T operation;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
T operation = machines.remove(pos);
|
operation = machines.remove(pos);
|
||||||
|
|
||||||
if (operation != null) {
|
|
||||||
/*
|
|
||||||
* Only call an event if the operation actually finished.
|
|
||||||
* If it was ended prematurely (aka aborted), then we don't call any event.
|
|
||||||
*/
|
|
||||||
if (operation.isFinished()) {
|
|
||||||
Event event = new AsyncMachineOperationFinishEvent(pos, this, operation);
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (operation != null) {
|
||||||
|
/*
|
||||||
|
* Only call an event if the operation actually finished.
|
||||||
|
* If it was ended prematurely (aka aborted), then we don't call any event.
|
||||||
|
*/
|
||||||
|
if (operation.isFinished()) {
|
||||||
|
Event event = new AsyncMachineOperationFinishEvent(pos, this, operation);
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgressBar(@Nonnull BlockMenu inv, int slot, @Nonnull T operation) {
|
public void updateProgressBar(@Nonnull BlockMenu inv, int slot, @Nonnull T operation) {
|
||||||
|
Loading…
Reference in New Issue
Block a user