Cleanup Bukkit internal id usage.

This commit is contained in:
wizjany 2019-06-14 20:34:38 -04:00 committed by Matthew Miller
parent 27c7d488a2
commit 0088fe79b3
4 changed files with 6 additions and 26 deletions

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.bukkit; package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -36,7 +35,6 @@ import javax.annotation.Nullable;
public class BukkitBlockRegistry extends BundledBlockRegistry { public class BukkitBlockRegistry extends BundledBlockRegistry {
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class); private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
private BlockState[] statesById = new BlockState[2 << 14];
@Nullable @Nullable
@Override @Override
@ -59,26 +57,10 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
@Override @Override
public OptionalInt getInternalBlockStateId(BlockState state) { public OptionalInt getInternalBlockStateId(BlockState state) {
if (state.getBlockType() == BlockTypes.AIR) {
statesById[0] = state;
return OptionalInt.of(0);
}
final OptionalInt id;
if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() != null) {
id = WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state); return WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
} else {
id = super.getInternalBlockStateId(state);
} }
if (id.isPresent()) { return OptionalInt.empty();
final int idx = id.getAsInt();
if (statesById.length <= idx) {
BlockState[] newArr = new BlockState[statesById.length * 2];
System.arraycopy(statesById, 0, newArr, 0, statesById.length);
statesById = newArr;
}
statesById[idx] = state;
}
return id;
} }
public static class BukkitBlockMaterial extends PassthroughBlockMaterial { public static class BukkitBlockMaterial extends PassthroughBlockMaterial {

View File

@ -48,6 +48,7 @@ import org.bukkit.block.Chest;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.inventory.DoubleChestInventory; import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.slf4j.Logger; import org.slf4j.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -238,15 +239,12 @@ public class BukkitWorld extends AbstractWorld {
@Override @Override
public boolean clearContainerBlockContents(BlockVector3 pt) { public boolean clearContainerBlockContents(BlockVector3 pt) {
Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ());
if (block == null) {
return false;
}
BlockState state = block.getState(); BlockState state = block.getState();
if (!(state instanceof org.bukkit.inventory.InventoryHolder)) { if (!(state instanceof InventoryHolder)) {
return false; return false;
} }
org.bukkit.inventory.InventoryHolder chest = (org.bukkit.inventory.InventoryHolder) state; InventoryHolder chest = (InventoryHolder) state;
Inventory inven = chest.getInventory(); Inventory inven = chest.getInventory();
if (chest instanceof Chest) { if (chest instanceof Chest) {
inven = getBlockInventory((Chest) chest); inven = getBlockInventory((Chest) chest);

View File

@ -27,7 +27,7 @@ import java.util.OptionalInt;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
public class BlockStateIdAccess { public final class BlockStateIdAccess {
private BlockStateIdAccess() { private BlockStateIdAccess() {
} }