diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java index 730e6c4e..96ec50d2 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/FaweBukkit.java @@ -20,6 +20,7 @@ import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.StringMan; import com.boydti.fawe.util.TaskManager; @@ -72,7 +73,7 @@ public class FaweBukkit implements IFawe, Listener { } } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); Bukkit.getServer().shutdown(); } TaskManager.IMP.task(new Runnable() { @@ -158,7 +159,7 @@ public class FaweBukkit implements IFawe, Listener { this.version[2] = Integer.parseInt(split[2]); } } catch (final NumberFormatException e) { - e.printStackTrace(); + MainUtil.handleError(e); Fawe.debug(StringMan.getString(Bukkit.getBukkitVersion())); Fawe.debug(StringMan.getString(Bukkit.getBukkitVersion().split("-")[0].split("\\."))); return new int[] { Integer.MAX_VALUE, 0, 0 }; @@ -235,7 +236,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new Worldguard(worldguardPlugin, this)); Fawe.debug("Plugin 'WorldGuard' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } final Plugin plotmePlugin = Bukkit.getServer().getPluginManager().getPlugin("PlotMe"); @@ -244,7 +245,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new PlotMeFeature(plotmePlugin, this)); Fawe.debug("Plugin 'PlotMe' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } final Plugin townyPlugin = Bukkit.getServer().getPluginManager().getPlugin("Towny"); @@ -253,7 +254,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new TownyFeature(townyPlugin, this)); Fawe.debug("Plugin 'Towny' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } final Plugin factionsPlugin = Bukkit.getServer().getPluginManager().getPlugin("Factions"); @@ -270,7 +271,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new FactionsOneFeature(factionsPlugin, this)); Fawe.debug("Plugin 'FactionsUUID' found. Using it now."); } catch (Throwable e3) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -282,7 +283,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new ResidenceFeature(residencePlugin, this)); Fawe.debug("Plugin 'Residence' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } final Plugin griefpreventionPlugin = Bukkit.getServer().getPluginManager().getPlugin("GriefPrevention"); @@ -291,7 +292,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new GriefPreventionFeature(griefpreventionPlugin, this)); Fawe.debug("Plugin 'GriefPrevention' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } final Plugin preciousstonesPlugin = Bukkit.getServer().getPluginManager().getPlugin("PreciousStones"); @@ -300,7 +301,7 @@ public class FaweBukkit implements IFawe, Listener { managers.add(new PreciousStonesFeature(preciousstonesPlugin, this)); Fawe.debug("Plugin 'PreciousStones' found. Using it now."); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } return managers; diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/Metrics.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/Metrics.java index 16d97623..3d2a1494 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/Metrics.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/Metrics.java @@ -1,6 +1,7 @@ package com.boydti.fawe.bukkit; import com.boydti.fawe.Fawe; +import com.boydti.fawe.util.MainUtil; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.File; @@ -89,7 +90,7 @@ public class Metrics { gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8")); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } finally { if (gzos != null) { try { @@ -243,7 +244,7 @@ public class Metrics { // Each post thereafter will be a ping this.firstPost = false; } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); if (Metrics.this.debug) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); } @@ -431,7 +432,7 @@ public class Metrics { } } catch (Exception e) { if (this.debug) { - e.printStackTrace(); + MainUtil.handleError(e); } } } diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java index 65128ac0..61ce2fa4 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/regions/FactionsOneFeature.java @@ -3,6 +3,7 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.Perm; import com.massivecraft.factions.FLocation; import java.lang.reflect.Method; @@ -106,7 +107,7 @@ public class FactionsOneFeature extends BukkitMaskManager implements Listener { } return true; } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return false; } } diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java index bc8c641b..f0e20a50 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_0.java @@ -6,6 +6,7 @@ import com.boydti.fawe.example.CharFaweChunk; import com.boydti.fawe.example.NMSMappedFaweQueue; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.bukkit.BukkitUtil; @@ -246,13 +247,13 @@ public abstract class BukkitQueue_0 extends NMSMa } return true; } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } @Override - public FaweChunk getChunk(int x, int z) { + public FaweChunk getFaweChunk(int x, int z) { return new CharFaweChunk(this, x, z) { @Override public Chunk getNewChunk() { diff --git a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java index 5f300e8a..ef20db9d 100644 --- a/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java +++ b/bukkit0/src/main/java/com/boydti/fawe/bukkit/v0/BukkitQueue_All.java @@ -1,6 +1,7 @@ package com.boydti.fawe.bukkit.v0; import com.boydti.fawe.FaweCache; +import com.sk89q.jnbt.CompoundTag; import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; @@ -20,7 +21,17 @@ public class BukkitQueue_All extends BukkitQueue_0 { } @Override - public Chunk getCachedChunk(World impWorld, int cx, int cz) { + public Chunk getCachedSections(World impWorld, int cx, int cz) { return impWorld.getChunkAt(cx, cz); } + + @Override + public CompoundTag getTileEntity(Chunk chunk, int x, int y, int z) { + return null; + } + + @Override + public Chunk getChunk(World world, int x, int z) { + return world.getChunkAt(x, z); + } } diff --git a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java index 6b34a306..db10602c 100644 --- a/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java +++ b/bukkit18/src/main/java/com/boydti/fawe/bukkit/v1_8/BukkitQueue18R3.java @@ -11,6 +11,7 @@ import com.boydti.fawe.object.FaweLocation; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -68,11 +69,11 @@ public class BukkitQueue18R3 extends BukkitQueue_0 tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; - CharFaweChunk previous = (CharFaweChunk) getChunk(fs.getX(), fs.getZ()); + CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { @@ -126,16 +127,15 @@ public class BukkitQueue18R3 extends BukkitQueue_0 entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); NBTTagCompound tag = new NBTTagCompound(); - tile.b(tag); // readTileEntityIntoTag BlockPosition pos = entry.getKey(); - CompoundTag nativeTag = (CompoundTag) methodToNative.invoke(adapter, tag); - previous.setTile(pos.getX(), pos.getY(), pos.getZ(), nativeTag); + CompoundTag nativeTag = getTag(tile); + previous.setTile(pos.getX() & 15, pos.getY(), pos.getZ() & 15, nativeTag); } } if (entities != null) { for (Collection entityList : entities) { for (Entity ent : entityList) { - if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && !createdEntities.contains(ent.getUniqueID()))) { + if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) { continue; } int x = ((int) Math.round(ent.locX) & 15); @@ -164,6 +164,33 @@ public class BukkitQueue18R3 extends BukkitQueue_0 tiles = ((CraftChunk) chunk).getHandle().getTileEntities(); + pos.c(x, y, z); + TileEntity tile = tiles.get(pos); + return tile != null ? getTag(tile) : null; + } + + + @Override + public Chunk getChunk(World world, int x, int z) { + return world.getChunkAt(x, z); + } + @Override public boolean setComponents(FaweChunk fc, RunnableVal changeTask) { CharFaweChunk fs = (CharFaweChunk) fc; @@ -342,7 +369,7 @@ public class BukkitQueue18R3 extends BukkitQueue_0 { value.sectionPalettes[i] = paletteBlock; } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } return value; diff --git a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java index 4c9e7977..8cff18b4 100644 --- a/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java +++ b/bukkit19/src/main/java/com/boydti/fawe/bukkit/v1_9/BukkitQueue_1_9_R1.java @@ -8,6 +8,7 @@ import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -70,7 +71,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0= 0; j--) { final Object section = sections[j]; if (section == null) { @@ -202,7 +202,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; - CharFaweChunk previous = (CharFaweChunk) getChunk(fs.getX(), fs.getZ()); + CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); // Copy blocks char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { @@ -320,17 +320,16 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 entry : tiles.entrySet()) { TileEntity tile = entry.getValue(); NBTTagCompound tag = new NBTTagCompound(); - tile.save(tag); // readTagIntoEntity BlockPosition pos = entry.getKey(); - CompoundTag nativeTag = (CompoundTag) methodToNative.invoke(adapter, tag); - previous.setTile(pos.getX(), pos.getY(), pos.getZ(), nativeTag); + CompoundTag nativeTag = getTag(tile); + previous.setTile(pos.getX() & 15, pos.getY(), pos.getZ() & 15, nativeTag); } } // Copy entities if (entities != null) { for (Collection entityList : entities) { for (Entity ent : entityList) { - if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && !createdEntities.contains(ent.getUniqueID()))) { + if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) { continue; } int x = ((int) Math.round(ent.locX) & 15); @@ -359,6 +358,32 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 tiles = ((CraftChunk) chunk).getHandle().getTileEntities(); + pos.c(x, y, z); + TileEntity tile = tiles.get(pos); + return tile != null ? getTag(tile) : null; + } + + public CompoundTag getTag(TileEntity tile) { + try { + NBTTagCompound tag = new NBTTagCompound(); + tile.save(tag); // readTagIntoEntity + return (CompoundTag) methodToNative.invoke(adapter, tag); + } catch (Exception e) { + MainUtil.handleError(e); + return null; + } + } + + @Override + public Chunk getChunk(World world, int x, int z) { + return world.getChunkAt(x, z); + } + @Override public boolean setComponents(final FaweChunk fc, RunnableVal changeTask) { final BukkitChunk_1_9 fs = (BukkitChunk_1_9) fc; @@ -396,6 +421,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 ents = new ArrayList<>(entities[i]); for (Entity entity : ents) { if (entsToRemove.contains(entity.getUniqueID())) { +// System.out.println("REMOVE ENT (action): " + entity); nmsWorld.removeEntity(entity); } } @@ -445,6 +472,7 @@ public class BukkitQueue_1_9_R1 extends BukkitQueue_0 extends FaweChunk { @Override public CharFaweChunk copy(boolean shallow) { - CharFaweChunk copy = (CharFaweChunk) getParent().getChunk(getX(), getZ()); + CharFaweChunk copy = (CharFaweChunk) getParent().getFaweChunk(getX(), getZ()); if (shallow) { copy.ids = ids; copy.air = air; diff --git a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java index 40d858a5..de8424e1 100644 --- a/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/MappedFaweQueue.java @@ -7,6 +7,7 @@ import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; import com.sk89q.jnbt.CompoundTag; @@ -53,7 +54,7 @@ public abstract class MappedFaweQueue extends FaweQueue { try { thread.join(); } catch (InterruptedException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } } @@ -77,11 +78,11 @@ public abstract class MappedFaweQueue extends FaweQueue { public abstract boolean setComponents(FaweChunk fc, RunnableVal changeTask); @Override - public abstract FaweChunk getChunk(int x, int z); + public abstract FaweChunk getFaweChunk(int x, int z); public abstract boolean loadChunk(WORLD world, int x, int z, boolean generate); - public abstract CHUNK getCachedChunk(WORLD world, int cx, int cz); + public abstract CHUNK getCachedSections(WORLD world, int cx, int cz); @Override public boolean isChunkLoaded(int x, int z) { @@ -105,7 +106,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (x) << 32 | (z) & 0xFFFFFFFFL; FaweChunk result = this.blocks.get(pair); if (result == null) { - result = this.getChunk(x, z); + result = this.getFaweChunk(x, z); result.addNotifyTask(runnable); FaweChunk previous = this.blocks.put(pair, result); if (previous == null) { @@ -137,7 +138,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL; lastWrappedChunk = this.blocks.get(pair); if (lastWrappedChunk == null) { - lastWrappedChunk = this.getChunk(x >> 4, z >> 4); + lastWrappedChunk = this.getFaweChunk(x >> 4, z >> 4); lastWrappedChunk.setBlock(x & 15, y, z & 15, id, data); FaweChunk previous = this.blocks.put(pair, lastWrappedChunk); if (previous == null) { @@ -165,7 +166,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL; lastWrappedChunk = this.blocks.get(pair); if (lastWrappedChunk == null) { - lastWrappedChunk = this.getChunk(x >> 4, z >> 4); + lastWrappedChunk = this.getFaweChunk(x >> 4, z >> 4); lastWrappedChunk.setTile(x & 15, y, z & 15, tag); FaweChunk previous = this.blocks.put(pair, lastWrappedChunk); if (previous == null) { @@ -192,7 +193,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL; lastWrappedChunk = this.blocks.get(pair); if (lastWrappedChunk == null) { - lastWrappedChunk = this.getChunk(x >> 4, z >> 4); + lastWrappedChunk = this.getFaweChunk(x >> 4, z >> 4); lastWrappedChunk.setEntity(tag); FaweChunk previous = this.blocks.put(pair, lastWrappedChunk); if (previous == null) { @@ -219,7 +220,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (cx) << 32 | (cz) & 0xFFFFFFFFL; lastWrappedChunk = this.blocks.get(pair); if (lastWrappedChunk == null) { - lastWrappedChunk = this.getChunk(x >> 4, z >> 4); + lastWrappedChunk = this.getFaweChunk(x >> 4, z >> 4); lastWrappedChunk.removeEntity(uuid); FaweChunk previous = this.blocks.put(pair, lastWrappedChunk); if (previous == null) { @@ -238,7 +239,7 @@ public abstract class MappedFaweQueue extends FaweQueue { long pair = (long) (x >> 4) << 32 | (z >> 4) & 0xFFFFFFFFL; FaweChunk result = this.blocks.get(pair); if (result == null) { - result = this.getChunk(x >> 4, z >> 4); + result = this.getFaweChunk(x >> 4, z >> 4); FaweChunk previous = this.blocks.put(pair, result); if (previous != null) { this.blocks.put(pair, previous); @@ -268,7 +269,7 @@ public abstract class MappedFaweQueue extends FaweQueue { } } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } return null; } @@ -283,7 +284,7 @@ public abstract class MappedFaweQueue extends FaweQueue { try { run.run(); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } } @@ -345,16 +346,16 @@ public abstract class MappedFaweQueue extends FaweQueue { public int lastChunkZ = Integer.MIN_VALUE; public int lastChunkY = Integer.MIN_VALUE; - private CHUNK lastChunk; - private SECTION lastSection; + public CHUNK lastChunkSections; + public SECTION lastSection; public SECTION getCachedSection(CHUNK chunk, int cy) { - return (SECTION) lastChunk; + return (SECTION) lastChunkSections; } public abstract int getCombinedId4Data(SECTION section, int x, int y, int z); - private final RunnableVal loadChunk = new RunnableVal() { + public final RunnableVal loadChunk = new RunnableVal() { @Override public void run(IntegerPair coord) { loadChunk(getWorld(), coord.x, coord.z, true); @@ -389,13 +390,13 @@ public abstract class MappedFaweQueue extends FaweQueue { return 0; } } - lastChunk = getCachedChunk(getWorld(), cx, cz); - lastSection = getCachedSection(lastChunk, cy); + lastChunkSections = getCachedSections(getWorld(), cx, cz); + lastSection = getCachedSection(lastChunkSections, cy); } else if (cy != lastChunkY) { - if (lastChunk == null) { + if (lastChunkSections == null) { return 0; } - lastSection = getCachedSection(lastChunk, cy); + lastSection = getCachedSection(lastChunkSections, cy); } if (lastSection == null) { diff --git a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java index adbf9cc9..e44d1970 100644 --- a/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/example/NMSMappedFaweQueue.java @@ -2,8 +2,10 @@ package com.boydti.fawe.example; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.FaweChunk; +import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.FaweQueue; import com.boydti.fawe.util.TaskManager; +import com.sk89q.jnbt.CompoundTag; import java.util.Collection; import java.util.Map; import java.util.Set; @@ -41,4 +43,24 @@ public abstract class NMSMappedFaweQueue ex public abstract void refreshChunk(WORLD world, CHUNK chunk); public abstract CharFaweChunk getPrevious(CharFaweChunk fs, CHUNKSECTION sections, Map tiles, Collection[] entities, Set createdEntities, boolean all) throws Exception; + + public abstract CompoundTag getTileEntity(CHUNK chunk, int x, int y, int z); + + public abstract CHUNK getChunk(WORLD world, int x, int z); + + private CHUNK lastChunk; + + @Override + public CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException { + if (y < 0 || y > 255) { + return null; + } + int cx = x >> 4; + int cz = z >> 4; + lastChunk = getChunk(getWorld(), cx, cz); + if (lastChunk == null) { + return null; + } + return getTileEntity(lastChunk, x, y, z); + } } diff --git a/core/src/main/java/com/boydti/fawe/object/FaweCommand.java b/core/src/main/java/com/boydti/fawe/object/FaweCommand.java index 6dc38130..079744ea 100644 --- a/core/src/main/java/com/boydti/fawe/object/FaweCommand.java +++ b/core/src/main/java/com/boydti/fawe/object/FaweCommand.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object; import com.boydti.fawe.config.BBC; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; public abstract class FaweCommand { @@ -41,7 +42,7 @@ public abstract class FaweCommand { } return true; } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } diff --git a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 8e93988b..a5ffc34c 100644 --- a/core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -7,6 +7,7 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.changeset.FaweStreamChangeSet; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; import com.boydti.fawe.wrappers.PlayerWrapper; @@ -66,7 +67,7 @@ public abstract class FawePlayer { Player player = (Player) fieldBasePlayer.get(actor); return wrap(player); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return Fawe.imp().wrap(actor.getName()); } } else if (obj instanceof PlayerWrapper){ @@ -77,7 +78,7 @@ public abstract class FawePlayer { fieldPlayer.setAccessible(true); return wrap(fieldPlayer.get(actor)); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return Fawe.imp().wrap(actor.getName()); } } @@ -103,7 +104,7 @@ public abstract class FawePlayer { } loadClipboardFromDisk(); } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); Fawe.debug("Failed to load history for: " + getName()); } } @@ -130,7 +131,7 @@ public abstract class FawePlayer { } } catch (Exception ignore) { Fawe.debug("====== INVALID CLIPBOARD ======"); - ignore.printStackTrace(); + MainUtil.handleError(ignore, false); Fawe.debug("===============---============="); Fawe.debug("This shouldn't result in any failure"); Fawe.debug("File: " + file.getName() + " (len:" + file.length() + ")"); diff --git a/core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index 293c42db..c7f12d85 100644 --- a/core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -3,6 +3,7 @@ package com.boydti.fawe.object; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.changeset.FaweChangeSet; import com.boydti.fawe.util.FaweQueue; +import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; @@ -59,7 +60,7 @@ public class HistoryExtent extends AbstractDelegateExtent { if (!FaweCache.hasData(id)) { return false; } - int data = id & 0xF; + int data = combined & 0xF; if (data == block.getData()) { return false; } @@ -72,8 +73,10 @@ public class HistoryExtent extends AbstractDelegateExtent { } } else { try { - this.changeSet.add(location, getBlock(location), block); + CompoundTag tag = queue.getTileEntity(x, y, z); + this.changeSet.add(location, new BaseBlock(id, combined & 0xF, tag), block); } catch (Throwable e) { + e.printStackTrace(); this.changeSet.add(x, y, z, combined, block); } } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java index a48e444e..63386d28 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/DiskStorageHistory.java @@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.RegionWrapper; +import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.worldedit.world.World; @@ -144,7 +145,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { osENTCT = null; } } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } return flushed; } @@ -305,7 +306,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { summary.add(x, z, ((combined2 << 4) + (combined1 >> 4))); } } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } return summary; @@ -331,7 +332,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet { fis.close(); gis.close(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } return new IntegerPair(ox, oz); diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 33d9cb2d..d520edfc 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -47,7 +47,7 @@ public abstract class FaweChangeSet implements ChangeSet { } } } catch (InterruptedException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return true; } @@ -109,7 +109,7 @@ public abstract class FaweChangeSet implements ChangeSet { BaseBlock to = change.getCurrent(); add(loc, from, to); } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -137,7 +137,7 @@ public abstract class FaweChangeSet implements ChangeSet { add(x, y, z, combinedFrom, combinedTo); } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -152,7 +152,7 @@ public abstract class FaweChangeSet implements ChangeSet { add(x, y, z, combinedFrom, combinedTo); } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -252,7 +252,7 @@ public abstract class FaweChangeSet implements ChangeSet { } } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } finally { waiting.decrementAndGet(); synchronized (lock) { diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java index f1be6a95..0e45a611 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/FaweStreamChangeSet.java @@ -4,6 +4,7 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.change.MutableBlockChange; import com.boydti.fawe.object.change.MutableEntityChange; import com.boydti.fawe.object.change.MutableTileChange; +import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; @@ -109,7 +110,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { stream.write(((combinedTo) >> 8) & 0xff); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -121,7 +122,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { NBTOutputStream nbtos = getTileCreateOS(); nbtos.writeNamedTag(tileCreateSize++ + "", tag); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -133,7 +134,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { NBTOutputStream nbtos = getTileRemoveOS(); nbtos.writeNamedTag(tileRemoveSize++ + "", tag); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -145,7 +146,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { NBTOutputStream nbtos = getEntityRemoveOS(); nbtos.writeNamedTag(entityRemoveSize++ + "", tag); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -157,7 +158,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { NBTOutputStream nbtos = getEntityCreateOS(); nbtos.writeNamedTag(entityCreateSize++ + "", tag); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -196,7 +197,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } return change; } catch (Exception ignoreEOF) { - ignoreEOF.printStackTrace(); + MainUtil.handleError(ignoreEOF); } return null; } @@ -212,7 +213,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { try { is.close(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } @@ -258,7 +259,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { try { is.close(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } @@ -276,7 +277,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } }; } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); return null; } } @@ -308,7 +309,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { try { is.close(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } @@ -326,7 +327,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } }; } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); return null; } } @@ -370,7 +371,7 @@ public abstract class FaweStreamChangeSet extends FaweChangeSet { } }; } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } return new ArrayList().iterator(); } diff --git a/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java b/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java index 0ac0c436..c326c5cd 100644 --- a/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java +++ b/core/src/main/java/com/boydti/fawe/object/changeset/MemoryOptimizedHistory.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.changeset; import com.boydti.fawe.config.Settings; +import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.worldedit.world.World; @@ -78,7 +79,7 @@ public class MemoryOptimizedHistory extends FaweStreamChangeSet { } return true; } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } diff --git a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index 6c8916eb..c6cc2bfa 100644 --- a/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -6,6 +6,7 @@ import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.BufferedRandomAccessFile; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.object.RunnableVal2; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.BlockVector; @@ -94,7 +95,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { clipboard.setOrigin(new Vector(ox, oy, oz)); return clipboard; } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } return null; } @@ -115,7 +116,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { } file.createNewFile(); } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -136,7 +137,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { raf.write((byte) (offset.getBlockZ() >> 8)); raf.write((byte) (offset.getBlockZ())); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -147,7 +148,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { file.setWritable(true); System.gc(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -163,7 +164,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { tmp = null; System.gc(); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -252,7 +253,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { task.run(pos, block); } } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } @@ -285,7 +286,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { } return block; } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } return EditSession.nullBlock; } @@ -313,7 +314,7 @@ public class DiskOptimizedClipboard extends FaweClipboard { } return true; } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } return false; } diff --git a/core/src/main/java/com/boydti/fawe/util/FaweQueue.java b/core/src/main/java/com/boydti/fawe/util/FaweQueue.java index f979c47d..4e452777 100644 --- a/core/src/main/java/com/boydti/fawe/util/FaweQueue.java +++ b/core/src/main/java/com/boydti/fawe/util/FaweQueue.java @@ -82,7 +82,7 @@ public abstract class FaweQueue { public abstract boolean setBiome(final int x, final int z, final BaseBiome biome); - public abstract FaweChunk getChunk(int x, int z); + public abstract FaweChunk getFaweChunk(int x, int z); public abstract void setChunk(final FaweChunk chunk); @@ -139,6 +139,8 @@ public abstract class FaweQueue { public abstract int getCombinedId4Data(int x, int y, int z) throws FaweException.FaweChunkLoadException; + public abstract CompoundTag getTileEntity(int x, int y, int z) throws FaweException.FaweChunkLoadException; + public int getCombinedId4Data(int x, int y, int z, int def) { try { return getCombinedId4Data(x, y, z); diff --git a/core/src/main/java/com/boydti/fawe/util/MainUtil.java b/core/src/main/java/com/boydti/fawe/util/MainUtil.java index f1338644..969fc565 100644 --- a/core/src/main/java/com/boydti/fawe/util/MainUtil.java +++ b/core/src/main/java/com/boydti/fawe/util/MainUtil.java @@ -22,6 +22,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Array; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; @@ -79,7 +80,7 @@ public class MainUtil { URL url = Fawe.class.getProtectionDomain().getCodeSource().getLocation(); return new File(new URL(url.toURI().toString().split("\\!")[0].replaceAll("jar:file", "file")).toURI().getPath()); } catch (MalformedURLException | URISyntaxException | SecurityException e) { - e.printStackTrace(); + MainUtil.handleError(e); return new File(Fawe.imp().getDirectory().getParentFile(), "FastAsyncWorldEdit.jar"); } } @@ -130,7 +131,7 @@ public class MainUtil { return newFile; } } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); Fawe.debug("&cCould not save " + resource); } return null; @@ -172,10 +173,76 @@ public class MainUtil { BBC.COMPRESSED.send(actor, saved, ratio); } } catch (Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } + public static void handleError(Throwable e) { + handleError(e, true); + } + + public static void handleError(Throwable e, boolean debug) { + if (e == null) { + return; + } + if (!debug) { + e.printStackTrace(); + return; + } + String header = "====== FAWE: " + e.getLocalizedMessage() + " ======"; + Fawe.debug(header); + String[] trace = getTrace(e); + for (int i = 0; i < trace.length && i < 8; i++) { + Fawe.debug(" - " + trace[i]); + } + String[] cause = getTrace(e.getCause()); + Fawe.debug("Cause: " + (cause.length == 0 ? "N/A" : "")); + for (int i = 0; i < cause.length && i < 8; i++) { + Fawe.debug(" - " + cause[i]); + } + Fawe.debug(StringMan.repeat("=", header.length())); + } + + public static String[] getTrace(Throwable e) { + if (e == null) { + return new String[0]; + } + StackTraceElement[] elems = e.getStackTrace(); + String[] msg = new String[elems.length];//[elems.length + 1]; +// HashSet packages = new HashSet<>(); + for (int i = 0; i < elems.length; i++) { + StackTraceElement elem = elems[i]; + elem.getLineNumber(); + String methodName = elem.getMethodName(); + int index = elem.getClassName().lastIndexOf('.'); + String className = elem.getClassName(); +// if (!(index == -1 || className.startsWith("io.netty") || className.startsWith("javax") || className.startsWith("java") || className.startsWith("sun") || className.startsWith("net.minecraft") || className.startsWith("org.spongepowered") || className.startsWith("org.bukkit") || className.startsWith("com.google"))) { +// packages.add(className.substring(0, index-1)); +// } + String name = className.substring(index == -1 ? 0 : index + 1); + name = name.length() == 0 ? elem.getClassName() : name; + String argString = "(...)"; + try { + for (Method method : Class.forName(elem.getClassName()).getDeclaredMethods()) { + if (method.getName().equals(methodName)) { + Class[] params = method.getParameterTypes(); + argString = ""; + String prefix = ""; + for (Class param : params) { + argString += prefix + param.getSimpleName(); + prefix = ","; + } + argString = "[" + method.getReturnType().getSimpleName() + "](" + argString + ")"; + break; + } + } + } catch(Throwable ignore) {} + msg[i] = name + "." + methodName + argString + ":" + elem.getLineNumber(); + } +// msg[msg.length-1] = StringMan.getString(packages); + return msg; + } + public static void smoothArray(int[] data, int width, int radius, int weight) { int[] copy = data.clone(); int length = data.length / width; diff --git a/core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java b/core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java index c5658169..62ea5d2a 100644 --- a/core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java +++ b/core/src/main/java/com/boydti/fawe/util/ReflectionUtils.java @@ -53,7 +53,7 @@ public class ReflectionUtils { preClassM = "net.minecraft.server." + verM; } } catch (final Exception ignored) { - ignored.printStackTrace(); + MainUtil.handleError(ignored); } } } @@ -65,7 +65,7 @@ public static Map getMap(Map map) { m.setAccessible(true); return (Map) m.get(map); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return map; } } @@ -77,7 +77,7 @@ public static List getList(List list) { m.setAccessible(true); return (List) m.get(list); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return list; } } diff --git a/core/src/main/java/com/boydti/fawe/util/SetQueue.java b/core/src/main/java/com/boydti/fawe/util/SetQueue.java index aa9dc32c..77c3fc00 100644 --- a/core/src/main/java/com/boydti/fawe/util/SetQueue.java +++ b/core/src/main/java/com/boydti/fawe/util/SetQueue.java @@ -103,12 +103,12 @@ public class SetQueue { try { thread.join(); } catch (InterruptedException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } finally { // Enable it again (note that we are still on the main thread) SET_TASK.value2.endSet(true); diff --git a/core/src/main/java/com/boydti/fawe/util/TaskManager.java b/core/src/main/java/com/boydti/fawe/util/TaskManager.java index 6985f59d..6607d58a 100644 --- a/core/src/main/java/com/boydti/fawe/util/TaskManager.java +++ b/core/src/main/java/com/boydti/fawe/util/TaskManager.java @@ -164,7 +164,7 @@ public abstract class TaskManager { } catch (RuntimeException e) { this.value = e; } catch (Throwable neverHappens) { - neverHappens.printStackTrace(); + MainUtil.handleError(neverHappens); } finally { running.set(false); } @@ -181,7 +181,7 @@ public abstract class TaskManager { } } } catch (InterruptedException e) { - e.printStackTrace(); + MainUtil.handleError(e); } if (run.value != null) { throw run.value; diff --git a/core/src/main/java/com/boydti/fawe/util/WEManager.java b/core/src/main/java/com/boydti/fawe/util/WEManager.java index 6a65a07e..9f70be13 100644 --- a/core/src/main/java/com/boydti/fawe/util/WEManager.java +++ b/core/src/main/java/com/boydti/fawe/util/WEManager.java @@ -29,7 +29,7 @@ public class WEManager { field.setAccessible(true); field.set(parent, new NullExtent((Extent) field.get(parent), reason)); } catch (final Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } throw new FaweException(reason); } @@ -148,7 +148,7 @@ public class WEManager { } }); } catch (final Exception e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }, false, false); diff --git a/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java index 001519af..1635a934 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java @@ -2,6 +2,7 @@ package com.boydti.fawe.wrappers; import com.boydti.fawe.Fawe; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSessionFactory; @@ -200,7 +201,7 @@ public class PlayerWrapper implements Player { session.remember(edit); } } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } TaskManager.IMP.sync(new RunnableVal() { @Override diff --git a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java index 0cb7970a..ddffac28 100644 --- a/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java +++ b/core/src/main/java/com/boydti/fawe/wrappers/WorldWrapper.java @@ -5,6 +5,7 @@ import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.object.changeset.FaweChangeSet; import com.boydti.fawe.object.extent.FaweRegionExtent; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; @@ -97,7 +98,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateTree(editSession, pt); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); @@ -111,7 +112,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateBigTree(editSession, pt); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); @@ -125,7 +126,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateBirchTree(editSession, pt); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); @@ -139,7 +140,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateRedwoodTree(editSession, pt); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); @@ -153,7 +154,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateTallRedwoodTree(editSession, pt); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); @@ -333,7 +334,7 @@ public class WorldWrapper extends AbstractWorld { try { this.value = parent.generateTree(editSession, position); } catch (MaxChangedBlocksException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } }); diff --git a/core/src/main/java/com/sk89q/worldedit/EditSession.java b/core/src/main/java/com/sk89q/worldedit/EditSession.java index e519fefc..64cfd79e 100644 --- a/core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -42,6 +42,7 @@ import com.boydti.fawe.object.extent.NullExtent; import com.boydti.fawe.object.extent.ProcessedWEExtent; import com.boydti.fawe.object.progress.DefaultProgressTracker; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.Perm; import com.boydti.fawe.util.SetQueue; @@ -659,7 +660,7 @@ public class EditSession implements Extent { BaseBlock block = this.world.getBlock(new Vector(x, y, z)); return block; } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); return FaweCache.CACHE_BLOCK[combinedId4Data]; } } diff --git a/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java b/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java index c58fc4f4..61301f9b 100644 --- a/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java +++ b/core/src/main/java/com/sk89q/worldedit/command/composition/SelectionCommand.java @@ -121,7 +121,7 @@ public class SelectionCommand extends SimpleCommand { final int id = block.getId(); final byte data = (byte) block.getData(); - final FaweChunk fc = queue.getChunk(0, 0); + final FaweChunk fc = queue.getFaweChunk(0, 0); fc.fillCuboid(0, 15, minY, maxY, 0, 15, id, data); fc.optimize(); @@ -147,7 +147,7 @@ public class SelectionCommand extends SimpleCommand { newChunk = fc.copy(true); newChunk.setLoc(queue, value[0], value[1]); } else { - newChunk = queue.getChunk(value[0], value[1]); + newChunk = queue.getFaweChunk(value[0], value[1]); newChunk.fillCuboid(value[2] & 15, value[4] & 15, minY, maxY, value[3] & 15, value[5] & 15, id, data); } } @@ -160,7 +160,7 @@ public class SelectionCommand extends SimpleCommand { return null; } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } } diff --git a/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 7b74a033..a431975e 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.extension.platform; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.exception.FaweException; +import com.boydti.fawe.util.MainUtil; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.ServerInterface; @@ -413,7 +414,7 @@ public class PlatformManager { } else { actor.printError("Please report this error: [See console]"); actor.printRaw(e.getClass().getName() + ": " + e.getMessage()); - e.printStackTrace(); + MainUtil.handleError(e); } } } @@ -500,7 +501,7 @@ public class PlatformManager { } else { player.printError("Please report this error: [See console]"); player.printRaw(e.getClass().getName() + ": " + e.getMessage()); - e.printStackTrace(); + MainUtil.handleError(e); } } } diff --git a/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java b/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java index d3d270f2..eac75e2b 100644 --- a/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java +++ b/core/src/main/java/net/jpountz/lz4/LZ4StreamTest.java @@ -1,5 +1,6 @@ package net.jpountz.lz4; +import com.boydti.fawe.util.MainUtil; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -99,7 +100,7 @@ public class LZ4StreamTest { assertEquals(-1, is.read(new byte[100])); assertEquals(-1, is.read()); } catch(Throwable t) { - t.printStackTrace(); + MainUtil.handleError(t); Assert.fail("Exception was thrown. Seed value was " + seed); } diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/FaweForge.java b/forge1710/src/main/java/com/boydti/fawe/forge/FaweForge.java index 06a1a17d..51a339b9 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/FaweForge.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/FaweForge.java @@ -9,6 +9,7 @@ import com.boydti.fawe.object.FaweCommand; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.wrappers.WorldWrapper; import com.sk89q.worldedit.EditSession; @@ -39,7 +40,7 @@ public class FaweForge implements IFawe { try { Fawe.set(this); } catch (InstanceAlreadyExistsException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/ForgeMetrics.java b/forge1710/src/main/java/com/boydti/fawe/forge/ForgeMetrics.java index 9d9f582b..d45902c2 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/ForgeMetrics.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/ForgeMetrics.java @@ -30,6 +30,7 @@ package com.boydti.fawe.forge; +import com.boydti.fawe.util.MainUtil; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; @@ -361,7 +362,7 @@ public class ForgeMetrics { gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8")); } catch (IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } finally { if (gzos != null) try { gzos.close(); diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/ForgeTaskMan.java b/forge1710/src/main/java/com/boydti/fawe/forge/ForgeTaskMan.java index ed946eda..c06b6f0f 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/ForgeTaskMan.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/ForgeTaskMan.java @@ -1,15 +1,16 @@ package com.boydti.fawe.forge; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; +import cpw.mods.fml.common.FMLCommonHandler; +import cpw.mods.fml.common.eventhandler.EventPriority; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.eventhandler.EventPriority; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent; public class ForgeTaskMan extends TaskManager { @@ -44,7 +45,7 @@ public class ForgeTaskMan extends TaskManager { try { r.run(); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } later(this, interval); } @@ -68,7 +69,7 @@ public class ForgeTaskMan extends TaskManager { try { item.run(); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } } @@ -90,7 +91,7 @@ public class ForgeTaskMan extends TaskManager { try { r.run(); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } laterAsync(this, interval); } @@ -127,7 +128,7 @@ public class ForgeTaskMan extends TaskManager { try { r.run(); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } return; } @@ -149,7 +150,7 @@ public class ForgeTaskMan extends TaskManager { try { async(r); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } return; } diff --git a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java index 09a1917b..7bfd96ac 100644 --- a/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java +++ b/forge1710/src/main/java/com/boydti/fawe/forge/v0/ForgeQueue_All.java @@ -11,6 +11,7 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -69,12 +70,40 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = chunk.chunkTileEntityMap; + ChunkPosition pos = new ChunkPosition(x, y, z); + TileEntity tile = tiles.get(pos); + return tile != null ? getTag(tile) : null; + } + + public CompoundTag getTag(TileEntity tile) { + try { + NBTTagCompound tag = new NBTTagCompound(); + tile.readFromNBT(tag); // readTagIntoEntity + return (CompoundTag) methodToNative.invoke(null, tag); + } catch (Exception e) { + MainUtil.handleError(e); + return null; + } } @Override - public ExtendedBlockStorage[] getCachedChunk(World world, int cx, int cz) { + public Chunk getChunk(World world, int x, int z) { + Chunk chunk = world.getChunkProvider().provideChunk(x, z); + if (chunk != null && !chunk.isChunkLoaded) { + chunk.onChunkLoad(); + } + return chunk; + } + + @Override + public boolean loadChunk(World world, int x, int z, boolean generate) { + return getCachedSections(world, x, z) != null; + } + + @Override + public ExtendedBlockStorage[] getCachedSections(World world, int cx, int cz) { Chunk chunk = world.getChunkProvider().provideChunk(cx, cz); if (chunk != null && !chunk.isChunkLoaded) { chunk.onChunkLoad(); @@ -173,7 +202,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; Collection[] entities = (Collection[]) entitiesGeneric; - CharFaweChunk previous = (CharFaweChunk) getChunk(fs.getX(), fs.getZ()); + CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { @@ -486,7 +515,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entityList : entities) { for (Entity ent : entityList) { - if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && !createdEntities.contains(ent.getUniqueID()))) { + if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) { continue; } int x = ((int) Math.round(ent.posX) & 15); @@ -515,7 +544,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tiles = chunk.getTileEntityMap(); + pos.set(x, y, z); + TileEntity tile = tiles.get(pos); + return tile != null ? getTag(tile) : null; + } + + public CompoundTag getTag(TileEntity tile) { + try { + NBTTagCompound tag = new NBTTagCompound(); + tile.readFromNBT(tag); // readTagIntoEntity + return (CompoundTag) methodToNative.invoke(null, tag); + } catch (Exception e) { + MainUtil.handleError(e); + return null; + } + } + + @Override + public Chunk getChunk(World world, int x, int z) { + Chunk chunk = world.getChunkProvider().provideChunk(x, z); + if (chunk != null && !chunk.isLoaded()) { + chunk.onChunkLoad(); + } + return chunk; + } + @Override public boolean isChunkLoaded(int x, int z) { return getWorld().getChunkProvider().chunkExists(x, z); @@ -101,7 +132,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; ClassInheritanceMultiMap[] entities = (ClassInheritanceMultiMap[]) entitiesGeneric; - CharFaweChunk previous = (CharFaweChunk) getChunk(fs.getX(), fs.getZ()); + CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { @@ -291,7 +321,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue entityList : entities) { for (Entity ent : entityList) { - if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && !createdEntities.contains(ent.getUniqueID()))) { + if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) { continue; } int x = ((int) Math.round(ent.posX) & 15); @@ -503,7 +533,7 @@ public class ForgeQueue_All extends NMSMappedFaweQueue getChunk(int x, int z) { + public FaweChunk getFaweChunk(int x, int z) { return new ForgeChunk_All(this, x, z); } diff --git a/sponge/src/main/java/com/boydti/fawe/sponge/FaweSponge.java b/sponge/src/main/java/com/boydti/fawe/sponge/FaweSponge.java index 7ce6b755..97534372 100644 --- a/sponge/src/main/java/com/boydti/fawe/sponge/FaweSponge.java +++ b/sponge/src/main/java/com/boydti/fawe/sponge/FaweSponge.java @@ -12,6 +12,7 @@ import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.sponge.v1_8.SpongeQueue_1_8; import com.boydti.fawe.sponge.v1_8.SpongeQueue_ALL; import com.boydti.fawe.util.FaweQueue; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.forge.ForgeWorldEdit; @@ -50,7 +51,7 @@ public class FaweSponge implements IFawe { try { Fawe.set(this); } catch (final Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } TaskManager.IMP.later(() -> SpongeUtil.initBiomeCache(), 0); } @@ -114,7 +115,7 @@ public class FaweSponge implements IFawe { try { return new SpongeQueue_1_8(world); } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } return new SpongeQueue_ALL(world); diff --git a/sponge/src/main/java/com/boydti/fawe/sponge/SpongeMetrics.java b/sponge/src/main/java/com/boydti/fawe/sponge/SpongeMetrics.java index ff0aee37..5e93c32f 100644 --- a/sponge/src/main/java/com/boydti/fawe/sponge/SpongeMetrics.java +++ b/sponge/src/main/java/com/boydti/fawe/sponge/SpongeMetrics.java @@ -29,6 +29,7 @@ package com.boydti.fawe.sponge; */ import com.boydti.fawe.Fawe; +import com.boydti.fawe.util.MainUtil; import com.google.inject.Inject; import java.io.BufferedReader; import java.io.ByteArrayOutputStream; @@ -137,7 +138,7 @@ public class SpongeMetrics { gzos = new GZIPOutputStream(baos); gzos.write(input.getBytes("UTF-8")); } catch (final IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } finally { if (gzos != null) { try { @@ -265,7 +266,7 @@ public class SpongeMetrics { guid = config.getNode("mcstats.guid").getString(); debug = config.getNode("mcstats.debug").getBoolean(); } catch (final IOException e) { - e.printStackTrace(); + MainUtil.handleError(e); } } diff --git a/sponge/src/main/java/com/boydti/fawe/sponge/SpongeUtil.java b/sponge/src/main/java/com/boydti/fawe/sponge/SpongeUtil.java index 2b738bc3..104e83d6 100644 --- a/sponge/src/main/java/com/boydti/fawe/sponge/SpongeUtil.java +++ b/sponge/src/main/java/com/boydti/fawe/sponge/SpongeUtil.java @@ -1,6 +1,7 @@ package com.boydti.fawe.sponge; import com.boydti.fawe.Fawe; +import com.boydti.fawe.util.MainUtil; import com.sk89q.worldedit.world.biome.BiomeData; import java.lang.reflect.Field; import java.util.HashMap; @@ -58,7 +59,7 @@ public class SpongeUtil { } } } catch (Throwable e) { - e.printStackTrace(); + MainUtil.handleError(e); } } diff --git a/sponge/src/main/java/com/boydti/fawe/sponge/v1_8/SpongeQueue_1_8.java b/sponge/src/main/java/com/boydti/fawe/sponge/v1_8/SpongeQueue_1_8.java index c86e529f..26dfa4a3 100644 --- a/sponge/src/main/java/com/boydti/fawe/sponge/v1_8/SpongeQueue_1_8.java +++ b/sponge/src/main/java/com/boydti/fawe/sponge/v1_8/SpongeQueue_1_8.java @@ -8,6 +8,7 @@ import com.boydti.fawe.object.BytePair; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.RunnableVal; +import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; @@ -65,6 +66,36 @@ public class SpongeQueue_1_8 extends NMSMappedFaweQueue tiles = chunk.getTileEntityMap(); + pos.set(x, y, z); + TileEntity tile = tiles.get(pos); + return tile != null ? getTag(tile) : null; + } + + public CompoundTag getTag(TileEntity tile) { + try { + NBTTagCompound tag = new NBTTagCompound(); + tile.readFromNBT(tag); // readTagIntoEntity + return (CompoundTag) methodToNative.invoke(null, tag); + } catch (Exception e) { + MainUtil.handleError(e); + return null; + } + } + + @Override + public net.minecraft.world.chunk.Chunk getChunk(World world, int x, int z) { + net.minecraft.world.chunk.Chunk chunk = ((net.minecraft.world.World) world).getChunkProvider().provideChunk(x, z); + if (chunk != null && !chunk.isLoaded()) { + chunk.onChunkLoad(); + } + return chunk; + } + @Override public void refreshChunk(World world, net.minecraft.world.chunk.Chunk chunk) { if (!chunk.isLoaded()) { @@ -145,7 +176,7 @@ public class SpongeQueue_1_8 extends NMSMappedFaweQueue tilesGeneric, Collection[] entitiesGeneric, Set createdEntities, boolean all) throws Exception { Map tiles = (Map) tilesGeneric; ClassInheritanceMultiMap[] entities = (ClassInheritanceMultiMap[]) entitiesGeneric; - CharFaweChunk previous = (CharFaweChunk) getChunk(fs.getX(), fs.getZ()); + CharFaweChunk previous = (CharFaweChunk) getFaweChunk(fs.getX(), fs.getZ()); char[][] idPrevious = new char[16][]; for (int layer = 0; layer < sections.length; layer++) { if (fs.getCount(layer) != 0 || all) { @@ -186,7 +217,7 @@ public class SpongeQueue_1_8 extends NMSMappedFaweQueue entityList : entities) { for (Entity ent : entityList) { - if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && !createdEntities.contains(ent.getUniqueID()))) { + if (ent instanceof EntityPlayer || (!createdEntities.isEmpty() && createdEntities.contains(ent.getUniqueID()))) { continue; } int x = ((int) Math.round(ent.posX) & 15); @@ -398,7 +429,7 @@ public class SpongeQueue_1_8 extends NMSMappedFaweQueue getChunk(int x, int z) { + public FaweChunk getFaweChunk(int x, int z) { return new SpongeChunk_1_8(this, x, z); } @@ -466,7 +497,6 @@ public class SpongeQueue_1_8 extends NMSMappedFaweQueue { + private Method methodToNative; + public SpongeQueue_ALL(String world) { super(world); + try { + Class converter = Class.forName("com.sk89q.worldedit.forge.NBTConverter"); + this.methodToNative = converter.getDeclaredMethod("fromNative", NBTBase.class); + methodToNative.setAccessible(true); + } catch (Throwable e) { + throw new RuntimeException(e); + } } @Override @@ -71,6 +86,33 @@ public class SpongeQueue_ALL extends NMSMappedFaweQueue tiles = chunk.getTileEntityMap(); + TileEntity tile = tiles.get(new BlockPos(x, y, z)); + return tile != null ? getTag(tile) : null; + } + + public CompoundTag getTag(TileEntity tile) { + try { + NBTTagCompound tag = new NBTTagCompound(); + tile.readFromNBT(tag); // readTagIntoEntity + return (CompoundTag) methodToNative.invoke(null, tag); + } catch (Exception e) { + MainUtil.handleError(e); + return null; + } + } + + @Override + public net.minecraft.world.chunk.Chunk getChunk(World world, int x, int z) { + net.minecraft.world.chunk.Chunk chunk = ((net.minecraft.world.World) world).getChunkProvider().provideChunk(x, z); + if (chunk != null && !chunk.isLoaded()) { + chunk.onChunkLoad(); + } + return chunk; + } + @Override public char[] getCachedSection(ExtendedBlockStorage[] chunk, int cy) { ExtendedBlockStorage value = chunk[cy]; @@ -124,7 +166,7 @@ public class SpongeQueue_ALL extends NMSMappedFaweQueue getChunk(int x, int z) { + public FaweChunk getFaweChunk(int x, int z) { return new SpongeChunk_1_8(this, x, z); } @@ -293,7 +335,7 @@ public class SpongeQueue_ALL extends NMSMappedFaweQueue