Fix PlotItem.

This commit is contained in:
sauilitired
2018-12-19 18:24:35 +01:00
parent 8f23299e7d
commit e724aa8caf
3 changed files with 57 additions and 15 deletions

View File

@ -43,7 +43,7 @@ public abstract class PlotBlock implements ConfigurationSerializable {
public static PlotBlock deserialize(@NonNull final Map<String, Object> map) {
if (map.containsKey("material")) {
final Object object = map.get("material");
return get(object);
return get(object.toString());
}
return null;
}
@ -52,6 +52,21 @@ public abstract class PlotBlock implements ConfigurationSerializable {
return ImmutableMap.of("material", this.getRawId());
}
public <T> T to(@NonNull final Class<T> clazz) {
if (blockRegistry == null) {
blockRegistry = PlotSquared.imp().getBlockRegistry();
if (blockRegistry == null) {
throw new UnsupportedOperationException("The PlotSquared implementation has not registered a custom block registry."
+ " This method can't be used.");
}
conversionType = blockRegistry.getType();
}
if (!clazz.equals(conversionType)) {
throw new UnsupportedOperationException("The PlotSquared implementation has not registered a block registry for this object type");
}
return clazz.cast(blockRegistry.getItem(this));
}
public abstract boolean isAir();
public static StringPlotBlock get(@NonNull final String itemId) {

View File

@ -1,20 +1,22 @@
package com.github.intellectualsites.plotsquared.plot.object.schematic;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
public class PlotItem {
public final int x;
public final int y;
public final int z;
public final short[] id;
public final byte[] data;
// public final short[] id;
// public final byte[] data;
public final PlotBlock[] types;
public final byte[] amount;
public PlotItem(short x, short y, short z, short[] id, byte[] data, byte[] amount) {
public PlotItem(short x, short y, short z, PlotBlock[] types, byte[] amount) {
this.x = x;
this.y = y;
this.z = z;
this.id = id;
this.data = data;
this.types = types;
this.amount = amount;
}
}