com.fastasyncworldedit.core.world.block.BlockTypeSwitchBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of FastAsyncWorldEdit-Core Show documentation
Show all versions of FastAsyncWorldEdit-Core Show documentation
Blazingly fast Minecraft world manipulation for artists, builders and everyone else.
package com.fastasyncworldedit.core.world.block;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.util.function.Predicate;
public class BlockTypeSwitchBuilder {
private final Object[] runnables;
private T defaultTask;
public BlockTypeSwitchBuilder(T defaultTask) {
this.runnables = new Object[BlockTypes.size()];
this.defaultTask = defaultTask;
}
public BlockTypeSwitchBuilder add(BlockType type, T task) {
this.runnables[type.getInternalId()] = task;
return this;
}
public BlockTypeSwitchBuilder add(Predicate predicate, T task) {
for (BlockType type : BlockTypesCache.values) {
if (predicate.test(type)) {
this.runnables[type.getInternalId()] = task;
}
}
return this;
}
public BlockTypeSwitchBuilder setDefaultTask(T defaultTask) {
this.defaultTask = defaultTask;
return this;
}
public BlockTypeSwitch build() {
for (int i = 0; i < runnables.length; i++) {
if (runnables[i] == null) {
runnables[i] = defaultTask;
}
}
return new BlockTypeSwitch(runnables);
}
}