Updating chunk sending algorithm effects #210,#204,#167,#162

This commit is contained in:
boy0001 2015-03-27 22:25:24 +11:00
parent 61569d5212
commit 348fb9cb1b
25 changed files with 74 additions and 93 deletions

View File

@ -74,7 +74,6 @@ public class Claim extends SubCommand {
SchematicHandler.manager.paste(sch, plot2, 0, 0); SchematicHandler.manager.paste(sch, plot2, 0, 0);
} }
PlotSquared.getPlotManager(world).claimPlot(plotworld, plot); PlotSquared.getPlotManager(world).claimPlot(plotworld, plot);
MainUtil.update(loc);
} }
return result; return result;
} }

View File

@ -70,7 +70,6 @@ public class Copy extends SubCommand {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, C.COPY_SUCCESS); MainUtil.sendMessage(plr, C.COPY_SUCCESS);
MainUtil.update(plr.getLocation());
} }
})) { })) {
return true; return true;

View File

@ -45,7 +45,6 @@ public class CreateRoadSchematic extends SubCommand {
return sendMessage(player, C.NOT_IN_PLOT_WORLD); return sendMessage(player, C.NOT_IN_PLOT_WORLD);
} }
HybridUtils.manager.setupRoadSchematic(plot); HybridUtils.manager.setupRoadSchematic(plot);
MainUtil.update(loc);
MainUtil.sendMessage(player, "&6Saved new road schematic"); MainUtil.sendMessage(player, "&6Saved new road schematic");
return true; return true;
} }

View File

@ -43,11 +43,7 @@ public class DebugRoadRegen extends SubCommand {
} }
final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4);
final boolean result = HybridUtils.manager.regenerateRoad(world, chunk); final boolean result = HybridUtils.manager.regenerateRoad(world, chunk);
if (result) {
MainUtil.update(loc);
}
MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed")); MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result == true ? "&aSuccess" : "&cFailed"));
MainUtil.update(loc);
return true; return true;
} }
} }

View File

@ -193,7 +193,6 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.SUCCESS_MERGE); MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true); MainUtil.mergePlots(world, plots, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
MainUtil.update(loc);
} }
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
} }
@ -223,7 +222,6 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.SUCCESS_MERGE); MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true); MainUtil.mergePlots(world, plots, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
MainUtil.update(loc);
return true; return true;
} }
} }

View File

@ -86,7 +86,6 @@ public class Move extends SubCommand {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(plr, C.MOVE_SUCCESS); MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
MainUtil.update(plr.getLocation());
} }
})) { })) {
return true; return true;

View File

@ -139,7 +139,6 @@ public class SchematicCmd extends SubCommand {
if (start > blen) { if (start > blen) {
SchematicHandler.manager.pasteStates(schematic, plot, 0, 0); SchematicHandler.manager.pasteStates(schematic, plot, 0, 0);
sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS);
MainUtil.update(plr.getLocation());
SchematicCmd.this.running = false; SchematicCmd.this.running = false;
PlotSquared.TASK.cancelTask(SchematicCmd.this.task); PlotSquared.TASK.cancelTask(SchematicCmd.this.task);
return; return;

View File

@ -246,7 +246,6 @@ public class Set extends SubCommand {
} }
} }
manager.setComponent(plotworld, plot.id, component, blocks); manager.setComponent(plotworld, plot.id, component, blocks);
MainUtil.update(loc);
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
return true; return true;
} }

View File

@ -125,7 +125,6 @@ public class Swap extends SubCommand {
public void run() { public void run() {
if (last) { if (last) {
MainUtil.sendMessage(plr, C.SWAP_SUCCESS); MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
MainUtil.update(plr.getLocation());
} }
} }
}); });

View File

@ -70,7 +70,6 @@ public class Unlink extends SubCommand {
MainUtil.sendMessage(plr, "&cUnlink has been cancelled"); MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
return; return;
} }
MainUtil.update(plr.getLocation());
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS); MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
} }
}; };

View File

@ -1,6 +1,5 @@
package com.intellectualcrafters.plot.generator; package com.intellectualcrafters.plot.generator;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
@ -19,9 +18,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager; import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager; import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
@ -132,7 +129,6 @@ public class AugmentedPopulator extends BlockPopulator {
public void run() { public void run() {
populateBiome(world, x, z); populateBiome(world, x, z);
chunk.unload(true, true); chunk.unload(true, true);
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
} }
}, 20); }, 20);
} else { } else {
@ -148,7 +144,6 @@ public class AugmentedPopulator extends BlockPopulator {
chunk.load(true); chunk.load(true);
populateBlocks(world, rand, X, Z, x, z, check); populateBlocks(world, rand, X, Z, x, z, check);
chunk.unload(true, true); chunk.unload(true, true);
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
} }
}, 40 + rand.nextInt(40)); }, 40 + rand.nextInt(40));
} }
@ -190,9 +185,6 @@ public class AugmentedPopulator extends BlockPopulator {
} }
for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) { for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) {
Chunk chunk = world.getChunkAt(X, Z); Chunk chunk = world.getChunkAt(X, Z);
if (MainUtil.canSetFast) {
((BukkitSetBlockManager) BlockUpdateUtil.setBlockManager).update(Arrays.asList(chunk));
}
populator.populate(world, this.r, chunk); populator.populate(world, this.r, chunk);
} }
} }

View File

@ -11,12 +11,10 @@ import org.bukkit.plugin.Plugin;
import com.intellectualcrafters.plot.BukkitMain; import com.intellectualcrafters.plot.BukkitMain;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitHybridUtils extends HybridUtils { public class BukkitHybridUtils extends HybridUtils {

View File

@ -24,10 +24,8 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;

View File

@ -2,12 +2,9 @@ package com.intellectualcrafters.plot.generator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random;
import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotLoc;
@ -17,7 +14,6 @@ import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
/** /**
* @author Citymonstret * @author Citymonstret

View File

@ -1,17 +1,13 @@
package com.intellectualcrafters.plot.object; package com.intellectualcrafters.plot.object;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;

View File

@ -2,7 +2,6 @@ package com.intellectualcrafters.plot.util;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.object.schematic.PlotItem;
public abstract class BlockManager { public abstract class BlockManager {

View File

@ -1,11 +1,11 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.List; import java.util.Collection;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
public abstract class BlockUpdateUtil { public abstract class BlockUpdateUtil {
public static BlockUpdateUtil setBlockManager = null; public static BlockUpdateUtil setBlockManager = null;
public abstract void update(String worldname, List<ChunkLoc> chunkLocs); public abstract void update(String worldname, Collection<ChunkLoc> chunkLocs);
} }

View File

@ -1,7 +1,6 @@
package com.intellectualcrafters.plot.util; package com.intellectualcrafters.plot.util;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
@ -23,7 +22,6 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -277,7 +275,6 @@ public class ClusterManager {
@Override @Override
public void run() { public void run() {
if ((populator == null) || (plotworld.TYPE == 0)) { if ((populator == null) || (plotworld.TYPE == 0)) {
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
world.regenerateChunk(chunk.getX(), chunk.getZ()); world.regenerateChunk(chunk.getX(), chunk.getZ());
chunk.unload(true, true); chunk.unload(true, true);
} else { } else {

View File

@ -29,7 +29,6 @@ import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotBlock;
@ -171,20 +170,20 @@ public class MainUtil {
} }
} }
public static void update(final Location loc) { // public static void update(final Location loc) {
final String world = loc.getWorld(); // final String world = loc.getWorld();
int ox = loc.getX() >> 4; // int ox = loc.getX() >> 4;
int oz = loc.getZ() >> 4; // int oz = loc.getZ() >> 4;
final ArrayList<ChunkLoc> chunks = new ArrayList<>(); // final ArrayList<ChunkLoc> chunks = new ArrayList<>();
final int distance = BukkitUtil.getViewDistance(); // final int distance = BukkitUtil.getViewDistance();
for (int cx = -distance; cx <= distance; cx++) { // for (int cx = -distance; cx <= distance; cx++) {
for (int cz = -distance; cz <= distance; cz++) { // for (int cz = -distance; cz <= distance; cz++) {
final ChunkLoc chunk = new ChunkLoc(ox + cx, oz + cz); // final ChunkLoc chunk = new ChunkLoc(ox + cx, oz + cz);
chunks.add(chunk); // chunks.add(chunk);
} // }
} // }
BlockUpdateUtil.setBlockManager.update(world, chunks); // BlockUpdateUtil.setBlockManager.update(world, chunks);
} // }
public static void createWorld(final String world, final String generator) { public static void createWorld(final String world, final String generator) {
} }
@ -418,7 +417,6 @@ public class MainUtil {
} }
merge = false; merge = false;
} }
update(getPlotHome(world, plot));
} }
private static boolean ownsPlots(final String world, final ArrayList<PlotId> plots, final UUID uuid, final int dir) { private static boolean ownsPlots(final String world, final ArrayList<PlotId> plots, final UUID uuid, final int dir) {
@ -547,7 +545,6 @@ public class MainUtil {
MainUtil.setBiome(world, plot, "FOREST"); MainUtil.setBiome(world, plot, "FOREST");
runners.remove(plot); runners.remove(plot);
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
update(location);
} }
}; };
manager.clearPlot(plotworld, plot, isDelete, run); manager.clearPlot(plotworld, plot, isDelete, run);
@ -611,7 +608,6 @@ public class MainUtil {
final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1; final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1;
final int topZ = getPlotTopLoc(world, plot.id).getZ(); final int topZ = getPlotTopLoc(world, plot.id).getZ();
BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome); BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome);
update(getPlotHome(world, plot));
} }
public static int getHeighestBlock(final String world, final int x, final int z) { public static int getHeighestBlock(final String world, final int x, final int z) {

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.Collection;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
@ -14,10 +14,10 @@ public abstract class BukkitSetBlockManager extends BlockUpdateUtil {
public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data); public abstract void set(final org.bukkit.World world, final int x, final int y, final int z, final int blockId, final byte data);
public abstract void update(List<Chunk> list); public abstract void update(Collection<Chunk> list);
@Override @Override
public void update(final String worldname, final List<ChunkLoc> chunkLocs) { public void update(final String worldname, final Collection<ChunkLoc> chunkLocs) {
final World world = BukkitUtil.getWorld(worldname); final World world = BukkitUtil.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<Chunk>(); final ArrayList<Chunk> chunks = new ArrayList<Chunk>();
for (final ChunkLoc loc : chunkLocs) { for (final ChunkLoc loc : chunkLocs) {

View File

@ -1,6 +1,5 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -95,17 +94,17 @@ public class BukkitUtil extends BlockManager {
return world.getChunkAt(x, z); return world.getChunkAt(x, z);
} }
public static void update(final String world, final int x, final int z) { // public static void update(final String world, final int x, final int z) {
final ArrayList<Chunk> chunks = new ArrayList<>(); // final ArrayList<Chunk> chunks = new ArrayList<>();
final int distance = Bukkit.getViewDistance(); // final int distance = Bukkit.getViewDistance();
for (int cx = -distance; cx < distance; cx++) { // for (int cx = -distance; cx < distance; cx++) {
for (int cz = -distance; cz < distance; cz++) { // for (int cz = -distance; cz < distance; cz++) {
final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz); // final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz);
chunks.add(chunk); // chunks.add(chunk);
} // }
} // }
BukkitSetBlockManager.setBlockManager.update(chunks); // BukkitSetBlockManager.setBlockManager.update(chunks);
} // }
public static String getWorld(final Entity entity) { public static String getWorld(final Entity entity) {
return entity.getWorld().getName(); return entity.getWorld().getName();

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util.bukkit;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -53,7 +54,7 @@ public class SendChunk {
ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class); ChunkCoordIntPairCon = classChunkCoordIntPair.getConstructor(int.class, int.class);
} }
public static void sendChunk(final List<Chunk> chunks) { public static void sendChunk(final Collection<Chunk> chunks) {
int diffx, diffz; int diffx, diffz;
final int view = Bukkit.getServer().getViewDistance() << 4; final int view = Bukkit.getServer().getViewDistance() << 4;
for (final Chunk chunk : chunks) { for (final Chunk chunk : chunks) {

View File

@ -22,14 +22,16 @@ package com.intellectualcrafters.plot.util.bukkit;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import java.util.List; import java.util.Collection;
import java.util.HashMap;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.TaskManager;
/** /**
* SetBlockFast class<br> Used to do fast world editing * SetBlockFast class<br> Used to do fast world editing
@ -46,6 +48,8 @@ public class SetBlockFast extends BukkitSetBlockManager {
private static RefMethod methodA; private static RefMethod methodA;
private static RefMethod methodGetById; private static RefMethod methodGetById;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
/** /**
* Constructor * Constructor
* *
@ -56,6 +60,15 @@ public class SetBlockFast extends BukkitSetBlockManager {
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class); methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class); methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, int.class);
methodGetById = classBlock.getMethod("getById", int.class); methodGetById = classBlock.getMethod("getById", int.class);
TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
update(toUpdate.values());
toUpdate = new HashMap<>();
}
}, 20);
} }
/** /**
@ -83,14 +96,13 @@ public class SetBlockFast extends BukkitSetBlockManager {
* @param chunks list of chunks to update * @param chunks list of chunks to update
*/ */
@Override @Override
public void update(final List<Chunk> chunks) { public void update(final Collection<Chunk> chunks) {
if (chunks.size() == 0) { if (chunks.size() == 0) {
return; return;
} }
if (!MainUtil.canSendChunk) { if (!MainUtil.canSendChunk) {
final World world = chunks.get(0).getWorld();
for (final Chunk chunk : chunks) { for (final Chunk chunk : chunks) {
world.refreshChunk(chunk.getX(), chunk.getZ()); chunk.unload();
chunk.load(false); chunk.load(false);
} }
return; return;

View File

@ -22,7 +22,8 @@ package com.intellectualcrafters.plot.util.bukkit;
import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass; import static com.intellectualcrafters.plot.util.ReflectionUtils.getRefClass;
import java.util.List; import java.util.Collection;
import java.util.HashMap;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
@ -33,6 +34,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor; import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod; import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.TaskManager;
/** /**
* SetBlockFast class<br> Used to do fast world editing * SetBlockFast class<br> Used to do fast world editing
@ -52,6 +54,8 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
private static RefMethod methodGetByCombinedId; private static RefMethod methodGetByCombinedId;
private static RefConstructor constructorBlockPosition; private static RefConstructor constructorBlockPosition;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
/** /**
* Constructor * Constructor
* *
@ -63,6 +67,15 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
methodGetHandle = classCraftWorld.getMethod("getHandle"); methodGetHandle = classCraftWorld.getMethod("getHandle");
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class); methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
methodA = classChunk.getMethod("a", classBlockPosition, classIBlockData); methodA = classChunk.getMethod("a", classBlockPosition, classIBlockData);
TaskManager.runTaskRepeat(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
update(toUpdate.values());
toUpdate = new HashMap<>();
}
}, 20);
} }
private ChunkLoc lastLoc = null; private ChunkLoc lastLoc = null;
@ -270,8 +283,12 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
int Z = z >> 4; int Z = z >> 4;
ChunkLoc loc = new ChunkLoc(X, Z); ChunkLoc loc = new ChunkLoc(X, Z);
if (!loc.equals(lastLoc)) { if (!loc.equals(lastLoc)) {
world.loadChunk(X, Z, false); Chunk chunk = toUpdate.get(loc);
lastLoc = loc; if (chunk == null) {
chunk = world.getChunkAt(X, Z);
toUpdate.put(loc, chunk);
}
chunk.load(false);
} }
// check sign // check sign
final Object w = methodGetHandle.of(world).call(); final Object w = methodGetHandle.of(world).call();
@ -281,20 +298,14 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
methodA.of(chunk).call(pos, combined); methodA.of(chunk).call(pos, combined);
} }
/**
* Update chunks
*
* @param chunks chunks to be updated
*/
@Override @Override
public void update(final List<Chunk> chunks) { public void update(final Collection<Chunk> chunks) {
if (chunks.size() == 0) { if (chunks.size() == 0) {
return; return;
} }
if (!MainUtil.canSendChunk) { if (!MainUtil.canSendChunk) {
final World world = chunks.get(0).getWorld();
for (final Chunk chunk : chunks) { for (final Chunk chunk : chunks) {
world.refreshChunk(chunk.getX(), chunk.getZ()); chunk.unload();
chunk.load(false); chunk.load(false);
} }
return; return;

View File

@ -1,6 +1,6 @@
package com.intellectualcrafters.plot.util.bukkit; package com.intellectualcrafters.plot.util.bukkit;
import java.util.List; import java.util.Collection;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
@ -24,7 +24,7 @@ public class SetBlockSlow extends BukkitSetBlockManager {
} }
@Override @Override
public void update(final List<Chunk> chunks) { public void update(final Collection<Chunk> chunks) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }