mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-11-16 17:16:11 +00:00
Cleanup Bukkit internal id usage.
This commit is contained in:
parent
27c7d488a2
commit
0088fe79b3
@ -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 {
|
||||||
|
@ -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);
|
||||||
|
Binary file not shown.
@ -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() {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user