From 6b55b8cd6793a05d1ed74a209da52598dcec1164 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 23 Sep 2017 19:10:57 +1000 Subject: [PATCH] Allow configuring a separate nonmember home position --- .../intellectualcrafters/plot/object/Plot.java | 17 +++++++++++------ .../plot/object/PlotArea.java | 15 +++++++++++++-- .../plot/object/PlotLoc.java | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 9e850ebbe..9999da990 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1147,7 +1147,7 @@ public class Plot { public Location getHome() { BlockLoc home = this.getPosition(); if (home == null || home.x == 0 && home.z == 0) { - return this.getDefaultHome(); + return this.getDefaultHome(true); } else { Location bot = this.getBottomAbs(); Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z, home.yaw, home.pitch); @@ -1182,11 +1182,16 @@ public class Plot { * @return */ public Location getDefaultHome() { + return getDefaultHome(false); + } + + public Location getDefaultHome(boolean member) { Plot plot = this.getBasePlot(false); - if (this.area.DEFAULT_HOME != null) { + PlotLoc loc = member ? area.DEFAULT_HOME : area.NONMEMBER_HOME; + if (loc != null) { int x; int z; - if (this.area.DEFAULT_HOME.x == Integer.MAX_VALUE && this.area.DEFAULT_HOME.z == Integer.MAX_VALUE) { + if (loc.x == Integer.MAX_VALUE && loc.z == Integer.MAX_VALUE) { // center RegionWrapper largest = plot.getLargestRegion(); x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; @@ -1194,8 +1199,8 @@ public class Plot { } else { // specific Location bot = plot.getBottomAbs(); - x = bot.getX() + this.area.DEFAULT_HOME.x; - z = bot.getZ() + this.area.DEFAULT_HOME.z; + x = bot.getX() + loc.x; + z = bot.getZ() + loc.z; } int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) : 64; return new Location(plot.getWorldName(), x, y + 1, z); @@ -2600,7 +2605,7 @@ public class Plot { if (this.area.HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) { location = this.getHome(); } else { - location = this.getDefaultHome(); + location = this.getDefaultHome(false); } if (Settings.Teleport.DELAY == 0 || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) { MainUtil.sendMessage(player, C.TELEPORTED_TO_PLOT); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index 9010ff69e..cf9506a34 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -68,6 +68,7 @@ public abstract class PlotArea { public int TYPE = 0; public int TERRAIN = 0; public boolean HOME_ALLOW_NONMEMBER = false; + public PlotLoc NONMEMBER_HOME; public PlotLoc DEFAULT_HOME; public int MAX_BUILD_HEIGHT = 256; public int MIN_BUILD_HEIGHT = 1; @@ -265,8 +266,17 @@ public abstract class PlotArea { break; } - this.HOME_ALLOW_NONMEMBER = config.getBoolean("home.allow-nonmembers"); + String homeNonMembers = config.getString("home.nonmembers"); String homeDefault = config.getString("home.default"); + this.DEFAULT_HOME = PlotLoc.fromString(homeDefault); + this.HOME_ALLOW_NONMEMBER = homeNonMembers.equalsIgnoreCase(homeDefault); + if (this.HOME_ALLOW_NONMEMBER) { + this.NONMEMBER_HOME = DEFAULT_HOME; + } else { + this.NONMEMBER_HOME = PlotLoc.fromString(homeNonMembers); + } + + if ("side".equalsIgnoreCase(homeDefault)) { this.DEFAULT_HOME = null; } else if (StringMan.isEqualIgnoreCaseToAny(homeDefault, "center", "middle")) { @@ -338,7 +348,8 @@ public abstract class PlotArea { options.put("world.border", this.WORLD_BORDER); options.put("limits.max-members", this.MAX_PLOT_MEMBERS); options.put("home.default", "side"); - options.put("home.allow-nonmembers", false); + String position = config.getString("home.nonmembers", config.getBoolean("home.allow-nonmembers", false) ? config.getString("home.default", "side") : "side"); + options.put("home.nonmembers", position); options.put("world.max_height", this.MAX_BUILD_HEIGHT); options.put("world.min_height", this.MIN_BUILD_HEIGHT); options.put("world.gamemode", this.GAMEMODE.name().toLowerCase()); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java index 96a9ad9fe..e2d737147 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotLoc.java @@ -1,5 +1,7 @@ package com.intellectualcrafters.plot.object; +import com.intellectualcrafters.plot.util.StringMan; + public class PlotLoc { public int x; public int z; @@ -8,6 +10,21 @@ public class PlotLoc { this.x = x; this.z = z; } + + public static PlotLoc fromString(String input) { + if ("side".equalsIgnoreCase(input)) { + return null; + } else if (StringMan.isEqualIgnoreCaseToAny(input, "center", "middle")) { + return new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE); + } else { + try { + String[] split = input.split(","); + return new PlotLoc(Integer.parseInt(split[0]), Integer.parseInt(split[1])); + } catch (NumberFormatException ignored) { + return null; + } + } + } @Override public int hashCode() {