3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 12:00:07 +01:00

Cleanup Bukkit internal id usage.

Dieser Commit ist enthalten in:
wizjany 2019-06-14 20:34:38 -04:00 committet von Matthew Miller
Ursprung 27c7d488a2
Commit 0088fe79b3
4 geänderte Dateien mit 6 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,6 @@
package com.sk89q.worldedit.bukkit;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
@ -36,7 +35,6 @@ import javax.annotation.Nullable;
public class BukkitBlockRegistry extends BundledBlockRegistry {
private Map<Material, BukkitBlockMaterial> materialMap = new EnumMap<>(Material.class);
private BlockState[] statesById = new BlockState[2 << 14];
@Nullable
@Override
@ -59,26 +57,10 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
@Override
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) {
id = WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
} else {
id = super.getInternalBlockStateId(state);
return WorldEditPlugin.getInstance().getBukkitImplAdapter().getInternalBlockStateId(state);
}
if (id.isPresent()) {
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;
return OptionalInt.empty();
}
public static class BukkitBlockMaterial extends PassthroughBlockMaterial {

Datei anzeigen

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

Datei anzeigen

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