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);
}
PlotSquared.getPlotManager(world).claimPlot(plotworld, plot);
MainUtil.update(loc);
}
return result;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -125,7 +125,6 @@ public class Swap extends SubCommand {
public void run() {
if (last) {
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");
return;
}
MainUtil.update(plr.getLocation());
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
}
};

View File

@ -1,6 +1,5 @@
package com.intellectualcrafters.plot.generator;
import java.util.Arrays;
import java.util.Iterator;
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.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
@ -132,7 +129,6 @@ public class AugmentedPopulator extends BlockPopulator {
public void run() {
populateBiome(world, x, z);
chunk.unload(true, true);
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
}
}, 20);
} else {
@ -148,7 +144,6 @@ public class AugmentedPopulator extends BlockPopulator {
chunk.load(true);
populateBlocks(world, rand, X, Z, x, z, check);
chunk.unload(true, true);
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
}
}, 40 + rand.nextInt(40));
}
@ -190,9 +185,6 @@ public class AugmentedPopulator extends BlockPopulator {
}
for (final BlockPopulator populator : this.generator.getDefaultPopulators(world)) {
Chunk chunk = world.getChunkAt(X, Z);
if (MainUtil.canSetFast) {
((BukkitSetBlockManager) BlockUpdateUtil.setBlockManager).update(Arrays.asList(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.PlotSquared;
import com.intellectualcrafters.plot.api.PlotAPI;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitSetBlockManager;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
public class BukkitHybridUtils extends HybridUtils {

View File

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

View File

@ -2,12 +2,9 @@ package com.intellectualcrafters.plot.generator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.generator.BlockPopulator;
import com.intellectualcrafters.plot.PlotSquared;
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.schematic.PlotItem;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
/**
* @author Citymonstret

View File

@ -1,17 +1,13 @@
package com.intellectualcrafters.plot.object;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
import java.util.Map.Entry;
import java.util.Random;
import org.bukkit.Chunk;
import org.bukkit.World;
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.bukkit.BukkitUtil;

View File

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

View File

@ -1,11 +1,11 @@
package com.intellectualcrafters.plot.util;
import java.util.List;
import java.util.Collection;
import com.intellectualcrafters.plot.object.ChunkLoc;
public abstract class BlockUpdateUtil {
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;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
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.PlotPlayer;
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.UUIDHandler;
@ -277,7 +275,6 @@ public class ClusterManager {
@Override
public void run() {
if ((populator == null) || (plotworld.TYPE == 0)) {
BukkitSetBlockManager.setBlockManager.update(Arrays.asList(new Chunk[] { chunk }));
world.regenerateChunk(chunk.getX(), chunk.getZ());
chunk.unload(true, true);
} else {

View File

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

View File

@ -1,7 +1,7 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import org.bukkit.Chunk;
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 update(List<Chunk> list);
public abstract void update(Collection<Chunk> list);
@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 ArrayList<Chunk> chunks = new ArrayList<Chunk>();
for (final ChunkLoc loc : chunkLocs) {

View File

@ -1,6 +1,5 @@
package com.intellectualcrafters.plot.util.bukkit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -95,17 +94,17 @@ public class BukkitUtil extends BlockManager {
return world.getChunkAt(x, z);
}
public static void update(final String world, final int x, final int z) {
final ArrayList<Chunk> chunks = new ArrayList<>();
final int distance = Bukkit.getViewDistance();
for (int cx = -distance; cx < distance; cx++) {
for (int cz = -distance; cz < distance; cz++) {
final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz);
chunks.add(chunk);
}
}
BukkitSetBlockManager.setBlockManager.update(chunks);
}
// public static void update(final String world, final int x, final int z) {
// final ArrayList<Chunk> chunks = new ArrayList<>();
// final int distance = Bukkit.getViewDistance();
// for (int cx = -distance; cx < distance; cx++) {
// for (int cz = -distance; cz < distance; cz++) {
// final Chunk chunk = getChunkAt(world, (x >> 4) + cx, (z >> 4) + cz);
// chunks.add(chunk);
// }
// }
// BukkitSetBlockManager.setBlockManager.update(chunks);
// }
public static String getWorld(final Entity entity) {
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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
@ -53,7 +54,7 @@ public class SendChunk {
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;
final int view = Bukkit.getServer().getViewDistance() << 4;
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 java.util.List;
import java.util.Collection;
import java.util.HashMap;
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.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.TaskManager;
/**
* 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 methodGetById;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
/**
* Constructor
*
@ -56,6 +60,15 @@ public class SetBlockFast extends BukkitSetBlockManager {
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
methodA = classChunk.getMethod("a", int.class, int.class, int.class, classBlock, 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
*/
@Override
public void update(final List<Chunk> chunks) {
public void update(final Collection<Chunk> chunks) {
if (chunks.size() == 0) {
return;
}
if (!MainUtil.canSendChunk) {
final World world = chunks.get(0).getWorld();
for (final Chunk chunk : chunks) {
world.refreshChunk(chunk.getX(), chunk.getZ());
chunk.unload();
chunk.load(false);
}
return;

View File

@ -22,7 +22,8 @@ package com.intellectualcrafters.plot.util.bukkit;
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.World;
@ -33,6 +34,7 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefClass;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefConstructor;
import com.intellectualcrafters.plot.util.ReflectionUtils.RefMethod;
import com.intellectualcrafters.plot.util.TaskManager;
/**
* 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 RefConstructor constructorBlockPosition;
public static HashMap<ChunkLoc, Chunk> toUpdate = new HashMap<>();
/**
* Constructor
*
@ -63,6 +67,15 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
methodGetHandle = classCraftWorld.getMethod("getHandle");
methodGetChunkAt = classWorld.getMethod("getChunkAt", int.class, int.class);
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;
@ -270,8 +283,12 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
int Z = z >> 4;
ChunkLoc loc = new ChunkLoc(X, Z);
if (!loc.equals(lastLoc)) {
world.loadChunk(X, Z, false);
lastLoc = loc;
Chunk chunk = toUpdate.get(loc);
if (chunk == null) {
chunk = world.getChunkAt(X, Z);
toUpdate.put(loc, chunk);
}
chunk.load(false);
}
// check sign
final Object w = methodGetHandle.of(world).call();
@ -281,20 +298,14 @@ public class SetBlockFast_1_8 extends BukkitSetBlockManager {
methodA.of(chunk).call(pos, combined);
}
/**
* Update chunks
*
* @param chunks chunks to be updated
*/
@Override
public void update(final List<Chunk> chunks) {
public void update(final Collection<Chunk> chunks) {
if (chunks.size() == 0) {
return;
}
if (!MainUtil.canSendChunk) {
final World world = chunks.get(0).getWorld();
for (final Chunk chunk : chunks) {
world.refreshChunk(chunk.getX(), chunk.getZ());
chunk.unload();
chunk.load(false);
}
return;

View File

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