2023-05-25 19:20:03 +02:00
|
|
|
package com.craftaro.ultimatestacker.stackable.block;
|
2020-08-25 01:01:11 +02:00
|
|
|
|
2023-06-30 22:28:37 +02:00
|
|
|
import com.craftaro.core.database.Data;
|
2023-06-29 11:18:18 +02:00
|
|
|
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
|
2023-05-30 11:20:31 +02:00
|
|
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
2023-05-25 19:20:03 +02:00
|
|
|
import com.craftaro.ultimatestacker.api.stack.block.BlockStack;
|
|
|
|
import com.craftaro.ultimatestacker.api.stack.block.BlockStackManager;
|
2020-08-25 01:01:11 +02:00
|
|
|
import org.bukkit.Location;
|
2023-05-30 11:20:31 +02:00
|
|
|
import org.bukkit.Material;
|
2020-08-25 01:01:11 +02:00
|
|
|
import org.bukkit.block.Block;
|
2023-05-30 11:20:31 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2020-08-25 01:01:11 +02:00
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
2023-05-25 19:20:03 +02:00
|
|
|
public class BlockStackManagerImpl implements BlockStackManager {
|
2020-08-25 01:01:11 +02:00
|
|
|
|
2023-04-10 17:14:37 +02:00
|
|
|
private final Map<Location, BlockStack> registeredBlocks = new HashMap<>();
|
2020-08-25 01:01:11 +02:00
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2020-08-25 01:01:11 +02:00
|
|
|
public void addBlocks(Map<Location, BlockStack> blocks) {
|
|
|
|
this.registeredBlocks.putAll(blocks);
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2020-08-25 01:01:11 +02:00
|
|
|
public BlockStack addBlock(BlockStack blockStack) {
|
|
|
|
this.registeredBlocks.put(roundLocation(blockStack.getLocation()), blockStack);
|
|
|
|
return blockStack;
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2020-08-25 01:01:11 +02:00
|
|
|
public BlockStack removeBlock(Location location) {
|
|
|
|
return registeredBlocks.remove(roundLocation(location));
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2023-04-07 18:58:21 +02:00
|
|
|
public BlockStack getBlock(Location location) {
|
|
|
|
return this.registeredBlocks.get(location);
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2023-06-29 11:18:18 +02:00
|
|
|
public BlockStack getBlock(Block block, XMaterial material) {
|
2023-04-10 17:17:00 +02:00
|
|
|
return this.getBlock(block.getLocation());
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2023-06-29 11:18:18 +02:00
|
|
|
public BlockStack createBlock(Location location, XMaterial material) {
|
2023-05-25 19:20:03 +02:00
|
|
|
return this.registeredBlocks.computeIfAbsent(location, b -> new BlockStackImpl(material, location));
|
2020-08-25 01:01:11 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2023-04-07 18:58:21 +02:00
|
|
|
public BlockStack createBlock(Block block) {
|
2023-06-29 11:18:18 +02:00
|
|
|
return this.createBlock(block.getLocation(), XMaterial.matchXMaterial(block.getType().name()).get());
|
2020-08-25 01:01:11 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2020-08-25 01:01:11 +02:00
|
|
|
public boolean isBlock(Location location) {
|
|
|
|
return this.registeredBlocks.get(location) != null;
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
2020-08-25 01:01:11 +02:00
|
|
|
public Collection<BlockStack> getStacks() {
|
|
|
|
return Collections.unmodifiableCollection(this.registeredBlocks.values());
|
|
|
|
}
|
|
|
|
|
2023-06-05 16:25:37 +02:00
|
|
|
@Override
|
|
|
|
public Collection<Data> getStacksData() {
|
|
|
|
return Collections.unmodifiableCollection(this.registeredBlocks.values());
|
|
|
|
}
|
|
|
|
|
2023-05-30 11:20:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isMaterialBlacklisted(ItemStack item) {
|
|
|
|
return UltimateStacker.isMaterialBlacklisted(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isMaterialBlacklisted(String type) {
|
|
|
|
return UltimateStacker.isMaterialBlacklisted(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isMaterialBlacklisted(Material type) {
|
|
|
|
return UltimateStacker.isMaterialBlacklisted(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isMaterialBlacklisted(Material type, byte data) {
|
|
|
|
return UltimateStacker.isMaterialBlacklisted(type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-25 01:01:11 +02:00
|
|
|
private Location roundLocation(Location location) {
|
|
|
|
location = location.clone();
|
|
|
|
location.setX(location.getBlockX());
|
|
|
|
location.setY(location.getBlockY());
|
|
|
|
location.setZ(location.getBlockZ());
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
}
|