Allow specifying Y value in default plot homes

This commit is contained in:
Sauilitired 2018-12-28 02:54:51 +01:00
parent 01a927ccad
commit 9ae8f803b5
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
3 changed files with 30 additions and 25 deletions

View file

@ -1202,8 +1202,8 @@ public class Plot {
x = bot.getX() + loc.x; x = bot.getX() + loc.x;
z = bot.getZ() + loc.z; z = bot.getZ() + loc.z;
} }
int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) : 64; int y = loc.y < 1 ? (isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) + 1 : 63) : loc.y;
return new Location(plot.getWorldName(), x, y + 1, z); return new Location(plot.getWorldName(), x, y, z);
} }
// Side // Side
return plot.getSide(); return plot.getSide();

View file

@ -10,28 +10,15 @@ import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.flag.Flags;
import com.intellectualcrafters.plot.generator.GridPlotWorld; import com.intellectualcrafters.plot.generator.GridPlotWorld;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.*;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.PlotGameMode;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.area.QuadMap; import com.intellectualcrafters.plot.util.area.QuadMap;
import com.intellectualcrafters.plot.util.block.GlobalBlockQueue; import com.intellectualcrafters.plot.util.block.GlobalBlockQueue;
import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import com.intellectualcrafters.plot.util.block.LocalBlockQueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* @author Jesse Boyd * @author Jesse Boyd
@ -283,8 +270,7 @@ public abstract class PlotArea {
this.DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE); this.DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
} else { } else {
try { try {
String[] split = homeDefault.split(","); this.DEFAULT_HOME = PlotLoc.fromString(homeDefault);
this.DEFAULT_HOME = new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
this.DEFAULT_HOME = null; this.DEFAULT_HOME = null;
} }

View file

@ -3,11 +3,20 @@ package com.intellectualcrafters.plot.object;
import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.StringMan;
public class PlotLoc { public class PlotLoc {
public int x; public int x;
public int y;
public int z; public int z;
public PlotLoc(int x, int z) { public PlotLoc(int x, int z) {
this.x = x; this.x = x;
this.y = -1;
this.z = z;
}
public PlotLoc(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z; this.z = z;
} }
@ -19,7 +28,13 @@ public class PlotLoc {
} else { } else {
try { try {
String[] split = input.split(","); String[] split = input.split(",");
return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1])); if (split.length == 2) {
return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} else if (split.length == 3) {
return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]));
} else {
throw new IllegalArgumentException(String.format("Unable to deserialize: %s", input));
}
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
return null; return null;
} }
@ -31,13 +46,17 @@ public class PlotLoc {
int prime = 31; int prime = 31;
int result = 1; int result = 1;
result = (prime * result) + this.x; result = (prime * result) + this.x;
result = (prime * result) + this.y;
result = (prime * result) + this.z; result = (prime * result) + this.z;
return result; return result;
} }
@Override @Override
public String toString() { public String toString() {
return this.x + "," + this.z; if (this.y == -1) {
return String.format("%d,%d", x, z);
}
return String.format("%d,%d,%d", x, y, z);
} }
@Override @Override
@ -52,6 +71,6 @@ public class PlotLoc {
return false; return false;
} }
PlotLoc other = (PlotLoc) obj; PlotLoc other = (PlotLoc) obj;
return (this.x == other.x) && (this.z == other.z); return (this.x == other.x) && (this.y == other.y) && (this.z == other.z);
} }
} }