2015-02-20 22:23:48 +11:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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;
|
|
|
|
|
2015-07-06 01:44:10 +10:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
2015-07-03 22:15:20 +10:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-02-20 22:23:48 +11:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
2015-07-06 01:44:10 +10:00
|
|
|
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.PlotCluster;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotId;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotManager;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotSettings;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
|
|
|
import com.intellectualcrafters.plot.object.PseudoRandom;
|
2015-02-20 22:23:48 +11:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
|
2015-04-30 23:57:44 +10:00
|
|
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
2015-02-20 22:23:48 +11:00
|
|
|
|
|
|
|
/**
|
|
|
|
* plot functions
|
|
|
|
*
|
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
|
|
|
public class MainUtil {
|
|
|
|
public final static HashMap<Plot, Integer> runners = new HashMap<>();
|
|
|
|
public static boolean canSendChunk = false;
|
2015-03-18 16:50:07 +11:00
|
|
|
public static boolean canSetFast = true;
|
2015-02-20 22:23:48 +11:00
|
|
|
public static ArrayList<String> runners_p = new ArrayList<>();
|
|
|
|
public static HashMap<String, PlotId> lastPlot = new HashMap<>();
|
|
|
|
public static HashMap<String, Integer> worldBorder = new HashMap<>();
|
2015-07-03 11:30:26 +02:00
|
|
|
static long state = 1;
|
2015-03-27 18:36:28 +11:00
|
|
|
static PseudoRandom random = new PseudoRandom();
|
2015-03-12 19:52:26 +11:00
|
|
|
|
2015-04-26 16:29:58 +10:00
|
|
|
public static boolean isPlotArea(final Location location) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(location.getWorld());
|
2015-04-26 16:29:58 +10:00
|
|
|
if (plotworld.TYPE == 2) {
|
|
|
|
return ClusterManager.getCluster(location) != null;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-10 04:54:00 +10:00
|
|
|
public static Location getPlotCenter(Plot plot) {
|
|
|
|
Location bot = getPlotBottomLoc(plot.world, plot.id);
|
|
|
|
Location top = getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
|
|
|
return new Location(plot.world, bot.getX() + (top.getX() - bot.getX()) / 2, 0, bot.getZ() + (top.getZ() - bot.getZ()) / 2);
|
|
|
|
}
|
|
|
|
|
2015-06-24 13:31:13 +10:00
|
|
|
public static Plot getPlotFromString(PlotPlayer player, String arg, boolean message) {
|
|
|
|
if (arg == null) {
|
|
|
|
if (player == null) {
|
|
|
|
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return getPlot(player.getLocation());
|
|
|
|
}
|
|
|
|
String worldname = null;
|
|
|
|
PlotId id = null;
|
|
|
|
if (player != null) {
|
|
|
|
worldname = player.getLocation().getWorld();
|
|
|
|
}
|
|
|
|
String[] split = arg.split(";|,");
|
|
|
|
if (split.length == 3) {
|
|
|
|
worldname = split[0];
|
|
|
|
id = PlotId.fromString(split[1] + ";" + split[2]);
|
|
|
|
}
|
|
|
|
else if (split.length == 2) {
|
|
|
|
id = PlotId.fromString(arg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (worldname == null) {
|
2015-07-03 22:15:20 +10:00
|
|
|
if (PS.get().getPlotWorlds().size() == 0) {
|
2015-06-24 13:31:13 +10:00
|
|
|
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
worldname = PS.get().getPlotWorlds().iterator().next();
|
2015-06-24 13:31:13 +10:00
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
for (Plot p : PS.get().getPlots(worldname).values()) {
|
2015-06-24 13:31:13 +10:00
|
|
|
String name = p.settings.getAlias();
|
|
|
|
if (name.length() != 0 && name.equalsIgnoreCase(arg)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
for (String world : PS.get().getPlotWorlds()) {
|
2015-06-24 13:31:13 +10:00
|
|
|
if (!world.endsWith(worldname)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
for (Plot p : PS.get().getPlots(world).values()) {
|
2015-06-24 13:31:13 +10:00
|
|
|
String name = p.settings.getAlias();
|
|
|
|
if (name.length() != 0 && name.equalsIgnoreCase(arg)) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
if (worldname == null || !PS.get().isPlotWorld(worldname)) {
|
2015-06-24 13:31:13 +10:00
|
|
|
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (id == null) {
|
|
|
|
if (message) MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return getPlot(worldname, id);
|
|
|
|
}
|
|
|
|
|
2015-06-05 22:39:48 +10:00
|
|
|
/**
|
|
|
|
* Merges all plots in the arraylist (with cost)
|
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param plotIds
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static boolean mergePlots(final PlotPlayer player, final String world, final ArrayList<PlotId> plotIds) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-06-05 22:39:48 +10:00
|
|
|
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY) {
|
|
|
|
final double cost = plotIds.size() * plotworld.MERGE_PRICE;
|
|
|
|
if (cost > 0d) {
|
|
|
|
if (EconHandler.manager.getMoney(player) < cost) {
|
|
|
|
MainUtil.sendMessage(player, C.CANNOT_AFFORD_MERGE, "" + cost);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
EconHandler.manager.withdrawMoney(player, cost);
|
|
|
|
MainUtil.sendMessage(player, C.REMOVED_BALANCE, cost + "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return MainUtil.mergePlots(world, plotIds, true);
|
|
|
|
}
|
|
|
|
|
2015-04-30 23:57:44 +10:00
|
|
|
public static boolean unlinkPlot(final Plot plot) {
|
|
|
|
final String world = plot.world;
|
|
|
|
final PlotId pos1 = MainUtil.getBottomPlot(plot).id;
|
|
|
|
final PlotId pos2 = MainUtil.getTopPlot(plot).id;
|
|
|
|
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(pos1, pos2);
|
|
|
|
final boolean result = EventUtil.manager.callUnlink(world, ids);
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-04-30 23:57:44 +10:00
|
|
|
manager.startPlotUnlink(plotworld, ids);
|
|
|
|
for (final PlotId id : ids) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot myplot = PS.get().getPlots(world).get(id);
|
2015-04-30 23:57:44 +10:00
|
|
|
if (plot == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-14 22:55:57 +10:00
|
|
|
if (plot.trusted != null) {
|
|
|
|
myplot.trusted = plot.trusted;
|
2015-04-30 23:57:44 +10:00
|
|
|
}
|
|
|
|
if (plot.denied != null) {
|
|
|
|
myplot.denied = plot.denied;
|
|
|
|
}
|
|
|
|
myplot.settings.setMerged(new boolean[] { false, false, false, false });
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setMerged(myplot, myplot.settings.getMerged());
|
2015-04-30 23:57:44 +10:00
|
|
|
}
|
2015-05-01 22:44:33 +10:00
|
|
|
if (plotworld.TERRAIN != 3) {
|
|
|
|
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 Plot p = MainUtil.getPlot(world, new PlotId(x, y));
|
|
|
|
if (lx) {
|
|
|
|
manager.createRoadEast(plotworld, p);
|
|
|
|
if (ly) {
|
|
|
|
manager.createRoadSouthEast(plotworld, p);
|
|
|
|
}
|
|
|
|
}
|
2015-04-30 23:57:44 +10:00
|
|
|
if (ly) {
|
2015-05-01 22:44:33 +10:00
|
|
|
manager.createRoadSouth(plotworld, p);
|
2015-04-30 23:57:44 +10:00
|
|
|
}
|
2015-05-01 22:44:33 +10:00
|
|
|
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
|
2015-04-30 23:57:44 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
manager.finishPlotUnlink(plotworld, ids);
|
|
|
|
for (final PlotId id : ids) {
|
|
|
|
final Plot myPlot = MainUtil.getPlot(world, id);
|
|
|
|
if (plot.hasOwner()) {
|
|
|
|
final String name = UUIDHandler.getName(myPlot.owner);
|
|
|
|
if (name != null) {
|
|
|
|
MainUtil.setSign(name, myPlot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-26 16:29:58 +10:00
|
|
|
public static boolean isPlotAreaAbs(final Location location) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(location.getWorld());
|
2015-04-26 16:29:58 +10:00
|
|
|
if (plotworld.TYPE == 2) {
|
|
|
|
return ClusterManager.getClusterAbs(location) != null;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPlotRoad(final Location location) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(location.getWorld());
|
2015-04-26 16:29:58 +10:00
|
|
|
if (plotworld.TYPE == 2) {
|
|
|
|
PlotCluster cluster = ClusterManager.getCluster(location);
|
|
|
|
if (cluster == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
PlotManager manager = PS.get().getPlotManager(location.getWorld());
|
2015-04-26 16:29:58 +10:00
|
|
|
return manager.getPlotId(plotworld, location.getX(), location.getY(), location.getZ()) == null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isPlotArea(final Plot plot) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
2015-04-26 16:29:58 +10:00
|
|
|
if (plotworld.TYPE == 2) {
|
|
|
|
return ClusterManager.getCluster(plot) != null;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean enteredPlot(final Location l1, final Location l2) {
|
|
|
|
final PlotId p1 = MainUtil.getPlotId(l1);
|
|
|
|
final PlotId p2 = MainUtil.getPlotId(l2);
|
|
|
|
return (p2 != null) && ((p1 == null) || !p1.equals(p2));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean leftPlot(final Location l1, final Location l2) {
|
|
|
|
final PlotId p1 = MainUtil.getPlotId(l1);
|
|
|
|
final PlotId p2 = MainUtil.getPlotId(l2);
|
|
|
|
return (p1 != null) && ((p2 == null) || !p1.equals(p2));
|
|
|
|
}
|
|
|
|
|
2015-02-23 12:32:27 +11:00
|
|
|
public static ArrayList<PlotId> getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) {
|
2015-07-03 11:30:26 +02:00
|
|
|
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot1 = PS.get().getPlots(world).get(pos1);
|
|
|
|
final Plot plot2 = PS.get().getPlots(world).get(pos2);
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-22 18:23:10 +11:00
|
|
|
if (plot1 != null) {
|
|
|
|
pos1 = getBottomPlot(plot1).id;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-22 18:23:10 +11:00
|
|
|
if (plot2 != null) {
|
|
|
|
pos2 = getTopPlot(plot2).id;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-22 18:23:10 +11:00
|
|
|
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;
|
|
|
|
}
|
2015-04-24 22:07:00 +10:00
|
|
|
|
|
|
|
public static boolean equals(Object a, Object b) {
|
|
|
|
if (a == b) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (a == null ^ b == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return a.equals(b);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-21 22:38:44 +11:00
|
|
|
/**
|
|
|
|
* Get the number of plots for a player
|
|
|
|
*
|
|
|
|
* @param plr
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return int plot count
|
2015-02-21 22:38:44 +11:00
|
|
|
*/
|
|
|
|
public static int getPlayerPlotCount(final String world, final PlotPlayer plr) {
|
|
|
|
final UUID uuid = plr.getUUID();
|
|
|
|
int count = 0;
|
2015-07-03 22:15:20 +10:00
|
|
|
for (final Plot plot : PS.get().getPlots(world).values()) {
|
2015-03-20 15:11:02 +11:00
|
|
|
if (plot.hasOwner() && plot.owner.equals(uuid) && plot.countsTowardsMax) {
|
2015-02-21 22:38:44 +11:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2015-04-14 06:47:12 -07:00
|
|
|
|
|
|
|
public static int getPlayerPlotCount(final PlotPlayer plr) {
|
|
|
|
int count = 0;
|
2015-07-03 22:15:20 +10:00
|
|
|
for (final String world : PS.get().getPlotWorldsString()) {
|
2015-04-14 06:47:12 -07:00
|
|
|
count += getPlayerPlotCount(world, plr);
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2015-03-17 19:17:15 +11:00
|
|
|
|
2015-04-07 16:19:16 +10:00
|
|
|
public static Location getDefaultHome(Plot plot) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
2015-04-07 16:19:16 +10:00
|
|
|
if (plotworld.DEFAULT_HOME != null) {
|
|
|
|
final Location bot = getPlotBottomLoc(plot.world, plot.id);
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(plot.world);
|
2015-04-07 16:19:16 +10:00
|
|
|
final int x;
|
|
|
|
final int z;
|
|
|
|
if (plotworld.DEFAULT_HOME.x == Integer.MAX_VALUE && plotworld.DEFAULT_HOME.z == Integer.MAX_VALUE) {
|
|
|
|
final Location top = getPlotTopLoc(plot.world, plot.id);
|
|
|
|
x = ((top.getX() - bot.getX()) / 2) + bot.getX();
|
|
|
|
z = ((top.getZ() - bot.getZ()) / 2) + bot.getZ();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = bot.getX() + plotworld.DEFAULT_HOME.x;
|
|
|
|
z = bot.getZ() + plotworld.DEFAULT_HOME.z;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PS.get().getPlotWorld(plot.world), plot).getY());
|
2015-06-09 15:28:59 -07:00
|
|
|
return new Location(plot.world, x, y + 1, z);
|
2015-04-07 16:19:16 +10:00
|
|
|
}
|
2015-03-17 19:17:15 +11:00
|
|
|
final Location top = getPlotTopLoc(plot.world, plot.id);
|
|
|
|
final Location bot = getPlotBottomLoc(plot.world, plot.id);
|
|
|
|
final int x = ((top.getX() - bot.getX()) / 2) + bot.getX();
|
2015-03-17 20:42:16 +11:00
|
|
|
final int z = bot.getZ();
|
2015-07-03 22:15:20 +10:00
|
|
|
PlotManager manager = PS.get().getPlotManager(plot.world);
|
|
|
|
final int y = Math.max(getHeighestBlock(plot.world, x, z), manager.getSignLoc(PS.get().getPlotWorld(plot.world), plot).getY());
|
2015-06-09 15:28:59 -07:00
|
|
|
return new Location(plot.world, x, y + 1, z);
|
2015-03-17 19:17:15 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static boolean teleportPlayer(final PlotPlayer player, final Location from, final Plot plot) {
|
|
|
|
final Plot bot = MainUtil.getBottomPlot(plot);
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-03-17 19:17:15 +11:00
|
|
|
boolean result = EventUtil.manager.callTeleport(player, from, plot);
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-03-17 19:17:15 +11:00
|
|
|
if (result) {
|
|
|
|
final Location location;
|
2015-07-03 22:15:20 +10:00
|
|
|
if (PS.get().getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) {
|
2015-07-04 16:37:33 +10:00
|
|
|
location = MainUtil.getPlotHome(bot);
|
2015-03-17 19:17:15 +11:00
|
|
|
}
|
|
|
|
else {
|
2015-04-07 16:19:16 +10:00
|
|
|
location = getDefaultHome(plot);
|
2015-03-17 19:17:15 +11:00
|
|
|
}
|
2015-07-11 00:08:07 +10:00
|
|
|
if ((Settings.TELEPORT_DELAY == 0) || Permissions.hasPermission(player, "plots.teleport.delay.bypass")) {
|
2015-02-20 22:23:48 +11:00
|
|
|
sendMessage(player, C.TELEPORTED_TO_PLOT);
|
|
|
|
player.teleport(location);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
sendMessage(player, C.TELEPORT_IN_SECONDS, Settings.TELEPORT_DELAY + "");
|
|
|
|
final String name = player.getName();
|
|
|
|
TaskManager.TELEPORT_QUEUE.add(name);
|
|
|
|
TaskManager.runTaskLater(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (!TaskManager.TELEPORT_QUEUE.contains(name)) {
|
|
|
|
sendMessage(player, C.TELEPORT_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TaskManager.TELEPORT_QUEUE.remove(name);
|
|
|
|
if (!player.isOnline()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sendMessage(player, C.TELEPORTED_TO_PLOT);
|
|
|
|
player.teleport(location);
|
|
|
|
}
|
|
|
|
}, Settings.TELEPORT_DELAY * 20);
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-17 19:17:15 +11:00
|
|
|
return result;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static int getBorder(final String worldname) {
|
|
|
|
if (worldBorder.containsKey(worldname)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlotWorld(worldname);
|
2015-02-20 22:23:48 +11:00
|
|
|
return worldBorder.get(worldname) + 16;
|
|
|
|
}
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static void setupBorder(final String world) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (!plotworld.WORLD_BORDER) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!worldBorder.containsKey(world)) {
|
|
|
|
worldBorder.put(world, 0);
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
for (final Plot plot : PS.get().getPlots(world).values()) {
|
2015-02-20 22:23:48 +11:00
|
|
|
updateWorldBorder(plot);
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-04-02 11:56:34 +11:00
|
|
|
public static void update(String world, ChunkLoc loc) {
|
|
|
|
BlockUpdateUtil.setBlockManager.update(world, Arrays.asList(loc));
|
|
|
|
}
|
|
|
|
|
2015-04-19 23:42:55 +10:00
|
|
|
public static void update(final Plot plot) {
|
|
|
|
Location bot = getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
2015-04-29 10:27:21 +10:00
|
|
|
Location top = getPlotTopLoc(plot.world, plot.id);
|
2015-04-19 23:42:55 +10:00
|
|
|
|
|
|
|
int bx = bot.getX() >> 4;
|
|
|
|
int bz = bot.getZ() >> 4;
|
|
|
|
|
2015-04-29 10:27:21 +10:00
|
|
|
int tx = (top.getX() >> 4);
|
|
|
|
int tz = (top.getZ() >> 4);
|
2015-04-19 23:42:55 +10:00
|
|
|
|
|
|
|
ArrayList<ChunkLoc> chunks = new ArrayList<>();
|
|
|
|
|
|
|
|
for (int x = bx; x <= tx; x++) {
|
|
|
|
for (int z = bz; z <= tz; z++) {
|
|
|
|
chunks.add(new ChunkLoc(x, z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
BlockUpdateUtil.setBlockManager.update(plot.world, chunks);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static void createWorld(final String world, final String generator) {
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* direction 0 = north, 1 = south, etc:
|
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param direction
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return PlotId relative
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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);
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-23 16:29:45 +11:00
|
|
|
boolean result = EventUtil.manager.callMerge(world, getPlot(world, pos1), plotIds);
|
|
|
|
if (!result) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
manager.startPlotMerge(plotworld, plotIds);
|
|
|
|
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);
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(world).get(id);
|
2015-02-20 22:23:48 +11:00
|
|
|
Plot plot2 = null;
|
|
|
|
if (removeRoads) {
|
|
|
|
removeSign(plot);
|
|
|
|
}
|
|
|
|
if (lx) {
|
|
|
|
if (ly) {
|
|
|
|
if (!plot.settings.getMerged(1) || !plot.settings.getMerged(2)) {
|
2015-05-01 17:52:32 +10:00
|
|
|
if (removeRoads) {
|
2015-05-01 21:00:17 +10:00
|
|
|
MainUtil.removeRoadSouthEast(plotworld, plot);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!plot.settings.getMerged(1)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
plot2 = PS.get().getPlots(world).get(new PlotId(x + 1, y));
|
2015-02-20 22:23:48 +11:00
|
|
|
mergePlot(world, plot, plot2, removeRoads);
|
|
|
|
plot.settings.setMerged(1, true);
|
|
|
|
plot2.settings.setMerged(3, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ly) {
|
|
|
|
if (!plot.settings.getMerged(2)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
plot2 = PS.get().getPlots(world).get(new PlotId(x, y + 1));
|
2015-02-20 22:23:48 +11:00
|
|
|
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);
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(world).get(id);
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setMerged(plot, plot.settings.getMerged());
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
manager.finishPlotMerge(plotworld, plotIds);
|
2015-02-21 22:38:44 +11:00
|
|
|
return true;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-05-01 17:52:32 +10:00
|
|
|
|
|
|
|
public static void removeRoadSouthEast(PlotWorld plotworld, Plot plot) {
|
|
|
|
if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) {
|
2015-05-01 22:44:33 +10:00
|
|
|
if (plotworld.TERRAIN == 3) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-01 17:52:32 +10:00
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x + 1, id.y + 1);
|
2015-05-02 00:12:27 +10:00
|
|
|
Location pos1 = getPlotTopLocAbs(plot.world, id).add(1, 0, 1);
|
|
|
|
Location pos2 = getPlotBottomLocAbs(plot.world, id2);
|
2015-05-01 22:42:10 +10:00
|
|
|
pos1.setY(0);
|
|
|
|
pos2.setY(256);
|
2015-05-01 17:52:32 +10:00
|
|
|
ChunkManager.manager.regenerateRegion(pos1, pos2, null);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlotManager(plot.world).removeRoadSouthEast(plotworld, plot);
|
2015-05-01 17:52:32 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeRoadEast(PlotWorld plotworld, Plot plot) {
|
|
|
|
if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) {
|
2015-05-01 22:44:33 +10:00
|
|
|
if (plotworld.TERRAIN == 3) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-01 17:52:32 +10:00
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x + 1, id.y);
|
|
|
|
Location bot = getPlotBottomLocAbs(plot.world, id2);
|
|
|
|
Location top = getPlotTopLocAbs(plot.world, id);
|
|
|
|
Location pos1 = new Location(plot.world, top.getX() + 1, 0, bot.getZ() + 1);
|
2015-05-01 22:42:10 +10:00
|
|
|
Location pos2 = new Location(plot.world, bot.getX(), 256, top.getZ());
|
2015-05-01 17:52:32 +10:00
|
|
|
ChunkManager.manager.regenerateRegion(pos1, pos2, null);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlotManager(plot.world).removeRoadEast(plotworld, plot);
|
2015-05-01 17:52:32 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeRoadSouth(PlotWorld plotworld, Plot plot) {
|
|
|
|
if (plotworld.TYPE != 0 && plotworld.TERRAIN > 1) {
|
2015-05-01 22:44:33 +10:00
|
|
|
if (plotworld.TERRAIN == 3) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-01 17:52:32 +10:00
|
|
|
PlotId id = plot.id;
|
|
|
|
PlotId id2 = new PlotId(id.x, id.y + 1);
|
|
|
|
Location bot = getPlotBottomLocAbs(plot.world, id2);
|
|
|
|
Location top = getPlotTopLocAbs(plot.world, id);
|
|
|
|
Location pos1 = new Location(plot.world, bot.getX() + 1, 0, top.getZ() + 1);
|
2015-05-01 22:42:10 +10:00
|
|
|
Location pos2 = new Location(plot.world, top.getX(), 256, bot.getZ());
|
2015-05-01 17:52:32 +10:00
|
|
|
ChunkManager.manager.regenerateRegion(pos1, pos2, null);
|
|
|
|
}
|
|
|
|
else {
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlotManager(plot.world).removeRoadSouth(plotworld, plot);
|
2015-05-01 17:52:32 +10:00
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-05-01 17:52:32 +10:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
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) {
|
2015-05-01 21:00:17 +10:00
|
|
|
MainUtil.removeRoadSouth(plotworld, lesserPlot);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!lesserPlot.settings.getMerged(1)) {
|
|
|
|
lesserPlot.settings.setMerged(1, true);
|
|
|
|
greaterPlot.settings.setMerged(3, true);
|
|
|
|
if (removeRoads) {
|
2015-05-01 21:00:17 +10:00
|
|
|
MainUtil.removeRoadEast(plotworld, lesserPlot);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static void removeSign(final Plot p) {
|
|
|
|
final String world = p.world;
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-03-19 23:07:57 +11:00
|
|
|
if (!plotworld.ALLOW_SIGNS) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-20 22:23:48 +11:00
|
|
|
final Location loc = manager.getSignLoc(plotworld, p);
|
2015-07-15 21:57:11 +02:00
|
|
|
BlockManager.setBlocks(world, new int[]{loc.getX()}, new int[]{loc.getY()}, new int[]{loc.getZ()}, new int[]{0}, new byte[]{0});
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-07-04 16:37:33 +10:00
|
|
|
|
|
|
|
public static void setSign(final Plot p) {
|
|
|
|
if (p.owner == null) {
|
|
|
|
setSign(null, p);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setSign(UUIDHandler.getName(p.owner), p);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static void setSign(String name, final Plot p) {
|
|
|
|
if (name == null) {
|
|
|
|
name = "unknown";
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(p.world);
|
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(p.world);
|
2015-02-24 18:11:14 +11:00
|
|
|
if (plotworld.ALLOW_SIGNS) {
|
2015-02-20 22:23:48 +11:00
|
|
|
final Location loc = manager.getSignLoc(plotworld, p);
|
2015-02-24 18:11:14 +11:00
|
|
|
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);
|
|
|
|
}
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static String getStringSized(final int max, final String string) {
|
|
|
|
if (string.length() > max) {
|
|
|
|
return string.substring(0, max);
|
|
|
|
}
|
|
|
|
return string;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-07-04 16:37:33 +10:00
|
|
|
public static void autoMerge(final Plot plot, final UUID uuid) {
|
2015-02-20 22:23:48 +11:00
|
|
|
if (plot == null) {
|
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:11:02 +11:00
|
|
|
if (plot.owner == null) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:11:02 +11:00
|
|
|
if (!plot.owner.equals(uuid)) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ArrayList<PlotId> plots;
|
|
|
|
boolean merge = true;
|
|
|
|
int count = 0;
|
|
|
|
while (merge) {
|
|
|
|
if (count > 16) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
final PlotId bot = getBottomPlot(plot).id;
|
2015-02-22 17:37:44 +11:00
|
|
|
final PlotId top = getTopPlot(plot).id;
|
2015-02-20 22:23:48 +11:00
|
|
|
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
2015-07-04 16:37:33 +10:00
|
|
|
if (ownsPlots(plot.world, plots, uuid, 0)) {
|
|
|
|
final boolean result = mergePlots(plot.world, plots, true);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (result) {
|
|
|
|
merge = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
2015-07-04 16:37:33 +10:00
|
|
|
if (ownsPlots(plot.world, plots, uuid, 1)) {
|
|
|
|
final boolean result = mergePlots(plot.world, plots, true);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (result) {
|
|
|
|
merge = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
2015-07-04 16:37:33 +10:00
|
|
|
if (ownsPlots(plot.world, plots, uuid, 2)) {
|
|
|
|
final boolean result = mergePlots(plot.world, plots, true);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (result) {
|
|
|
|
merge = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
2015-07-04 16:37:33 +10:00
|
|
|
if (ownsPlots(plot.world, plots, uuid, 3)) {
|
|
|
|
final boolean result = mergePlots(plot.world, plots, true);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (result) {
|
|
|
|
merge = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
merge = false;
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot myplot = PS.get().getPlots(world).get(myid);
|
2015-03-20 15:11:02 +11:00
|
|
|
if ((myplot == null) || myplot.owner == null || !(myplot.owner.equals(uuid))) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return false;
|
|
|
|
}
|
2015-02-22 17:37:44 +11:00
|
|
|
final PlotId top = getTopPlot(myplot).id;
|
2015-02-20 22:23:48 +11:00
|
|
|
if (((top.x > id_max.x) && (dir != 1)) || ((top.y > id_max.y) && (dir != 2))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final PlotId bot = getBottomPlot(myplot).id;
|
|
|
|
if (((bot.x < id_min.x) && (dir != 3)) || ((bot.y < id_min.y) && (dir != 0))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static void updateWorldBorder(final Plot plot) {
|
|
|
|
if (!worldBorder.containsKey(plot.world)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String world = plot.world;
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Create a plot and notify the world border and plot merger
|
|
|
|
*/
|
|
|
|
public static boolean createPlot(final UUID uuid, final Plot plot) {
|
|
|
|
if (MainUtil.worldBorder.containsKey(plot.world)) {
|
|
|
|
updateWorldBorder(plot);
|
|
|
|
}
|
|
|
|
final Plot p = createPlotAbs(uuid, plot);
|
2015-07-04 16:37:33 +10:00
|
|
|
if (p == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (plotworld.AUTO_MERGE) {
|
2015-07-04 16:37:33 +10:00
|
|
|
autoMerge(p, uuid);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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;
|
2015-07-04 16:37:33 +10:00
|
|
|
HashMap<PlotId, Plot> plots = PS.get().getPlots(plot.world);
|
|
|
|
Plot p = plots.get(plot.id);
|
|
|
|
if (p != null) {
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
p = new Plot(w, plot.id, uuid);
|
|
|
|
if (p.owner == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().updatePlot(p);
|
2015-02-20 22:23:48 +11:00
|
|
|
DBFunc.createPlotAndSettings(p);
|
|
|
|
return p;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static String createId(final int x, final int z) {
|
|
|
|
return x + ";" + z;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static int square(final int x) {
|
|
|
|
return x * x;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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 };
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Clear a plot and associated sections: [sign, entities, border]
|
|
|
|
*
|
|
|
|
* @param plot
|
2015-03-13 18:02:48 +11:00
|
|
|
* @param isDelete
|
|
|
|
* @param whenDone
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static boolean clearAsPlayer(final Plot plot, final boolean isDelete, final Runnable whenDone) {
|
|
|
|
if (runners.containsKey(plot)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-23 16:29:45 +11:00
|
|
|
ChunkManager.manager.clearAllEntities(plot);
|
2015-07-04 16:37:33 +10:00
|
|
|
clear(plot, isDelete, whenDone);
|
2015-02-20 22:23:48 +11:00
|
|
|
removeSign(plot);
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-07-04 16:37:33 +10:00
|
|
|
public static void clear(final Plot plot, final boolean isDelete, final Runnable whenDone) {
|
|
|
|
final PlotManager manager = PS.get().getPlotManager(plot.world);
|
|
|
|
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
|
2015-02-20 22:23:48 +11:00
|
|
|
final int prime = 31;
|
|
|
|
int h = 1;
|
|
|
|
h = (prime * h) + pos1.getX();
|
|
|
|
h = (prime * h) + pos1.getZ();
|
|
|
|
state = h;
|
|
|
|
System.currentTimeMillis();
|
2015-07-04 16:37:33 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
2015-02-20 22:23:48 +11:00
|
|
|
runners.put(plot, 1);
|
2015-03-17 19:32:21 +11:00
|
|
|
if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) {
|
2015-07-04 16:37:33 +10:00
|
|
|
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
|
2015-02-23 16:29:45 +11:00
|
|
|
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
|
2015-02-20 22:23:48 +11:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
runners.remove(plot);
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final Runnable run = new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
2015-06-08 05:37:40 +10:00
|
|
|
// MainUtil.setBiome(world, plot, "FOREST");
|
2015-02-20 22:23:48 +11:00
|
|
|
runners.remove(plot);
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
manager.clearPlot(plotworld, plot, isDelete, run);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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++) {
|
2015-03-27 18:36:28 +11:00
|
|
|
final int i = random.random(blocks.length);
|
2015-02-20 22:23:48 +11:00
|
|
|
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);
|
|
|
|
}
|
2015-04-30 14:33:57 +10:00
|
|
|
|
|
|
|
public static void setCuboidAsync(final String world, final Location pos1, final Location pos2, final PlotBlock[] blocks) {
|
|
|
|
if (blocks.length == 1) {
|
|
|
|
setSimpleCuboidAsync(world, pos1, pos2, blocks[0]);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-30 14:46:24 +10:00
|
|
|
for (int y = pos1.getY(); y < Math.min(256, pos2.getY()); y++) {
|
2015-04-30 14:33:57 +10:00
|
|
|
for (int x = pos1.getX(); x < pos2.getX(); x++) {
|
|
|
|
for (int z = pos1.getZ(); z < pos2.getZ(); z++) {
|
|
|
|
final int i = random.random(blocks.length);
|
|
|
|
final PlotBlock block = blocks[i];
|
|
|
|
SetBlockQueue.setBlock(world, x, y, z, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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);
|
|
|
|
}
|
2015-04-30 14:33:57 +10:00
|
|
|
|
|
|
|
public static void setSimpleCuboidAsync(final String world, final Location pos1, final Location pos2, final PlotBlock newblock) {
|
2015-04-30 14:46:24 +10:00
|
|
|
for (int y = pos1.getY(); y < Math.min(256, pos2.getY()); y++) {
|
2015-04-30 14:33:57 +10:00
|
|
|
for (int x = pos1.getX(); x < pos2.getX(); x++) {
|
|
|
|
for (int z = pos1.getZ(); z < pos2.getZ(); z++) {
|
|
|
|
SetBlockQueue.setBlock(world, x, y, z, newblock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-07-04 16:37:33 +10:00
|
|
|
public static void setBiome(final Plot plot, final String biome) {
|
|
|
|
final int bottomX = getPlotBottomLoc(plot.world, plot.id).getX() + 1;
|
|
|
|
final int topX = getPlotTopLoc(plot.world, plot.id).getX();
|
|
|
|
final int bottomZ = getPlotBottomLoc(plot.world, plot.id).getZ() + 1;
|
|
|
|
final int topZ = getPlotTopLoc(plot.world, plot.id).getZ();
|
|
|
|
BukkitUtil.setBiome(plot.world, bottomX, bottomZ, topX, topZ, biome);
|
2015-04-19 23:42:55 +10:00
|
|
|
update(plot);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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);
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(w);
|
2015-02-20 22:23:48 +11:00
|
|
|
if ((home == null) || ((home.x == 0) && (home.z == 0))) {
|
2015-04-07 16:19:16 +10:00
|
|
|
return getDefaultHome(plot);
|
2015-02-20 22:23:48 +11:00
|
|
|
} else {
|
2015-07-15 21:57:11 +02:00
|
|
|
Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z);
|
|
|
|
if (BukkitUtil.getBlock(loc).id != 0) {
|
2015-07-15 21:57:28 +02:00
|
|
|
// sendConsoleMessage("ID was " + BukkitUtil.getBlock(loc).id);
|
2015-07-15 21:57:11 +02:00
|
|
|
loc.setY(Math.max(getHeighestBlock(w, bot.getX(), bot.getZ()), bot.getY()));
|
|
|
|
}
|
|
|
|
return loc;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Get the plot home
|
|
|
|
*
|
|
|
|
* @param plot Plot Object
|
|
|
|
*
|
|
|
|
* @return Plot Home Location
|
|
|
|
*
|
|
|
|
*/
|
2015-07-04 16:37:33 +10:00
|
|
|
public static Location getPlotHome(final Plot plot) {
|
|
|
|
return getPlotHome(plot.world, plot.id);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return Location top
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static Location getPlotTopLocAbs(final String world, final PlotId id) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
return manager.getPlotTopLocAbs(plotworld, id);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return Location bottom
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static Location getPlotBottomLocAbs(final String world, final PlotId id) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
return manager.getPlotBottomLocAbs(plotworld, id);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Obtains the width of a plot (x width)
|
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return int width of plot
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static int getPlotWidth(final String world, final PlotId id) {
|
|
|
|
return getPlotTopLoc(world, id).getX() - getPlotBottomLoc(world, id).getX();
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return Location top of mega plot
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static Location getPlotTopLoc(final String world, PlotId id) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(world).get(id);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (plot != null) {
|
2015-02-22 17:37:44 +11:00
|
|
|
id = getTopPlot(plot).id;
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
return manager.getPlotTopLocAbs(plotworld, id);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return Location bottom of mega plot
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static Location getPlotBottomLoc(final String world, PlotId id) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(world).get(id);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (plot != null) {
|
|
|
|
id = getBottomPlot(plot).id;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
return manager.getPlotBottomLocAbs(plotworld, id);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-04-07 23:21:51 +10:00
|
|
|
public static boolean canClaim(PlotPlayer player, 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);
|
|
|
|
Plot plot = getPlot(world, id);
|
|
|
|
if (!canClaim(player, plot)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean canClaim(PlotPlayer player, Plot plot) {
|
|
|
|
if (plot == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Settings.ENABLE_CLUSTERS) {
|
|
|
|
PlotCluster cluster = ClusterManager.getCluster(plot);
|
|
|
|
if (cluster != null) {
|
2015-07-11 00:08:07 +10:00
|
|
|
if (!cluster.isAdded(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.claim")) {
|
2015-04-07 23:21:51 +10:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-03 11:30:26 +02:00
|
|
|
return plot.owner == null;
|
2015-04-07 23:21:51 +10:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
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);
|
2015-07-03 22:15:20 +10:00
|
|
|
if (PS.get().getPlots(world).get(id) != null) {
|
|
|
|
if (PS.get().getPlots(world).get(id).owner != null) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-28 16:19:52 +11:00
|
|
|
|
|
|
|
public static boolean swap(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
|
2015-07-03 22:15:20 +10:00
|
|
|
Plot p1 = PS.get().getPlots(world).get(current);
|
|
|
|
Plot p2 = PS.get().getPlots(world).get(newPlot);
|
2015-03-20 15:11:02 +11:00
|
|
|
if (p1==null || p2 == null || p1.owner == null || !p1.owner.equals(p2.owner)) {
|
2015-02-28 16:19:52 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Swap blocks
|
|
|
|
ChunkManager.manager.swap(world, current, newPlot);
|
|
|
|
// Swap cached
|
|
|
|
PlotId temp = new PlotId(p1.id.x.intValue(), p1.id.y.intValue());
|
|
|
|
p1.id.x = p2.id.x.intValue();
|
|
|
|
p1.id.y = p2.id.y.intValue();
|
|
|
|
p2.id.x = temp.x;
|
|
|
|
p2.id.y = temp.y;
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(world).remove(p1.id);
|
|
|
|
PS.get().getPlots(world).remove(p2.id);
|
2015-06-09 02:01:09 +10:00
|
|
|
p1.id.recalculateHash();
|
|
|
|
p2.id.recalculateHash();
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(world).put(p1.id, p1);
|
|
|
|
PS.get().getPlots(world).put(p2.id, p2);
|
2015-02-28 16:19:52 +11:00
|
|
|
// Swap database
|
|
|
|
DBFunc.dbManager.swapPlots(p2, p1);
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-23 00:49:03 +11:00
|
|
|
|
|
|
|
public static boolean swapData(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
|
2015-07-03 22:15:20 +10:00
|
|
|
Plot p1 = PS.get().getPlots(world).get(current);
|
|
|
|
Plot p2 = PS.get().getPlots(world).get(newPlot);
|
2015-03-23 22:15:26 +11:00
|
|
|
if (p1 == null || p1.owner == null) {
|
|
|
|
if (p2 != null && p2.owner != null) {
|
2015-03-24 14:11:28 +11:00
|
|
|
moveData(p2, p1, whenDone);
|
2015-03-23 22:15:26 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (p2 == null || p2.owner == null) {
|
|
|
|
if (p1 != null && p1.owner != null) {
|
2015-03-24 14:11:28 +11:00
|
|
|
moveData(p1, p2, whenDone);
|
2015-03-23 22:15:26 +11:00
|
|
|
return true;
|
|
|
|
}
|
2015-03-23 00:49:03 +11:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Swap cached
|
|
|
|
PlotId temp = new PlotId(p1.id.x.intValue(), p1.id.y.intValue());
|
|
|
|
p1.id.x = p2.id.x.intValue();
|
|
|
|
p1.id.y = p2.id.y.intValue();
|
|
|
|
p2.id.x = temp.x;
|
|
|
|
p2.id.y = temp.y;
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(world).remove(p1.id);
|
|
|
|
PS.get().getPlots(world).remove(p2.id);
|
2015-06-09 02:01:09 +10:00
|
|
|
p1.id.recalculateHash();
|
|
|
|
p2.id.recalculateHash();
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(world).put(p1.id, p1);
|
|
|
|
PS.get().getPlots(world).put(p2.id, p2);
|
2015-03-23 00:49:03 +11:00
|
|
|
// Swap database
|
|
|
|
DBFunc.dbManager.swapPlots(p2, p1);
|
2015-03-23 22:22:37 +11:00
|
|
|
TaskManager.runTask(whenDone);
|
2015-03-23 00:49:03 +11:00
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-03-24 14:11:28 +11:00
|
|
|
public static boolean moveData(final Plot plot1, final Plot plot2, final Runnable whenDone) {
|
|
|
|
if (plot1.owner == null) {
|
2015-03-23 22:15:26 +11:00
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-24 14:11:28 +11:00
|
|
|
final Plot pos1 = getBottomPlot(plot1);
|
|
|
|
final Plot pos2 = getTopPlot(plot1);
|
2015-07-04 16:37:33 +10:00
|
|
|
final PlotId size = MainUtil.getSize(plot1);
|
2015-03-24 14:11:28 +11:00
|
|
|
if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) {
|
2015-03-23 22:15:26 +11:00
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
|
|
|
return false;
|
|
|
|
}
|
2015-03-24 14:11:28 +11:00
|
|
|
final int offset_x = plot2.id.x - pos1.id.x;
|
|
|
|
final int offset_y = plot2.id.y - pos1.id.y;
|
2015-03-23 22:15:26 +11:00
|
|
|
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
|
|
|
|
for (final PlotId id : selection) {
|
2015-03-24 14:11:28 +11:00
|
|
|
DBFunc.movePlot(getPlot(plot1.world, new PlotId(id.x, id.y)), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y)));
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(plot1.world).get(id);
|
|
|
|
PS.get().getPlots(plot1.world).remove(id);
|
2015-03-23 22:15:26 +11:00
|
|
|
plot.id.x += offset_x;
|
|
|
|
plot.id.y += offset_y;
|
2015-06-09 02:01:09 +10:00
|
|
|
plot.id.recalculateHash();
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(plot2.world).put(plot.id, plot);
|
2015-03-23 22:15:26 +11:00
|
|
|
}
|
2015-03-24 14:11:28 +11:00
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
2015-03-23 22:15:26 +11:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-24 14:11:28 +11:00
|
|
|
public static boolean move(final Plot plot1, final Plot plot2, final Runnable whenDone) {
|
|
|
|
final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(plot1.world, plot1.id);
|
2015-04-01 23:36:46 +11:00
|
|
|
final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(plot2.world, plot2.id);
|
2015-03-24 14:11:28 +11:00
|
|
|
final Location top = MainUtil.getPlotTopLoc(plot1.world, plot1.id);
|
|
|
|
if (plot1.owner == null) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-24 14:11:28 +11:00
|
|
|
final Plot pos1 = getBottomPlot(plot1);
|
|
|
|
final Plot pos2 = getTopPlot(plot1);
|
2015-07-04 16:37:33 +10:00
|
|
|
final PlotId size = MainUtil.getSize(plot1);
|
2015-03-24 14:11:28 +11:00
|
|
|
if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) {
|
2015-02-20 22:23:48 +11:00
|
|
|
return false;
|
|
|
|
}
|
2015-03-24 14:11:28 +11:00
|
|
|
final int offset_x = plot2.id.x - pos1.id.x;
|
|
|
|
final int offset_y = plot2.id.y - pos1.id.y;
|
2015-02-20 22:23:48 +11:00
|
|
|
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
|
|
|
|
for (final PlotId id : selection) {
|
2015-04-01 23:36:46 +11:00
|
|
|
String worldOriginal = plot1.world;
|
|
|
|
PlotId idOriginal = new PlotId(id.x, id.y);
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot plot = PS.get().getPlots(plot1.world).get(id);
|
|
|
|
PS.get().getPlots(plot1.world).remove(id);
|
2015-02-20 22:23:48 +11:00
|
|
|
plot.id.x += offset_x;
|
|
|
|
plot.id.y += offset_y;
|
2015-06-09 02:01:09 +10:00
|
|
|
plot.id.recalculateHash();
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(plot2.world).put(plot.id, plot);
|
2015-04-01 23:36:46 +11:00
|
|
|
DBFunc.movePlot(getPlot(worldOriginal, idOriginal), getPlot(plot2.world, new PlotId(id.x + offset_x, id.y + offset_y)));
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 16:29:45 +11:00
|
|
|
ChunkManager.manager.copyRegion(bot1, top, bot2, new Runnable() {
|
2015-02-20 22:23:48 +11:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
final Location bot = bot1.clone().add(1, 0, 1);
|
2015-02-23 16:29:45 +11:00
|
|
|
ChunkManager.manager.regenerateRegion(bot, top, null);
|
2015-02-20 22:23:48 +11:00
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
2015-03-15 14:21:50 +11:00
|
|
|
|
|
|
|
public static boolean copy(final String world, final PlotId current, final PlotId newPlot, final Runnable whenDone) {
|
|
|
|
final com.intellectualcrafters.plot.object.Location bot1 = MainUtil.getPlotBottomLoc(world, current);
|
|
|
|
final com.intellectualcrafters.plot.object.Location bot2 = MainUtil.getPlotBottomLoc(world, newPlot);
|
|
|
|
final Location top = MainUtil.getPlotTopLoc(world, current);
|
|
|
|
final Plot currentPlot = MainUtil.getPlot(world, current);
|
2015-03-20 15:11:02 +11:00
|
|
|
if (currentPlot.owner == null) {
|
2015-03-15 14:21:50 +11:00
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final Plot pos1 = getBottomPlot(currentPlot);
|
|
|
|
final Plot pos2 = getTopPlot(currentPlot);
|
2015-07-04 16:37:33 +10:00
|
|
|
final PlotId size = MainUtil.getSize(currentPlot);
|
2015-03-15 14:21:50 +11:00
|
|
|
if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
|
|
|
|
TaskManager.runTaskLater(whenDone, 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final ArrayList<PlotId> selection = getPlotSelectionIds(pos1.id, pos2.id);
|
|
|
|
final int offset_x = newPlot.x - pos1.id.x;
|
|
|
|
final int offset_y = newPlot.y - pos1.id.y;
|
|
|
|
for (final PlotId id : selection) {
|
|
|
|
int x = id.x + offset_x;
|
|
|
|
int y = id.y + offset_y;
|
2015-03-20 15:11:02 +11:00
|
|
|
Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y)));
|
2015-03-15 14:21:50 +11:00
|
|
|
if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) {
|
|
|
|
plot.settings.flags = currentPlot.settings.flags;
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setFlags(plot, currentPlot.settings.flags.values());
|
2015-03-15 14:21:50 +11:00
|
|
|
}
|
|
|
|
if (currentPlot.settings.isMerged()) {
|
|
|
|
plot.settings.setMerged(currentPlot.settings.getMerged());
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setMerged(plot, currentPlot.settings.getMerged());
|
2015-03-15 14:21:50 +11:00
|
|
|
}
|
2015-05-14 22:55:57 +10:00
|
|
|
if (currentPlot.members != null && currentPlot.members.size() > 0) {
|
|
|
|
plot.members = currentPlot.members;
|
|
|
|
for (UUID member : plot.members) {
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setMember(plot, member);
|
2015-05-14 22:55:57 +10:00
|
|
|
}
|
|
|
|
}
|
2015-03-15 14:21:50 +11:00
|
|
|
if (currentPlot.trusted != null && currentPlot.trusted.size() > 0) {
|
2015-05-14 22:55:57 +10:00
|
|
|
plot.members = currentPlot.trusted;
|
2015-03-15 14:21:50 +11:00
|
|
|
for (UUID trusted : plot.trusted) {
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setTrusted(plot, trusted);
|
2015-03-15 14:21:50 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentPlot.denied != null && currentPlot.denied.size() > 0) {
|
2015-05-14 22:55:57 +10:00
|
|
|
plot.members = currentPlot.denied;
|
2015-03-15 14:21:50 +11:00
|
|
|
for (UUID denied : plot.denied) {
|
2015-07-04 16:37:33 +10:00
|
|
|
DBFunc.setDenied(plot, denied);
|
2015-03-15 14:21:50 +11:00
|
|
|
}
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
PS.get().getPlots(world).put(plot.id, plot);
|
2015-03-15 14:21:50 +11:00
|
|
|
}
|
|
|
|
ChunkManager.manager.copyRegion(bot1, top, bot2, whenDone);
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Send a message to the player
|
|
|
|
*
|
|
|
|
* @param plr Player to recieve message
|
|
|
|
* @param msg Message to send
|
|
|
|
*
|
|
|
|
* @return true Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
|
|
|
|
*/
|
|
|
|
public static boolean sendMessage(final PlotPlayer plr, final String msg) {
|
|
|
|
return sendMessage(plr, msg, true);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-03-13 14:15:00 +11:00
|
|
|
public static void sendConsoleMessage(String msg) {
|
|
|
|
sendMessage(null, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void sendConsoleMessage(C caption, String... args) {
|
|
|
|
sendMessage(null, caption, args);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-23 11:05:25 +11:00
|
|
|
public static boolean sendMessage(final PlotPlayer plr, String msg, final boolean prefix) {
|
2015-02-20 22:23:48 +11:00
|
|
|
if ((msg.length() > 0) && !msg.equals("")) {
|
|
|
|
if (plr == null) {
|
2015-07-17 20:48:13 +10:00
|
|
|
PS.log(C.PREFIX.s() + msg);
|
2015-02-20 22:23:48 +11:00
|
|
|
} else {
|
2015-07-17 20:48:13 +10:00
|
|
|
plr.sendMessage(C.PREFIX.s() + C.color(msg));
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-21 16:48:49 +11:00
|
|
|
public static String[] wordWrap(final String rawString, final int lineLength) {
|
|
|
|
if (rawString == null) {
|
|
|
|
return new String[] { "" };
|
|
|
|
}
|
|
|
|
if ((rawString.length() <= lineLength) && (!rawString.contains("\n"))) {
|
|
|
|
return new String[] { rawString };
|
|
|
|
}
|
|
|
|
final char[] rawChars = (rawString + ' ').toCharArray();
|
|
|
|
StringBuilder word = new StringBuilder();
|
|
|
|
StringBuilder line = new StringBuilder();
|
|
|
|
final ArrayList<String> lines = new ArrayList();
|
|
|
|
int lineColorChars = 0;
|
|
|
|
for (int i = 0; i < rawChars.length; i++) {
|
|
|
|
final char c = rawChars[i];
|
2015-03-09 18:17:22 -04:00
|
|
|
if (c == '\u00A7') {
|
|
|
|
word.append('\u00A7' + (rawChars[(i + 1)]));
|
2015-02-21 16:48:49 +11:00
|
|
|
lineColorChars += 2;
|
|
|
|
i++;
|
|
|
|
} else if ((c == ' ') || (c == '\n')) {
|
|
|
|
if ((line.length() == 0) && (word.length() > lineLength)) {
|
|
|
|
for (final String partialWord : word.toString().split("(?<=\\G.{" + lineLength + "})")) {
|
|
|
|
lines.add(partialWord);
|
|
|
|
}
|
|
|
|
} else if (((line.length() + word.length()) - lineColorChars) == lineLength) {
|
|
|
|
line.append(word);
|
|
|
|
lines.add(line.toString());
|
|
|
|
line = new StringBuilder();
|
|
|
|
lineColorChars = 0;
|
|
|
|
} else if (((line.length() + 1 + word.length()) - lineColorChars) > lineLength) {
|
|
|
|
for (final String partialWord : word.toString().split("(?<=\\G.{" + lineLength + "})")) {
|
|
|
|
lines.add(line.toString());
|
|
|
|
line = new StringBuilder(partialWord);
|
|
|
|
}
|
|
|
|
lineColorChars = 0;
|
|
|
|
} else {
|
|
|
|
if (line.length() > 0) {
|
|
|
|
line.append(' ');
|
|
|
|
}
|
|
|
|
line.append(word);
|
|
|
|
}
|
|
|
|
word = new StringBuilder();
|
|
|
|
if (c == '\n') {
|
|
|
|
lines.add(line.toString());
|
|
|
|
line = new StringBuilder();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
word.append(c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (line.length() > 0) {
|
|
|
|
lines.add(line.toString());
|
|
|
|
}
|
2015-03-09 18:17:22 -04:00
|
|
|
if ((lines.get(0).length() == 0) || (lines.get(0).charAt(0) != '\u00A7')) {
|
|
|
|
lines.set(0, "\u00A7f" + lines.get(0));
|
2015-02-21 16:48:49 +11:00
|
|
|
}
|
|
|
|
for (int i = 1; i < lines.size(); i++) {
|
|
|
|
final String pLine = lines.get(i - 1);
|
|
|
|
final String subLine = lines.get(i);
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-03-09 18:17:22 -04:00
|
|
|
final char color = pLine.charAt(pLine.lastIndexOf('\u00A7') + 1);
|
|
|
|
if ((subLine.length() == 0) || (subLine.charAt(0) != '\u00A7')) {
|
|
|
|
lines.set(i, '\u00A7' + (color) + subLine);
|
2015-02-21 16:48:49 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return lines.toArray(new String[lines.size()]);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Send a message to the player
|
|
|
|
*
|
|
|
|
* @param plr Player to recieve message
|
|
|
|
* @param c Caption to send
|
|
|
|
*
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return boolean success
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static boolean sendMessage(final PlotPlayer plr, final C c, final String... args) {
|
|
|
|
if (c.s().length() > 1) {
|
|
|
|
String msg = c.s();
|
|
|
|
if ((args != null) && (args.length > 0)) {
|
2015-07-17 20:48:13 +10:00
|
|
|
msg = C.format(c, args);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
if (plr == null) {
|
2015-07-17 20:48:13 +10:00
|
|
|
PS.log(msg);
|
2015-02-20 22:23:48 +11:00
|
|
|
} else {
|
|
|
|
sendMessage(plr, msg, c.usePrefix());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static Plot getBottomPlot(final Plot plot) {
|
|
|
|
if (plot.settings.getMerged(0)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot p = PS.get().getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y - 1));
|
2015-02-20 22:23:48 +11:00
|
|
|
if (p == null) {
|
|
|
|
return plot;
|
|
|
|
}
|
|
|
|
return getBottomPlot(p);
|
|
|
|
}
|
|
|
|
if (plot.settings.getMerged(3)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot p = PS.get().getPlots(plot.world).get(new PlotId(plot.id.x - 1, plot.id.y));
|
2015-02-20 22:23:48 +11:00
|
|
|
if (p == null) {
|
|
|
|
return plot;
|
|
|
|
}
|
|
|
|
return getBottomPlot(p);
|
|
|
|
}
|
|
|
|
return plot;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-22 17:37:44 +11:00
|
|
|
public static Plot getTopPlot(final Plot plot) {
|
2015-02-20 22:23:48 +11:00
|
|
|
if (plot.settings.getMerged(2)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot p = PS.get().getPlots(plot.world).get(new PlotId(plot.id.x, plot.id.y + 1));
|
2015-03-23 01:43:19 +11:00
|
|
|
if (p == null) {
|
|
|
|
return plot;
|
|
|
|
}
|
|
|
|
return getTopPlot(p);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
if (plot.settings.getMerged(1)) {
|
2015-07-03 22:15:20 +10:00
|
|
|
final Plot p = PS.get().getPlots(plot.world).get(new PlotId(plot.id.x + 1, plot.id.y));
|
2015-03-23 01:43:19 +11:00
|
|
|
if (p == null) {
|
|
|
|
return plot;
|
|
|
|
}
|
|
|
|
return getTopPlot(p);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
|
|
|
return plot;
|
2015-03-23 01:43:19 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-07-04 16:37:33 +10:00
|
|
|
public static PlotId getSize(final Plot plot) {
|
2015-02-20 22:23:48 +11:00
|
|
|
final PlotSettings settings = plot.settings;
|
|
|
|
if (!settings.isMerged()) {
|
|
|
|
return new PlotId(1, 1);
|
|
|
|
}
|
2015-02-22 17:37:44 +11:00
|
|
|
final Plot top = getTopPlot(plot);
|
2015-02-20 22:23:48 +11:00
|
|
|
final Plot bot = getBottomPlot(plot);
|
|
|
|
return new PlotId((top.id.x - bot.id.x) + 1, (top.id.y - bot.id.y) + 1);
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Fetches the plot from the main class
|
|
|
|
*/
|
|
|
|
public static Plot getPlot(final String world, final PlotId id) {
|
|
|
|
if (id == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
if (PS.get().getPlots(world).containsKey(id)) {
|
|
|
|
return PS.get().getPlots(world).get(id);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-07-04 16:37:33 +10:00
|
|
|
return new Plot(world, id, null);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Returns the plot at a location (mega plots are not considered, all plots are treated as small plots)
|
|
|
|
* @param loc
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return PlotId underlying plot id of loc
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static PlotId getPlotAbs(final Location loc) {
|
|
|
|
final String world = loc.getWorld();
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (manager == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
return manager.getPlotIdAbs(plotworld, loc.getX(), loc.getY(), loc.getZ());
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Returns the plot id at a location (mega plots are considered)
|
|
|
|
* @param loc
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return PlotId PlotId observed id
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
|
|
|
public static PlotId getPlotId(final Location loc) {
|
|
|
|
final String world = loc.getWorld();
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotManager manager = PS.get().getPlotManager(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (manager == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-07-03 22:15:20 +10:00
|
|
|
final PlotWorld plotworld = PS.get().getPlotWorld(world);
|
2015-02-20 22:23:48 +11:00
|
|
|
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;
|
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
/**
|
|
|
|
* Get the maximum number of plots a player is allowed
|
|
|
|
*
|
|
|
|
* @param p
|
2015-03-13 18:02:48 +11:00
|
|
|
* @return int
|
2015-02-20 22:23:48 +11:00
|
|
|
*/
|
2015-03-11 11:08:51 -04:00
|
|
|
public static int getAllowedPlots(final PlotPlayer p) {
|
2015-07-11 00:08:07 +10:00
|
|
|
return Permissions.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS);
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|
2015-02-23 12:32:27 +11:00
|
|
|
|
2015-02-20 22:23:48 +11:00
|
|
|
public static Plot getPlot(final Location loc) {
|
2015-02-21 16:48:49 +11:00
|
|
|
final PlotId id = getPlotId(loc);
|
2015-02-20 22:23:48 +11:00
|
|
|
if (id == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return getPlot(loc.getWorld(), id);
|
|
|
|
}
|
2015-06-28 10:54:57 +10:00
|
|
|
|
|
|
|
public static double getAverageRating(Plot plot) {
|
|
|
|
HashMap<UUID, Integer> rating;
|
|
|
|
if (plot.settings.ratings != null) {
|
|
|
|
rating = plot.settings.ratings;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rating = DBFunc.getRatings(plot);
|
|
|
|
}
|
|
|
|
if (rating == null || rating.size() == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
double val = 0;
|
2015-07-03 12:11:41 +10:00
|
|
|
int size = 0;
|
2015-06-28 10:54:57 +10:00
|
|
|
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
2015-07-03 12:11:41 +10:00
|
|
|
int current = entry.getValue();
|
|
|
|
if (Settings.RATING_CATEGORIES == null || Settings.RATING_CATEGORIES.size() == 0) {
|
|
|
|
val += current;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
|
|
|
|
val += (current % 10) - 1;
|
|
|
|
current /= 10;
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return val / (double) size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static double[] getAverageRatings(Plot plot) {
|
|
|
|
HashMap<UUID, Integer> rating;
|
|
|
|
if (plot.settings.ratings != null) {
|
|
|
|
rating = plot.settings.ratings;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rating = DBFunc.getRatings(plot);
|
|
|
|
}
|
|
|
|
int size = 1;
|
|
|
|
if (Settings.RATING_CATEGORIES != null) {
|
|
|
|
size = Math.max(1, Settings.RATING_CATEGORIES.size());
|
|
|
|
}
|
|
|
|
double[] ratings = new double[size];
|
|
|
|
if (rating == null || rating.size() == 0) {
|
|
|
|
return ratings;
|
|
|
|
}
|
|
|
|
for (Entry<UUID, Integer> entry : rating.entrySet()) {
|
|
|
|
int current = entry.getValue();
|
|
|
|
if (Settings.RATING_CATEGORIES == null || Settings.RATING_CATEGORIES.size() == 0) {
|
|
|
|
ratings[0] += current;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int i = 0 ; i < Settings.RATING_CATEGORIES.size(); i++) {
|
|
|
|
ratings[i] += (current % 10) - 1;
|
|
|
|
current /= 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
ratings[i] /= (double) rating.size();
|
2015-06-28 10:54:57 +10:00
|
|
|
}
|
2015-07-03 12:11:41 +10:00
|
|
|
return ratings;
|
2015-06-28 10:54:57 +10:00
|
|
|
}
|
2015-02-20 22:23:48 +11:00
|
|
|
}
|