misc fixes

This commit is contained in:
boy0001 2015-05-04 23:53:24 +10:00
parent 02b169d311
commit 3b1cae732c
7 changed files with 145 additions and 71 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>2.10.2</version> <version>2.10.4</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -322,10 +322,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override @Override
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) { final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
WorldEvents.lastWorld = world;
if (!PlotSquared.setupPlotWorld(world, id)) { if (!PlotSquared.setupPlotWorld(world, id)) {
return null; return null;
} }
return new HybridGen(); HybridGen result = new HybridGen();
TaskManager.runTaskLater(new Runnable() {
@Override
public void run() {
if (WorldEvents.lastWorld != null && WorldEvents.lastWorld.equals(world)) {
WorldEvents.lastWorld = null;
}
}
}, 20);
return result;
} }
@Override @Override

View File

@ -23,16 +23,12 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.C;
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.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue; import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
import com.intellectualcrafters.plot.uuid.DefaultUUIDWrapper;
import com.intellectualcrafters.plot.uuid.LowerOfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.OfflineUUIDWrapper;
import com.intellectualcrafters.plot.uuid.UUIDWrapper;
public class DebugFill extends SubCommand { public class DebugFill extends SubCommand {
public DebugFill() { public DebugFill() {
@ -61,6 +57,9 @@ public class DebugFill extends SubCommand {
final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id); final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
MainUtil.sendMessage(player, "&cPreparing task"); MainUtil.sendMessage(player, "&cPreparing task");
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -73,6 +72,12 @@ public class DebugFill extends SubCommand {
} }
} }
} }
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&aFill task complete!");
}
});
} }
else if (args[0].equals("outline")) { else if (args[0].equals("outline")) {
int x, z; int x, z;
@ -100,17 +105,24 @@ public class DebugFill extends SubCommand {
SetBlockQueue.setBlock(plot.world, x, y, z, 7); SetBlockQueue.setBlock(plot.world, x, y, z, 7);
} }
} }
int y = 255; SetBlockQueue.addNotify(new Runnable() {
for (x = bottom.getX(); x <= top.getX(); x++) { @Override
for (z = bottom.getZ(); z <= top.getZ(); z++) { public void run() {
SetBlockQueue.setBlock(plot.world, x, y, z, 7); MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
} bottom.setY(255);
} top.add(1,0,1);
} SetBlockQueue.setSlow(true);
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
SetBlockQueue.addNotify(new Runnable() { SetBlockQueue.addNotify(new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.sendMessage(player, "&aFill task complete!"); MainUtil.sendMessage(player, "&aFill task complete!");
SetBlockQueue.setSlow(false);
}
});
}
});
}
} }
}); });
} }

View File

@ -13,17 +13,32 @@ import com.intellectualcrafters.plot.object.PlotGenerator;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
public class WorldEvents implements Listener { public class WorldEvents implements Listener {
public static String lastWorld = null;
public static String getName(World world) {
if (lastWorld != null) {
return lastWorld;
}
else {
return world.getName();
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public static void onWorldInit(final WorldInitEvent event) { public static void onWorldInit(final WorldInitEvent event) {
final World world = event.getWorld(); final World world = event.getWorld();
String name = getName(world);
final ChunkGenerator gen = world.getGenerator(); final ChunkGenerator gen = world.getGenerator();
if (gen instanceof PlotGenerator) { if (gen instanceof PlotGenerator) {
PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen); //
PlotSquared.loadWorld(name, (PlotGenerator) gen);
} else { } else {
if (PlotSquared.config.contains("worlds." + world.getName())) { if (PlotSquared.config.contains("worlds." + name)) {
PlotSquared.loadWorld(world.getName(), null); PlotSquared.loadWorld(name, null);
} }
} }
lastWorld = null;
} }
@EventHandler @EventHandler

View File

@ -31,6 +31,7 @@ import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.listeners.WorldEvents;
import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.ChunkManager;
public abstract class PlotGenerator extends ChunkGenerator { public abstract class PlotGenerator extends ChunkGenerator {
@ -43,8 +44,8 @@ public abstract class PlotGenerator extends ChunkGenerator {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<BlockPopulator> getDefaultPopulators(World world) { public List<BlockPopulator> getDefaultPopulators(World world) {
PlotSquared.loadWorld(world.getName(), this); PlotSquared.loadWorld(WorldEvents.getName(world), this);
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName()); PlotWorld plotworld = PlotSquared.getPlotWorld(WorldEvents.getName(world));
if (!plotworld.MOB_SPAWNING) { if (!plotworld.MOB_SPAWNING) {
if (!plotworld.SPAWN_EGGS) { if (!plotworld.SPAWN_EGGS) {
world.setSpawnFlags(false, false); world.setSpawnFlags(false, false);
@ -61,7 +62,7 @@ public abstract class PlotGenerator extends ChunkGenerator {
world.setMonsterSpawnLimit(-1); world.setMonsterSpawnLimit(-1);
world.setWaterAnimalSpawnLimit(-1); world.setWaterAnimalSpawnLimit(-1);
} }
return (List<BlockPopulator>)(List<?>) getPopulators(world.getName()); return (List<BlockPopulator>)(List<?>) getPopulators(WorldEvents.getName(world));
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package com.intellectualcrafters.plot.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry; import java.util.Map.Entry;
import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.PlotSquared;
@ -16,6 +15,7 @@ public class SetBlockQueue {
private volatile static boolean running = false; private volatile static boolean running = false;
private volatile static boolean locked = false; private volatile static boolean locked = false;
private volatile static HashSet<Runnable> runnables; private volatile static HashSet<Runnable> runnables;
private volatile static boolean slow = false;
public synchronized static void allocate(int t) { public synchronized static void allocate(int t) {
allocate = t; allocate = t;
@ -25,15 +25,23 @@ public class SetBlockQueue {
return allocate; return allocate;
} }
public static void setSlow(boolean value) {
slow = value;
}
public synchronized static void addNotify(Runnable whenDone) { public synchronized static void addNotify(Runnable whenDone) {
if (runnables == null) { if (runnables == null) {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
slow = false;
locked = false;
} }
else { else {
runnables.add(whenDone); runnables.add(whenDone);
} }
} }
private static long last;
public synchronized static void init() { public synchronized static void init() {
if (blocks == null) { if (blocks == null) {
if (AugmentedPopulator.x_loc == null) { if (AugmentedPopulator.x_loc == null) {
@ -59,22 +67,48 @@ public class SetBlockQueue {
runnables = null; runnables = null;
blocks = null; blocks = null;
running = false; running = false;
slow = false;
return; return;
} }
long start = System.currentTimeMillis() + allocate; long newLast = System.currentTimeMillis();
Iterator<Entry<ChunkWrapper, PlotBlock[][]>> i = blocks.entrySet().iterator(); last = Math.max(newLast - 100, last);
while (System.currentTimeMillis() < start && i.hasNext()) { while (blocks.size() > 0 && (System.currentTimeMillis() - last < 100 + allocate)) {
if (locked) { if (locked) {
return; return;
} }
Entry<ChunkWrapper, PlotBlock[][]> n = i.next(); Entry<ChunkWrapper, PlotBlock[][]> n = blocks.entrySet().iterator().next();
i.remove();
ChunkWrapper chunk = n.getKey(); ChunkWrapper chunk = n.getKey();
PlotBlock[][] blocks = n.getValue();
int X = chunk.x << 4; int X = chunk.x << 4;
int Z = chunk.z << 4; int Z = chunk.z << 4;
PlotBlock[][] blocks = n.getValue();
String world = chunk.world; String world = chunk.world;
// ChunkManager.manager.setChunk(chunk, blocks); if (slow) {
boolean once = false;
for (int j = 0; j < blocks.length; j++) {
PlotBlock[] blocksj = blocks[j];
if (blocksj != null) {
long start = System.currentTimeMillis();
for (int k = 0; k < blocksj.length; k++) {
if (once && (System.currentTimeMillis() - start > allocate)) {
SetBlockQueue.blocks.put(n.getKey(), blocks);
return;
}
PlotBlock block = blocksj[k];
if (block != null) {
int x = AugmentedPopulator.x_loc[j][k];
int y = AugmentedPopulator.y_loc[j][k];
int z = AugmentedPopulator.z_loc[j][k];
BlockManager.manager.functionSetBlock(world, X + x, y, Z + z, block.id, block.data);
blocks[j][k] = null;
once = true;
}
}
}
}
SetBlockQueue.blocks.remove(n.getKey());
return;
}
SetBlockQueue.blocks.remove(n.getKey());
for (int j = 0; j < blocks.length; j++) { for (int j = 0; j < blocks.length; j++) {
PlotBlock[] blocksj = blocks[j]; PlotBlock[] blocksj = blocks[j];
if (blocksj != null) { if (blocksj != null) {
@ -108,11 +142,13 @@ public class SetBlockQueue {
z -= Z << 4; z -= Z << 4;
ChunkWrapper wrap = new ChunkWrapper(world, X, Z); ChunkWrapper wrap = new ChunkWrapper(world, X, Z);
PlotBlock[][] result = blocks.get(wrap); PlotBlock[][] result;
result = blocks.get(wrap);
if (!blocks.containsKey(wrap)) { if (!blocks.containsKey(wrap)) {
result = new PlotBlock[16][]; result = new PlotBlock[16][];
blocks.put(wrap, result); blocks.put(wrap, result);
} }
if (result[y >> 4] == null) { if (result[y >> 4] == null) {
result[y >> 4] = new PlotBlock[4096]; result[y >> 4] = new PlotBlock[4096];
} }
@ -132,9 +168,9 @@ public class SetBlockQueue {
int Z = z >> 4; int Z = z >> 4;
x -= X << 4; x -= X << 4;
z -= Z << 4; z -= Z << 4;
ChunkWrapper wrap = new ChunkWrapper(world, X, Z); ChunkWrapper wrap = new ChunkWrapper(world, X, Z);
PlotBlock[][] result = blocks.get(wrap); PlotBlock[][] result;
result = blocks.get(wrap);
if (!blocks.containsKey(wrap)) { if (!blocks.containsKey(wrap)) {
result = new PlotBlock[16][]; result = new PlotBlock[16][];
blocks.put(wrap, result); blocks.put(wrap, result);