This commit is contained in:
boy0001 2015-02-20 22:23:53 +11:00
parent 16f5cc1f36
commit 632a6e4268
2 changed files with 0 additions and 857 deletions

View File

@ -1,18 +0,0 @@
package com.intellectualcrafters.plot.config;
public class Permissions {
// ADMIN
public static String ADMIN = "plots.admin";
// BUILD
public static String BUILD_OTHER = "plots.admin.build.other";
public static String BUILD_ROAD = "plots.admin.build.road";
public static String BUILD_UNOWNED = "plots.admin.build.unowned";
// INTERACT
public static String INTERACT_OTHER = "plots.admin.interact.other";
public static String INTERACT_ROAD = "plots.admin.interact.road";
public static String INTERACT_UNOWNED = "plots.admin.interact.unowned";
// BREAK
public static String BREAK_OTHER = "plots.admin.break.other";
public static String BREAK_ROAD = "plots.admin.break.road";
public static String BREAK_UNOWNED = "plots.admin.break.unowned";
}

View File

@ -1,839 +0,0 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.UUID;
import com.intellectualcrafters.plot.PlotSquared;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.BlockLoc;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotSettings;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.PlayerFunctions;
import com.intellectualcrafters.plot.util.bukkit.SendChunk;
/**
* plot functions
*
* @author Citymonstret
*/
public class PlotHelper {
public final static HashMap<Plot, Integer> runners = new HashMap<>();
public static boolean canSendChunk = false;
public static ArrayList<String> runners_p = new ArrayList<>();
static long state = 1;
public static HashMap<String, PlotId> lastPlot = new HashMap<>();
public static HashMap<String, Integer> worldBorder = new HashMap<>();
public static int getBorder(final String worldname) {
if (worldBorder.containsKey(worldname)) {
PlotSquared.getPlotWorld(worldname);
return worldBorder.get(worldname) + 16;
}
return Integer.MAX_VALUE;
}
public static void setupBorder(final String world) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
if (!plotworld.WORLD_BORDER) {
return;
}
if (!worldBorder.containsKey(world)) {
worldBorder.put(world, 0);
}
for (final Plot plot : PlotSquared.getPlots(world).values()) {
updateWorldBorder(plot);
}
}
public static void update(final Location loc) {
final String world = loc.getWorld();
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
final int distance = BukkitUtil.getViewDistance();
for (int cx = -distance; cx < distance; cx++) {
for (int cz = -distance; cz < distance; cz++) {
final ChunkLoc chunk = new ChunkLoc(cx, cz);
chunks.add(chunk);
}
}
AbstractSetBlock.setBlockManager.update(world, chunks);
}
public static void createWorld(final String world, final String generator) {
}
public static PlotId parseId(final String arg) {
try {
final String[] split = arg.split(";");
return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
} catch (final Exception e) {
return null;
}
}
/**
* direction 0 = north, 1 = south, etc:
*
* @param id
* @param direction
*
* @return
*/
public static PlotId getPlotIdRelative(final PlotId id, final int direction) {
switch (direction) {
case 0:
return new PlotId(id.x, id.y - 1);
case 1:
return new PlotId(id.x + 1, id.y);
case 2:
return new PlotId(id.x, id.y + 1);
case 3:
return new PlotId(id.x - 1, id.y);
}
return id;
}
public static ArrayList<PlotId> getPlotSelectionIds(final PlotId pos1, final PlotId pos2) {
final ArrayList<PlotId> myplots = new ArrayList<>();
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
myplots.add(new PlotId(x, y));
}
}
return myplots;
}
/**
* Completely merges a set of plots<br> <b>(There are no checks to make sure you supply the correct
* arguments)</b><br> - Misuse of this method can result in unusable plots<br> - the set of plots must belong to one
* owner and be rectangular<br> - the plot array must be sorted in ascending order<br> - Road will be removed where
* required<br> - changes will be saved to DB<br>
*
* @param world
* @param plotIds
*
* @return boolean (success)
*/
public static boolean mergePlots(final String world, final ArrayList<PlotId> plotIds, final boolean removeRoads) {
if (plotIds.size() < 2) {
return false;
}
final PlotId pos1 = plotIds.get(0);
final PlotId pos2 = plotIds.get(plotIds.size() - 1);
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
manager.startPlotMerge(plotworld, plotIds);
final boolean result = false;
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final boolean lx = x < pos2.x;
final boolean ly = y < pos2.y;
final PlotId id = new PlotId(x, y);
final Plot plot = PlotSquared.getPlots(world).get(id);
Plot plot2 = null;
if (removeRoads) {
removeSign(plot);
}
if (lx) {
if (ly) {
if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) {
if (removeRoads) {
manager.removeRoadSouthEast(plotworld, plot);
}
}
}
if (!plot.settings.getMerged(1)) {
plot2 = PlotSquared.getPlots(world).get(new PlotId(x + 1, y));
mergePlot(world, plot, plot2, removeRoads);
plot.settings.setMerged(1, true);
plot2.settings.setMerged(3, true);
}
}
if (ly) {
if (!plot.settings.getMerged(2)) {
plot2 = PlotSquared.getPlots(world).get(new PlotId(x, y + 1));
mergePlot(world, plot, plot2, removeRoads);
plot.settings.setMerged(2, true);
plot2.settings.setMerged(0, true);
}
}
}
}
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
final Plot plot = PlotSquared.getPlots(world).get(id);
DBFunc.setMerged(world, plot, plot.settings.getMerged());
}
}
manager.finishPlotMerge(plotworld, plotIds);
return result;
}
/**
* Merges 2 plots Removes the road inbetween <br> - Assumes the first plot parameter is lower <br> - Assumes neither
* are a Mega-plot <br> - Assumes plots are directly next to each other <br> - Saves to DB
*
* @param world
* @param lesserPlot
* @param greaterPlot
*/
public static void mergePlot(final String world, final Plot lesserPlot, final Plot greaterPlot, final boolean removeRoads) {
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
if (lesserPlot.id.x.equals(greaterPlot.id.x)) {
if (!lesserPlot.settings.getMerged(2)) {
lesserPlot.settings.setMerged(2, true);
greaterPlot.settings.setMerged(0, true);
if (removeRoads) {
manager.removeRoadSouth(plotworld, lesserPlot);
}
}
} else {
if (!lesserPlot.settings.getMerged(1)) {
lesserPlot.settings.setMerged(1, true);
greaterPlot.settings.setMerged(3, true);
if (removeRoads) {
manager.removeRoadEast(plotworld, lesserPlot);
}
}
}
}
public static void removeSign(final Plot p) {
final String world = p.world;
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final Location loc = manager.getSignLoc(plotworld, p);
BlockManager.setBlocks(world, new int[] { loc.getX() }, new int[] { loc.getY() }, new int[] { loc.getZ() }, new int[] { 0 }, new byte[] { 0 });
}
public static void setSign(String name, final Plot p) {
if (name == null) {
name = "unknown";
}
final PlotManager manager = PlotSquared.getPlotManager(p.world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(p.world);
final Location loc = manager.getSignLoc(plotworld, p);
final String id = p.id.x + ";" + p.id.y;
final String[] lines = new String[] { C.OWNER_SIGN_LINE_1.translated().replaceAll("%id%", id), C.OWNER_SIGN_LINE_2.translated().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_3.translated().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_4.translated().replaceAll("%id%", id).replaceAll("%plr%", name) };
BlockManager.setSign(p.world, loc.getX(), loc.getY(), loc.getZ(), lines);
}
public static String getStringSized(final int max, final String string) {
if (string.length() > max) {
return string.substring(0, max);
}
return string;
}
public static void autoMerge(final String world, final Plot plot, final UUID uuid) {
if (plot == null) {
return;
}
if (plot.owner == null) {
return;
}
if (!plot.owner.equals(uuid)) {
return;
}
ArrayList<PlotId> plots;
boolean merge = true;
int count = 0;
while (merge) {
if (count > 16) {
break;
}
count++;
final PlotId bot = getBottomPlot(world, plot).id;
final PlotId top = getTopPlot(world, plot).id;
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, uuid, 0)) {
final boolean result = mergePlots(world, plots, true);
if (result) {
merge = true;
continue;
}
}
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
if (ownsPlots(world, plots, uuid, 1)) {
final boolean result = mergePlots(world, plots, true);
if (result) {
merge = true;
continue;
}
}
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
if (ownsPlots(world, plots, uuid, 2)) {
final boolean result = mergePlots(world, plots, true);
if (result) {
merge = true;
continue;
}
}
plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, uuid, 3)) {
final boolean result = mergePlots(world, plots, true);
if (result) {
merge = true;
continue;
}
}
merge = false;
}
update(getPlotHome(world, plot));
}
private static boolean ownsPlots(final String world, final ArrayList<PlotId> plots, final UUID uuid, final int dir) {
final PlotId id_min = plots.get(0);
final PlotId id_max = plots.get(plots.size() - 1);
for (final PlotId myid : plots) {
final Plot myplot = PlotSquared.getPlots(world).get(myid);
if ((myplot == null) || !myplot.hasOwner() || !(myplot.getOwner().equals(uuid))) {
return false;
}
final PlotId top = getTopPlot(world, myplot).id;
if (((top.x > id_max.x) && (dir != 1)) || ((top.y > id_max.y) && (dir != 2))) {
return false;
}
final PlotId bot = getBottomPlot(world, myplot).id;
if (((bot.x < id_min.x) && (dir != 3)) || ((bot.y < id_min.y) && (dir != 0))) {
return false;
}
}
return true;
}
public static void updateWorldBorder(final Plot plot) {
if (!worldBorder.containsKey(plot.world)) {
return;
}
final String world = plot.world;
final PlotManager manager = PlotSquared.getPlotManager(world);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final Location bot = manager.getPlotBottomLocAbs(plotworld, plot.id);
final Location top = manager.getPlotTopLocAbs(plotworld, plot.id);
final int border = worldBorder.get(plot.world);
final int botmax = Math.max(Math.abs(bot.getX()), Math.abs(bot.getZ()));
final int topmax = Math.max(Math.abs(top.getX()), Math.abs(top.getZ()));
final int max = Math.max(botmax, topmax);
if (max > border) {
worldBorder.put(plot.world, max);
}
}
/**
* Create a plot and notify the world border and plot merger
*/
public static boolean createPlot(final UUID uuid, final Plot plot) {
if (PlotHelper.worldBorder.containsKey(plot.world)) {
updateWorldBorder(plot);
}
final Plot p = createPlotAbs(uuid, plot);
final PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world);
if (plotworld.AUTO_MERGE) {
autoMerge(plot.world, p, uuid);
}
return true;
}
/**
* Create a plot without notifying the merge function or world border manager
*/
public static Plot createPlotAbs(final UUID uuid, final Plot plot) {
final String w = plot.world;
final Plot p = new Plot(plot.id, uuid, new ArrayList<UUID>(), new ArrayList<UUID>(), w);
PlotSquared.updatePlot(p);
DBFunc.createPlotAndSettings(p);
return p;
}
public static String createId(final int x, final int z) {
return x + ";" + z;
}
public static int square(final int x) {
return x * x;
}
public static short[] getBlock(final String block) {
if (block.contains(":")) {
final String[] split = block.split(":");
return new short[] { Short.parseShort(split[0]), Short.parseShort(split[1]) };
}
return new short[] { Short.parseShort(block), 0 };
}
/**
* Clear a plot and associated sections: [sign, entities, border]
*
* @param requester
* @param plot
*/
public static boolean clearAsPlayer(final Plot plot, final boolean isDelete, final Runnable whenDone) {
if (runners.containsKey(plot)) {
return false;
}
AChunkManager.manager.clearAllEntities(plot);
clear(plot.world, plot, isDelete, whenDone);
removeSign(plot);
return true;
}
public static void clear(final String world, final Plot plot, final boolean isDelete, final Runnable whenDone) {
final PlotManager manager = PlotSquared.getPlotManager(world);
final Location pos1 = PlotHelper.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final int prime = 31;
int h = 1;
h = (prime * h) + pos1.getX();
h = (prime * h) + pos1.getZ();
state = h;
System.currentTimeMillis();
final Location location = PlotHelper.getPlotHomeDefault(plot);
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
runners.put(plot, 1);
if (plotworld.TERRAIN != 0) {
final Location pos2 = PlotHelper.getPlotTopLoc(world, plot.id);
AChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
@Override
public void run() {
runners.remove(plot);
TaskManager.runTask(whenDone);
}
});
return;
}
final Runnable run = new Runnable() {
@Override
public void run() {
PlotHelper.setBiome(world, plot, "FOREST");
runners.remove(plot);
TaskManager.runTask(whenDone);
update(location);
}
};
manager.clearPlot(plotworld, plot, isDelete, run);
}
public static void setCuboid(final String world, final Location pos1, final Location pos2, final PlotBlock[] blocks) {
if (blocks.length == 1) {
setSimpleCuboid(world, pos1, pos2, blocks[0]);
return;
}
final int length = (pos2.getX() - pos1.getX()) * (pos2.getY() - pos1.getY()) * (pos2.getZ() - pos1.getZ());
final int[] xl = new int[length];
final int[] yl = new int[length];
final int[] zl = new int[length];
final int[] ids = new int[length];
final byte[] data = new byte[length];
int index = 0;
for (int y = pos1.getY(); y < pos2.getY(); y++) {
for (int x = pos1.getX(); x < pos2.getX(); x++) {
for (int z = pos1.getZ(); z < pos2.getZ(); z++) {
final int i = BlockManager.random(blocks.length);
xl[index] = x;
yl[index] = y;
zl[index] = z;
final PlotBlock block = blocks[i];
ids[index] = block.id;
data[index] = block.data;
index++;
}
}
}
BlockManager.setBlocks(world, xl, yl, zl, ids, data);
}
public static void setSimpleCuboid(final String world, final Location pos1, final Location pos2, final PlotBlock newblock) {
final int length = (pos2.getX() - pos1.getX()) * (pos2.getY() - pos1.getY()) * (pos2.getZ() - pos1.getZ());
final int[] xl = new int[length];
final int[] yl = new int[length];
final int[] zl = new int[length];
final int[] ids = new int[length];
final byte[] data = new byte[length];
int index = 0;
for (int y = pos1.getY(); y < pos2.getY(); y++) {
for (int x = pos1.getX(); x < pos2.getX(); x++) {
for (int z = pos1.getZ(); z < pos2.getZ(); z++) {
xl[index] = x;
yl[index] = y;
zl[index] = z;
ids[index] = newblock.id;
data[index] = newblock.data;
index++;
}
}
}
BlockManager.setBlocks(world, xl, yl, zl, ids, data);
}
public static void setBiome(final String world, final Plot plot, final String biome) {
final int bottomX = getPlotBottomLoc(world, plot.id).getX() + 1;
final int topX = getPlotTopLoc(world, plot.id).getX();
final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1;
final int topZ = getPlotTopLoc(world, plot.id).getZ();
BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome);
}
public static int getHeighestBlock(final String world, final int x, final int z) {
final int result = BukkitUtil.getHeighestBlock(world, x, z);
if (result == 0) {
return 64;
}
return result;
// for (int i = 1; i < world.getMaxHeight(); i++) {
// id = world.getBlockAt(x, i, z).getTypeId();
// if (id == 0) {
// if (safe) {
// return i;
// }
// safe = true;
// }
// }
// return 64;
}
/**
* Get plot home
*
* @param w World in which the plot is located
* @param plotid Plot ID
*
* @return Home Location
*/
public static Location getPlotHome(final String w, final PlotId plotid) {
final Plot plot = getPlot(w, plotid);
final BlockLoc home = plot.settings.getPosition();
final Location bot = getPlotBottomLoc(w, plotid);
final PlotManager manager = PlotSquared.getPlotManager(w);
if ((home == null) || ((home.x == 0) && (home.z == 0))) {
final Location top = getPlotTopLoc(w, plotid);
final int x = ((top.getX() - bot.getX()) / 2) + bot.getX();
final int z = ((top.getZ() - bot.getZ()) / 2) + bot.getZ();
final int y = Math.max(getHeighestBlock(w, x, z), manager.getSignLoc(PlotSquared.getPlotWorld(w), plot).getY());
return new Location(w, x, y, z);
} else {
final int y = Math.max(getHeighestBlock(w, home.x, home.z), home.y);
return bot.add(home.x, y, home.z);
}
}
/**
* Retrieve the location of the default plot home position
*
* @param plot Plot
*
* @return the location
*/
public static Location getPlotHomeDefault(final Plot plot) {
final Location l = getPlotBottomLoc(plot.world, plot.getId()).subtract(0, 0, 0);
l.setY(getHeighestBlock(plot.world, l.getX(), l.getZ()));
return l;
}
/**
* Get the plot home
*
* @param w World
* @param plot Plot Object
*
* @return Plot Home Location
*
* @see #getPlotHome(org.bukkit.World, com.intellectualcrafters.plot.object.PlotId)
*/
public static Location getPlotHome(final String w, final Plot plot) {
return getPlotHome(w, plot.id);
}
/**
* Refresh the plot chunks
*
* @param world World in which the plot is located
* @param plot Plot Object
*/
public static void refreshPlotChunks(final String world, final Plot plot) {
final int bottomX = getPlotBottomLoc(world, plot.id).getX();
final int topX = getPlotTopLoc(world, plot.id).getX();
final int bottomZ = getPlotBottomLoc(world, plot.id).getZ();
final int topZ = getPlotTopLoc(world, plot.id).getZ();
final int minChunkX = (int) Math.floor((double) bottomX / 16);
final int maxChunkX = (int) Math.floor((double) topX / 16);
final int minChunkZ = (int) Math.floor((double) bottomZ / 16);
final int maxChunkZ = (int) Math.floor((double) topZ / 16);
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
for (int x = minChunkX; x <= maxChunkX; x++) {
for (int z = minChunkZ; z <= maxChunkZ; z++) {
if (canSendChunk) {
final ChunkLoc chunk = new ChunkLoc(x, z);
chunks.add(chunk);
} else {
BukkitUtil.refreshChunk(world, x, z);
}
}
}
try {
SendChunk.sendChunk(world, chunks);
} catch (final Throwable e) {
canSendChunk = false;
for (int x = minChunkX; x <= maxChunkX; x++) {
for (int z = minChunkZ; z <= maxChunkZ; z++) {
BukkitUtil.refreshChunk(world, x, z);
}
}
}
}
/**
* Gets the top plot location of a plot (all plots are treated as small plots) - To get the top loc of a mega plot
* use getPlotTopLoc(...)
*
* @param world
* @param id
*
* @return
*/
public static Location getPlotTopLocAbs(final String world, final PlotId id) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world);
return manager.getPlotTopLocAbs(plotworld, id);
}
/**
* Gets the bottom plot location of a plot (all plots are treated as small plots) - To get the top loc of a mega
* plot use getPlotBottomLoc(...)
*
* @param world
* @param id
*
* @return
*/
public static Location getPlotBottomLocAbs(final String world, final PlotId id) {
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, id);
}
/**
* Obtains the width of a plot (x width)
*
* @param world
* @param id
*
* @return
*/
public static int getPlotWidth(final String world, final PlotId id) {
return getPlotTopLoc(world, id).getX() - getPlotBottomLoc(world, id).getX();
}
/**
* Gets the top loc of a plot (if mega, returns top loc of that mega plot) - If you would like each plot treated as
* a small plot use getPlotTopLocAbs(...)
*
* @param world
* @param id
*
* @return
*/
public static Location getPlotTopLoc(final String world, PlotId id) {
final Plot plot = PlotSquared.getPlots(world).get(id);
if (plot != null) {
id = getTopPlot(world, plot).id;
}
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world);
return manager.getPlotTopLocAbs(plotworld, id);
}
/**
* Gets the bottom loc of a plot (if mega, returns bottom loc of that mega plot) - If you would like each plot
* treated as a small plot use getPlotBottomLocAbs(...)
*
* @param world
* @param id
*
* @return
*/
public static Location getPlotBottomLoc(final String world, PlotId id) {
final Plot plot = PlotSquared.getPlots(world).get(id);
if (plot != null) {
id = getBottomPlot(world, plot).id;
}
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final PlotManager manager = PlotSquared.getPlotManager(world);
return manager.getPlotBottomLocAbs(plotworld, id);
}
public static boolean isUnowned(final String world, final PlotId pos1, final PlotId pos2) {
for (int x = pos1.x; x <= pos2.x; x++) {
for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y);
if (PlotSquared.getPlots(world).get(id) != null) {
if (PlotSquared.getPlots(world).get(id).owner != null) {
return false;
}
}
}
}
return true;
}
public static boolean move(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
final com.intellectualcrafters.plot.object.Location bot1 = PlotHelper.getPlotBottomLoc(world, current);
final com.intellectualcrafters.plot.object.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;
}
final Plot pos1 = getBottomPlot(world, currentPlot);
final Plot pos2 = getTopPlot(world, currentPlot);
final 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;
}
final int offset_x = newPlot.x - pos1.id.x;
final int offset_y = newPlot.y - pos1.id.y;
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
for (final PlotId id : selection) {
DBFunc.movePlot(world, new PlotId(id.x, id.y), new PlotId(id.x + offset_x, id.y + offset_y));
final Plot plot = PlotSquared.getPlots(world).get(id);
PlotSquared.getPlots(world).remove(id);
plot.id.x += offset_x;
plot.id.y += offset_y;
PlotSquared.getPlots(world).put(plot.id, plot);
}
AChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
@Override
public void run() {
final Location bot = bot1.clone().add(1, 0, 1);
AChunkManager.manager.regenerateRegion(bot, top, null);
TaskManager.runTaskLater(whenDone, 1);
}
});
return true;
}
public static Plot getBottomPlot(final String world, final Plot plot) {
if (plot.settings.getMerged(0)) {
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y - 1));
if (p == null) {
return plot;
}
return getBottomPlot(world, p);
}
if (plot.settings.getMerged(3)) {
final Plot p = PlotSquared.getPlots(world).get(new PlotId(plot.id.x - 1, plot.id.y));
if (p == null) {
return plot;
}
return getBottomPlot(world, p);
}
return plot;
}
public static Plot getTopPlot(final String world, final Plot plot) {
if (plot.settings.getMerged(2)) {
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x, plot.id.y + 1)));
}
if (plot.settings.getMerged(1)) {
return getTopPlot(world, PlotSquared.getPlots(world).get(new PlotId(plot.id.x + 1, plot.id.y)));
}
return plot;
}
public static PlotId getSize(final String world, final Plot plot) {
final PlotSettings settings = plot.settings;
if (!settings.isMerged()) {
return new PlotId(1, 1);
}
final Plot top = getTopPlot(world, plot);
final Plot bot = getBottomPlot(world, plot);
return new PlotId((top.id.x - bot.id.x) + 1, (top.id.y - bot.id.y) + 1);
}
/**
* Fetches the plot from the main class
*/
public static Plot getPlot(final String world, final PlotId id) {
if (id == null) {
return null;
}
if (PlotSquared.getPlots(world).containsKey(id)) {
return PlotSquared.getPlots(world).get(id);
}
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world);
}
/**
* Returns the plot at a location (mega plots are not considered, all plots are treated as small plots)
* @param loc
* @return
*/
public static PlotId getPlotAbs(final Location loc) {
final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world);
if (manager == null) {
return null;
}
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ());
}
/**
* Returns the plot id at a location (mega plots are considered)
* @param loc
* @return
*/
public static PlotId getPlotId(final Location loc) {
final String world = loc.getWorld();
final PlotManager manager = PlotSquared.getPlotManager(world);
if (manager == null) {
return null;
}
final PlotWorld plotworld = PlotSquared.getPlotWorld(world);
final PlotId id = manager.getPlotId(plotworld, loc.getX(), loc.getY(), loc.getZ());
if ((id != null) && (plotworld.TYPE == 2)) {
if (ClusterManager.getCluster(world, id) == null) {
return null;
}
}
return id;
}
public static Plot getPlot(final Location loc) {
PlotId id = getPlotId(loc);
if (id == null) {
return null;
}
return getPlot(loc.getWorld(), id);
}
}