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

4
.gitignore vendored
View File

@ -94,4 +94,6 @@ local.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*
.classpath .classpath
.project .project
/target
/plotsquared/target

View File

@ -326,7 +326,7 @@ public class Metrics {
// enabled // enabled
String pluginVersion = description.getVersion(); String pluginVersion = description.getVersion();
String serverVersion = Bukkit.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 // END server software specific section -- all code below does not use
// any code outside of this class / Java // any code outside of this class / Java
// Construct the post data // Construct the post data

View File

@ -9,6 +9,7 @@
package com.intellectualcrafters.plot; package com.intellectualcrafters.plot;
import com.intellectualcrafters.plot.Logger.LogLevel; import com.intellectualcrafters.plot.Logger.LogLevel;
import com.intellectualcrafters.plot.commands.Auto;
import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.MainCommand;
import com.intellectualcrafters.plot.database.*; import com.intellectualcrafters.plot.database.*;
import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent; import com.intellectualcrafters.plot.events.PlayerTeleportToPlotEvent;
@ -475,6 +476,9 @@ public class PlotMain extends JavaPlugin {
PlotHelper.removeSign(worldobj, plot); PlotHelper.removeSign(worldobj, plot);
DBFunc.delete(world, plot); DBFunc.delete(world, plot);
removePlot(world, plot.id, true); 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); 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 @Override
public boolean execute(Player plr, String... args) { public boolean execute(Player plr, String... args) {
World world; World world;
@ -109,6 +111,15 @@ public class Auto extends SubCommand {
int x = 0, z = 0, q = 100; int x = 0, z = 0, q = 100;
PlotId id; PlotId id;
if ((size_x == 1) && (size_z == 1)) { 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) { while (!br) {
id = new PlotId(x, z); id = new PlotId(x, z);
if (PlotHelper.getPlot(world, id).owner == null) { if (PlotHelper.getPlot(world, id).owner == null) {
@ -133,39 +144,69 @@ public class Auto extends SubCommand {
} }
} }
else { else {
while (!br) { boolean claimed = true;
PlotId start = new PlotId(x, z); while (!br) {
PlotId end = new PlotId((x + size_x) - 1, (z + size_z) - 1); PlotId start = getNextPlot(Auto.lastPlot, 1);
if (isUnowned(world, start, end)) {
for (int i = start.x; i <= end.x; i++) { if (claimed) {
for (int j = start.y; j <= end.y; j++) { if (PlotMain.getPlots(world).get(start) == null || PlotMain.getPlots(world).get(start).owner == null) {
Plot plot = PlotHelper.getPlot(world, new PlotId(i, j)); Auto.lastPlot = start;
boolean teleport = ((i == end.x) && (j == end.y)); continue;
Claim.claimPlot(plr, plot, teleport); }
} }
}
if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) { PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1);
return false; if (isUnowned(world, start, end)) {
} for (int i = start.x; i <= end.x; i++) {
br = true; for (int j = start.y; j <= end.y; j++) {
} Plot plot = PlotHelper.getPlot(world, new PlotId(i, j));
if ((z < q) && ((z - x) < q)) { boolean teleport = ((i == end.x) && (j == end.y));
z += size_z; Claim.claimPlot(plr, plot, teleport);
} }
else }
if (x < q) { if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) {
x += size_x; return false;
z = q - 100; }
} br = true;
else { }
q += 100; }
x = q;
z = q;
}
}
} }
return 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) { public boolean isUnowned(World world, PlotId pos1, PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {

View File

@ -58,6 +58,9 @@ public class Delete extends SubCommand {
if (result) { if (result) {
plot.clear(plr); plot.clear(plr);
DBFunc.delete(plr.getWorld().getName(), plot); 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 { else {
PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); PlayerFunctions.sendMessage(plr, "Plot clearing has been denied.");