mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2025-02-18 01:31:40 +01:00
Integration changes, don't run actions if previous output is null
This commit is contained in:
parent
102c4ec5a1
commit
80c1b2b7e4
@ -8,6 +8,16 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public final class DefaultStorageIntegrable implements StorageIntegrable {
|
||||
|
||||
@Override
|
||||
public boolean isFull(Location location) {
|
||||
BlockState state = location.getBlock().getState();
|
||||
if (state instanceof Container container) {
|
||||
return container.getInventory().firstEmpty() == -1;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean flush(Location location, ObjectArrayList<ItemStack> items) {
|
||||
BlockState state = location.getBlock().getState();
|
||||
|
@ -7,5 +7,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface StorageIntegrable extends Integrable {
|
||||
|
||||
boolean isFull(Location location);
|
||||
|
||||
boolean flush(Location location, ObjectArrayList<ItemStack> items);
|
||||
}
|
||||
|
@ -13,6 +13,16 @@ public final class StorageIntegration extends Integration<StorageIntegrable> {
|
||||
this.register(new DefaultStorageIntegrable());
|
||||
}
|
||||
|
||||
public boolean isFull(Location location) {
|
||||
for (StorageIntegrable integration : this.integrations()) {
|
||||
if (integration.isFull(location)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void push(Location location, ItemStack... itemStacks) {
|
||||
ObjectArrayList<ItemStack> items = this.items.get(location);
|
||||
if (items != null) {
|
||||
|
@ -89,6 +89,10 @@ public final class Minion {
|
||||
}
|
||||
}
|
||||
|
||||
public Location linkedChest() {
|
||||
return this.minionData.linkedChest();
|
||||
}
|
||||
|
||||
public Map<String, String> extraData() {
|
||||
return this.minionData.extraData();
|
||||
}
|
||||
|
@ -29,9 +29,13 @@ public abstract class Effect<T, Z> {
|
||||
}
|
||||
|
||||
public void dispatch(Minion minion, T argument) {
|
||||
new EffectDispatchEvent(minion, this, argument).call();
|
||||
Z out = run(minion, argument);
|
||||
|
||||
new EffectDispatchEvent(minion, this, argument).call();
|
||||
if (out == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ObjectArrayList<Effect<Z, ?>> children = this.children;
|
||||
if (children == null) {
|
||||
return;
|
||||
|
@ -1,8 +1,10 @@
|
||||
package com.artillexstudios.axminions.minions.actions.effects.implementation;
|
||||
|
||||
import com.artillexstudios.axminions.integrations.Integrations;
|
||||
import com.artillexstudios.axminions.minions.Minion;
|
||||
import com.artillexstudios.axminions.minions.actions.effects.Effect;
|
||||
import com.artillexstudios.axminions.utils.ItemCollection;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -14,8 +16,12 @@ public class AddToContainerEffect extends Effect<ItemCollection, ItemCollection>
|
||||
|
||||
@Override
|
||||
public ItemCollection run(Minion minion, ItemCollection argument) {
|
||||
// TODO: Add to container
|
||||
return argument;
|
||||
if (minion.linkedChest() == null) {
|
||||
return argument;
|
||||
}
|
||||
|
||||
Integrations.STORAGE.push(minion.linkedChest(), argument.elements());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,10 @@ public class DropAtMinionEffect extends Effect<ItemCollection, ItemCollection> {
|
||||
|
||||
@Override
|
||||
public ItemCollection run(Minion minion, ItemCollection argument) {
|
||||
if (argument == ItemCollection.EMPTY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
World world = minion.location().getWorld();
|
||||
if (world == null) {
|
||||
throw new MinionTickFailException("World is null!");
|
||||
@ -26,7 +30,7 @@ public class DropAtMinionEffect extends Effect<ItemCollection, ItemCollection> {
|
||||
world.dropItem(minion.location(), itemStack);
|
||||
}
|
||||
|
||||
return ItemCollection.EMPTY;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.artillexstudios.axminions.utils;
|
||||
|
||||
import com.artillexstudios.axapi.reflection.FastFieldAccessor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -13,6 +14,7 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ItemCollection {
|
||||
private static final FastFieldAccessor ELEMENT_DATA = FastFieldAccessor.forClassField(ArrayList.class, "elementData");
|
||||
public static final ItemCollection EMPTY = new ItemCollection(0) {
|
||||
@Override
|
||||
public ItemStack remove(int index) {
|
||||
@ -52,6 +54,7 @@ public class ItemCollection {
|
||||
}
|
||||
|
||||
public ItemCollection(Collection<ItemStack> collection) {
|
||||
LogUtils.debug("ItemCollection with class: {}", collection.getClass());
|
||||
this.items = collection instanceof List<ItemStack> list ? list : new ArrayList<>(collection);
|
||||
}
|
||||
|
||||
@ -95,6 +98,10 @@ public class ItemCollection {
|
||||
return this.items;
|
||||
}
|
||||
|
||||
public ItemStack[] elements() {
|
||||
return ELEMENT_DATA.get(this.items);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Iterator<ItemStack> iterator() {
|
||||
return this.items.iterator();
|
||||
|
Loading…
Reference in New Issue
Block a user