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>
</properties>
<artifactId>PlotSquared</artifactId>
<version>2.10.2</version>
<version>2.10.4</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -322,10 +322,20 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
final public ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
WorldEvents.lastWorld = world;
if (!PlotSquared.setupPlotWorld(world, id)) {
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

View File

@ -23,16 +23,12 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue;
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 DebugFill() {
@ -61,56 +57,72 @@ public class DebugFill extends SubCommand {
final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
MainUtil.sendMessage(player, "&cPreparing task");
TaskManager.runTaskAsync(new Runnable() {
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&7 - Starting");
if (args[0].equalsIgnoreCase("all")) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = 0; y <= 255; y++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
}
}
else if (args[0].equals("outline")) {
int x, z;
z = bottom.getZ();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
int y = 255;
for (x = bottom.getX(); x <= top.getX(); x++) {
for (z = bottom.getZ(); z <= top.getZ(); z++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
}
SetBlockQueue.addNotify(new Runnable() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&aFill task complete!");
MainUtil.sendMessage(player, "&7 - Starting");
if (args[0].equalsIgnoreCase("all")) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = 0; y <= 255; y++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
}
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&aFill task complete!");
}
});
}
else if (args[0].equals("outline")) {
int x, z;
z = bottom.getZ();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
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() {
@Override
public void run() {
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;
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)
public static void onWorldInit(final WorldInitEvent event) {
final World world = event.getWorld();
String name = getName(world);
final ChunkGenerator gen = world.getGenerator();
if (gen instanceof PlotGenerator) {
PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen);
//
PlotSquared.loadWorld(name, (PlotGenerator) gen);
} else {
if (PlotSquared.config.contains("worlds." + world.getName())) {
PlotSquared.loadWorld(world.getName(), null);
if (PlotSquared.config.contains("worlds." + name)) {
PlotSquared.loadWorld(name, null);
}
}
lastWorld = null;
}
@EventHandler

View File

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

View File

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