mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Cache conversions to BaseBlock and fix leaky abstraction
This commit is contained in:
parent
bbff898073
commit
908a5784a1
@ -1,6 +1,10 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.object;
|
package com.github.intellectualsites.plotsquared.plot.object;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
public class LegacyPlotBlock extends PlotBlock {
|
public class LegacyPlotBlock extends PlotBlock {
|
||||||
|
|
||||||
@ -15,6 +19,7 @@ public class LegacyPlotBlock extends PlotBlock {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Setter private BaseBlock baseBlock = null;
|
||||||
@Getter public final short id;
|
@Getter public final short id;
|
||||||
@Getter public final byte data;
|
@Getter public final byte data;
|
||||||
|
|
||||||
@ -27,6 +32,13 @@ public class LegacyPlotBlock extends PlotBlock {
|
|||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public BaseBlock getBaseBlock() {
|
||||||
|
if (baseBlock == null) {
|
||||||
|
baseBlock = LegacyMapper.getInstance().getBlockFromLegacy(id, data).toBaseBlock();
|
||||||
|
}
|
||||||
|
return baseBlock;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean isAir() {
|
@Override public boolean isAir() {
|
||||||
return this.id == 0;
|
return this.id == 0;
|
||||||
}
|
}
|
||||||
|
@ -133,4 +133,6 @@ public abstract class PlotBlock implements ConfigurationSerializable {
|
|||||||
|
|
||||||
public abstract Object getRawId();
|
public abstract Object getRawId();
|
||||||
|
|
||||||
|
public abstract BaseBlock getBaseBlock();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.object;
|
package com.github.intellectualsites.plotsquared.plot.object;
|
||||||
|
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@ -15,7 +16,7 @@ public class StringPlotBlock extends PlotBlock {
|
|||||||
private static final Map<String, StringPlotBlock> STRING_PLOT_BLOCK_CACHE = new HashMap<>();
|
private static final Map<String, StringPlotBlock> STRING_PLOT_BLOCK_CACHE = new HashMap<>();
|
||||||
@Getter private final String nameSpace;
|
@Getter private final String nameSpace;
|
||||||
@Getter private final String itemId;
|
@Getter private final String itemId;
|
||||||
@Getter @Setter private BaseBlock baseBlock = null;
|
@Setter private BaseBlock baseBlock = null;
|
||||||
private boolean isForeign = false;
|
private boolean isForeign = false;
|
||||||
|
|
||||||
public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) {
|
public StringPlotBlock(@NonNull final String nameSpace, @NonNull final String itemId) {
|
||||||
@ -79,6 +80,13 @@ public class StringPlotBlock extends PlotBlock {
|
|||||||
return this.getItemId();
|
return this.getItemId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override public BaseBlock getBaseBlock() {
|
||||||
|
if (baseBlock == null) {
|
||||||
|
baseBlock = BlockTypes.get(itemId).getDefaultState().toBaseBlock();
|
||||||
|
}
|
||||||
|
return baseBlock;
|
||||||
|
}
|
||||||
|
|
||||||
@Override public boolean equals(Object obj) {
|
@Override public boolean equals(Object obj) {
|
||||||
if (this == obj) {
|
if (this == obj) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -121,15 +121,7 @@ public abstract class BasicLocalBlockQueue extends LocalBlockQueue {
|
|||||||
// Trying to mix PlotBlock and BaseBlock leads to all kinds of issues.
|
// Trying to mix PlotBlock and BaseBlock leads to all kinds of issues.
|
||||||
// Since BaseBlock has more features than PlotBlock, simply convert
|
// Since BaseBlock has more features than PlotBlock, simply convert
|
||||||
// all PlotBlocks to BaseBlocks
|
// all PlotBlocks to BaseBlocks
|
||||||
if (id instanceof StringPlotBlock) {
|
return setBlock(x, y, z, id.getBaseBlock());
|
||||||
StringPlotBlock stringPlotBlock = (StringPlotBlock) id;
|
|
||||||
return setBlock(x, y, z, BlockTypes.get(stringPlotBlock.getItemId()).getDefaultState().toBaseBlock());
|
|
||||||
} else if (id instanceof LegacyPlotBlock) {
|
|
||||||
LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) id;
|
|
||||||
return setBlock(x, y, z, LegacyMapper.getInstance().getBlockFromLegacy(legacyPlotBlock.getId(), legacyPlotBlock.getData()).toBaseBlock());
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Unknown PlotBock class: " + id.getClass().getName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public final boolean setBiome(int x, int z, String biome) {
|
@Override public final boolean setBiome(int x, int z, String biome) {
|
||||||
|
Loading…
Reference in New Issue
Block a user