mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Update to WorldEdit 7 (and WE7-compatible schematics, *hopefully keeping legacy*)
This commit is contained in:
@ -1,47 +1,14 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.ClassicPlotMeConnector;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.ChunkListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.EntityPortal_1_7_9;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.EntitySpawnListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents183;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents_1_8;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlayerEvents_1_9;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener_1_12;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.PlotPlusListener_Legacy;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.SingleWorldListener;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.WorldEvents;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.listeners.*;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.titles.DefaultTitle_111;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitBlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChatManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitCommand;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEconHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitLegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.Metrics;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.SendChunk;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.*;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.block.BukkitLocalQueue;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.DefaultUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.FileUUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.OfflineUUIDWrapper;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.SQLUUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.uuid.*;
|
||||
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
|
||||
import com.github.intellectualsites.plotsquared.plot.IPlotMain;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
@ -52,58 +19,20 @@ import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridGen;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.generator.IndependentPlotGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.BlockRegistry;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.SetupObject;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.chat.PlainChatManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.PlotAreaManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SinglePlotAreaManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.worlds.SingleWorldGenerator;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.AbstractTitle;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChatManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ConsoleColors;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
||||
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
@ -116,6 +45,15 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils.getRefClass;
|
||||
|
||||
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
||||
|
||||
@Getter private static WorldEdit worldEdit;
|
||||
@ -168,12 +106,13 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
}
|
||||
|
||||
private final LegacyMappings legacyMappings = new BukkitLegacyMappings();
|
||||
private final BlockRegistry<Material> blockRegistry =
|
||||
new BukkitBlockRegistry(Material.values());
|
||||
private int[] version;
|
||||
@Getter private String pluginName;
|
||||
@Getter private SingleWorldListener singleWorldListener;
|
||||
private Method methodUnloadChunk0;
|
||||
private boolean methodUnloadSetup = false;
|
||||
private final BlockRegistry<Material> blockRegistry = new BukkitBlockRegistry(Material.values());
|
||||
|
||||
@Override public int[] getServerVersion() {
|
||||
if (this.version == null) {
|
||||
@ -927,11 +866,10 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockRegistry<Material> getBlockRegistry() {
|
||||
@Override public BlockRegistry<Material> getBlockRegistry() {
|
||||
return this.blockRegistry;
|
||||
}
|
||||
|
||||
|
||||
@Override public LegacyMappings getLegacyMappings() {
|
||||
return this.legacyMappings;
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.object.schematic;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.jnbt.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.ItemType;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
import com.sk89q.jnbt.*;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
@ -39,21 +38,14 @@ public class StateWrapper {
|
||||
case "chest":
|
||||
List<Tag> itemsTag = this.tag.getListTag("Items").getValue();
|
||||
int length = itemsTag.size();
|
||||
short[] ids = new short[length];
|
||||
byte[] datas = new byte[length];
|
||||
String[] ids = new String[length];
|
||||
byte[] amounts = new byte[length];
|
||||
byte[] slots = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
Tag itemTag = itemsTag.get(i);
|
||||
CompoundTag itemComp = (CompoundTag) itemTag;
|
||||
short id = itemComp.getShort("id");
|
||||
String idStr = itemComp.getString("id");
|
||||
if (idStr != null && !MathMan.isInteger(idStr)) {
|
||||
idStr = idStr.split(":")[1].toLowerCase();
|
||||
id = (short) ItemType.getId(idStr);
|
||||
}
|
||||
String id = itemComp.getString("id");
|
||||
ids[i] = id;
|
||||
datas[i] = (byte) itemComp.getShort("Damage");
|
||||
amounts[i] = itemComp.getByte("Count");
|
||||
slots[i] = itemComp.getByte("Slot");
|
||||
}
|
||||
@ -67,7 +59,8 @@ public class StateWrapper {
|
||||
InventoryHolder holder = (InventoryHolder) state;
|
||||
Inventory inv = holder.getInventory();
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
ItemStack item = new ItemStack(ids[i], amounts[i], datas[i]);
|
||||
ItemStack item =
|
||||
new ItemStack(Material.getMaterial(ids[i]), (int) amounts[i]);
|
||||
inv.addItem(item);
|
||||
}
|
||||
state.update(true);
|
||||
@ -85,8 +78,7 @@ public class StateWrapper {
|
||||
InventoryHolder inv = (InventoryHolder) this.state;
|
||||
ItemStack[] contents = inv.getInventory().getContents();
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
values.put("Items",
|
||||
new ListTag("Items", CompoundTag.class, serializeInventory(contents)));
|
||||
values.put("Items", new ListTag(CompoundTag.class, serializeInventory(contents)));
|
||||
return new CompoundTag(values);
|
||||
}
|
||||
return null;
|
||||
@ -101,41 +93,29 @@ public class StateWrapper {
|
||||
for (int i = 0; i < items.length; ++i) {
|
||||
if (items[i] != null) {
|
||||
Map<String, Tag> tagData = serializeItem(items[i]);
|
||||
tagData.put("Slot", new ByteTag("Slot", (byte) i));
|
||||
tagData.put("Slot", new ByteTag((byte) i));
|
||||
tags.add(new CompoundTag(tagData));
|
||||
}
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Move this into the sponge module!
|
||||
*
|
||||
public Map<String, Tag> serializeItem(final org.spongepowered.api.item.inventory.ItemStack item) {
|
||||
final Map<String, Tag> data = new HashMap<String, Tag>();
|
||||
|
||||
// FIXME serialize sponge item
|
||||
|
||||
return data;
|
||||
}
|
||||
*/
|
||||
|
||||
public Map<String, Tag> serializeItem(ItemStack item) {
|
||||
Map<String, Tag> data = new HashMap<>();
|
||||
data.put("id", new ShortTag("id", (short) item.getTypeId()));
|
||||
data.put("Damage", new ShortTag("Damage", item.getDurability()));
|
||||
data.put("Count", new ByteTag("Count", (byte) item.getAmount()));
|
||||
data.put("id", new StringTag(item.getType().name()));
|
||||
data.put("Damage", new ShortTag(item.getDurability()));
|
||||
data.put("Count", new ByteTag((byte) item.getAmount()));
|
||||
if (!item.getEnchantments().isEmpty()) {
|
||||
List<CompoundTag> enchantmentList = new ArrayList<>();
|
||||
for (Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
|
||||
Map<String, Tag> enchantment = new HashMap<>();
|
||||
enchantment.put("id", new ShortTag("id", (short) entry.getKey().getId()));
|
||||
enchantment.put("lvl", new ShortTag("lvl", entry.getValue().shortValue()));
|
||||
enchantment.put("id", new StringTag(entry.getKey().toString()));
|
||||
enchantment.put("lvl", new ShortTag(entry.getValue().shortValue()));
|
||||
enchantmentList.add(new CompoundTag(enchantment));
|
||||
}
|
||||
Map<String, Tag> auxData = new HashMap<>();
|
||||
auxData.put("ench", new ListTag("ench", CompoundTag.class, enchantmentList));
|
||||
data.put("tag", new CompoundTag("tag", auxData));
|
||||
auxData.put("ench", new ListTag(CompoundTag.class, enchantmentList));
|
||||
data.put("tag", new CompoundTag(auxData));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
@ -5,20 +5,12 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.StringPlotBlock;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.*;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Borrowed from https://github.com/Phoenix616/IDConverter/blob/master/mappings/src/main/java/de/themoep/idconverter/IdMappings.java
|
||||
* Original License:
|
||||
@ -705,8 +697,10 @@ public class BukkitLegacyMappings extends LegacyMappings {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestsMatch(@NonNull final String string) {
|
||||
final StringComparison<PlotBlock> comparison = new StringComparison<>(string, getPlotBlocks());
|
||||
public StringComparison<PlotBlock>.ComparisonResult getClosestsMatch(
|
||||
@NonNull final String string) {
|
||||
final StringComparison<PlotBlock> comparison =
|
||||
new StringComparison<>(string, getPlotBlocks());
|
||||
return comparison.getBestMatchAdvanced();
|
||||
}
|
||||
|
||||
@ -812,8 +806,7 @@ public class BukkitLegacyMappings extends LegacyMappings {
|
||||
return LegacyPlotBlock.get(numericalId, dataValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
return this.newName;
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,29 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.schematic.StateWrapper;
|
||||
import com.github.intellectualsites.plotsquared.jnbt.*;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.ChunkLoc;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RegionWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||
import com.sk89q.jnbt.*;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Schematic Handler.
|
||||
*/
|
||||
public class BukkitSchematicHandler extends SchematicHandler {
|
||||
public abstract class BukkitSchematicHandler extends SchematicHandler {
|
||||
|
||||
@Override public void getCompoundTag(final String world, final Set<RegionWrapper> regions,
|
||||
final RunnableVal<CompoundTag> whenDone) {
|
||||
@ -34,25 +35,35 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
final Location bot = corners[0];
|
||||
Location top = corners[1];
|
||||
|
||||
CuboidRegion cuboidRegion =
|
||||
new CuboidRegion(BukkitUtil.IMP.getWeWorld(world), bot.getBlockVector3(),
|
||||
top.getBlockVector3());
|
||||
|
||||
final int width = top.getX() - bot.getX() + 1;
|
||||
int height = top.getY() - bot.getY() + 1;
|
||||
final int length = top.getZ() - bot.getZ() + 1;
|
||||
// Main Schematic tag
|
||||
final HashMap<String, Tag> schematic = new HashMap<>();
|
||||
schematic.put("Width", new ShortTag("Width", (short) width));
|
||||
schematic.put("Length", new ShortTag("Length", (short) length));
|
||||
schematic.put("Height", new ShortTag("Height", (short) height));
|
||||
schematic.put("Materials", new StringTag("Materials", "Alpha"));
|
||||
schematic.put("WEOriginX", new IntTag("WEOriginX", 0));
|
||||
schematic.put("WEOriginY", new IntTag("WEOriginY", 0));
|
||||
schematic.put("WEOriginZ", new IntTag("WEOriginZ", 0));
|
||||
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
|
||||
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
|
||||
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
|
||||
// Arrays of data types
|
||||
final List<CompoundTag> tileEntities = new ArrayList<>();
|
||||
final byte[] blocks = new byte[width * height * length];
|
||||
final byte[] blockData = new byte[width * height * length];
|
||||
Map<String, Tag> schematic = new HashMap<>();
|
||||
schematic.put("Version", new IntTag(1));
|
||||
|
||||
Map<String, Tag> metadata = new HashMap<>();
|
||||
metadata.put("WEOffsetX", new IntTag(0));
|
||||
metadata.put("WEOffsetY", new IntTag(0));
|
||||
metadata.put("WEOffsetZ", new IntTag(0));
|
||||
|
||||
schematic.put("Metadata", new CompoundTag(metadata));
|
||||
|
||||
schematic.put("Width", new ShortTag((short) width));
|
||||
schematic.put("Height", new ShortTag((short) height));
|
||||
schematic.put("Length", new ShortTag((short) length));
|
||||
|
||||
// The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin'
|
||||
schematic.put("Offset", new IntArrayTag(new int[] {0, 0, 0,}));
|
||||
|
||||
final int[] paletteMax = {0};
|
||||
Map<String, Integer> palette = new HashMap<>();
|
||||
|
||||
List<CompoundTag> tileEntities = new ArrayList<>();
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length);
|
||||
// Queue
|
||||
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
|
||||
TaskManager.runTask(new Runnable() {
|
||||
@ -60,15 +71,18 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
if (queue.isEmpty()) {
|
||||
TaskManager.runTaskAsync(new Runnable() {
|
||||
@Override public void run() {
|
||||
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
|
||||
schematic.put("Data", new ByteArrayTag("Data", blockData));
|
||||
schematic.put("Entities",
|
||||
new ListTag("Entities", CompoundTag.class,
|
||||
new ArrayList<Tag>()));
|
||||
schematic.put("PaletteMax", new IntTag(paletteMax[0]));
|
||||
|
||||
Map<String, Tag> paletteTag = new HashMap<>();
|
||||
palette.forEach(
|
||||
(key, value) -> paletteTag.put(key, new IntTag(value)));
|
||||
|
||||
schematic.put("Palette", new CompoundTag(paletteTag));
|
||||
schematic
|
||||
.put("BlockData", new ByteArrayTag(buffer.toByteArray()));
|
||||
schematic.put("TileEntities",
|
||||
new ListTag("TileEntities", CompoundTag.class,
|
||||
tileEntities));
|
||||
whenDone.value = new CompoundTag("Schematic", schematic);
|
||||
new ListTag(CompoundTag.class, tileEntities));
|
||||
whenDone.value = new CompoundTag(schematic);
|
||||
TaskManager.runTask(whenDone);
|
||||
System.gc();
|
||||
System.gc();
|
||||
@ -140,148 +154,48 @@ public class BukkitSchematicHandler extends SchematicHandler {
|
||||
for (int x = xxb; x <= xxt; x++) {
|
||||
int rx = x - bx;
|
||||
int index = i2 + rx;
|
||||
Block block = worldObj.getBlockAt(x, y, z);
|
||||
int id = LegacyMappings.fromNewName(block.getType().name()).getNumericalId();
|
||||
switch (id) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 4:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
case 24:
|
||||
case 30:
|
||||
case 32:
|
||||
case 37:
|
||||
case 39:
|
||||
case 40:
|
||||
case 41:
|
||||
case 42:
|
||||
case 45:
|
||||
case 46:
|
||||
case 47:
|
||||
case 48:
|
||||
case 49:
|
||||
case 51:
|
||||
case 55:
|
||||
case 56:
|
||||
case 57:
|
||||
case 58:
|
||||
case 60:
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
case 11:
|
||||
case 73:
|
||||
case 74:
|
||||
case 78:
|
||||
case 79:
|
||||
case 80:
|
||||
case 81:
|
||||
case 82:
|
||||
case 83:
|
||||
case 85:
|
||||
case 87:
|
||||
case 88:
|
||||
case 101:
|
||||
case 102:
|
||||
case 103:
|
||||
case 110:
|
||||
case 112:
|
||||
case 113:
|
||||
case 121:
|
||||
case 122:
|
||||
case 129:
|
||||
case 133:
|
||||
case 165:
|
||||
case 166:
|
||||
case 169:
|
||||
case 170:
|
||||
case 172:
|
||||
case 173:
|
||||
case 174:
|
||||
case 181:
|
||||
case 182:
|
||||
case 188:
|
||||
case 189:
|
||||
case 190:
|
||||
case 191:
|
||||
case 192:
|
||||
break;
|
||||
case 54:
|
||||
case 130:
|
||||
case 142:
|
||||
case 27:
|
||||
case 137:
|
||||
case 52:
|
||||
case 154:
|
||||
case 84:
|
||||
case 25:
|
||||
case 144:
|
||||
case 138:
|
||||
case 176:
|
||||
case 177:
|
||||
case 63:
|
||||
case 68:
|
||||
case 323:
|
||||
case 117:
|
||||
case 116:
|
||||
case 28:
|
||||
case 66:
|
||||
case 157:
|
||||
case 61:
|
||||
case 62:
|
||||
case 140:
|
||||
case 146:
|
||||
case 149:
|
||||
case 150:
|
||||
case 158:
|
||||
case 23:
|
||||
case 123:
|
||||
case 124:
|
||||
case 29:
|
||||
case 33:
|
||||
case 151:
|
||||
case 178:
|
||||
// TODO implement fully
|
||||
BlockState state = block.getState();
|
||||
if (state != null) {
|
||||
StateWrapper wrapper =
|
||||
new StateWrapper(state);
|
||||
CompoundTag rawTag = wrapper.getTag();
|
||||
if (rawTag != null) {
|
||||
Map<String, Tag> values =
|
||||
new HashMap<>(
|
||||
rawTag.getValue());
|
||||
values.put("id", new StringTag("id",
|
||||
wrapper.getId()));
|
||||
values.put("x", new IntTag("x", x));
|
||||
values.put("y", new IntTag("y", y));
|
||||
values.put("z", new IntTag("z", z));
|
||||
CompoundTag tileEntityTag =
|
||||
new CompoundTag(values);
|
||||
tileEntities.add(tileEntityTag);
|
||||
}
|
||||
}
|
||||
default:
|
||||
blockData[index] = block.getData();
|
||||
BlockVector3 point = BlockVector3.at(x, y, z);
|
||||
BaseBlock block =
|
||||
cuboidRegion.getWorld().getFullBlock(point);
|
||||
if (block.getNbtData() != null) {
|
||||
Map<String, Tag> values = new HashMap<>();
|
||||
for (Map.Entry<String, Tag> entry : block
|
||||
.getNbtData().getValue().entrySet()) {
|
||||
values
|
||||
.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
values.remove(
|
||||
"id"); // Remove 'id' if it exists. We want 'Id'
|
||||
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
|
||||
values
|
||||
.put("Id", new StringTag(block.getNbtId()));
|
||||
values.put("Pos",
|
||||
new IntArrayTag(new int[] {x, y, z}));
|
||||
|
||||
tileEntities.add(new CompoundTag(values));
|
||||
}
|
||||
// For optimization reasons, we are not supporting custom data types
|
||||
// Especially since the most likely reason beyond this range is modded servers in which the blocks
|
||||
// have NBT
|
||||
// if (type > 255) {
|
||||
// if (addBlocks == null) {
|
||||
// addBlocks = new byte[(blocks.length >> 1) + 1];
|
||||
// }
|
||||
// addBlocks[index >> 1] = (byte) (((index & 1) == 0) ?
|
||||
// (addBlocks[index >> 1] & 0xF0) | ((type >> 8) & 0xF) : (addBlocks[index >> 1] & 0xF) | (((type
|
||||
// >> 8) & 0xF) << 4));
|
||||
// }
|
||||
blocks[index] = (byte) id;
|
||||
String blockKey =
|
||||
block.toImmutableState().getAsString();
|
||||
int blockId;
|
||||
if (palette.containsKey(blockKey)) {
|
||||
blockId = palette.get(blockKey);
|
||||
} else {
|
||||
blockId = paletteMax[0];
|
||||
palette.put(blockKey, blockId);
|
||||
paletteMax[0]++;
|
||||
}
|
||||
|
||||
while ((blockId & -128) != 0) {
|
||||
buffer.write(blockId & 127 | 128);
|
||||
blockId >>>= 7;
|
||||
}
|
||||
buffer.write(blockId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,6 +467,10 @@ import org.bukkit.material.Wool;
|
||||
}
|
||||
}
|
||||
|
||||
public com.sk89q.worldedit.world.World getWeWorld(String world) {
|
||||
return new BukkitWorld(Bukkit.getWorld(world));
|
||||
}
|
||||
|
||||
@Override public PlotBlock getBlock(@NonNull final Location location) {
|
||||
final World world = getWorld(location.getWorld());
|
||||
final Block block = world.getBlockAt(location.getX(), location.getY(), location.getZ());
|
||||
|
Reference in New Issue
Block a user