mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
mass condense
This commit is contained in:
parent
e073113856
commit
8cf148fb57
@ -29,6 +29,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@ -70,7 +71,7 @@ public class Condense extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String worldname = args[0];
|
String worldname = args[0];
|
||||||
World world = Bukkit.getWorld(worldname);
|
final World world = Bukkit.getWorld(worldname);
|
||||||
if (world == null || !PlotMain.isPlotWorld(worldname)) {
|
if (world == null || !PlotMain.isPlotWorld(worldname)) {
|
||||||
PlayerFunctions.sendMessage(plr, "INVALID WORLD");
|
PlayerFunctions.sendMessage(plr, "INVALID WORLD");
|
||||||
return false;
|
return false;
|
||||||
@ -81,11 +82,92 @@ public class Condense extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(plr, "NOT IMPLEMENTED");
|
if (TASK) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "TASK ALREADY STARTED");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (args.length == 2) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "/plot condense " + worldname + " start <radius>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!StringUtils.isNumeric(args[2])) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "INVALID RADIUS");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
int radius = Integer.parseInt(args[2]);
|
||||||
|
Collection<Plot> plots = PlotMain.getPlots(worldname).values();
|
||||||
|
int size = plots.size();
|
||||||
|
int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1);
|
||||||
|
if (radius < minimum_radius) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
|
||||||
|
final List<PlotId> free = new ArrayList<>();
|
||||||
|
PlotId start = new PlotId(0,0);
|
||||||
|
while (start.x <= minimum_radius && start.y <= minimum_radius) {
|
||||||
|
Plot plot = PlotHelper.getPlot(world, start);
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
|
free.add(plot.id);
|
||||||
|
}
|
||||||
|
start = Auto.getNextPlot(start, 1);
|
||||||
|
}
|
||||||
|
PlotHelper.move(world, to_move.get(0), free.get(0), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (!TASK) {
|
||||||
|
sendMessage("CONDENSE TASK CANCELLED");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
to_move.remove(0);
|
||||||
|
free.remove(0);
|
||||||
|
int index = 0;
|
||||||
|
for (PlotId id : to_move) {
|
||||||
|
Plot plot = PlotHelper.getPlot(world, id);
|
||||||
|
if (plot.hasOwner()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
for (int i = 0; i<index; i++) {
|
||||||
|
to_move.remove(0);
|
||||||
|
}
|
||||||
|
index = 0;
|
||||||
|
for (PlotId id : free) {
|
||||||
|
Plot plot = PlotHelper.getPlot(world, id);
|
||||||
|
if (!plot.hasOwner()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
for (int i = 0; i<index; i++) {
|
||||||
|
free.remove(0);
|
||||||
|
}
|
||||||
|
if (to_move.size() == 0) {
|
||||||
|
sendMessage("TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
|
||||||
|
TASK = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (free.size() == 0) {
|
||||||
|
sendMessage("TASK FAILED. NO FREE PLOTS FOUND!");
|
||||||
|
TASK = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendMessage("MOVING " + to_move.get(0) +" to " + free.get(0));
|
||||||
|
PlotHelper.move(world, to_move.get(0), free.get(0), this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TASK = true;
|
||||||
|
PlayerFunctions.sendMessage(plr, "TASK STARTED...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "stop": {
|
case "stop": {
|
||||||
PlayerFunctions.sendMessage(plr, "NOT IMPLEMENTED");
|
if (!TASK) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "TASK ALREADY STOPPED");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
TASK = false;
|
||||||
|
PlayerFunctions.sendMessage(plr, "TASK STOPPED");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case "info": {
|
case "info": {
|
||||||
@ -101,6 +183,10 @@ public class Condense extends SubCommand {
|
|||||||
Collection<Plot> plots = PlotMain.getPlots(worldname).values();
|
Collection<Plot> plots = PlotMain.getPlots(worldname).values();
|
||||||
int size = plots.size();
|
int size = plots.size();
|
||||||
int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1);
|
int minimum_radius = (int) Math.ceil((Math.sqrt(size)/2) + 1);
|
||||||
|
if (radius < minimum_radius) {
|
||||||
|
PlayerFunctions.sendMessage(plr, "RADIUS TOO SMALL");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int max_move = getPlots(plots, minimum_radius).size();
|
int max_move = getPlots(plots, minimum_radius).size();
|
||||||
int user_move = getPlots(plots, radius).size();
|
int user_move = getPlots(plots, radius).size();
|
||||||
PlayerFunctions.sendMessage(plr, "=== DEFAULT EVAL ===");
|
PlayerFunctions.sendMessage(plr, "=== DEFAULT EVAL ===");
|
||||||
@ -109,6 +195,7 @@ public class Condense extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, "=== INPUT EVAL ===");
|
PlayerFunctions.sendMessage(plr, "=== INPUT EVAL ===");
|
||||||
PlayerFunctions.sendMessage(plr, "INPUT RADIUS: " + radius);
|
PlayerFunctions.sendMessage(plr, "INPUT RADIUS: " + radius);
|
||||||
PlayerFunctions.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
PlayerFunctions.sendMessage(plr, "ESTIMATED MOVES: " + user_move);
|
||||||
|
PlayerFunctions.sendMessage(plr, "ESTIMATED TIME: " + (user_move * 16) +" seconds");
|
||||||
PlayerFunctions.sendMessage(plr, "&e - Radius is measured in plot width");
|
PlayerFunctions.sendMessage(plr, "&e - Radius is measured in plot width");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -117,11 +204,11 @@ public class Condense extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Plot> getPlots(Collection<Plot> plots, int radius) {
|
public Set<PlotId> getPlots(Collection<Plot> plots, int radius) {
|
||||||
HashSet<Plot> outside = new HashSet<>();
|
HashSet<PlotId> outside = new HashSet<>();
|
||||||
for (Plot plot : plots) {
|
for (Plot plot : plots) {
|
||||||
if (plot.id.x > radius || plot.id.x < -radius || plot.id.y > radius || plot.id.y < -radius) {
|
if (plot.id.x > radius || plot.id.x < -radius || plot.id.y > radius || plot.id.y < -radius) {
|
||||||
outside.add(plot);
|
outside.add(plot.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outside;
|
return outside;
|
||||||
|
@ -68,7 +68,7 @@ public class Move extends SubCommand {
|
|||||||
PlayerFunctions.sendMessage(plr, "DUPLICATE ID");
|
PlayerFunctions.sendMessage(plr, "DUPLICATE ID");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (move(world, plot1, plot2, new Runnable() {
|
if (PlotHelper.move(world, plot1, plot2, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
|
PlayerFunctions.sendMessage(plr, "MOVE SUCCESS");
|
||||||
@ -81,42 +81,4 @@ public class Move extends SubCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean move(final World world, final PlotId current, PlotId newPlot, final Runnable whenDone) {
|
|
||||||
final Location bot1 = PlotHelper.getPlotBottomLoc(world, current);
|
|
||||||
Location bot2 = PlotHelper.getPlotBottomLoc(world, newPlot);
|
|
||||||
final Location top = PlotHelper.getPlotTopLoc(world, current);
|
|
||||||
final Plot currentPlot = PlotHelper.getPlot(world, current);
|
|
||||||
if (currentPlot.owner == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
Plot pos1 = PlayerFunctions.getBottomPlot(world, currentPlot);
|
|
||||||
Plot pos2 = PlayerFunctions.getTopPlot(world, currentPlot);
|
|
||||||
PlotId size = PlotHelper.getSize(world, currentPlot);
|
|
||||||
if (!PlotHelper.isUnowned(world, newPlot, new PlotId(newPlot.x + size.x - 1, newPlot.y + size.y - 1))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int offset_x = newPlot.x - current.x;
|
|
||||||
int offset_y = newPlot.y - current.y;
|
|
||||||
final ArrayList<PlotId> selection = PlayerFunctions.getPlotSelectionIds(pos1.id, pos2.id);
|
|
||||||
String worldname = world.getName();
|
|
||||||
for (PlotId id : selection) {
|
|
||||||
DBFunc.movePlot(world.getName(), new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y));
|
|
||||||
Plot plot = PlotMain.getPlots(worldname).get(id);
|
|
||||||
PlotMain.getPlots(worldname).remove(id);
|
|
||||||
plot.id.x += offset_x;
|
|
||||||
plot.id.y += offset_y;
|
|
||||||
PlotMain.getPlots(worldname).put(plot.id, plot);
|
|
||||||
}
|
|
||||||
ChunkManager.copyRegion(bot1, top, bot2, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Location bot = bot1.clone().add(1, 0, 1);
|
|
||||||
ChunkManager.regenerateRegion(bot, top, null);
|
|
||||||
TaskManager.runTaskLater(whenDone, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -977,6 +977,44 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean move(final World world, final PlotId current, PlotId newPlot, final Runnable whenDone) {
|
||||||
|
final Location bot1 = PlotHelper.getPlotBottomLoc(world, current);
|
||||||
|
Location bot2 = PlotHelper.getPlotBottomLoc(world, newPlot);
|
||||||
|
final Location top = PlotHelper.getPlotTopLoc(world, current);
|
||||||
|
final Plot currentPlot = PlotHelper.getPlot(world, current);
|
||||||
|
if (currentPlot.owner == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Plot pos1 = PlayerFunctions.getBottomPlot(world, currentPlot);
|
||||||
|
Plot pos2 = PlayerFunctions.getTopPlot(world, currentPlot);
|
||||||
|
PlotId size = PlotHelper.getSize(world, currentPlot);
|
||||||
|
if (!PlotHelper.isUnowned(world, newPlot, new PlotId(newPlot.x + size.x - 1, newPlot.y + size.y - 1))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int offset_x = newPlot.x - pos1.id.x;
|
||||||
|
int offset_y = newPlot.y - pos1.id.y;
|
||||||
|
final ArrayList<PlotId> selection = PlayerFunctions.getPlotSelectionIds(pos1.id, pos2.id);
|
||||||
|
String worldname = world.getName();
|
||||||
|
for (PlotId id : selection) {
|
||||||
|
DBFunc.movePlot(world.getName(), new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y));
|
||||||
|
Plot plot = PlotMain.getPlots(worldname).get(id);
|
||||||
|
PlotMain.getPlots(worldname).remove(id);
|
||||||
|
plot.id.x += offset_x;
|
||||||
|
plot.id.y += offset_y;
|
||||||
|
PlotMain.getPlots(worldname).put(plot.id, plot);
|
||||||
|
}
|
||||||
|
ChunkManager.copyRegion(bot1, top, bot2, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Location bot = bot1.clone().add(1, 0, 1);
|
||||||
|
ChunkManager.regenerateRegion(bot, top, null);
|
||||||
|
TaskManager.runTaskLater(whenDone, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static PlotId getSize(World world, Plot plot) {
|
public static PlotId getSize(World world, Plot plot) {
|
||||||
PlotSettings settings = plot.settings;
|
PlotSettings settings = plot.settings;
|
||||||
if (!settings.isMerged()) {
|
if (!settings.isMerged()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user