All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fastasyncworldedit.core.world.block.BlockTypeSwitchBuilder Maven / Gradle / Ivy

Go to download

Blazingly fast Minecraft world manipulation for artists, builders and everyone else.

There is a newer version: 2.9.2
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy