use of org.spongepowered.api.event.item.inventory.InteractInventoryEvent in project LanternServer by LanternPowered.
the class LanternInventoryBuilder method build.
@Override
public T build(Object plugin) {
checkState(this.inventoryArchetype != null, "The inventory archetype must be set");
AbstractBuilder builder = this.builder;
LanternInventoryArchetype<T> inventoryArchetype = this.inventoryArchetype;
if (builder == null) {
builder = this.inventoryArchetype.getBuilder();
}
if (this.forCarrierType != null || this.forCarrier != null || this.carrier != null) {
AbstractArchetypeBuilder builder1 = (AbstractArchetypeBuilder) builder;
if (builder1.carrierTransformer != null) {
final Supplier supplier = () -> {
final AbstractArchetypeBuilder copy = builder1.copy();
copy.carrierTransformer = null;
return copy;
};
final LanternInventoryArchetype archetype;
if (this.forCarrier != null) {
archetype = builder1.carrierTransformer.apply(this.forCarrier, supplier);
} else if (this.forCarrierType != null) {
archetype = builder1.carrierTransformer.apply(this.forCarrierType, supplier);
} else {
// Fall back to actual carrier
archetype = builder1.carrierTransformer.apply(this.carrier, supplier);
}
if (archetype != null) {
builder = archetype.getBuilder();
}
}
}
final AbstractInventory inventory = builder.build(this.carrier != null, plugin, inventoryArchetype);
if (inventory instanceof AbstractMutableInventory && this.carrier != null) {
final AbstractMutableInventory mutableInventory = (AbstractMutableInventory) inventory;
mutableInventory.setCarrier0(this.carrier);
}
if (this.carrier instanceof AbstractCarrier) {
((AbstractCarrier) this.carrier).setInventory((CarriedInventory<?>) inventory);
}
if (!this.listeners.isEmpty()) {
final List<InventoryListeners> listenersList = new ArrayList<>();
for (Map.Entry<Class<? extends InteractInventoryEvent>, List<Consumer<? extends InteractInventoryEvent>>> entry : this.listeners.entrySet()) {
final InventoryListeners listeners = new InventoryListeners(inventory, entry.getKey(), entry.getValue());
Sponge.getEventManager().registerListener(plugin, entry.getKey(), listeners);
}
inventoryListeners.put(inventory, listenersList);
}
return (T) inventory;
}
Aggregations