24package com.dreamfirestudios.dreamcore.DreamBlockDisplay;
26import org.bukkit.Bukkit;
27import org.bukkit.Location;
28import org.bukkit.World;
29import org.bukkit.block.data.BlockData;
30import org.bukkit.entity.BlockDisplay;
32import java.util.ArrayList;
49 private static final List<BlockDisplay> pool =
new ArrayList<>();
54 private static final Location HIDDEN_LOCATION =
55 new Location(Bukkit.getWorlds().isEmpty() ?
null : Bukkit.getWorlds().get(0), 0, -1000, 0);
65 public static BlockDisplay
acquire(World world, Location location, BlockData blockData) {
66 if (world ==
null || location ==
null || blockData ==
null) {
67 throw new IllegalArgumentException(
"World, location, and blockData cannot be null");
71 if (!pool.isEmpty()) {
72 display = pool.remove(pool.size() - 1);
73 display.teleport(location);
74 display.setBlock(blockData);
76 display = world.spawn(location, BlockDisplay.class, bd -> bd.setBlock(blockData));
88 public static void release(BlockDisplay display) {
89 if (display ==
null || !display.isValid())
return;
91 display.setBlock(Bukkit.createBlockData(
"minecraft:air"));
92 if (HIDDEN_LOCATION.getWorld() !=
null) {
93 display.teleport(HIDDEN_LOCATION);
105 for (BlockDisplay display : pool) {
106 if (display.isValid()) {
A simple pool for BlockDisplay entities to reduce the overhead of frequent spawning and removal.
static void release(BlockDisplay display)
Releases a BlockDisplay back into the pool for later reuse.
static BlockDisplay acquire(World world, Location location, BlockData blockData)
Acquires a BlockDisplay from the pool if available, or spawns a new one.
static void clear()
Clears the entire pool and removes all pooled displays from the world.