2020-08-25 01:01:11 +02:00
|
|
|
package com.songoda.ultimatestacker.stackable.block;
|
|
|
|
|
|
|
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
public class BlockStackManager {
|
|
|
|
|
2023-04-10 17:14:37 +02:00
|
|
|
private final Map<Location, BlockStack> registeredBlocks = new HashMap<>();
|
2020-08-25 01:01:11 +02:00
|
|
|
|
|
|
|
public void addBlocks(Map<Location, BlockStack> blocks) {
|
|
|
|
this.registeredBlocks.putAll(blocks);
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockStack addBlock(BlockStack blockStack) {
|
|
|
|
this.registeredBlocks.put(roundLocation(blockStack.getLocation()), blockStack);
|
|
|
|
return blockStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BlockStack removeBlock(Location location) {
|
|
|
|
return registeredBlocks.remove(roundLocation(location));
|
|
|
|
}
|
|
|
|
|
2023-04-07 18:58:21 +02:00
|
|
|
public BlockStack getBlock(Location location) {
|
|
|
|
return this.registeredBlocks.get(location);
|
|
|
|
}
|
|
|
|
|
2023-04-10 17:17:00 +02:00
|
|
|
public BlockStack getBlock(Block block, CompatibleMaterial material) {
|
|
|
|
return this.getBlock(block.getLocation());
|
|
|
|
}
|
|
|
|
|
2023-04-07 18:58:21 +02:00
|
|
|
public BlockStack createBlock(Location location, CompatibleMaterial material) {
|
2020-08-25 01:01:11 +02:00
|
|
|
return this.registeredBlocks.computeIfAbsent(location, b -> new BlockStack(material, location));
|
|
|
|
}
|
|
|
|
|
2023-04-07 18:58:21 +02:00
|
|
|
public BlockStack createBlock(Block block) {
|
|
|
|
return this.createBlock(block.getLocation(), CompatibleMaterial.getMaterial(block));
|
2020-08-25 01:01:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isBlock(Location location) {
|
|
|
|
return this.registeredBlocks.get(location) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Collection<BlockStack> getStacks() {
|
|
|
|
return Collections.unmodifiableCollection(this.registeredBlocks.values());
|
|
|
|
}
|
|
|
|
|
|
|
|
private Location roundLocation(Location location) {
|
|
|
|
location = location.clone();
|
|
|
|
location.setX(location.getBlockX());
|
|
|
|
location.setY(location.getBlockY());
|
|
|
|
location.setZ(location.getBlockZ());
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
}
|