1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

More work on this, added a new event and deprecated the old ones.

This commit is contained in:
TheBusyBiscuit 2021-04-27 17:08:09 +02:00
parent 57df9e8df9
commit 7bd588175b
9 changed files with 113 additions and 4 deletions

View File

@ -16,7 +16,10 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
*
* @author poma123
*
* @deprecated This event is no longer fired. Use the {@link AsyncMachineOperationFinishEvent} instead.
*
*/
@Deprecated
public class AsyncGeneratorProcessCompleteEvent extends AsyncMachineProcessCompleteEvent {
private static final HandlerList handlers = new HandlerList();

View File

@ -0,0 +1,77 @@
package io.github.thebusybiscuit.slimefun4.api.events;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import io.github.thebusybiscuit.slimefun4.core.machines.MachineOperation;
import io.github.thebusybiscuit.slimefun4.core.machines.MachineProcessor;
/**
* This {@link Event} is fired whenever an {@link MachineProcessor} has completed a {@link MachineOperation}.
*
* @author poma123
* @author TheBusyBiscuit
*
*/
public class AsyncMachineOperationFinishEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private final Location location;
private final MachineProcessor<?> machineProcessor;
private final MachineOperation machineOperation;
public <T extends MachineOperation> AsyncMachineOperationFinishEvent(Location l, MachineProcessor<T> processor, T operation) {
super(!Bukkit.isPrimaryThread());
this.location = l;
this.machineProcessor = processor;
this.machineOperation = operation;
}
/**
* This returns the {@link Location} of the machine.
*
* @return The {@link Location} of the machine
*/
@Nonnull
public Location getLocation() {
return location;
}
/**
* 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();
}
}

View File

@ -17,7 +17,10 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
*
* @author poma123
*
* @deprecated This event is no longer fired. Use the {@link AsyncMachineOperationFinishEvent} instead.
*
*/
@Deprecated
public class AsyncMachineProcessCompleteEvent extends Event {
private static final HandlerList handlers = new HandlerList();

View File

@ -15,8 +15,11 @@ import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
* This {@link Event} is fired whenever a {@link Reactor} has completed its process.
*
* @author poma123
*
* @deprecated This event is no longer fired. Use the {@link AsyncMachineOperationFinishEvent} instead.
*
*/
@Deprecated
public class AsyncReactorProcessCompleteEvent extends AsyncMachineProcessCompleteEvent {
private static final HandlerList handlers = new HandlerList();

View File

@ -34,8 +34,31 @@ public class MachineProcessor<T extends MachineOperation> {
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Map<BlockPosition, T> machines = new HashMap<>();
private final MachineProcessHolder<T> owner;
private ItemStack progressBar;
/**
* This creates a new {@link MachineProcessor}.
*
* @param owner
* The owner of this {@link MachineProcessor}.
*/
public MachineProcessor(@Nonnull MachineProcessHolder<T> owner) {
Validate.notNull(owner, "The MachineProcessHolder cannot be null.");
this.owner = owner;
}
/**
* This returns the owner of this {@link MachineProcessor}.
*
* @return The owner / holder
*/
@Nonnull
public MachineProcessHolder<T> getOwner() {
return owner;
}
/**
* This returns the progress bar icon for this {@link MachineProcessor}
* or null if no progress bar was set.

View File

@ -75,7 +75,7 @@ public abstract class Reactor extends AbstractEnergyProvider implements Hologram
private static final int[] border_4 = { 25, 34, 43 };
private final Set<Location> explosionsQueue = new HashSet<>();
private final MachineProcessor<FuelOperation> processor = new MachineProcessor<>();
private final MachineProcessor<FuelOperation> processor = new MachineProcessor<>(this);
@ParametersAreNonnullByDefault
protected Reactor(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {

View File

@ -57,7 +57,7 @@ public class GEOMiner extends SlimefunItem implements RecipeDisplayItem, EnergyN
private static final int PROCESSING_TIME = 14;
private static final int ENERGY_CONSUMPTION = 24;
private final MachineProcessor<MiningOperation> processor = new MachineProcessor<>();
private final MachineProcessor<MiningOperation> processor = new MachineProcessor<>(this);
@ParametersAreNonnullByDefault
public GEOMiner(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {

View File

@ -51,7 +51,7 @@ public abstract class AContainer extends SlimefunItem implements InventoryBlock,
private static final int[] BORDER_OUT = { 14, 15, 16, 17, 23, 26, 32, 33, 34, 35 };
protected final List<MachineRecipe> recipes = new ArrayList<>();
private final MachineProcessor<CraftingOperation> processor = new MachineProcessor<>();
private final MachineProcessor<CraftingOperation> processor = new MachineProcessor<>(this);
private int energyConsumedPerTick = -1;
private int energyCapacity = -1;

View File

@ -47,7 +47,7 @@ public abstract class AGenerator extends AbstractEnergyProvider implements Machi
private static final int[] border_in = { 9, 10, 11, 12, 18, 21, 27, 28, 29, 30 };
private static final int[] border_out = { 14, 15, 16, 17, 23, 26, 32, 33, 34, 35 };
private final MachineProcessor<FuelOperation> processor = new MachineProcessor<>();
private final MachineProcessor<FuelOperation> processor = new MachineProcessor<>(this);
private int energyProducedPerTick = -1;
private int energyCapacity = -1;