mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Fix PlotItem.
This commit is contained in:
parent
8f23299e7d
commit
e724aa8caf
@ -1,10 +1,28 @@
|
|||||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
import com.github.intellectualsites.plotsquared.plot.object.LegacyPlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
import com.github.intellectualsites.plotsquared.plot.object.schematic.PlotItem;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -19,10 +37,12 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.material.*;
|
import org.bukkit.material.MaterialData;
|
||||||
|
import org.bukkit.material.Sandstone;
|
||||||
import javax.annotation.Nullable;
|
import org.bukkit.material.Step;
|
||||||
import java.util.*;
|
import org.bukkit.material.Tree;
|
||||||
|
import org.bukkit.material.WoodenStep;
|
||||||
|
import org.bukkit.material.Wool;
|
||||||
|
|
||||||
@SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil {
|
@SuppressWarnings({"unused", "WeakerAccess"}) public class BukkitUtil extends WorldUtil {
|
||||||
|
|
||||||
@ -359,6 +379,10 @@ import java.util.*;
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BukkitLegacyMappings getBukkitLegacyMappings() {
|
||||||
|
return (BukkitLegacyMappings) PlotSquared.imp().getLegacyMappings();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) {
|
public boolean addItems(@NonNull final String worldName, @NonNull final PlotItem items) {
|
||||||
final World world = getWorld(worldName);
|
final World world = getWorld(worldName);
|
||||||
@ -370,8 +394,9 @@ import java.util.*;
|
|||||||
if (state instanceof InventoryHolder) {
|
if (state instanceof InventoryHolder) {
|
||||||
InventoryHolder holder = (InventoryHolder) state;
|
InventoryHolder holder = (InventoryHolder) state;
|
||||||
Inventory inv = holder.getInventory();
|
Inventory inv = holder.getInventory();
|
||||||
for (int i = 0; i < items.id.length; i++) {
|
for (int i = 0; i < items.types.length; i++) {
|
||||||
ItemStack item = new ItemStack(LegacyMappings.fromLegacyId(items.id[i]).getMaterial(), items.amount[i], items.data[i]);
|
// ItemStack item = new ItemStack(LegacyMappings.fromLegacyId(items.id[i]).getMaterial(), items.amount[i], items.data[i]);
|
||||||
|
ItemStack item = new ItemStack(items.types[i].to(Material.class), items.amount[i]);
|
||||||
inv.addItem(item);
|
inv.addItem(item);
|
||||||
}
|
}
|
||||||
state.update(true);
|
state.update(true);
|
||||||
@ -385,7 +410,7 @@ import java.util.*;
|
|||||||
return Material.getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH));
|
return Material.getMaterial(((StringPlotBlock) plotBlock).getItemId().toUpperCase(Locale.ENGLISH));
|
||||||
} else {
|
} else {
|
||||||
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
final LegacyPlotBlock legacyPlotBlock = (LegacyPlotBlock) plotBlock;
|
||||||
return LegacyMappings.fromLegacyId(legacyPlotBlock.getId()).getMaterial();
|
return getBukkitLegacyMappings().fromLegacyToString(legacyPlotBlock.getId(), legacyPlotBlock.getData()).to(Material.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ public abstract class PlotBlock implements ConfigurationSerializable {
|
|||||||
public static PlotBlock deserialize(@NonNull final Map<String, Object> map) {
|
public static PlotBlock deserialize(@NonNull final Map<String, Object> map) {
|
||||||
if (map.containsKey("material")) {
|
if (map.containsKey("material")) {
|
||||||
final Object object = map.get("material");
|
final Object object = map.get("material");
|
||||||
return get(object);
|
return get(object.toString());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -52,6 +52,21 @@ public abstract class PlotBlock implements ConfigurationSerializable {
|
|||||||
return ImmutableMap.of("material", this.getRawId());
|
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 abstract boolean isAir();
|
||||||
|
|
||||||
public static StringPlotBlock get(@NonNull final String itemId) {
|
public static StringPlotBlock get(@NonNull final String itemId) {
|
||||||
|
@ -1,20 +1,22 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.object.schematic;
|
package com.github.intellectualsites.plotsquared.plot.object.schematic;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
|
|
||||||
public class PlotItem {
|
public class PlotItem {
|
||||||
|
|
||||||
public final int x;
|
public final int x;
|
||||||
public final int y;
|
public final int y;
|
||||||
public final int z;
|
public final int z;
|
||||||
public final short[] id;
|
// public final short[] id;
|
||||||
public final byte[] data;
|
// public final byte[] data;
|
||||||
|
public final PlotBlock[] types;
|
||||||
public final byte[] amount;
|
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.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.id = id;
|
this.types = types;
|
||||||
this.data = data;
|
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user