From 560ebf412bc60c2c8916e1775a31f5bc3255636f Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 30 Mar 2016 04:34:48 +1100 Subject: [PATCH] Relight command --- .../plotme/ClassicPlotMeConnector.java | 10 ++--- .../plot/commands/MainCommand.java | 1 + .../plot/commands/Relight.java | 45 +++++++++++++++++++ .../plot/flag/FlagValue.java | 3 -- .../plot/util/ChunkManager.java | 21 ++++++++- 5 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java index 67df06031..fa988839b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/ClassicPlotMeConnector.java @@ -129,12 +129,12 @@ public class ClassicPlotMeConnector extends APlotMeConnector { } } if (owner == null) { - if (!name.isEmpty()) { - owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); + if (name.isEmpty()) { + PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); + missing++; + continue; } - PS.log("&cCould not identify owner for plot: " + id + " -> '" + name + "'"); - missing++; - continue; + owner = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name.toLowerCase()).getBytes(Charsets.UTF_8)); } } } else { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 09c9392da..8d2d7e203 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -70,6 +70,7 @@ public class MainCommand extends Command { new PluginCmd(); new Purge(); new Reload(); + new Relight(); new Merge(); new DebugPaste(); new Unlink(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java new file mode 100644 index 000000000..d2b3fd3e9 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java @@ -0,0 +1,45 @@ +package com.intellectualcrafters.plot.commands; + +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.object.RunnableVal2; +import com.intellectualcrafters.plot.object.RunnableVal3; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.PlotChunk; +import com.intellectualcrafters.plot.util.SetQueue; +import com.plotsquared.general.commands.Command; +import com.plotsquared.general.commands.CommandDeclaration; +import java.util.HashSet; + +@CommandDeclaration(command = "relight", description = "Relight your plot", category = CommandCategory.DEBUG) +public class Relight extends Command { + public Relight() { + super(MainCommand.getInstance(), true); + } + + @Override + public void execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) { + final Plot plot = player.getCurrentPlot(); + if (plot == null) { + C.NOT_IN_PLOT.send(player); + return; + } + HashSet regions = plot.getRegions(); + ChunkManager.chunkTask(plot, new RunnableVal() { + @Override + public void run(int[] value) { + SetQueue.ChunkWrapper cw = SetQueue.IMP.new ChunkWrapper(plot.getArea().worldname, value[0], value[1]); + PlotChunk pc = SetQueue.IMP.queue.getChunk(cw); + pc.fixLighting(); + } + }, new Runnable() { + @Override + public void run() { + C.SET_BLOCK_ACTION_FINISHED.send(player); + } + }, 5); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java index d93734c7d..33b14627b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagValue.java @@ -1,11 +1,9 @@ package com.intellectualcrafters.plot.flag; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.WorldUtil; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -443,7 +441,6 @@ public abstract class FlagValue { @Override public List parse(final String t) { System.out.println("PARSE: " + t); - PS.stacktrace(); return new ArrayList<>(Arrays.asList(t.split(","))); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index a82a0755b..e7e562c5e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -8,7 +8,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.SetQueue.ChunkWrapper; - import java.io.File; import java.util.ArrayList; import java.util.Collection; @@ -107,6 +106,24 @@ public abstract class ChunkManager { }); } + public static void chunkTask(final Plot plot, final RunnableVal task, final Runnable whenDone, final int allocate) { + final ArrayList regions = new ArrayList<>(plot.getRegions()); + Runnable smallTask = new Runnable() { + @Override + public void run() { + if (regions.size() == 0) { + TaskManager.runTask(whenDone); + return; + } + RegionWrapper value = regions.remove(0); + Location pos1 = new Location(plot.getArea().worldname, value.minX, 0, value.minZ); + Location pos2 = new Location(plot.getArea().worldname, value.maxX, 0, value.maxZ); + chunkTask(pos1, pos2, task, this, allocate); + } + }; + smallTask.run(); + } + /** * The int[] will be in the form: [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge] and will represent the bottom and top parts of the chunk * @param pos1 @@ -123,7 +140,7 @@ public abstract class ChunkManager { final int bcz = p1z >> 4; final int tcx = p2x >> 4; final int tcz = p2z >> 4; - final ArrayList chunks = new ArrayList(); + final ArrayList chunks = new ArrayList<>(); for (int x = bcx; x <= tcx; x++) { for (int z = bcz; z <= tcz; z++) {