Fixed plot auto algorithms and

also made some performance improvements
This commit is contained in:
boy0001 2014-10-29 17:18:17 +11:00
parent 13a2d4234b
commit f60bac0e0e
5 changed files with 83 additions and 33 deletions

2
.gitignore vendored
View File

@ -95,3 +95,5 @@ local.properties
hs_err_pid*
.classpath
.project
/target
/plotsquared/target

View File

@ -326,7 +326,7 @@ public class Metrics {
// enabled
String pluginVersion = description.getVersion();
String serverVersion = Bukkit.getVersion();
int playersOnline = Bukkit.getServer().getOnlinePlayers().size();
int playersOnline = Bukkit.getServer().getOnlinePlayers().length;
// END server software specific section -- all code below does not use
// any code outside of this class / Java
// Construct the post data

View File

@ -9,6 +9,7 @@
package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.commands.Auto;
import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.database.*;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
@ -475,6 +476,9 @@ public class PlotMain extends JavaPlugin {
PlotHelper.removeSign(worldobj, plot);
DBFunc.delete(world, plot);
removePlot(world, plot.id, true);
if (Math.abs(plot.id.x)<Math.abs(Auto.lastPlot.x) && Math.abs(plot.id.y)<Math.abs(Auto.lastPlot.y)) {
Auto.lastPlot = plot.id;
}
}
}
}

View File

@ -27,7 +27,9 @@ public class Auto extends SubCommand {
super("auto", "plots.auto", "Claim the nearest plot", "auto", "a", CommandCategory.CLAIMING, true);
}
// TODO auto claim a mega plot!!!!!!!!!!!!
public static PlotId lastPlot = new PlotId(0,0);
// TODO auto claim a mega plot with schematic
@Override
public boolean execute(Player plr, String... args) {
World world;
@ -109,6 +111,15 @@ public class Auto extends SubCommand {
int x = 0, z = 0, q = 100;
PlotId id;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
Plot plot = PlotHelper.getPlot(world, Auto.lastPlot);
if (plot==null || plot.owner == null) {
plot = PlotHelper.getPlot(world, Auto.lastPlot);
boolean result = Claim.claimPlot(plr, plot, true);
br = !result;
}
Auto.lastPlot = getNextPlot(Auto.lastPlot, 1);
}
while (!br) {
id = new PlotId(x, z);
if (PlotHelper.getPlot(world, id).owner == null) {
@ -133,40 +144,70 @@ public class Auto extends SubCommand {
}
}
else {
while (!br) {
PlotId start = new PlotId(x, z);
PlotId end = new PlotId((x + size_x) - 1, (z + size_z) - 1);
if (isUnowned(world, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));
boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport);
}
}
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) {
return false;
}
br = true;
}
if ((z < q) && ((z - x) < q)) {
z += size_z;
}
else
if (x < q) {
x += size_x;
z = q - 100;
}
else {
q += 100;
x = q;
z = q;
}
}
boolean claimed = true;
while (!br) {
PlotId start = getNextPlot(Auto.lastPlot, 1);
if (claimed) {
if (PlotMain.getPlots(world).get(start) == null || PlotMain.getPlots(world).get(start).owner == null) {
Auto.lastPlot = start;
continue;
}
}
PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
if (isUnowned(world, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));
boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport);
}
}
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) {
return false;
}
br = true;
}
}
}
return true;
}
public static PlotId getNextPlot(PlotId id, int step) {
int absX = Math.abs(id.x);
int absY = Math.abs(id.y);
if (absX > absY) {
if (id.x > 0) {
return new PlotId(id.x, id.y + 1);
}
else {
return new PlotId(id.x, id.y - 1);
}
}
else if (absY > absX ){
if (id.y > 0) {
return new PlotId(id.x - 1, id.y);
}
else {
return new PlotId(id.x + 1, id.y);
}
}
else {
if (id.x==id.y && id.x > 0) {
return new PlotId(id.x, id.y + step);
}
if (id.x==absX) {
return new PlotId(id.x, id.y + 1);
}
if (id.y == absY) {
return new PlotId(id.x, id.y - 1);
}
return new PlotId(id.x + 1, id.y);
}
}
public boolean isUnowned(World world, PlotId pos1, PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {

View File

@ -58,6 +58,9 @@ public class Delete extends SubCommand {
if (result) {
plot.clear(plr);
DBFunc.delete(plr.getWorld().getName(), plot);
if (Math.abs(plot.id.x)<=Math.abs(Auto.lastPlot.x) && Math.abs(plot.id.y)<=Math.abs(Auto.lastPlot.y)) {
Auto.lastPlot = plot.id;
}
}
else {
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");