restructure a couple things.

This commit is contained in:
boy0001 2015-09-22 23:23:28 +10:00
parent c948b18239
commit d42ef3cf63
101 changed files with 2846 additions and 2586 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<artifactId>PlotSquared</artifactId>
<version>3.1.10</version>
<version>3.2.0</version>
<name>PlotSquared</name>
<packaging>jar</packaging>
<build>

View File

@ -399,6 +399,9 @@ public class PS {
plots.put(world, new ConcurrentHashMap<PlotId, Plot>());
}
plots.get(world).put(plot.id, plot);
for (PlotPlayer pp : plot.getPlayersInPlot()) {
pp.setMeta("lastplot", plot);
}
}
/**
@ -1090,13 +1093,13 @@ public class PS {
}
return new HashMap<>(myplots);
}
return new HashMap<>();
return new HashMap<>(0);
}
public Collection<Plot> getPlotsInWorld(final String world) {
final ConcurrentHashMap<PlotId, Plot> map = plots.get(world);
if (map == null) {
return new HashSet<>();
return new HashSet<>(0);
}
try {
return map.values();
@ -1776,24 +1779,25 @@ public class PS {
// Clearing + Expiry
options.put("clear.fastmode", Settings.ENABLE_CLUSTERS);
options.put("clear.on.ban", false);
options.put("clear.auto.enabled", false);
options.put("clear.auto.days", 365);
options.put("clear.auto.enabled", true);
options.put("clear.auto.days", 7);
options.put("clear.auto.clear-interval-seconds", Settings.CLEAR_INTERVAL);
options.put("clear.auto.calibration.changes", 1);
options.put("clear.auto.calibration.faces", 2);
options.put("clear.auto.calibration.data", 32);
options.put("clear.auto.calibration.faces", 0);
options.put("clear.auto.calibration.data", 0);
options.put("clear.auto.calibration.air", 0);
options.put("clear.auto.calibration.variety", 1);
options.put("clear.auto.calibration.changes_sd", 64);
options.put("clear.auto.calibration.faces_sd", 32);
options.put("clear.auto.calibration.data_sd", 1);
options.put("clear.auto.calibration.variety", 0);
options.put("clear.auto.calibration.changes_sd", 1);
options.put("clear.auto.calibration.faces_sd", 0);
options.put("clear.auto.calibration.data_sd", 0);
options.put("clear.auto.calibration.air_sd", 0);
options.put("clear.auto.calibration.variety_sd", 1);
options.put("clear.auto.calibration.variety_sd", 0);
final int keep = config.getInt("clear.keep-if-modified");
final int ignore = config.getInt("clear.ignore-if-modified");
if ((keep > 0) || (ignore > 0)) {
options.put("clear.auto.threshold", 1);
options.put("clear.auto.enabled", false);
log("&cIMPORTANT MESSAGE ABOUT THIS UPDATE!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
log("&cSorry for all the exclamation marks, but this could be important.");
log("&cPlot clearing has changed to a new system that requires calibration.");

View File

@ -429,11 +429,11 @@ public class PlotAPI {
*
* @return plot, null if ID is wrong
*
* @see MainUtil#getPlot(String, com.intellectualcrafters.plot.object.PlotId)
* @see MainUtil#getPlotAbs(String, com.intellectualcrafters.plot.object.PlotId)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot getPlot(final World world, final int x, final int z) {
return MainUtil.getPlot(world.getName(), new PlotId(x, z));
return MainUtil.getPlotAbs(world.getName(), new PlotId(x, z));
}
/**
@ -443,11 +443,11 @@ public class PlotAPI {
*
* @return plot if found, otherwise it creates a temporary plot-
*
* @see MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
* @see MainUtil#getPlotAbs(com.intellectualcrafters.plot.object.Location)
* @see com.intellectualcrafters.plot.object.Plot
*/
public Plot getPlot(final Location l) {
return MainUtil.getPlot(BukkitUtil.getLocation(l));
return MainUtil.getPlotAbs(BukkitUtil.getLocation(l));
}
/**
@ -558,8 +558,8 @@ public class PlotAPI {
*/
public Location[] getLocations(final Plot p) {
return new Location[] {
BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id)),
BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id)),
BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.id).subtract(1, 0, 1)),
BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.id)),
BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.id)) };
}
@ -590,7 +590,7 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location getBottomLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotBottomLoc(p.world, p.id));
return BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.id).subtract(1, 0, 1));
}
/**
@ -604,7 +604,7 @@ public class PlotAPI {
* @see com.intellectualcrafters.plot.object.Plot
*/
public Location getTopLocation(final Plot p) {
return BukkitUtil.getLocation(MainUtil.getPlotTopLoc(p.world, p.id));
return BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.id));
}
/**
@ -614,10 +614,10 @@ public class PlotAPI {
*
* @return true if the player is in a plot, false if not-
*
* @see com.intellectualcrafters.plot.util.MainUtil#getPlot(com.intellectualcrafters.plot.object.Location)
* @see com.intellectualcrafters.plot.util.MainUtil#getPlotAbs(com.intellectualcrafters.plot.object.Location)
*/
public boolean isInPlot(final Player player) {
return MainUtil.getPlot(BukkitUtil.getLocation(player)) != null;
return MainUtil.getPlotAbs(BukkitUtil.getLocation(player)) != null;
}
/**

View File

@ -52,7 +52,7 @@ public class Add extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -161,7 +161,7 @@ public class Auto extends SubCommand {
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld.TYPE == 2) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
final Plot plot = MainUtil.getPlotAbs(new Location(worldname, loc.getX(), loc.getY(), loc.getZ()));
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
@ -180,8 +180,8 @@ public class Auto extends SubCommand {
//
for (int i = 0; i <= max; i++) {
final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y);
final Plot current = MainUtil.getPlot(worldname, currentId);
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(current.getCluster())) {
final Plot current = MainUtil.getPlotAbs(worldname, currentId);
if (MainUtil.canClaim(plr, current) && (current.isMerged() == false) && cluster.equals(current.getCluster())) {
Claim.claimPlot(plr, current, true, true);
return true;
}
@ -194,7 +194,7 @@ public class Auto extends SubCommand {
boolean br = false;
if ((size_x == 1) && (size_z == 1)) {
while (!br) {
final Plot plot = MainUtil.getPlot(worldname, getLastPlot(worldname));
final Plot plot = MainUtil.getPlotAbs(worldname, getLastPlot(worldname));
if (MainUtil.canClaim(plr, plot)) {
Claim.claimPlot(plr, plot, true, true);
br = true;
@ -217,7 +217,7 @@ public class Auto extends SubCommand {
if (MainUtil.canClaim(plr, worldname, start, end)) {
for (int i = start.x; i <= end.x; i++) {
for (int j = start.y; j <= end.y; j++) {
final Plot plot = MainUtil.getPlot(worldname, new PlotId(i, j));
final Plot plot = MainUtil.getPlotAbs(worldname, new PlotId(i, j));
final boolean teleport = ((i == end.x) && (j == end.y));
Claim.claimPlot(plr, plot, teleport, true);
}

View File

@ -40,7 +40,7 @@ public class BO3 extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -20,6 +20,9 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
@ -58,64 +61,54 @@ public class Buy extends SubCommand {
if (!PS.get().isPlotWorld(world)) {
return sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
Set<Plot> plots;
Plot plot;
if (args.length > 0) {
try {
final String[] split = args[0].split(";");
final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
plot = MainUtil.getPlot(world, id);
plot = MainUtil.getPlotAbs(world, id);
plots = MainUtil.getConnectedPlots(plot);
} catch (final Exception e) {
return sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
} else {
plot = MainUtil.getPlot(loc);
plot = MainUtil.getPlotAbs(loc);
plots = MainUtil.getConnectedPlots(plot);
}
if (plot == null) {
if (plots == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr);
if (currentPlots >= MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
if (!plot.hasOwner()) {
return sendMessage(plr, C.PLOT_UNOWNED);
}
if (PlotHandler.isOwner(plot, plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN);
final int currentPlots = MainUtil.getPlayerPlotCount(plr) + plots.size();
if (currentPlots > MainUtil.getAllowedPlots(plr)) {
return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS);
}
final Flag flag = FlagManager.getPlotFlag(plot, "price");
if (flag == null) {
return sendMessage(plr, C.NOT_FOR_SALE);
}
double initPrice = (double) flag.getValue();
double price = initPrice;
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int size = MainUtil.getPlotSelectionIds(id, id2).size();
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld.USE_ECONOMY) {
price += plotworld.PLOT_PRICE * size;
initPrice += plotworld.SELL_PRICE * size;
if (plot.isOwner(plr.getUUID())) {
return sendMessage(plr, C.CANNOT_BUY_OWN);
}
double price = (double) flag.getValue();
if ((EconHandler.manager != null) && (price > 0d)) {
if (EconHandler.manager.getMoney(plr) < price) {
return sendMessage(plr, C.CANNOT_AFFORD_PLOT, "" + price);
}
EconHandler.manager.withdrawMoney(plr, price);
sendMessage(plr, C.REMOVED_BALANCE, price + "");
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), initPrice);
EconHandler.manager.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price);
final PlotPlayer owner = UUIDHandler.getPlayer(plot.owner);
if (owner != null) {
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), initPrice + "");
sendMessage(plr, C.PLOT_SOLD, plot.id + "", plr.getName(), price + "");
}
FlagManager.removePlotFlag(plot, "price");
}
final Plot top = MainUtil.getTopPlot(plot);
for (final PlotId myId : MainUtil.getPlotSelectionIds(plot.id, top.id)) {
final Plot myPlot = MainUtil.getPlot(plot.world, myId);
myPlot.owner = plr.getUUID();
DBFunc.setOwner(plot, myPlot.owner);
for (final Plot current : plots) {
plot.setOwner(plr.getUUID());
}
MainUtil.sendMessage(plr, C.CLAIMED);
return true;

View File

@ -51,7 +51,7 @@ public class Claim extends SubCommand {
}
public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic, final boolean auto) {
if (plot.hasOwner() || plot.getSettings().isMerged()) {
if (plot.hasOwner() || plot.isMerged()) {
return false;
}
final boolean result = EventUtil.manager.callClaim(player, plot, false);
@ -94,13 +94,12 @@ public class Claim extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String... args) {
String schematic = "";
if (args.length >= 1) {
schematic = args[0];
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -33,6 +33,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.CmdConfirm;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@ -59,10 +60,10 @@ public class Clear extends SubCommand {
return false;
}
} else {
plot = MainUtil.getPlot(loc.getWorld(), id);
plot = MainUtil.getPlotAbs(loc.getWorld(), id);
}
} else {
plot = MainUtil.getPlot(loc);
plot = MainUtil.getPlotAbs(loc);
}
if (plot == null) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
@ -71,11 +72,10 @@ public class Clear extends SubCommand {
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
assert plot != null;
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() != 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
@ -91,6 +91,11 @@ public class Clear extends SubCommand {
final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() {
@Override
public void run() {
plot.unlink();
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
plot.removeRunning();
// If the state changes, then mark it as no longer done
if (FlagManager.getPlotFlag(plot, "done") != null) {
FlagManager.removePlotFlag(plot, "done");
@ -101,9 +106,14 @@ public class Clear extends SubCommand {
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
}
});
if (!result) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
else {
plot.addRunning();
}
}
};
if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {

View File

@ -59,10 +59,10 @@ public class Comment extends SubCommand {
return false;
}
index = 2;
plot = MainUtil.getPlot(loc.getWorld(), id);
plot = MainUtil.getPlotAbs(loc.getWorld(), id);
} else {
index = 1;
plot = MainUtil.getPlot(loc);
plot = MainUtil.getPlotAbs(loc);
}
if (!inbox.canWrite(plot, player)) {
sendMessage(player, C.NO_PERM_INBOX, "");

View File

@ -23,8 +23,10 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Plot;
@ -33,6 +35,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE)
@ -70,18 +73,53 @@ public class Condense extends SubCommand {
return false;
}
final int radius = Integer.parseInt(args[2]);
final Collection<Plot> plots = PS.get().getPlotsInWorld(worldname);
final int size = plots.size();
ArrayList<Plot> plots = new ArrayList<>(PS.get().getPlotsInWorld(worldname));
// remove non base plots
Iterator<Plot> iter = plots.iterator();
int maxSize = 0;
ArrayList<Integer> sizes = new ArrayList<>();
while (iter.hasNext()) {
Plot plot = iter.next();
if (!plot.isBasePlot()) {
iter.remove();
continue;
}
int size = plot.getConnectedPlots().size();
if (size > maxSize) {
maxSize = size;
}
sizes.add(size - 1);
}
// Sort plots by size (buckets?)]
ArrayList<Plot>[] buckets = new ArrayList[maxSize];
for (int i = 0; i < plots.size(); i++) {
Plot plot = plots.get(i);
int size = sizes.get(i);
ArrayList<Plot> array = buckets[size];
if (array == null) {
array = new ArrayList<Plot>();
buckets[size] = array;
}
array.add(plot);
}
final ArrayList<Plot> allPlots = new ArrayList<Plot>(plots.size());
for (int i = buckets.length - 1; i >= 0; i--) {
ArrayList<Plot> array = buckets[i];
if (array != null) {
allPlots.addAll(array);
}
}
final int size = allPlots.size();
final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1);
if (radius < minimum_radius) {
MainUtil.sendMessage(plr, "RADIUS TOO SMALL");
return false;
}
final List<PlotId> to_move = new ArrayList<>(getPlots(plots, radius));
final List<PlotId> to_move = new ArrayList<>(getPlots(allPlots, radius));
final List<PlotId> free = new ArrayList<>();
PlotId start = new PlotId(0, 0);
while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) {
final Plot plot = MainUtil.getPlot(worldname, start);
final Plot plot = MainUtil.getPlotAbs(worldname, start);
if (!plot.hasOwner()) {
free.add(plot.id);
}
@ -91,53 +129,54 @@ public class Condense extends SubCommand {
MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND");
return false;
}
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), new Runnable() {
MainUtil.sendMessage(plr, "TASK STARTED...");
Runnable run = new Runnable() {
@Override
public void run() {
if (!TASK) {
MainUtil.sendMessage(plr, "CONDENSE TASK CANCELLED");
return;
MainUtil.sendMessage(plr, "TASK CANCELLED.");
}
to_move.remove(0);
free.remove(0);
int index = 0;
for (final PlotId id : to_move) {
final Plot plot = MainUtil.getPlot(worldname, id);
if (plot.hasOwner()) {
break;
}
index++;
}
for (int i = 0; i < index; i++) {
to_move.remove(0);
}
index = 0;
for (final PlotId id : free) {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plot.hasOwner()) {
break;
}
index++;
}
for (int i = 0; i < index; i++) {
free.remove(0);
}
if (to_move.size() == 0) {
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
if (allPlots.size() == 0) {
TASK = false;
MainUtil.sendMessage(plr, "TASK COMPLETE. PLEASE VERIFY THAT NO NEW PLOTS HAVE BEEN CLAIMED DURING TASK.");
return;
}
final Runnable task = this;
final Plot origin = allPlots.remove(0);
int i = 0;
while (free.size() > i) {
final Plot possible = MainUtil.getPlotAbs(origin.world, free.get(i));
if (possible.owner != null) {
free.remove(i);
continue;
}
i++;
final AtomicBoolean result = new AtomicBoolean(false);
result.set(MainUtil.move(origin, possible, new Runnable() {
@Override
public void run() {
if (result.get()) {
MainUtil.sendMessage(plr, "Moving: " + origin + " -> " + possible);
TaskManager.runTaskLater(task, 1);
}
}
}, false));
if (result.get()) {
break;
}
}
if (free.size() == 0) {
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
TASK = false;
MainUtil.sendMessage(plr, "TASK FAILED. NO FREE PLOTS FOUND!");
return;
}
MainUtil.sendMessage(plr, "MOVING " + to_move.get(0) + " to " + free.get(0));
MainUtil.move(MainUtil.getPlot(worldname, to_move.get(0)), MainUtil.getPlot(worldname, free.get(0)), this);
if (i >= free.size()) {
MainUtil.sendMessage(plr, "SKIPPING COMPLEX PLOT: " + origin);
}
});
}
};
TASK = true;
MainUtil.sendMessage(plr, "TASK STARTED...");
TaskManager.runTaskAsync(run);
return true;
}
case "stop": {

View File

@ -41,7 +41,7 @@ public class Continue extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -49,7 +49,7 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (!plot.getSettings().flags.containsKey("done")) {
if (!plot.getFlags().containsKey("done")) {
MainUtil.sendMessage(plr, C.DONE_NOT_DONE);
return false;
}
@ -57,7 +57,7 @@ public class Continue extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue");
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}

View File

@ -23,7 +23,6 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
@ -45,29 +44,30 @@ public class Copy extends SubCommand {
}
@Override
public boolean onCommand(final PlotPlayer plr, final String... args) {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlot(loc);
final Plot plot1 = MainUtil.getPlotAbs(loc);
if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (!plot1.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2 = MainUtil.parseId(args[0]);
final Plot plot2 = MainUtil.getPlotFromString(plr, args[0], true);
if ((plot2 == null)) {
return false;
}
if (plot1.equals(plot2)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (plot1.id.equals(plot2)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
if (!plot1.getWorld().equals(plot2.getWorld())) {
C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false;
}
if (MainUtil.copy(world, plot1.id, plot2, new Runnable() {
if (MainUtil.copy(plot1, plot2, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, C.COPY_SUCCESS);

View File

@ -43,7 +43,7 @@ public class CreateRoadSchematic extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, final String... args) {
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return sendMessage(player, C.NOT_IN_PLOT);
}

View File

@ -95,7 +95,7 @@ public class DebugClaimTest extends SubCommand {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final ArrayList<Plot> plots = new ArrayList<>();
for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) {
final Plot plot = MainUtil.getPlot(world, id);
final Plot plot = MainUtil.getPlotAbs(world, id);
if (PS.get().getPlot(world, plot.id) != null) {
MainUtil.sendMessage(null, " - &cDB Already contains: " + plot.id);
continue;

View File

@ -1,67 +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.commands;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.generator.SquarePlotWorld;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "debugclear", aliases = { "fastclear" }, description = "Clear a plot using a fast experiment algorithm", category = CommandCategory.DEBUG)
public class DebugClear extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if ((plot == null) || !(PS.get().getPlotWorld(loc.getWorld()) instanceof SquarePlotWorld)) {
return sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return sendMessage(plr, C.UNLINK_REQUIRED);
}
if ((!plot.hasOwner() || !plot.isOwner(UUIDHandler.getUUID(plr))) && !Permissions.hasPermission(plr, "plots.admin.command.debugclear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
final Location pos1 = MainUtil.getPlotBottomLoc(loc.getWorld(), plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(loc.getWorld(), plot.id);
if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
@Override
public void run() {
MainUtil.runners.remove(plot);
MainUtil.sendMessage(plr, "&aDone!");
}
});
return true;
}
}

View File

@ -160,7 +160,7 @@ public class DebugExec extends SubCommand {
boolean async = false;
switch (arg) {
case "analyze": {
final Plot plot = MainUtil.getPlot(player.getLocation());
final Plot plot = MainUtil.getPlotAbs(player.getLocation());
if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
@ -168,7 +168,7 @@ public class DebugExec extends SubCommand {
final PlotAnalysis analysis = plot.getComplexity();
if (analysis != null) {
final int complexity = analysis.getComplexity();
MainUtil.sendMessage(player, "Changes: " + analysis.changes);
MainUtil.sendMessage(player, "Changes/column: " + (analysis.changes / 1.0));
MainUtil.sendMessage(player, "Complexity: " + complexity);
return true;
}

View File

@ -1,166 +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.commands;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.SetBlockQueue;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
command = "fill",
permission = "plots.fill",
description = "Fill or surround a plot in bedrock",
usage = "/plot fill",
aliases = { "debugfill" },
category = CommandCategory.DEBUG,
requiredType = RequiredType.NONE)
public class DebugFill extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, final String... args) {
if ((args.length != 1) || (!args[0].equalsIgnoreCase("outline") && !args[0].equalsIgnoreCase("all"))) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill <outline|all>");
return true;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
MainUtil.sendMessage(player, C.PLOT_UNOWNED);
return false;
}
if (!plot.isOwner(player.getUUID()) && !Permissions.hasPermission(player, "plots.admin.command.fill")) {
MainUtil.sendMessage(player, C.NO_PLOT_PERMS);
return true;
}
if (MainUtil.runners.containsKey(plot)) {
MainUtil.sendMessage(player, C.WAIT_FOR_TIMER);
return false;
}
final Location bottom = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
MainUtil.sendMessage(player, "&cPreparing task");
MainUtil.runners.put(plot, 1);
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&7 - Starting");
if (args[0].equalsIgnoreCase("all")) {
int height = 255;
PlotBlock block = new PlotBlock((short) 7, (byte) 0);
final PlotBlock air = new PlotBlock((short) 0, (byte) 0);
if (args.length > 2) {
try {
block = new PlotBlock(Short.parseShort(args[1]), (byte) 0);
if (args.length == 3) {
height = Integer.parseInt(args[2]);
}
} catch (final Exception e) {
MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot fill all <id> <height>");
MainUtil.runners.remove(plot);
return;
}
}
for (int y = 0; y <= height; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
SetBlockQueue.setBlock(plot.world, x, y, z, block);
}
}
}
for (int y = height + 1; y <= 255; y++) {
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
SetBlockQueue.setBlock(plot.world, x, y, z, air);
}
}
}
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
}
});
} else if (args[0].equals("outline")) {
int x, z;
z = bottom.getZ();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
for (int y = 1; y <= 255; y++) {
SetBlockQueue.setBlock(plot.world, x, y, z, 7);
}
}
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(player, "&aWalls complete! The ceiling will take a while :(");
bottom.setY(255);
top.add(1, 0, 1);
SetBlockQueue.setSlow(true);
MainUtil.setSimpleCuboidAsync(plot.world, bottom, top, new PlotBlock((short) 7, (byte) 0));
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.runners.remove(plot);
MainUtil.sendMessage(player, "&aFill task complete!");
SetBlockQueue.setSlow(false);
}
});
}
});
}
}
});
}
});
return true;
}
}

View File

@ -58,7 +58,7 @@ public class DebugFixFlags extends SubCommand {
}
MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---");
for (final Plot plot : PS.get().getPlotsInWorld(world)) {
final HashMap<String, Flag> flags = plot.getSettings().flags;
final HashMap<String, Flag> flags = plot.getFlags();
final Iterator<Entry<String, Flag>> i = flags.entrySet().iterator();
boolean changed = false;
while (i.hasNext()) {
@ -68,7 +68,7 @@ public class DebugFixFlags extends SubCommand {
}
}
if (changed) {
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
}
}
MainUtil.sendMessage(plr, "&aDone!");

View File

@ -20,6 +20,8 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands;
import java.util.HashSet;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
@ -49,51 +51,52 @@ public class Delete extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
if (!plot.hasOwner()) {
return !sendMessage(plr, C.PLOT_UNOWNED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if (MainUtil.runners.containsKey(plot)) {
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
final HashSet<Plot> plots = MainUtil.getConnectedPlots(plot);
final Runnable run = new Runnable() {
@Override
public void run() {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
return;
}
final Runnable runnable = new Runnable() {
@Override
public void run() {
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY && plot.hasOwner() && plot.isOwner(UUIDHandler.getUUID(plr))) {
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
final long start = System.currentTimeMillis();
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
boolean result = plot.deletePlot(new Runnable() {
@Override
public void run() {
plot.removeRunning();
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY) {
final double value = plotworld.SELL_PRICE * plots.size();
if (value > 0d) {
EconHandler.manager.depositMoney(plr, value);
sendMessage(plr, C.ADDED_BALANCE, value + "");
}
}
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
});
if (!result) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
if (result) {
plot.addRunning();
}
} else {
MainUtil.sendMessage(plr, C.UNCLAIM_FAILED);
else {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
}
}
};
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
CmdConfirm.addPending(plr, "/plot delete " + plot.id, run);
} else {
TaskManager.runTask(runnable);
TaskManager.runTask(run);
}
return true;
}

View File

@ -47,7 +47,7 @@ public class Deny extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -95,7 +95,7 @@ public class Deny extends SubCommand {
private void handleKick(final UUID uuid, final Plot plot) {
final PlotPlayer pp = UUIDHandler.getPlayer(uuid);
if ((pp != null) && plot.equals(MainUtil.getPlot(pp.getLocation()))) {
if ((pp != null) && plot.equals(MainUtil.getPlotAbs(pp.getLocation()))) {
pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld()));
MainUtil.sendMessage(pp, C.YOU_GOT_DENIED);
}

View File

@ -40,7 +40,7 @@ public class Done extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if ((plot == null) || !plot.hasOwner()) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -48,11 +48,11 @@ public class Done extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (plot.getSettings().flags.containsKey("done")) {
if (plot.getFlags().containsKey("done")) {
MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}

View File

@ -30,7 +30,7 @@ public class Download extends SubCommand {
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
final Plot plot = MainUtil.getPlot(plr.getLocation());
final Plot plot = MainUtil.getPlotAbs(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -42,7 +42,7 @@ public class Download extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}

View File

@ -68,7 +68,7 @@ public class FlagCmd extends SubCommand {
return false;
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
MainUtil.sendMessage(player, C.NOT_IN_PLOT);
return false;
@ -172,7 +172,7 @@ public class FlagCmd extends SubCommand {
if ((args.length == 3) && flag.getAbstractFlag().isList()) {
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
} else {
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) {
@ -222,7 +222,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false;
}
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
MainUtil.sendMessage(player, C.FLAG_ADDED);
return true;
}

View File

@ -83,7 +83,7 @@ public class Inbox extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
final Plot plot = MainUtil.getPlot(player.getLocation());
final Plot plot = MainUtil.getPlotAbs(player.getLocation());
if (args.length == 0) {
sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete <index>|clear|page]");
for (final CommentInbox inbox : CommentManager.inboxes.values()) {

View File

@ -32,10 +32,12 @@ import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
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.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
@ -139,14 +141,14 @@ public class Info extends SubCommand {
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cPlot Info", new String[] {
"&cID: &6" + plot.getId().toString(),
"&cOwner: &6" + name,
"&cAlias: &6" + plot.getSettings().getAlias(),
"&cAlias: &6" + plot.getAlias(),
"&cBiome: &6" + plot.getBiome().toString().replaceAll("_", "").toLowerCase(),
"&cCan Build: &6" + plot.isAdded(uuid),
"&cIs Denied: &6" + plot.isDenied(uuid) }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cTrusted", new String[] { "&cAmount: &6" + plot.getTrusted().size(), "&8Click to view a list of the trusted users" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cMembers", new String[] { "&cAmount: &6" + plot.getMembers().size(), "&8Click to view a list of plot members" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cDenied", new String[] { "&cDenied", "&cAmount: &6" + plot.getDenied().size(), "&8Click to view a list of denied players" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] { "&cFlags", "&cAmount: &6" + plot.getSettings().flags.size(), "&8Click to view a list of plot flags" }));
inv.setItem(1, new PlotItemStack(388, (short) 0, 1, "&cFlags", new String[] { "&cFlags", "&cAmount: &6" + plot.getFlags().size(), "&8Click to view a list of plot flags" }));
inv.openInventory();
return true;
}
@ -205,12 +207,10 @@ public class Info extends SubCommand {
}
private void formatAndSend(String info, final String world, final Plot plot, final PlotPlayer player, final boolean full) {
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
final String alias = plot.getSettings().getAlias().length() > 0 ? plot.getSettings().getAlias() : C.NONE.s();
final Location top = MainUtil.getPlotTopLoc(world, plot.id);
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final int num = MainUtil.getConnectedPlots(plot).size();
final String alias = plot.getAlias().length() > 0 ? plot.getAlias() : C.NONE.s();
final Location top = MainUtil.getPlotTopLocAbs(world, plot.id);
final Location bot = MainUtil.getPlotBottomLocAbs(world, plot.id);
final String biome = BlockManager.manager.getBiome(plot.world, bot.getX() + ((top.getX() - bot.getX()) / 2), bot.getZ() + ((top.getZ() - bot.getZ()) / 2));
final String trusted = getPlayerList(plot.getTrusted());
final String members = getPlayerList(plot.getMembers());
@ -227,9 +227,8 @@ public class Info extends SubCommand {
final String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());
info = info.replaceAll("%id%", plot.id.toString());
info = info.replaceAll("%alias%", alias);
info = info.replaceAll("%id%", id.toString());
info = info.replaceAll("%id2%", id2.toString());
info = info.replaceAll("%num%", num + "");
info = info.replaceAll("%desc%", description);
info = info.replaceAll("%biome%", biome);

View File

@ -37,7 +37,7 @@ public class Kick extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -55,7 +55,7 @@ public class Kick extends SubCommand {
return false;
}
final Location otherLoc = player.getLocation();
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlot(otherLoc))) {
if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlotAbs(otherLoc))) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}

View File

@ -39,7 +39,7 @@ public class Load extends SubCommand {
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
final Plot plot = MainUtil.getPlot(plr.getLocation());
final Plot plot = MainUtil.getPlotAbs(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -51,14 +51,13 @@ public class Load extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
if (args.length != 0) {
if (args.length == 1) {
// TODO load save here
final List<String> schematics = (List<String>) plr.getMeta("plot_schematics");
if (schematics == null) {
// No schematics found:

View File

@ -72,13 +72,11 @@ public class MainCommand extends CommandManager<PlotPlayer> {
createCommand(new Update());
createCommand(new Template());
createCommand(new Setup());
createCommand(new DebugFill());
createCommand(new DebugSaveTest());
createCommand(new DebugLoadTest());
createCommand(new CreateRoadSchematic());
createCommand(new DebugAllowUnsafe());
createCommand(new RegenAllRoads());
createCommand(new DebugClear());
createCommand(new Claim());
createCommand(new Auto());
createCommand(new Home());
@ -294,9 +292,9 @@ public class MainCommand extends CommandManager<PlotPlayer> {
world = null;
}
if ((id != null) && PS.get().isPlotWorld(world)) {
final Plot plot = MainUtil.getPlot(world, id);
final Plot plot = MainUtil.getPlotAbs(world, id);
if (plot != null) {
player.teleport(MainUtil.getPlotCenter(plot));
player.teleport(plot.getBottomAbs());
args = Arrays.copyOfRange(args, 1, args.length);
}
}

View File

@ -50,8 +50,8 @@ usage = "/plot merge [direction]",
category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Merge extends SubCommand {
public final static String[] values = new String[] { "north", "east", "south", "west" };
public final static String[] aliases = new String[] { "n", "e", "s", "w" };
public final static String[] values = new String[] { "north", "east", "south", "west", "auto" };
public final static String[] aliases = new String[] { "n", "e", "s", "w", "all" };
public static String direction(float yaw) {
yaw = yaw / 90;
@ -77,9 +77,8 @@ public class Merge extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocationFull();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -92,28 +91,47 @@ public class Merge extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
int direction = -1;
if (args.length == 0) {
switch (direction(plr.getLocationFull().getYaw())) {
case "NORTH":
direction = 0;
break;
case "EAST":
direction = 1;
break;
case "SOUTH":
direction = 2;
break;
case "WEST":
direction = 3;
break;
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d && EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, plotworld.MERGE_PRICE + "");
return false;
}
int direction = -1;
final int size = plot.getConnectedPlots().size();
final int maxSize = Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS);
if (size >= maxSize) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
return false;
}
if (args.length == 0) {
// switch (direction(plr.getLocationFull().getYaw())) {
// case "NORTH":
// direction = 0;
// break;
// case "EAST":
// direction = 1;
// break;
// case "SOUTH":
// direction = 2;
// break;
// case "WEST":
// direction = 3;
// break;
// }
} else {
if (args[0].equalsIgnoreCase("all")) {
plot.autoMerge((args.length != 2) || !args[1].equalsIgnoreCase("false"));
if (args[0].equalsIgnoreCase("all") || args[0].equalsIgnoreCase("auto")) {
if (MainUtil.autoMerge(plot, -1, maxSize - size, plr.getUUID(), (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
}
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
return true;
}
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false;
}
for (int i = 0; i < values.length; i++) {
if (args[0].equalsIgnoreCase(values[i]) || args[0].equalsIgnoreCase(aliases[i])) {
direction = i;
@ -122,135 +140,63 @@ public class Merge extends SubCommand {
}
}
if (direction == -1) {
MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(values, C.BLOCK_LIST_SEPARATER.s()));
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot merge <" + StringMan.join(values, "|") + ">");
MainUtil.sendMessage(plr, C.DIRECTION.s().replaceAll("%dir%", direction(loc.getYaw())));
return false;
}
PlotId bot = MainUtil.getBottomPlot(plot).id;
PlotId top = MainUtil.getTopPlot(plot).id;
ArrayList<PlotId> selPlots;
final String world = loc.getWorld();
switch (direction) {
case 0: // north = -y
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
break;
case 1: // east = +x
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
break;
case 2: // south = +y
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
break;
case 3: // west = -x
selPlots = MainUtil.getMaxPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
break;
default:
if (MainUtil.autoMerge(plot, direction, maxSize - size, plot.owner, (args.length != 2) || !args[1].equalsIgnoreCase("false"))) {
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
}
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
return true;
}
Plot adjacent = MainUtil.getPlotAbs(plot.world, MainUtil.getPlotIdRelative(plot.id, direction));
if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4)) {
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false;
}
final int size = selPlots.size();
if (Permissions.hasPermissionRange(plr, "plots.merge", Settings.MAX_PLOTS) < size) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.merge." + size);
return false;
}
final PlotId botId = selPlots.get(0);
final PlotId topId = selPlots.get(selPlots.size() - 1);
final PlotId bot1 = MainUtil.getBottomPlot(MainUtil.getPlot(world, botId)).id;
final PlotId bot2 = MainUtil.getBottomPlot(MainUtil.getPlot(world, topId)).id;
final PlotId top1 = MainUtil.getTopPlot(MainUtil.getPlot(world, topId)).id;
final PlotId top2 = MainUtil.getTopPlot(MainUtil.getPlot(world, botId)).id;
bot = new PlotId(Math.min(bot1.x, bot2.x), Math.min(bot1.y, bot2.y));
top = new PlotId(Math.max(top1.x, top2.x), Math.max(top1.y, top2.y));
final ArrayList<PlotId> plots = MainUtil.getMaxPlotSelectionIds(world, bot, top);
boolean multiMerge = false;
final HashSet<UUID> multiUUID = new HashSet<UUID>();
final HashSet<PlotId> multiPlots = new HashSet<>();
final UUID u1 = plot.owner;
for (final PlotId myid : plots) {
final Plot myplot = PS.get().getPlot(world, myid);
if ((myplot == null) || (myplot.owner == null)) {
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
final UUID u2 = myplot.owner;
if (u2.equals(u1)) {
continue;
}
final PlotPlayer p2 = UUIDHandler.getPlayer(u2);
if (p2 == null) {
MainUtil.sendMessage(plr, C.NO_PERM_MERGE.s().replaceAll("%plot%", myid.toString()));
return false;
}
multiMerge = true;
multiPlots.add(myid);
multiUUID.add(u2);
}
if (multiMerge) {
if (!Permissions.hasPermission(plr, C.PERMISSION_MERGE_OTHER)) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, C.PERMISSION_MERGE_OTHER.s());
return false;
}
for (final UUID uuid : multiUUID) {
HashSet<UUID> uuids = adjacent.getOwners();
boolean isOnline = false;
for (final UUID uuid : uuids) {
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
if (accepter == null) {
continue;
}
isOnline = true;
final int dir = direction;
CmdConfirm.addPending(accepter, C.MERGE_REQUEST_CONFIRM.s().replaceAll("%s", plr.getName()), new Runnable() {
@Override
public void run() {
final PlotPlayer accepter = UUIDHandler.getPlayer(uuid);
multiUUID.remove(uuid);
if (multiUUID.size() == 0) {
final PlotPlayer pp = UUIDHandler.getPlayer(u1);
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
MainUtil.autoMerge(plot, dir, maxSize - size, uuid, true);
final PlotPlayer pp = UUIDHandler.getPlayer(plr.getUUID());
if (pp == null) {
sendMessage(accepter, C.MERGE_NOT_VALID);
return;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) {
if (EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, plotworld.MERGE_PRICE + "");
return;
}
EconHandler.manager.withdrawMoney(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return;
EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE);
sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + "");
}
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
}
MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED);
}
});
}
if (isOnline == false) {
MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE);
return false;
}
MainUtil.sendMessage(plr, C.MERGE_REQUESTED);
return true;
}
final PlotWorld plotWorld = PS.get().getPlotWorld(world);
if ((EconHandler.manager != null) && plotWorld.USE_ECONOMY) {
double cost = plotWorld.MERGE_PRICE;
cost = plots.size() * cost;
if (cost > 0d) {
if (EconHandler.manager.getMoney(plr) < cost) {
sendMessage(plr, C.CANNOT_AFFORD_MERGE, cost + "");
return false;
}
EconHandler.manager.withdrawMoney(plr, cost);
sendMessage(plr, C.REMOVED_BALANCE, cost + "");
}
}
final boolean result = EventUtil.manager.callMerge(world, plot, plots);
if (!result) {
MainUtil.sendMessage(plr, "&cMerge has been cancelled");
return false;
}
MainUtil.sendMessage(plr, C.SUCCESS_MERGE);
MainUtil.mergePlots(world, plots, true, true);
MainUtil.setSign(UUIDHandler.getName(plot.owner), plot);
return true;
}
}

View File

@ -41,40 +41,26 @@ public class Move extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot1 = MainUtil.getPlot(loc);
final Plot plot1 = MainUtil.getPlotAbs(loc);
if (plot1 == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot1.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
if (!plot1.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final String world = loc.getWorld();
final PlotId plot2id = MainUtil.parseId(args[0]);
if ((plot2id == null)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
final Plot plot2 = MainUtil.getPlotFromString(plr, args[0], true);
if ((plot2 == null)) {
return false;
}
String world2;
if (args.length == 2) {
final PlotWorld other = PS.get().getPlotWorld(args[1]);
final PlotWorld current = PS.get().getPlotWorld(loc.getWorld());
if ((other == null) || (current == null) || !other.equals(current)) {
MainUtil.sendMessage(plr, C.PLOTWORLD_INCOMPATIBLE);
return false;
}
world2 = other.worldname;
} else {
world2 = world;
}
final Plot plot2 = MainUtil.getPlot(world2, plot2id);
if (plot1.equals(plot2)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot move <X;Z>");
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (!plot1.getWorld().equals(plot2.getWorld())) {
C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false;
}
if (MainUtil.move(plot1, plot2, new Runnable() {
@ -82,11 +68,12 @@ public class Move extends SubCommand {
public void run() {
MainUtil.sendMessage(plr, C.MOVE_SUCCESS);
}
})) {
}, false)) {
return true;
} else {
MainUtil.sendMessage(plr, C.REQUIRES_UNOWNED);
return false;
}
}
}

View File

@ -39,7 +39,7 @@ public class MusicSubcommand extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer player, final String[] args) {
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}

View File

@ -93,7 +93,7 @@ public class Purge extends SubCommand {
final PlotId id = getId(arg);
if (id != null) {
final HashSet<Integer> ids = new HashSet<Integer>();
final int DBid = DBFunc.getId(MainUtil.getPlot(worldname, id));
final int DBid = DBFunc.getId(MainUtil.getPlotAbs(worldname, id));
if (DBid != Integer.MAX_VALUE) {
ids.add(DBid);
}

View File

@ -82,7 +82,7 @@ public class Rate extends SubCommand {
});
final UUID uuid = player.getUUID();
for (final Plot p : plots) {
if ((!Settings.REQUIRE_DONE || p.getSettings().flags.containsKey("done"))
if ((!Settings.REQUIRE_DONE || p.getFlags().containsKey("done"))
&& p.isBasePlot()
&& ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid))
&& !p.isAdded(uuid)) {
@ -96,7 +96,7 @@ public class Rate extends SubCommand {
}
}
final Location loc = player.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(player, C.NOT_IN_PLOT);
}
@ -108,7 +108,7 @@ public class Rate extends SubCommand {
sendMessage(player, C.RATING_NOT_YOUR_OWN);
return false;
}
if (Settings.REQUIRE_DONE && !plot.getSettings().flags.containsKey("done")) {
if (Settings.REQUIRE_DONE && !plot.getFlags().containsKey("done")) {
sendMessage(player, C.RATING_NOT_DONE);
return false;
}

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands;
import java.util.List;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
@ -66,7 +67,7 @@ public class RegenAllRoads extends SubCommand {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
final List<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
final Set<ChunkLoc> chunks = ChunkManager.manager.getChunkChunks(name);
MainUtil.sendMessage(plr, "&cIf no schematic is set, the following will not do anything");
MainUtil.sendMessage(plr, "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic");
MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024));

View File

@ -56,7 +56,7 @@ public class Remove extends SubCommand {
return true;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -8,6 +8,7 @@ import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer;
@ -32,7 +33,7 @@ public class Save extends SubCommand {
if (!PS.get().isPlotWorld(world)) {
return !sendMessage(plr, C.NOT_IN_PLOT_WORLD);
}
final Plot plot = MainUtil.getPlot(plr.getLocation());
final Plot plot = MainUtil.getPlotAbs(plr.getLocation());
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -44,7 +45,7 @@ public class Save extends SubCommand {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
@ -57,7 +58,8 @@ public class Save extends SubCommand {
public void run() {
final String time = (System.currentTimeMillis() / 1000) + "";
final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", "");
final int size = (plot.getTop().getX() - plot.getBottom().getX()) + 1;
Location[] corners = MainUtil.getCorners(plot);
final int size = (corners[1].getX() - corners[0].getX()) + 1;
final PlotId id = plot.id;
final String world = plot.world.replaceAll("[^A-Za-z0-9]", "");
final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name;

View File

@ -40,8 +40,6 @@ import com.intellectualcrafters.plot.util.SchematicHandler.Schematic;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.general.commands.CommandDeclaration;
// TODO Add sub-subcommands
@CommandDeclaration(
command = "schematic",
permission = "plots.schematic",
@ -73,7 +71,7 @@ public class SchematicCmd extends SubCommand {
break;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -130,37 +128,38 @@ public class SchematicCmd extends SubCommand {
});
break;
}
case "test": {
if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
return false;
}
if (args.length < 2) {
sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
file = args[1];
schematic = SchematicHandler.manager.getSchematic(file);
if (schematic == null) {
sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
return false;
}
final int l1 = schematic.getSchematicDimension().getX();
final int l2 = schematic.getSchematicDimension().getZ();
final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
if ((l1 < length) || (l2 < length)) {
sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
break;
}
sendMessage(plr, C.SCHEMATIC_VALID);
break;
}
// TODO test
// case "test": {
// if (!Permissions.hasPermission(plr, "plots.schematic.test")) {
// MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.schematic.test");
// return false;
// }
// if (args.length < 2) {
// sendMessage(plr, C.SCHEMATIC_MISSING_ARG);
// return false;
// }
// final Location loc = plr.getLocation();
// final Plot plot = MainUtil.getPlot(loc);
// if (plot == null) {
// sendMessage(plr, C.NOT_IN_PLOT);
// return false;
// }
// file = args[1];
// schematic = SchematicHandler.manager.getSchematic(file);
// if (schematic == null) {
// sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent");
// return false;
// }
// final int l1 = schematic.getSchematicDimension().getX();
// final int l2 = schematic.getSchematicDimension().getZ();
// final int length = MainUtil.getPlotWidth(loc.getWorld(), plot.id);
// if ((l1 < length) || (l2 < length)) {
// sendMessage(plr, C.SCHEMATIC_INVALID, String.format("Wrong size (x: %s, z: %d) vs %d ", l1, l2, length));
// break;
// }
// sendMessage(plr, C.SCHEMATIC_VALID);
// break;
// }
case "saveall":
case "exportall": {
if (!ConsolePlayer.isConsole(plr)) {
@ -203,7 +202,7 @@ public class SchematicCmd extends SubCommand {
}
final Plot p2;
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -47,7 +47,6 @@ import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
// TODO Make sub-subcommands
@CommandDeclaration(
command = "set",
description = "Set a plot value",
@ -62,9 +61,8 @@ public class Set extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String... args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
@ -93,7 +91,7 @@ public class Set extends SubCommand {
}
}
if (args[0].equalsIgnoreCase("flag")) {
List<String> arglist = Arrays.asList("flag", "set");
List<String> arglist = new ArrayList<>(Arrays.asList("flag", "set"));
for (String arg : Arrays.copyOfRange(args, 1, args.length)) {
arglist.add(arg);
}
@ -113,7 +111,7 @@ public class Set extends SubCommand {
}
//set to current location
final String world = plr.getLocation().getWorld();
final Location base = MainUtil.getPlotBottomLoc(world, plot.id);
final Location base = MainUtil.getPlotBottomLocAbs(world, plot.id).subtract(1, 0, 1);
base.setY(0);
final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ());
final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ(), relative.getYaw(), relative.getPitch());
@ -159,7 +157,7 @@ public class Set extends SubCommand {
return false;
}
for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) {
if (p.getSettings().getAlias().equalsIgnoreCase(alias)) {
if (p.getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}
@ -179,26 +177,26 @@ public class Set extends SubCommand {
}
if (args.length < 2) {
MainUtil.sendMessage(plr, C.NEED_BIOME);
return true;
return false;
}
if (args[1].length() < 2) {
sendMessage(plr, C.NAME_LITTLE, "Biome", args[1].length() + "", "2");
return true;
return false;
}
final int biome = BlockManager.manager.getBiomeFromString(args[1]);
if (biome == -1) {
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
return true;
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
plot.addRunning();
plot.setBiome(args[1].toUpperCase(), new Runnable() {
@Override
public void run() {
MainUtil.runners.remove(plot);
plot.removeRunning();
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
}
});
@ -265,17 +263,19 @@ public class Set extends SubCommand {
MainUtil.sendMessage(plr, C.NOT_VALID_BLOCK, args[1]);
return false;
}
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
return false;
}
MainUtil.runners.put(plot, 1);
manager.setComponent(plotworld, plot.id, component, blocks);
plot.addRunning();
for (Plot current : MainUtil.getConnectedPlots(plot)) {
manager.setComponent(plotworld, current.id, component, blocks);
}
MainUtil.sendMessage(plr, C.GENERATING_COMPONENT);
SetBlockQueue.addNotify(new Runnable() {
@Override
public void run() {
MainUtil.runners.remove(plot);
plot.removeRunning();
}
});
return true;

View File

@ -21,6 +21,7 @@
package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
@ -58,7 +59,7 @@ public class SetOwner extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if ((plot == null) || ((plot.owner == null) && !Permissions.hasPermission(plr, "plots.admin.command.setowner"))) {
MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
return false;
@ -67,14 +68,11 @@ public class SetOwner extends SubCommand {
MainUtil.sendMessage(plr, C.NEED_USER);
return false;
}
final PlotId bot = MainUtil.getBottomPlot(plot).id;
final PlotId top = MainUtil.getTopPlot(plot).id;
final ArrayList<PlotId> plots = MainUtil.getPlotSelectionIds(bot, top);
HashSet<Plot> plots = MainUtil.getConnectedPlots(plot);
UUID uuid = UUIDHandler.getUUID(args[0], null);
final PlotPlayer other = UUIDHandler.getPlayer(args[0]);
if (other == null) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
if (uuid == null || !Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
@ -88,32 +86,13 @@ public class SetOwner extends SubCommand {
}
}
}
if (!plot.isOwner(plr.getUUID())) {
if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) {
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.setowner");
return false;
}
}
final String world = loc.getWorld();
final UUID uuid = getUUID(args[0]);
if (uuid == null) {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false;
}
for (final PlotId id : plots) {
Plot current = PS.get().getPlot(world, id);
if (current == null) {
current = MainUtil.getPlot(world, id);
current.owner = uuid;
current.create();
} else {
current.owner = uuid;
DBFunc.setOwner(current, current.owner);
}
PS.get().updatePlot(current);
}
plot.setOwner(uuid);
MainUtil.setSign(args[0], plot);
MainUtil.sendMessage(plr, C.SET_OWNER);
if (other != null) {

View File

@ -40,91 +40,38 @@ public class Swap extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
MainUtil.sendMessage(plr, "&cThis command has not been optimized for large selections yet. Please bug me if this becomes an issue.");
if (args.length < 1) {
MainUtil.sendMessage(plr, C.NEED_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
final Plot plot1 = MainUtil.getPlotAbs(loc);
if (plot1 == null) {
return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.swap")) {
if (!plot1.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, C.PERMISSION_ADMIN.s())) {
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
return false;
}
final Plot bot1 = MainUtil.getBottomPlot(plot);
final Plot top1 = MainUtil.getTopPlot(plot);
final PlotId id2 = PlotId.fromString(args[0]);
if (id2 == null) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
final Plot plot2 = MainUtil.getPlotFromString(plr, args[0], true);
if ((plot2 == null)) {
return false;
}
final String world = loc.getWorld();
final Plot plot2 = MainUtil.getPlot(world, id2);
final PlotId id3 = new PlotId((id2.x + top1.id.x) - bot1.id.x, (id2.y + top1.id.y) - bot1.id.y);
final Plot plot3 = MainUtil.getPlot(world, id3);
// Getting secon selection
final Plot bot2 = MainUtil.getBottomPlot(plot2);
final Plot top2 = MainUtil.getTopPlot(plot3);
// cancel swap if intersection
final PlotCluster cluster1 = new PlotCluster(world, bot1.id, top1.id, null);
final PlotClusterId cluster2id = new PlotClusterId(bot2.id, top2.id);
if (ClusterManager.intersects(cluster1, cluster2id)) {
if (plot1.equals(plot2)) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy <X;Z>");
return false;
}
if (!plot1.getWorld().equals(plot2.getWorld())) {
C.PLOTWORLD_INCOMPATIBLE.send(plr);
return false;
}
if (MainUtil.move(plot1, plot2, new Runnable() {
@Override
public void run() {
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
}
}, true)) {
return true;
} else {
MainUtil.sendMessage(plr, C.SWAP_OVERLAP);
return false;
}
// Check dimensions
if (((top1.id.x - bot1.id.x) != (top2.id.x - bot2.id.x)) || ((top1.id.y - bot1.id.y) != (top2.id.y - bot2.id.y))) {
MainUtil.sendMessage(plr, C.SWAP_DIMENSIONS, "1");
MainUtil.sendMessage(plr, C.SWAP_SYNTAX);
return false;
}
// Getting selections as ids
final ArrayList<PlotId> selection1 = MainUtil.getPlotSelectionIds(bot1.id, top1.id);
final ArrayList<PlotId> selection2 = MainUtil.getPlotSelectionIds(bot2.id, top2.id);
// Getting selections as location coordinates
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, bot1.id);
final Location pos2 = MainUtil.getPlotTopLocAbs(world, top1.id).subtract(1, 0, 1);
final Location pos3 = MainUtil.getPlotBottomLocAbs(world, bot2.id);
final Location pos4 = MainUtil.getPlotTopLocAbs(world, top2.id).subtract(1, 0, 1);
if (MainUtil.getPlot(pos2) != null) {
pos1.add(1, 0, 1);
pos2.add(1, 0, 1);
pos3.add(1, 0, 1);
pos4.add(1, 0, 1);
}
// Swapping the blocks, states and entites
ChunkManager.manager.swap(world, pos1, pos2, pos3, pos4);
// Swapping the plot data
for (int i = 0; i < selection1.size(); i++) {
final boolean last = i == (selection1.size() - 1);
final PlotId swaper = selection1.get(i);
final PlotId swapee = selection2.get(i);
MainUtil.swapData(world, swaper, swapee, new Runnable() {
@Override
public void run() {
if (last) {
MainUtil.sendMessage(plr, C.SWAP_SUCCESS);
}
}
});
}
MainUtil.sendMessage(plr, C.STARTED_SWAP);
return true;
}
}

View File

@ -63,7 +63,7 @@ public class TP extends SubCommand {
}
try {
plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1]));
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlot(world, plotid));
MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlotAbs(world, plotid));
return true;
} catch (final Exception e) {
MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID);
@ -90,7 +90,7 @@ public class TP extends SubCommand {
return null;
}
for (final Plot p : PS.get().getPlotsInWorld(world)) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
if ((p.getAlias().length() > 0) && p.getAlias().equalsIgnoreCase(a)) {
return p;
}
}

View File

@ -52,7 +52,7 @@ public class Target extends SubCommand {
Plot closest = null;
int distance = Integer.MAX_VALUE;
for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) {
final double current = plot.getBottom().getEuclideanDistanceSquared(ploc);
final double current = plot.getBottomAbs().getEuclideanDistanceSquared(ploc);
if (current < distance) {
distance = (int) current;
closest = plot;

View File

@ -133,8 +133,8 @@ public class Trim extends SubCommand {
}
final Plot plot = plots.remove(0);
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id);
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.id);
final Location pos2 = MainUtil.getPlotTopLocAbs(world, plot.id);
final int ccx1 = (pos1.getX() >> 9);
final int ccz1 = (pos1.getZ() >> 9);
@ -204,7 +204,7 @@ public class Trim extends SubCommand {
sendMessage(C.TRIM_IN_PROGRESS.s());
return false;
}
sendMessage(C.TRIM_START.s());
sendMessage(C.TASK_START.s());
final ArrayList<ChunkLoc> empty = new ArrayList<>();
getTrimRegions(empty, world, new Runnable() {
public void run() {

View File

@ -53,7 +53,7 @@ public class Trust extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -31,33 +31,25 @@ import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "unclaim", usage = "/plot unclaim", requiredType = RequiredType.NONE, description = "Unclaim a plot", category = CommandCategory.ACTIONS)
/**
* Unclaiming a plot makes no changes to the terrain or plot border and only removes the owner and should be regarded as an admin command.
*/
@CommandDeclaration(command = "unclaim", usage = "/plot unclaim", requiredType = RequiredType.NONE, description = "Unclaim a plot (admin command)", category = CommandCategory.ACTIONS)
public class Unclaim extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if (!plot.hasOwner()) {
return !sendMessage(plr, C.PLOT_NOT_CLAIMED);
}
if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
return !sendMessage(plr, C.UNLINK_REQUIRED);
}
if (((!plot.hasOwner() || !plot.isOwner(plr.getUUID()))) && !Permissions.hasPermission(plr, "plots.admin.command.unclaim")) {
return !sendMessage(plr, C.NO_PLOT_PERMS);
}
final PlotWorld pWorld = PS.get().getPlotWorld(plot.world);
if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) {
final double c = pWorld.SELL_PRICE;
if (c > 0d) {
EconHandler.manager.depositMoney(plr, c);
sendMessage(plr, C.ADDED_BALANCE, c + "");
}
}
if (plot.unclaim()) {
MainUtil.sendMessage(plr, C.UNCLAIM_SUCCESS);
} else {

View File

@ -51,7 +51,7 @@ public class Undeny extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String... args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -38,20 +38,23 @@ public class Unlink extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
if (!plot.hasOwner()) {
return !sendMessage(plr, C.PLOT_UNOWNED);
}
if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.unlink")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
if (!plot.isMerged()) {
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
}
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (!MainUtil.unlinkPlot(plot, true)) {
if (!MainUtil.unlinkPlot(plot, true, true)) {
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
return;
}

View File

@ -52,7 +52,7 @@ public class Untrust extends SubCommand {
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
return !sendMessage(plr, C.NOT_IN_PLOT);
}

View File

@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
@ -170,7 +171,7 @@ public class list extends SubCommand {
match = null;
}
for (final Plot plot : PS.get().getPlots()) {
final Flag flag = plot.getSettings().flags.get("done");
final Flag flag = plot.getFlags().get("done");
if (flag == null) {
continue;
}
@ -189,8 +190,8 @@ public class list extends SubCommand {
Collections.sort(plots, new Comparator<Plot>() {
@Override
public int compare(final Plot a, final Plot b) {
final String va = a.getSettings().flags.get("done").getValueString();
final String vb = b.getSettings().flags.get("done").getValueString();
final String va = a.getFlags().get("done").getValueString();
final String vb = b.getFlags().get("done").getValueString();
if (MathMan.isInteger(va)) {
if (MathMan.isInteger(vb)) {
return Integer.parseInt(vb) - Integer.parseInt(va);
@ -332,6 +333,13 @@ public class list extends SubCommand {
}
public void displayPlots(final PlotPlayer player, List<Plot> plots, final int pageSize, int page, final String world, final String[] args, final boolean sort) {
int rawSize = plots.size();
Iterator<Plot> iter = plots.iterator();
while (iter.hasNext()) {
if (!iter.next().isBasePlot()) {
iter.remove();
}
}
if (sort) {
plots = PS.get().sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, world);
}
@ -351,17 +359,12 @@ public class list extends SubCommand {
final List<Plot> subList = plots.subList(page * pageSize, max);
// Header
final String header = C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%amount%", plots.size() + "")
final String header = C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + "").replaceAll("%max", totalPages + 1 + "").replaceAll("%amount%", plots.size() + "/" + rawSize)
.replaceAll("%word%", "all");
MainUtil.sendMessage(player, header);
int i = page * pageSize;
for (final Plot plot : subList) {
if (plot.getSettings().isMerged()) {
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
continue;
}
}
i++;
String color;
if (plot.owner == null) {
@ -379,7 +382,7 @@ public class list extends SubCommand {
final PlotMessage members = new PlotMessage().text(C.color(C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers())))).color("$1");
String strFlags = StringMan.join(plot.getSettings().flags.values(), ",");
String strFlags = StringMan.join(plot.getFlags().values(), ",");
if (strFlags.length() == 0) {
strFlags = C.NONE.s();
}

View File

@ -283,6 +283,7 @@ public enum C {
/*
* Core Stuff
*/
TASK_START("Starting task...", "Core"),
PREFIX("$3[$1P2$3] $2", "Core"),
ENABLED("$1PlotSquared is now enabled", "Core"),
EXAMPLE_MESSAGE("$2This is an example message &k!!!", "Core"),
@ -328,16 +329,20 @@ public enum C {
CANT_TRANSFER_MORE_PLOTS("$2You can't send more plots to that user", "Permission"),
CANT_CLAIM_MORE_PLOTS_NUM("$2You can't claim more than $1%s $2plots at once", "Permission"),
YOU_BE_DENIED("$2You are not allowed to enter this plot", "Permission"),
NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%", "Permission"),
UNLINK_REQUIRED("$2An unlink is required to do this.", "Permission"),
UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot", "Permission"),
UNLINK_SUCCESS("$2Successfully unlinked plots.", "Permission"),
NO_MERGE_TO_MEGA("$2Mega plots cannot be merged into. Please merge from the desired mega plot.", "Permission"),
MERGE_NOT_VALID("$2This merge request is no longer valid.", "Permission"),
MERGE_ACCEPTED("$2The merge request has been accepted", "Permission"),
SUCCESS_MERGE("$2Plots have been merged!", "Permission"),
MERGE_REQUESTED("$2Successfully sent a merge request", "Permission"),
/*
* Merge
*/
MERGE_NOT_VALID("$2This merge request is no longer valid.", "Merge"),
MERGE_ACCEPTED("$2The merge request has been accepted", "Merge"),
SUCCESS_MERGE("$2Plots have been merged!", "Merge"),
MERGE_REQUESTED("$2Successfully sent a merge request", "Merge"),
MERGE_REQUEST_CONFIRM("merge request from %s", "Permission"),
NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%", "Merge"),
NO_AVAILABLE_AUTOMERGE("$2You do not own any adjacent plots in the specified direction.", "Merge"),
UNLINK_REQUIRED("$2An unlink is required to do this.", "Merge"),
UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot", "Merge"),
UNLINK_SUCCESS("$2Successfully unlinked plots.", "Merge"),
/*
* Commands
*/
@ -368,7 +373,6 @@ public enum C {
* trim
*/
TRIM_SYNTAX("Use /plot trim <all|x;y> <world>", "Trim"),
TRIM_START("Starting a world trim task...", "Trim"),
TRIM_IN_PROGRESS("A world trim task is already in progress!", "Trim"),
NOT_VALID_HYBRID_PLOT_WORLD("The hybrid plot manager is required to perform this action", "Trim"),
/*

View File

@ -212,10 +212,7 @@ public class Settings {
/**
* MongoDB enabled?
*/
public static boolean USE_MONGO = false; /*
* TODO: Implement Mongo
* @Brandon
*/
public static boolean USE_MONGO = false;
/**
* SQLite enabled?
*/

View File

@ -151,6 +151,7 @@ public class DBFunc {
return;
}
dbManager.delete(plot);
plot.temp = -1;
}
public static void delete(final PlotCluster toDelete) {
@ -399,7 +400,7 @@ public class DBFunc {
public static HashMap<UUID, Integer> getRatings(final Plot plot) {
if (plot.temp == -1) {
return new HashMap<>();
return new HashMap<>(0);
}
return dbManager.getRatings(plot);
}

View File

@ -763,11 +763,8 @@ public class SQLManager implements AbstractDB {
stmt.setString((i * 10) + 8, flag_string.toString());
}
final boolean[] merged = pair.settings.getMerged();
int n = 0;
for (int j = 0; j < 4; ++j) {
n = (n << 1) + (merged[j] ? 1 : 0);
}
stmt.setInt((i * 10) + 9, n);
int hash = MainUtil.hash(merged);
stmt.setInt((i * 10) + 9, hash);
final BlockLoc loc = pair.settings.getPosition();
String position;
if (loc.y == 0) {
@ -1311,9 +1308,6 @@ public class SQLManager implements AbstractDB {
}
public void updateTables() {
// TODO task
if (PS.get().getVersion().equals(PS.get().getLastVersion()) || (PS.get().getLastVersion() == null)) {
return;
}
@ -1646,11 +1640,8 @@ public class SQLManager implements AbstractDB {
addPlotTask(plot, new UniqueStatement("setMerged") {
@Override
public void set(final PreparedStatement stmt) throws SQLException {
int n = 0;
for (int i = 0; i < 4; ++i) {
n = (n << 1) + (merged[i] ? 1 : 0);
}
stmt.setInt(1, n);
int hash = MainUtil.hash(merged);
stmt.setInt(1, hash);
stmt.setInt(2, getId(plot));
}
@ -1702,12 +1693,13 @@ public class SQLManager implements AbstractDB {
public void set(final PreparedStatement stmt) throws SQLException {
stmt.setInt(1, newPlot.id.x);
stmt.setInt(2, newPlot.id.y);
stmt.setInt(3, getId(original));
stmt.setString(3, newPlot.world);
stmt.setInt(4, getId(original));
}
@Override
public PreparedStatement get() throws SQLException {
return connection.prepareStatement("UPDATE `" + prefix + "plot` SET `plot_id_x` = ?, `plot_id_z` = ? WHERE `id` = ?");
return connection.prepareStatement("UPDATE `" + prefix + "plot` SET `plot_id_x` = ?, `plot_id_z` = ?, `world` = ? WHERE `id` = ?");
}
});
addPlotTask(newPlot, null);

View File

@ -45,10 +45,6 @@ import com.intellectualcrafters.plot.util.Permissions;
*/
@SuppressWarnings("unused")
public class FlagManager {
// TODO add some flags
// - Plot clear interval
// - Mob cap
// - customized plot composition
private final static HashSet<String> reserved = new HashSet<>();
@ -108,7 +104,7 @@ public class FlagManager {
}
if (PS.get().getAllPlotsRaw() != null) {
for (final Plot plot : PS.get().getPlotsRaw()) {
final Flag flag = plot.getSettings().flags.get(af.getKey());
final Flag flag = plot.getFlags().get(af.getKey());
if (flag != null) {
flag.setKey(af);
}
@ -204,14 +200,16 @@ public class FlagManager {
* @param plot
* @param flag
*/
public static boolean addPlotFlag(final Plot plot, final Flag flag) {
final boolean result = EventUtil.manager.callFlagAdd(flag, plot);
public static boolean addPlotFlag(final Plot origin, final Flag flag) {
final boolean result = EventUtil.manager.callFlagAdd(flag, origin);
if (!result) {
return false;
}
plot.getSettings().flags.put(flag.getKey(), flag);
for (Plot plot : MainUtil.getConnectedPlots(origin)) {
plot.getFlags().put(flag.getKey(), flag);
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
}
return true;
}
@ -220,7 +218,7 @@ public class FlagManager {
if (!result) {
return false;
}
plot.getSettings().flags.put(flag.getKey(), flag);
plot.getFlags().put(flag.getKey(), flag);
return true;
}
@ -270,17 +268,17 @@ public class FlagManager {
}
public static boolean removePlotFlag(final Plot plot, final String id) {
final Flag flag = plot.getSettings().flags.remove(id);
final Flag flag = plot.getFlags().remove(id);
if (flag == null) {
return false;
}
final boolean result = EventUtil.manager.callFlagRemove(flag, plot);
if (!result) {
plot.getSettings().flags.put(id, flag);
plot.getFlags().put(id, flag);
return false;
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
return true;
}
@ -298,19 +296,21 @@ public class FlagManager {
return true;
}
public static void setPlotFlags(final Plot plot, final Set<Flag> flags) {
public static void setPlotFlags(final Plot origin, final Set<Flag> flags) {
for (Plot plot : origin.getConnectedPlots()) {
if ((flags != null) && (flags.size() != 0)) {
plot.getSettings().flags.clear();
plot.getFlags().clear();
for (final Flag flag : flags) {
plot.getSettings().flags.put(flag.getKey(), flag);
plot.getFlags().put(flag.getKey(), flag);
}
} else if (plot.getSettings().flags.size() == 0) {
} else if (plot.getFlags().size() == 0) {
return;
} else {
plot.getSettings().flags.clear();
plot.getFlags().clear();
}
MainUtil.reEnterPlot(plot);
DBFunc.setFlags(plot, plot.getSettings().flags.values());
DBFunc.setFlags(plot, plot.getFlags().values());
}
}
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) {

View File

@ -8,6 +8,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SetBlockQueue;
@ -26,6 +27,14 @@ public class ClassicPlotManager extends SquarePlotManager {
setWallFilling(plotworld, plotid, blocks);
return true;
}
case "all": {
setAir(plotworld, plotid, blocks);
return true;
}
case "outline": {
setOutline(plotworld, plotid, blocks);
return true;
}
case "border": {
setWall(plotworld, plotid, blocks);
return true;
@ -46,12 +55,81 @@ public class ClassicPlotManager extends SquarePlotManager {
}
public boolean setFloor(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid);
if (plot.isBasePlot()) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location pos1 = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
pos1.setY(dpw.PLOT_HEIGHT);
pos2.setY(dpw.PLOT_HEIGHT + 1);
for (RegionWrapper region : MainUtil.getRegions(plot)) {
Location pos1 = new Location(plot.world, region.minX, dpw.PLOT_HEIGHT, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, dpw.PLOT_HEIGHT, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
}
}
return true;
}
public boolean setAir(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid);
if (!plot.isBasePlot()) {
return false;
}
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
for (RegionWrapper region : MainUtil.getRegions(plot)) {
Location pos1 = new Location(plot.world, region.minX, dpw.PLOT_HEIGHT + 1, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, 255, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
}
return true;
}
public boolean setOutline(final PlotWorld plotworld, final PlotId plotid, final PlotBlock[] blocks) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
if (dpw.ROAD_WIDTH == 0) {
return false;
}
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid);
final Location bottom = MainUtil.getPlotBottomLocAbs(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc_(plot);
final PseudoRandom random = new PseudoRandom();
if (!plot.getMerged(0)) {
int z = bottom.getZ();
for (int x = bottom.getX(); x <= (top.getX()); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
}
if (!plot.getMerged(3)) {
int x = bottom.getX();
for (int z = bottom.getZ(); z <= (top.getZ()); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
}
if (!plot.getMerged(2)) {
int z = top.getZ();
for (int x = bottom.getX(); x <= (top.getX()); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
}
if (!plot.getMerged(1)) {
int x = top.getX();
for (int z = bottom.getZ(); z <= (top.getZ()); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= 255; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
}
if (plot.isBasePlot()) {
for (RegionWrapper region : MainUtil.getRegions(plot)) {
Location pos1 = new Location(plot.world, region.minX, 255, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, 255, region.maxZ);
MainUtil.setCuboidAsync(plotworld.worldname, pos1, pos2, blocks);
}
}
return true;
}
@ -60,34 +138,42 @@ public class ClassicPlotManager extends SquarePlotManager {
if (dpw.ROAD_WIDTH == 0) {
return false;
}
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
int x, z;
z = bottom.getZ();
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid);
final Location bot = MainUtil.getPlotBottomLoc_(plot).subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1);
final Location top = MainUtil.getPlotTopLoc_(plot).add(1, 0, 1);
final PseudoRandom random = new PseudoRandom();
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
if (!plot.getMerged(0)) {
int z = bot.getZ();
for (int x = bot.getX(); x < (top.getX()); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
}
if (!plot.getMerged(3)) {
int x = bot.getX();
for (int z = bot.getZ(); z < (top.getZ()); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
}
if (!plot.getMerged(2)) {
int z = top.getZ();
for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
}
if (!plot.getMerged(1)) {
int x = top.getX();
for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
}
return true;
}
@ -96,27 +182,35 @@ public class ClassicPlotManager extends SquarePlotManager {
if (dpw.ROAD_WIDTH == 0) {
return false;
}
final Location bottom = MainUtil.getPlotBottomLoc(plotworld.worldname, plotid);
final Location top = MainUtil.getPlotTopLoc(plotworld.worldname, plotid).add(1, 0, 1);
int x, z;
z = bottom.getZ();
Plot plot = MainUtil.getPlotAbs(plotworld.worldname, plotid);
final Location bot = MainUtil.getPlotBottomLoc_(plot).subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1);
final Location top = MainUtil.getPlotTopLoc_(plot).add(1, 0, 1);
final PseudoRandom random = new PseudoRandom();
final int y = dpw.WALL_HEIGHT + 1;
for (x = bottom.getX(); x <= (top.getX() - 1); x++) {
if (!plot.getMerged(0)) {
int z = bot.getZ();
for (int x = bot.getX(); x < (top.getX()); x++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
x = top.getX();
for (z = bottom.getZ(); z <= (top.getZ() - 1); z++) {
}
if (!plot.getMerged(3)) {
int x = bot.getX();
for (int z = bot.getZ(); z < (top.getZ()); z++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
z = top.getZ();
for (x = top.getX(); x >= (bottom.getX() + 1); x--) {
}
if (!plot.getMerged(2)) {
int z = top.getZ();
for (int x = bot.getX(); x < (top.getX() + (plot.getMerged(1) ? 0 : 1)); x++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
x = bottom.getX();
for (z = top.getZ(); z >= (bottom.getZ() + 1); z--) {
}
if (!plot.getMerged(1)) {
int x = top.getX();
for (int z = bot.getZ(); z < (top.getZ() + (plot.getMerged(2) ? 0 : 1)); z++) {
SetBlockQueue.setBlock(plotworld.worldname, x, y, z, blocks[random.random(blocks.length)]);
}
}
return true;
}
@ -130,19 +224,18 @@ public class ClassicPlotManager extends SquarePlotManager {
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
final int sx = pos2.getX() + 1;
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos1.getZ() - 1;
final int sz = pos1.getZ() - 2;
final int ez = pos2.getZ() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex + 1,
257, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), new PlotBlock((short) 7,
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1), new Location(plotworld.worldname, ex, 255, ez - 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez - 1), new PlotBlock((short) 7,
(byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 2, ez),
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, sx, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 1, ez), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.WALL_HEIGHT + 2, ez),
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT, ez - 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez - 1),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
return true;
}
@ -153,18 +246,17 @@ public class ClassicPlotManager extends SquarePlotManager {
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
final int sz = pos2.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
final int sx = pos1.getX() - 1;
final int sx = pos1.getX() - 2;
final int ex = pos2.getX() + 2;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex, 1, ez + 1), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, sz + 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, sz + 1),
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex - 1, 255, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz), new Location(plotworld.worldname, ex - 1, 0, ez), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex - 1, dpw.WALL_HEIGHT, sz), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, sz), new Location(plotworld.worldname, ex - 1, dpw.WALL_HEIGHT + 1, sz),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 1, ez + 1), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex, dpw.WALL_HEIGHT + 2, ez + 1),
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, ez), new Location(plotworld.worldname, ex - 1, dpw.WALL_HEIGHT, ez), dpw.WALL_FILLING);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.WALL_HEIGHT + 1, ez), new Location(plotworld.worldname, ex - 1, dpw.WALL_HEIGHT + 1, ez),
dpw.WALL_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
return true;
}
@ -176,10 +268,10 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos2.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex, 257, ez), new PlotBlock(
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.ROAD_HEIGHT + 1, sz + 1), new Location(plotworld.worldname, ex - 1, 255, ez - 1), new PlotBlock(
(short) 0, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz + 1), new Location(plotworld.worldname, ex, 1, ez), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT + 1, ez), dpw.ROAD_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 0, sz + 1), new Location(plotworld.worldname, ex - 1, 0, ez - 1), new PlotBlock((short) 7, (byte) 0));
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz + 1), new Location(plotworld.worldname, ex - 1, dpw.ROAD_HEIGHT, ez - 1), dpw.ROAD_BLOCK);
return true;
}
@ -190,12 +282,11 @@ public class ClassicPlotManager extends SquarePlotManager {
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
final int sx = pos2.getX() + 1;
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = pos1.getZ();
final int sz = pos1.getZ() - 1;
final int ez = pos2.getZ() + 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT, ez), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.PLOT_HEIGHT, sz + 1), new Location(plotworld.worldname, ex + 1, dpw.PLOT_HEIGHT + 1, ez), dpw.TOP_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 255, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz + 1), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT - 1, ez - 1), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.PLOT_HEIGHT, sz + 1), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez - 1), dpw.TOP_BLOCK);
return true;
}
@ -206,12 +297,11 @@ public class ClassicPlotManager extends SquarePlotManager {
final Location pos2 = getPlotTopLocAbs(plotworld, plot.id);
final int sz = pos2.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
final int sx = pos1.getX();
final int sx = pos1.getX() - 1;
final int ex = pos2.getX() + 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex + 1, 257,
ez + 1), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT, ez + 1), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.PLOT_HEIGHT, sz), new Location(plotworld.worldname, ex, dpw.PLOT_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz), new Location(plotworld.worldname, ex, 255, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, 1, sz), new Location(plotworld.worldname, ex - 1, dpw.PLOT_HEIGHT - 1, ez), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx + 1, dpw.PLOT_HEIGHT, sz), new Location(plotworld.worldname, ex - 1, dpw.PLOT_HEIGHT, ez), dpw.TOP_BLOCK);
return true;
}
@ -223,10 +313,9 @@ public class ClassicPlotManager extends SquarePlotManager {
final int ex = (sx + dpw.ROAD_WIDTH) - 1;
final int sz = loc.getZ() + 1;
final int ez = (sz + dpw.ROAD_WIDTH) - 1;
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex + 1, 257, ez + 1), new PlotBlock(
(short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT, ez + 1), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT, sz), new Location(plotworld.worldname, ex + 1, dpw.ROAD_HEIGHT + 1, ez + 1), dpw.TOP_BLOCK);
MainUtil.setSimpleCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT + 1, sz), new Location(plotworld.worldname, ex, 255, ez), new PlotBlock((short) 0, (byte) 0));
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, 1, sz), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT - 1, ez), dpw.MAIN_BLOCK);
MainUtil.setCuboidAsync(plotworld.worldname, new Location(plotworld.worldname, sx, dpw.ROAD_HEIGHT, sz), new Location(plotworld.worldname, ex, dpw.ROAD_HEIGHT, ez), dpw.TOP_BLOCK);
return true;
}
@ -235,11 +324,12 @@ public class ClassicPlotManager extends SquarePlotManager {
*/
@Override
public boolean finishPlotMerge(final PlotWorld plotworld, final ArrayList<PlotId> plotIds) {
final PlotId pos1 = plotIds.get(0);
final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK;
final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK;
if ((block.id != 0) || !block.equals(unclaim)) {
setWall(plotworld, pos1, new PlotBlock[] { block });
for (final PlotId id : plotIds) {
setWall(plotworld, id, new PlotBlock[] { block });
}
}
return true;
}
@ -278,16 +368,17 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override
public String[] getPlotComponents(final PlotWorld plotworld, final PlotId plotid) {
return new String[] { "floor", "wall", "border" };
return new String[] { "floor", "wall", "border", "all", "outline" };
}
/**
* Remove sign for a plot
*/
@Override
public Location getSignLoc(final PlotWorld plotworld, final Plot plot) {
public Location getSignLoc(final PlotWorld plotworld, Plot plot) {
final ClassicPlotWorld dpw = (ClassicPlotWorld) plotworld;
final Location bot = MainUtil.getPlotBottomLoc(plotworld.worldname, plot.id);
return new com.intellectualcrafters.plot.object.Location(plotworld.worldname, bot.getX(), dpw.ROAD_HEIGHT + 1, bot.getZ() - 1);
plot = plot.getBasePlot(false);
final Location bot = plot.getBottomAbs();
return new com.intellectualcrafters.plot.object.Location(plotworld.worldname, bot.getX() - 1, dpw.ROAD_HEIGHT + 1, bot.getZ() - 2);
}
}

View File

@ -171,8 +171,8 @@ public class HybridPlotManager extends ClassicPlotManager {
final String world = plotworld.worldname;
final HybridPlotWorld dpw = ((HybridPlotWorld) plotworld);
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id);
final Location pos1 = MainUtil.getPlotBottomLocAbs(world, plot.id);
final Location pos2 = MainUtil.getPlotTopLoc_(plot);
// If augmented
final boolean canRegen = (plotworld.TYPE == 0) && (plotworld.TERRAIN == 0);
// The component blocks
@ -198,7 +198,7 @@ public class HybridPlotManager extends ClassicPlotManager {
MainUtil.setBiome(world, value[2], value[3], value[4], value[5], dpw.PLOT_BIOME);
// These two locations are for each component (e.g. bedrock, main block, floor, air)
final Location bot = new Location(world, value[2], 0, value[3]);
final Location top = new Location(world, value[4] + 1, 1, value[5] + 1);
final Location top = new Location(world, value[4], 1, value[5]);
MainUtil.setCuboidAsync(world, bot, top, bedrock);
// Each component has a different layer
bot.setY(1);

View File

@ -1,14 +1,21 @@
package com.intellectualcrafters.plot.generator;
import java.io.File;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import com.intellectualcrafters.jnbt.CompoundTag;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
@ -18,6 +25,7 @@ import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotLoc;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
@ -29,12 +37,78 @@ public abstract class HybridUtils {
public static HybridUtils manager;
public abstract void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone);
public abstract void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone);
public void analyzePlot(final Plot origin, final RunnableVal<PlotAnalysis> whenDone) {
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(MainUtil.getRegions(origin));
final ArrayList<PlotAnalysis> analysis = new ArrayList<>();
Runnable run = new Runnable() {
@Override
public void run() {
if (zones.size() == 0) {
if (analysis.size() > 0) {
whenDone.value = new PlotAnalysis();
for (PlotAnalysis data : analysis) {
whenDone.value.air += data.air;
whenDone.value.air_sd += data.air_sd;
whenDone.value.changes += data.changes;
whenDone.value.changes_sd += data.changes_sd;
whenDone.value.data += data.data;
whenDone.value.data_sd += data.data_sd;
whenDone.value.faces += data.faces;
whenDone.value.faces_sd += data.faces_sd;
whenDone.value.variety += data.variety;
whenDone.value.variety_sd += data.variety_sd;
}
whenDone.value.air /= analysis.size();
whenDone.value.air_sd /= analysis.size();
whenDone.value.changes /= analysis.size();
whenDone.value.changes_sd /= analysis.size();
whenDone.value.data /= analysis.size();
whenDone.value.data_sd /= analysis.size();
whenDone.value.faces /= analysis.size();
whenDone.value.faces_sd /= analysis.size();
whenDone.value.variety /= analysis.size();
whenDone.value.variety_sd /= analysis.size();
}
else {
whenDone.value = analysis.get(0);
}
final List<Integer> result = new ArrayList<>();
result.add(whenDone.value.changes);
result.add(whenDone.value.faces);
result.add(whenDone.value.data);
result.add(whenDone.value.air);
result.add(whenDone.value.variety);
result.add(whenDone.value.changes_sd);
result.add(whenDone.value.faces_sd);
result.add(whenDone.value.data_sd);
result.add(whenDone.value.air_sd);
result.add(whenDone.value.variety_sd);
final Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
FlagManager.addPlotFlag(origin, flag);
TaskManager.runTask(whenDone);
return;
}
RegionWrapper region = zones.poll();
final Runnable task = this;
analyzeRegion(origin.world, region, new RunnableVal<PlotAnalysis>() {
@Override
public void run() {
analysis.add(value);
TaskManager.runTaskLater(task, 1);
}
});
}
};
run.run();
}
public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks);
public static List<ChunkLoc> regions;
public static List<ChunkLoc> chunks = new ArrayList<>();
public static Set<ChunkLoc> regions;
public static Set<ChunkLoc> chunks = new HashSet<>();
public static String world;
public static boolean UPDATE = false;
@ -50,12 +124,15 @@ public abstract class HybridUtils {
return chunks;
}
/**
* Checks all connected plots
* @param plot
* @param whenDone
*/
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
if (whenDone == null) {
return;
}
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
if (!(plotworld instanceof ClassicPlotWorld)) {
whenDone.value = -1;
@ -64,6 +141,18 @@ public abstract class HybridUtils {
}
whenDone.value = 0;
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(MainUtil.getRegions(plot));
Runnable run = new Runnable() {
@Override
public void run() {
if (zones.size() == 0) {
TaskManager.runTask(whenDone);
return;
}
RegionWrapper region = zones.poll();
Location pos1 = new Location(plot.world, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override
public void run() {
@ -77,12 +166,11 @@ public abstract class HybridUtils {
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez, cpw.TOP_BLOCK);
whenDone.value += checkModified(plot.world, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez, new PlotBlock[] { new PlotBlock((short) 0, (byte) 0) });
}
}, new Runnable() {
@Override
public void run() {
TaskManager.runTask(whenDone);
}, this, 5);
}
}, 5);
};
run.run();
}
public boolean scheduleRoadUpdate(final String world, final int extend) {
@ -90,14 +178,14 @@ public abstract class HybridUtils {
return false;
}
HybridUtils.UPDATE = true;
final List<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
final Set<ChunkLoc> regions = ChunkManager.manager.getChunkChunks(world);
return scheduleRoadUpdate(world, regions, extend);
}
public boolean scheduleRoadUpdate(final String world, final List<ChunkLoc> rgs, final int extend) {
public boolean scheduleRoadUpdate(final String world, final Set<ChunkLoc> rgs, final int extend) {
HybridUtils.regions = rgs;
HybridUtils.world = world;
chunks = new ArrayList<ChunkLoc>();
chunks = new HashSet<ChunkLoc>();
final AtomicInteger count = new AtomicInteger(0);
final long baseTime = System.currentTimeMillis();
final AtomicInteger last = new AtomicInteger();
@ -106,9 +194,10 @@ public abstract class HybridUtils {
public void run() {
if (UPDATE == false) {
last.set(0);
while (chunks.size() > 0) {
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
Iterator<ChunkLoc> iter = chunks.iterator();
while (iter.hasNext()) {
final ChunkLoc chunk = iter.next();
iter.remove();
regenerateRoad(world, chunk, extend);
ChunkManager.manager.unloadChunk(world, chunk, true, true);
}
@ -135,11 +224,12 @@ public abstract class HybridUtils {
}
if (chunks.size() < 1024) {
if (regions.size() > 0) {
final ChunkLoc loc = regions.get(0);
Iterator<ChunkLoc> iter = regions.iterator();
final ChunkLoc loc = iter.next();
iter.remove();
PS.debug("&3Updating .mcr: " + loc.x + ", " + loc.z + " (aprrox 1024 chunks)");
PS.debug(" - Remaining: " + regions.size());
chunks.addAll(getChunks(loc));
regions.remove(0);
System.gc();
}
}
@ -148,8 +238,9 @@ public abstract class HybridUtils {
if (((System.currentTimeMillis() - baseTime - last.get()) > 2000) && (last.get() != 0)) {
last.set(0);
PS.debug(C.PREFIX.s() + "Detected low TPS. Rescheduling in 30s");
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
Iterator<ChunkLoc> iter = chunks.iterator();
final ChunkLoc chunk = iter.next();
iter.remove();
TaskManager.runTask(new Runnable() {
@Override
public void run() {
@ -162,8 +253,9 @@ public abstract class HybridUtils {
}
if ((((System.currentTimeMillis() - baseTime) - last.get()) < 1500) && (last.get() != 0)) {
while ((System.currentTimeMillis() < diff) && (chunks.size() > 0)) {
final ChunkLoc chunk = chunks.get(0);
chunks.remove(0);
Iterator<ChunkLoc> iter = chunks.iterator();
final ChunkLoc chunk = iter.next();
iter.remove();
TaskManager.runTask(new Runnable() {
@Override
public void run() {
@ -176,7 +268,9 @@ public abstract class HybridUtils {
}
} catch (final Exception e) {
e.printStackTrace();
final ChunkLoc loc = regions.get(0);
Iterator<ChunkLoc> iter = regions.iterator();
final ChunkLoc loc = iter.next();
iter.remove();
PS.debug("&c[ERROR]&7 Could not update '" + world + "/region/r." + loc.x + "." + loc.z + ".mca' (Corrupt chunk?)");
final int sx = loc.x << 5;
final int sz = loc.z << 5;
@ -204,8 +298,8 @@ public abstract class HybridUtils {
public boolean setupRoadSchematic(final Plot plot) {
final String world = plot.world;
final Location bot = MainUtil.getPlotBottomLoc(world, plot.id);
final Location top = MainUtil.getPlotTopLoc(world, plot.id);
final Location bot = MainUtil.getPlotBottomLocAbs(world, plot.id).subtract(1, 0, 1);
final Location top = MainUtil.getPlotTopLocAbs(world, plot.id);
final HybridPlotWorld plotworld = (HybridPlotWorld) PS.get().getPlotWorld(world);
final int sx = (bot.getX() - plotworld.ROAD_WIDTH) + 1;
final int sz = bot.getZ() + 1;
@ -221,14 +315,18 @@ public abstract class HybridUtils {
final int tx = ex;
final int tz = sz - 1;
final int ty = get_ey(world, bx, tx, bz, tz, by);
final Set<RegionWrapper> sideroad = new HashSet<>(Arrays.asList(new RegionWrapper(sx, ex, sz, ez)));
final Set<RegionWrapper> intersection = new HashSet<>(Arrays.asList(new RegionWrapper(bx, tx, bz, tz)));
final Location pos3 = new Location(world, bx, by, bz);
final Location pos4 = new Location(world, tx, ty, tz);
final String dir = PS.get().IMP.getDirectory() + File.separator + "schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator + plot.world + File.separator;
SchematicHandler.manager.getCompoundTag(world, pos1, pos2, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(world, sideroad, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "sideroad.schematic");
SchematicHandler.manager.getCompoundTag(world, pos3, pos4, new RunnableVal<CompoundTag>() {
SchematicHandler.manager.getCompoundTag(world, intersection, new RunnableVal<CompoundTag>() {
@Override
public void run() {
SchematicHandler.manager.save(value, dir + "intersection.schematic");
@ -272,14 +370,14 @@ public abstract class HybridUtils {
final boolean result = ChunkManager.manager.loadChunk(world, chunk, false);
if (result) {
if (id1 != null) {
final Plot p1 = MainUtil.getPlot(world, id1);
if ((p1 != null) && p1.hasOwner() && p1.getSettings().isMerged()) {
final Plot p1 = MainUtil.getPlotAbs(world, id1);
if ((p1 != null) && p1.hasOwner() && p1.isMerged()) {
toCheck = true;
}
}
if ((id2 != null) && !toCheck) {
final Plot p2 = MainUtil.getPlot(world, id2);
if ((p2 != null) && p2.hasOwner() && p2.getSettings().isMerged()) {
final Plot p2 = MainUtil.getPlotAbs(world, id2);
if ((p2 != null) && p2.hasOwner() && p2.isMerged()) {
toCheck = true;
}
}

View File

@ -1,12 +1,17 @@
package com.intellectualcrafters.plot.generator;
import java.util.HashSet;
import java.util.Iterator;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.StringMan;
/**
* A plot manager with a square grid layout, with square shaped plots
@ -14,9 +19,23 @@ import com.intellectualcrafters.plot.util.MainUtil;
public abstract class SquarePlotManager extends GridPlotManager {
@Override
public boolean clearPlot(final PlotWorld plotworld, final Plot plot, final Runnable whenDone) {
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
ChunkManager.manager.regenerateRegion(pos1, pos2, whenDone);
final HashSet<RegionWrapper> regions = MainUtil.getRegions(plot);
Runnable run = new Runnable() {
@Override
public void run() {
if (regions.size() == 0) {
whenDone.run();
return;
}
Iterator<RegionWrapper> iter = regions.iterator();
RegionWrapper region = iter.next();
iter.remove();
Location pos1 = new Location(plot.world, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ);
ChunkManager.manager.regenerateRegion(pos1, pos2, this);
}
};
run.run();
return true;
}
@ -33,8 +52,12 @@ public abstract class SquarePlotManager extends GridPlotManager {
@Override
public PlotId getPlotIdAbs(final PlotWorld plotworld, int x, final int y, int z) {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
if (dpw.ROAD_OFFSET_X != 0) {
x -= dpw.ROAD_OFFSET_X;
}
if (dpw.ROAD_OFFSET_Z != 0) {
z -= dpw.ROAD_OFFSET_Z;
}
int pathWidthLower;
int end;
if (dpw.ROAD_WIDTH == 0) {
@ -65,12 +88,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
idz = (z / size) + 1;
z = (z % size);
}
final boolean northSouth = (z <= pathWidthLower) || (z > end);
final boolean eastWest = (x <= pathWidthLower) || (x > end);
if (northSouth || eastWest) {
return null;
}
return new PlotId(idx, idz);
return ((z <= pathWidthLower) || (z > end) || (x <= pathWidthLower) || (x > end)) ? null : new PlotId(idx, idz);
}
@Override
@ -113,53 +131,46 @@ public abstract class SquarePlotManager extends GridPlotManager {
dz = (z / size) + 1;
rz = (z % size);
}
final boolean northSouth = (rz <= pathWidthLower) || (rz > end);
final boolean eastWest = (rx <= pathWidthLower) || (rx > end);
if (northSouth && eastWest) {
// This means you are in the intersection
final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH + dpw.ROAD_OFFSET_X, 0, z + dpw.ROAD_WIDTH + dpw.ROAD_OFFSET_Z);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PS.get().getPlot(plotworld.worldname, id);
if (plot == null) {
return null;
}
if ((plot.getMerged(0) && plot.getMerged(3))) {
return MainUtil.getBottomPlot(plot).id;
}
return null;
}
if (northSouth) {
// You are on a road running West to East (yeah, I named the var poorly)
final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_OFFSET_X, 0, z + dpw.ROAD_WIDTH + dpw.ROAD_OFFSET_Z);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PS.get().getPlot(plotworld.worldname, id);
if (plot == null) {
return null;
}
if (plot.getMerged(0)) {
return MainUtil.getBottomPlot(plot).id;
}
return null;
}
if (eastWest) {
// This is the road separating an Eastern and Western plot
final Location loc = new Location(plotworld.worldname, x + dpw.ROAD_WIDTH + dpw.ROAD_OFFSET_X, 0, z + dpw.ROAD_OFFSET_Z);
final PlotId id = MainUtil.getPlotAbs(loc);
final Plot plot = PS.get().getPlot(plotworld.worldname, id);
if (plot == null) {
return null;
}
if (plot.getMerged(3)) {
return MainUtil.getBottomPlot(plot).id;
}
return null;
}
final PlotId id = new PlotId(dx, dz);
final Plot plot = PS.get().getPlot(plotworld.worldname, id);
if (plot == null) {
PlotId id = new PlotId(dx, dz);
boolean[] merged = new boolean[] {(rz <= pathWidthLower), (rx > end), (rz > end), (rx <= pathWidthLower)};
int hash = MainUtil.hash(merged);
// Not merged, and no need to check if it is
if (hash == 0) {
return id;
}
return MainUtil.getBottomPlot(plot).id;
Plot plot = PS.get().getPlot(plotworld.worldname, id);
// Not merged, and standing on road
if (plot == null) {
return null;
}
switch (hash) {
case 8:
// north
return plot.getMerged(0) ? id : null;
case 4:
// east
return plot.getMerged(1) ? id : null;
case 2:
// south
return plot.getMerged(2) ? id : null;
case 1:
// west
return plot.getMerged(3) ? id : null;
case 12:
// northest
return plot.getMerged(4) ? id : null;
case 6:
// southeast
return plot.getMerged(5) ? id : null;
case 3:
// southwest
return plot.getMerged(6) ? id : null;
case 9:
// northwest
return plot.getMerged(7) ? id : null;
}
PS.debug("invalid location: " + merged);
return null;
}
/**
@ -170,8 +181,8 @@ public abstract class SquarePlotManager extends GridPlotManager {
final SquarePlotWorld dpw = ((SquarePlotWorld) plotworld);
final int px = plotid.x;
final int pz = plotid.y;
final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2)) - 1;
final int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2));
final int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - dpw.PLOT_WIDTH - ((int) Math.floor(dpw.ROAD_WIDTH / 2));
return new Location(plotworld.worldname, x, plotworld.MIN_BUILD_HEIGHT, z);
}
}

View File

@ -32,4 +32,9 @@ public class ChunkLoc {
final ChunkLoc other = (ChunkLoc) obj;
return ((x == other.x) && (z == other.z));
}
@Override
public String toString() {
return x + "," + z;
}
}

View File

@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.object;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@ -38,6 +39,7 @@ import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.comment.PlotComment;
import com.intellectualcrafters.plot.util.BO3Handler;
import com.intellectualcrafters.plot.util.BlockManager;
import com.intellectualcrafters.plot.util.ChunkManager;
@ -131,7 +133,8 @@ public class Plot {
* Constructor for a new plot<br>
* (Only changes after plot.create() will be properly set in the database)
*
*@see MainUtil#getPlot(String, PlotId) for existing plots
* @see Plot#getPlot(String, PlotId) for existing plots
* @see Plot#getPlot(Location) for existing plots
*
* @param world
* @param id
@ -143,6 +146,20 @@ public class Plot {
this.owner = owner;
}
/**
* Constructor for an unowned plot<br>
* (Only changes after plot.create() will be properly set in the database)
*
* @see Plot#getPlot(String, PlotId) for existing plots
*
* @param world
* @param id
*/
public Plot(final String world, final PlotId id) {
this.world = world;
this.id = id;
}
/**
* Return a new/cached plot object at a given world/plot id
*
@ -173,7 +190,7 @@ public class Plot {
* The database will ignore any queries regarding temporary plots.
* Please note that some bulk plot management functions may still affect temporary plots (TODO: fix this)
*
* @see MainUtil#getPlot(String, PlotId) for existing plots
* @see Plot#getPlot(String, PlotId) for existing plots
*
* @param world
* @param id
@ -190,7 +207,7 @@ public class Plot {
/**
* Constructor for a saved plots (Used by the database manager when plots are fetched)
*
* @see MainUtil#getPlot(String, PlotId) for existing plots
* @see Plot#getPlot(String, PlotId) for existing plots
*
* @param id
* @param owner
@ -203,7 +220,7 @@ public class Plot {
this.id = id;
this.world = world;
this.owner = owner;
settings = new PlotSettings(this);
settings = new PlotSettings();
this.members = members;
this.trusted = trusted;
this.denied = denied;
@ -354,20 +371,32 @@ public class Plot {
}
/**
* Get the world
* @return
* Get the plot world object for this plot<br>
* - The generic PlotWorld object can be casted to it's respective class for more control
* @return PlotWorld
*/
public String getWorld() {
return world;
public PlotWorld getWorld() {
return PS.get().getPlotWorld(world);
}
/**
* Get the plot manager object for this plot<br>
* - The generic PlotManager object can be casted to it's respective class for more control
* @return PlotManager
*/
public PlotManager getManager() {
return PS.get().getPlotManager(world);
}
/**
* Get or create plot settings
* @return PlotSettings
* @deprecated use equivalent plot method;
*/
@Deprecated
public PlotSettings getSettings() {
if (settings == null) {
settings = new PlotSettings(this);
settings = new PlotSettings();
}
return settings;
}
@ -377,10 +406,54 @@ public class Plot {
* @return
*/
public boolean isBasePlot() {
if (settings == null) {
if (settings == null || !isMerged()) {
return true;
}
return !settings.getMerged(0) && !settings.getMerged(3);
return equals(getBasePlot(false));
}
/**
* The cached origin plot<br>
* - The origin plot is used for plot grouping and relational data
*/
private Plot origin;
/**
* The base plot is an arbitrary but specific connected plot. It is useful for the following:<br>
* - Merged plots need to be treated as a single plot for most purposes<br>
* - Some data such as home location needs to be associated with the group rather than each plot<br>
* - If the plot is not merged it will return itself.<br>
* - The result is cached locally
* @return base Plot
*/
public Plot getBasePlot(boolean recalculate) {
if ((origin != null && !recalculate)) {
return origin;
}
if (!isMerged()) {
origin = this;
return origin;
}
int min = Integer.MAX_VALUE;
for (Plot plot : MainUtil.getConnectedPlots(this)) {
if (plot.temp != -1) {
if (plot.temp < min) {
min = plot.temp;
origin = plot;
}
}
else {
if (plot.hashCode() < min) {
origin = plot;
min = plot.hashCode();
}
}
}
for (Plot plot : MainUtil.getConnectedPlots(this)) {
plot.origin = origin;
}
return origin;
}
/**
@ -414,7 +487,25 @@ public class Plot {
if (settings == null) {
return false;
}
switch (direction) {
case 0:
case 1:
case 2:
case 3:
return settings.getMerged(direction);
case 7:
int i = direction - 4;
int i2 = 0;
return settings.getMerged(i2) && settings.getMerged(i) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i)).getMerged(i2) && settings.getMerged(i) && settings.getMerged(i2) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i2)).getMerged(i);
case 4:
case 5:
case 6:
i = direction - 4;
i2 = direction - 3;
return settings.getMerged(i2) && settings.getMerged(i) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i)).getMerged(i2) && settings.getMerged(i) && settings.getMerged(i2) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i2)).getMerged(i);
}
return false;
}
/**
@ -456,9 +547,7 @@ public class Plot {
* @param uuid
*/
public void addDenied(final UUID uuid) {
if (getDenied().add(uuid)) {
DBFunc.setDenied(this, uuid);
}
PlotHandler.addDenied(this, uuid);
}
/**
@ -467,9 +556,7 @@ public class Plot {
* @param uuid
*/
public void addTrusted(final UUID uuid) {
if (getTrusted().add(uuid)) {
DBFunc.setTrusted(this, uuid);
}
PlotHandler.addTrusted(this, uuid);
}
/**
@ -478,9 +565,7 @@ public class Plot {
* @param uuid
*/
public void addMember(final UUID uuid) {
if (getMembers().add(uuid)) {
DBFunc.setMember(this, uuid);
}
PlotHandler.addMember(this, uuid);
}
/**
@ -488,10 +573,7 @@ public class Plot {
* @param owner
*/
public void setOwner(final UUID owner) {
if (!this.owner.equals(owner)) {
this.owner = owner;
DBFunc.setOwner(this, owner);
}
PlotHandler.setOwner(this, owner);
}
/**
@ -499,19 +581,7 @@ public class Plot {
* @param uuids
*/
public void setTrusted(final Set<UUID> uuids) {
if (uuids.size() == 0) {
return;
}
if ((trusted != null) && (trusted.size() > 0)) {
trusted.removeAll(uuids);
for (final UUID uuid : trusted) {
DBFunc.removeTrusted(this, uuid);
}
trusted.clear();
}
for (final UUID uuid : uuids) {
addTrusted(uuid);
}
PlotHandler.setTrusted(this, uuids);
}
/**
@ -519,19 +589,7 @@ public class Plot {
* @param uuids
*/
public void setMembers(final Set<UUID> uuids) {
if (uuids.size() == 0) {
return;
}
if ((members != null) && (members.size() > 0)) {
members.removeAll(uuids);
for (final UUID uuid : members) {
DBFunc.removeMember(this, uuid);
}
members.clear();
}
for (final UUID uuid : uuids) {
addMember(uuid);
}
PlotHandler.setMembers(this, uuids);
}
/**
@ -539,19 +597,7 @@ public class Plot {
* @param uuids
*/
public void setDenied(final Set<UUID> uuids) {
if (uuids.size() == 0) {
return;
}
if ((denied != null) && (denied.size() > 0)) {
denied.removeAll(uuids);
for (final UUID uuid : denied) {
DBFunc.removeDenied(this, uuid);
}
denied.clear();
}
for (final UUID uuid : uuids) {
addDenied(uuid);
}
PlotHandler.setDenied(this, uuids);
}
/**
@ -586,6 +632,15 @@ public class Plot {
FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value));
}
/**
* Set a flag for this plot
* @param flag
* @param value
*/
public void setFlags(Set<Flag> flags) {
FlagManager.setPlotFlags(this, flags);
}
/**
* Remove a flag from this plot
* @param flag
@ -607,25 +662,45 @@ public class Plot {
* @see PS#removePlot(String, PlotId, boolean)
* @see #clear(Runnable) to simply clear a plot
*/
public void deletePlot(final Runnable whenDone) {
MainUtil.removeSign(this);
MainUtil.clear(this, true, new Runnable() {
@Override
public void run() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
TaskManager.runTask(whenDone);
public boolean deletePlot(final Runnable whenDone) {
boolean result = MainUtil.delete(this, whenDone);
return result;
}
/**
* Returns true if a previous task was running
* @return
*/
public int addRunning() {
int value = getRunning();
for (Plot plot : getConnectedPlots()) {
MainUtil.runners.put(plot, value + 1);
}
return value;
}
public int removeRunning() {
int value = getRunning();
if (value < 2) {
for (Plot plot : getConnectedPlots()) {
MainUtil.runners.remove(plot);
}
}
});
else {
for (Plot plot : getConnectedPlots()) {
MainUtil.runners.put(plot, value - 1);
}
}
return value;
}
public int getRunning() {
Integer value = MainUtil.runners.get(this);
return value == null ? 0 : value;
}
public boolean unclaim() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
return true;
}
return false;
return PlotHandler.unclaim(this);
}
/**
@ -634,7 +709,7 @@ public class Plot {
* @return true if plot was linked
*/
public boolean unlink() {
return MainUtil.unlinkPlot(this, true);
return MainUtil.unlinkPlot(this, true, true);
}
/**
@ -681,7 +756,7 @@ public class Plot {
*/
public void setHome(final BlockLoc loc) {
final BlockLoc pos = getSettings().getPosition();
if (((pos == null) && (loc == null)) || ((pos != null) && pos.equals(loc))) {
if (((pos == null || pos.equals(new BlockLoc(0, 0, 0))) && (loc == null)) || ((pos != null) && pos.equals(loc))) {
return;
}
getSettings().setPosition(loc);
@ -746,8 +821,8 @@ public class Plot {
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
* @param removeRoads If to remove roads when merging
*/
public void autoMerge(final boolean removeRoads) {
MainUtil.autoMerge(this, owner, removeRoads);
public boolean autoMerge(final boolean removeRoads) {
return MainUtil.autoMerge(this, -1, Integer.MAX_VALUE, owner, removeRoads);
}
/**
@ -761,23 +836,27 @@ public class Plot {
* Set components such as border, wall, floor
* (components are generator specific)
*/
public void setComponent(final String component, final PlotBlock... blocks) {
MainUtil.setComponent(this, component, blocks);
public boolean setComponent(final String component, final PlotBlock... blocks) {
return MainUtil.setComponent(this, component, blocks);
}
/**
* Set components such as border, wall, floor
* (components are generator specific)
*/
public void setComponent(final String component, final String blocks) {
MainUtil.setComponent(this, component, Configuration.BLOCKLIST.parseString(blocks));
public boolean setComponent(final String component, final String blocks) {
PlotBlock[] parsed = Configuration.BLOCKLIST.parseString(blocks);
if (parsed == null || parsed.length == 0) {
return false;
}
return MainUtil.setComponent(this, component, parsed);
}
/**
* Get the biome (String)
*/
public String getBiome() {
final Location loc = getBottom();
final Location loc = getBottomAbs();
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
}
@ -785,32 +864,68 @@ public class Plot {
* Return the top location for the plot
* @return
*/
public Location getTop() {
return MainUtil.getPlotTopLoc(world, id);
public Location getTopAbs() {
return MainUtil.getPlotTopLocAbs(world, id);
}
/**
* Return the bottom location for the plot
* @return
*/
public Location getBottomAbs() {
return MainUtil.getPlotBottomLocAbs(world, id);
}
/**
* Returns the top and bottom connected plot.<br>
* - If the plot is not connected, it will return itself for the top/bottom<br>
* - the returned IDs will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape
* @deprecated as merged plots no longer need to be rectangular
* @param plot
* @return new PlotId[] { bottom, top }
* @see MainUtil#getCornerIds(Plot)
*/
@Deprecated
public Location[] getCorners() {
return MainUtil.getCorners(this);
}
/**
* @deprecated in favor of getCorners()[0];
* @return
*/
@Deprecated
public Location getBottom() {
return MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1);
return getCorners()[0];
}
/**
* Get the top plot, or this plot if it is not part of a mega plot
* @return The bottom plot
* @deprecated in favor of getCorners()[1];
* @return
*/
public Plot getTopPlot() {
return MainUtil.getTopPlot(this);
@Deprecated
public Location getTop() {
return getCorners()[0];
}
/**
* Get the bottom plot, or this plot if it is not part of a mega plot
* @return The bottom plot
* Get a set of plots connected (and including) this plot<br>
* - This result is cached globally
* @see MainUtil#getConnectedPlots(Plot)
* @return
*/
public Plot getBottomPlot() {
return MainUtil.getBottomPlot(this);
public Set<Plot> getConnectedPlots() {
return MainUtil.getConnectedPlots(this);
}
/**
* This will combine each plot into effective rectangular regions
* - This result is cached globally
* @see MainUtil#getRegions(Plot)
* @return
*/
public Set<RegionWrapper> getRegions() {
return MainUtil.getRegions(this);
}
/**
@ -819,13 +934,13 @@ public class Plot {
* @see ChunkManager#swap(String, bot1, top1, bot2, top2) to swap terrain
* @see MainUtil#getPlotSelectionIds(PlotId, PlotId) to get the plots inside a selection
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable) to swap plot settings
* @param other The other plot id to swap with
* @param other The other plot to swap with
* @param whenDone A task to run when finished, or null
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable)
* @return boolean if swap was successful
*/
public boolean swap(final PlotId destination, final Runnable whenDone) {
return MainUtil.swap(world, id, destination, whenDone);
public boolean swap(final Plot destination, final Runnable whenDone) {
return MainUtil.move(this, destination, whenDone, true);
}
/**
@ -836,7 +951,7 @@ public class Plot {
* @return if the move was successful
*/
public boolean move(final Plot destination, final Runnable whenDone) {
return MainUtil.move(this, destination, whenDone);
return MainUtil.move(this, destination, whenDone, false);
}
/**
@ -846,8 +961,8 @@ public class Plot {
* @param whenDone The task to run when done
* @return If the copy was successful
*/
public boolean copy(final PlotId destination, final Runnable whenDone) {
return MainUtil.copy(world, id, destination, whenDone);
public boolean copy(final Plot destination, final Runnable whenDone) {
return MainUtil.copy(this, destination, whenDone);
}
/**
@ -996,4 +1111,56 @@ public class Plot {
public int hashCode() {
return id.hashCode();
}
public HashMap<String, Flag> getFlags() {
if (settings == null) {
return new HashMap<>(0);
}
return settings.flags;
}
public String getAlias() {
return getSettings().getAlias();
}
/**
* Set the raw merge data<br>
* - Updates DB
* - Does not modify terrain
* @param merged
*/
public void setMerged(boolean[] merged) {
getSettings().merged = merged;
DBFunc.setMerged(this, merged);
MainUtil.connected_cache = null;
MainUtil.regions_cache = null;
}
/**
* Set the raw merge data<br>
* - Updates DB
* - Does not modify terrain
* @param merged
*/
public void setMerged(int direction, boolean value) {
if (getSettings().setMerged(direction, value)) {
DBFunc.setMerged(this, getSettings().getMerged());
MainUtil.connected_cache = null;
MainUtil.regions_cache = null;
}
}
public boolean[] getMerged() {
if (settings == null) {
return new boolean[] {false, false, false, false };
}
return settings.getMerged();
}
public BlockLoc getPosition() {
if (settings == null) {
return new BlockLoc(0, 0, 0);
}
return settings.getPosition();
}
}

View File

@ -35,7 +35,7 @@ public class PlotCluster {
this.pos1 = pos1;
this.pos2 = pos2;
this.owner = owner;
settings = new PlotSettings(null);
settings = new PlotSettings();
}
public boolean isAdded(final UUID uuid) {

View File

@ -3,8 +3,10 @@ package com.intellectualcrafters.plot.object;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
@ -15,13 +17,14 @@ public class PlotHandler {
return new HashSet<UUID>();
}
if (plot.isMerged()) {
final HashSet<UUID> owners = new HashSet<UUID>();
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids) {
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null) {
owners.add(owner);
HashSet<Plot> plots = MainUtil.getConnectedPlots(plot);
final HashSet<UUID> owners = new HashSet<UUID>(2);
UUID last = plot.owner;
owners.add(plot.owner);
for (Plot current : plots) {
if (last == null || current.owner.getMostSignificantBits() != last.getMostSignificantBits()) {
owners.add(current.owner);
last = current.owner;
}
}
return owners;
@ -33,37 +36,49 @@ public class PlotHandler {
if (plot.owner == null) {
return false;
}
if (plot.isMerged()) {
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids) {
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if ((owner != null) && owner.equals(uuid)) {
if (plot.owner.equals(uuid)) {
return true;
}
if (!plot.isMerged()) {
return false;
}
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (current.owner.equals(uuid)) {
return true;
}
}
}
return plot.owner.equals(uuid);
return false;
}
public static boolean isOnline(final Plot plot) {
if (plot.owner == null) {
return false;
}
if (plot.isMerged()) {
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids) {
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if (owner != null) {
if (UUIDHandler.getPlayer(owner) != null) {
return true;
if (!plot.isMerged()) {
return UUIDHandler.getPlayer(plot.owner) != null;
}
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (current.owner != null && UUIDHandler.getPlayer(current.owner) != null) {
return true;
}
}
return false;
}
return UUIDHandler.getPlayer(plot.owner) != null;
public static void setOwner(Plot plot, UUID owner) {
if (!plot.isMerged()) {
if (!plot.owner.equals(owner)) {
plot.owner = owner;
DBFunc.setOwner(plot, owner);
}
return;
}
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (!owner.equals(current.owner)) {
current.owner = owner;
DBFunc.setOwner(current, owner);
}
}
}
public static boolean sameOwners(final Plot plot1, final Plot plot2) {
@ -79,30 +94,116 @@ public class PlotHandler {
if (plot.owner == null) {
return false;
}
if (isOwner(plot, uuid)) {
return true;
}
if (plot.getDenied().contains(uuid)) {
return false;
}
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) {
return true;
}
if (isOwner(plot, uuid)) {
return true;
}
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(plot)) {
return true;
}
}
if (plot.isMerged()) {
final Plot top = MainUtil.getTopPlot(plot);
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (final PlotId id : ids) {
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
if ((owner != null) && owner.equals(uuid)) {
return true;
}
}
}
return false;
}
public static void setDenied(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getDenied().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
intersection.retainAll(larger ? uuids : plot.getDenied());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
}
for (UUID uuid : uuids) {
plot.addDenied(uuid);
}
}
public static void setTrusted(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getTrusted().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getTrusted() : uuids);
intersection.retainAll(larger ? uuids : plot.getTrusted());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getTrusted());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeTrusted(uuid);
}
for (UUID uuid : uuids) {
plot.addTrusted(uuid);
}
}
public static void setMembers(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getMembers().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getMembers() : uuids);
intersection.retainAll(larger ? uuids : plot.getMembers());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getMembers());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeMember(uuid);
}
for (UUID uuid : uuids) {
plot.addMember(uuid);
}
}
public static void set(Plot plot, Set<UUID> uuids) {
boolean larger = uuids.size() > plot.getDenied().size();
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
intersection.retainAll(larger ? uuids : plot.getDenied());
uuids.removeAll(intersection);
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
toRemove.removeAll(intersection);
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
}
for (UUID uuid : uuids) {
plot.addDenied(uuid);
}
}
public static void addDenied(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (current.getDenied().add(uuid)) {
DBFunc.setDenied(current, uuid);
}
}
}
public static void addMember(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (current.getMembers().add(uuid)) {
DBFunc.setMember(current, uuid);
}
}
}
public static void addTrusted(Plot plot, UUID uuid) {
for (Plot current : MainUtil.getConnectedPlots(plot)) {
if (current.getTrusted().add(uuid)) {
DBFunc.setTrusted(current, uuid);
}
}
}
public static boolean unclaim(Plot plot) {
if (plot.owner == null) {
return false;
}
for (Plot current : MainUtil.getConnectedPlots(plot)) {
current.settings = null;
PS.get().removePlot(current.world, current.id, true);
DBFunc.delete(current);
}
return true;
}
}

View File

@ -33,24 +33,19 @@ import com.intellectualcrafters.plot.object.comment.PlotComment;
* plot settings
*
*/
@SuppressWarnings("unused")
public class PlotSettings {
/**
* Plot
*/
private final Plot plot;
/**
* merged plots
*/
private boolean[] merged = new boolean[] { false, false, false, false };
public boolean[] merged = new boolean[] { false, false, false, false };
/**
* plot alias
*/
private String alias;
public String alias = "";
/**
* Comments
*/
private List<PlotComment> comments = null;
public List<PlotComment> comments = null;
/**
* The ratings for a plot
@ -71,9 +66,7 @@ public class PlotSettings {
*
* @param plot object
*/
public PlotSettings(final Plot plot) {
alias = "";
this.plot = plot;
public PlotSettings() {
flags = new HashMap<>();
}
@ -103,8 +96,12 @@ public class PlotSettings {
this.merged = merged;
}
public void setMerged(final int direction, final boolean merged) {
public boolean setMerged(final int direction, final boolean merged) {
if (this.merged[direction] != merged) {
this.merged[direction] = merged;
return true;
}
return false;
}
public BlockLoc getPosition() {
@ -131,8 +128,8 @@ public class PlotSettings {
this.alias = alias;
}
public String getJoinMessage() {
final Flag greeting = FlagManager.getPlotFlag(plot, "greeting");
public String getJoinMessage(String world) {
final Flag greeting = FlagManager.getSettingFlag(world, this, "greeting");
if (greeting != null) {
return greeting.getValueString();
}
@ -144,8 +141,8 @@ public class PlotSettings {
*
* @return Farewell flag
*/
public String getLeaveMessage() {
final Flag farewell = FlagManager.getPlotFlag(plot, "farewell");
public String getLeaveMessage(String world) {
final Flag farewell = FlagManager.getSettingFlag(world, this, "farewell");
if (farewell != null) {
return farewell.getValueString();
}

View File

@ -63,80 +63,7 @@ public abstract class PlotWorld {
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
public final static int MIN_BUILD_HEIGHT_DEFAULT = 1;
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
// are plot clusters enabled
// require claim in cluster
// TODO make this configurable
// make non static and static_default_valu + add config option
public static int[] BLOCKS;
static {
BLOCKS = new int[] {
1,
2,
3,
4,
5,
7,
14,
15,
16,
17,
19,
21,
22,
23,
24,
25,
35,
41,
42,
43,
45,
47,
48,
49,
52,
56,
57,
58,
61,
62,
73,
74,
80,
82,
84,
86,
87,
88,
91,
97,
98,
99,
100,
103,
110,
112,
120,
121,
123,
124,
125,
129,
133,
153,
155,
159,
162,
165,
166,
168,
170,
172,
173,
174,
179,
181 };
}
public final String worldname;
public int MAX_PLOT_MEMBERS;
public boolean AUTO_MERGE;
@ -183,6 +110,9 @@ public abstract class PlotWorld {
return false;
}
final PlotWorld plotworld = (PlotWorld) obj;
if (this.worldname.equals(plotworld.worldname)) {
return true;
}
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
for (final ConfigurationNode setting : plotworld.getSettingNodes()) {
final Object constant = section.get(plotworld.worldname + "." + setting.getConstant());

View File

@ -39,7 +39,7 @@ public class Rating {
public List<String> getCategories() {
if (ratingMap.size() == 1) {
return new ArrayList<>();
return new ArrayList<>(0);
}
return new ArrayList<>(ratingMap.keySet());
}

View File

@ -33,4 +33,29 @@ public class RegionWrapper {
public boolean isIn(final int x, final int z) {
return ((x >= minX) && (x <= maxX) && (z >= minZ) && (z <= maxZ));
}
@Override
public int hashCode() {
return minX + 13 * maxX + 23 * minZ + 39 * maxZ;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj instanceof RegionWrapper) {
RegionWrapper other = (RegionWrapper) obj;
return minX == other.minX && minZ == other.minZ && minY == other.minY && maxX == other.maxX && maxZ == other.maxZ && maxY == other.maxY;
}
return false;
}
@Override
public String toString() {
return minX + "->" + maxX + "," + minZ + "->" + maxZ;
}
}

View File

@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map.Entry;
@ -17,8 +18,10 @@ 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.PlotPlayer;
import com.intellectualcrafters.plot.object.PlotWorld;
import com.intellectualcrafters.plot.object.RegionWrapper;
public class BO3Handler {
@ -54,17 +57,22 @@ public class BO3Handler {
return false;
}
final String alias = plot.toString();
final Location pos1 = plot.getBottom();
final Location pos2 = plot.getTop();
Location[] corners = MainUtil.getCorners(plot);
Location bot = corners[0];
Location top = corners[1];
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotworld;
final int height = cpw.PLOT_HEIGHT;
final int cx = (pos1.getX() + pos2.getX()) / 2;
final int cz = (pos1.getZ() + pos2.getZ()) / 2;
final int cx = (bot.getX() + top.getX()) / 2;
final int cz = (bot.getZ() + top.getZ()) / 2;
final HashMap<ChunkLoc, BO3> map = new HashMap<>();
HashSet<RegionWrapper> regions = MainUtil.getRegions(plot);
boolean content = false;
for (RegionWrapper region : regions) {
Location pos1 = new Location(plot.world, region.minX, region.minY, region.minZ);
Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ);
for (int x = pos1.getX(); x <= pos2.getX(); x++) {
final int X = ((x + 7) - cx) >> 4;
final int xx = (x - cx) % 16;
@ -106,6 +114,7 @@ public class BO3Handler {
}
}
}
}
if (!content) {
MainUtil.sendMessage(plr, "No content found!");

View File

@ -3,6 +3,7 @@ package com.intellectualcrafters.plot.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
@ -102,7 +103,7 @@ public abstract class ChunkManager {
public abstract boolean unloadChunk(final String world, final ChunkLoc loc, final boolean save, final boolean safe);
public abstract List<ChunkLoc> getChunkChunks(final String world);
public abstract Set<ChunkLoc> getChunkChunks(final String world);
public abstract void regenerateChunk(final String world, final ChunkLoc loc);
@ -114,6 +115,9 @@ public abstract class ChunkManager {
public abstract Plot hasPlot(String world, ChunkLoc chunk);
/**
* Copy a region to a new location (in the same world)
*/
public abstract boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone);
/**
@ -129,7 +133,5 @@ public abstract class ChunkManager {
public abstract void clearAllEntities(final Location pos1, final Location pos2);
public abstract void swap(final String world, final PlotId id, final PlotId plotid);
public abstract void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2);
public abstract void swap(final Location bot1, final Location top1, final Location bot2, final Location top2, Runnable whenDone);
}

View File

@ -42,7 +42,7 @@ public class ClusterManager {
if (clusters.containsKey(world)) {
return clusters.get(world);
}
return new HashSet<>();
return new HashSet<>(0);
}
public static int getPlayerClusterCount(final String world, final PlotPlayer player) {
@ -74,7 +74,7 @@ public class ClusterManager {
if (toReturn.getY() == 0) {
final PlotManager manager = PS.get().getPlotManager(cluster.world);
final PlotWorld plotworld = PS.get().getPlotWorld(cluster.world);
final Location loc = manager.getSignLoc(plotworld, MainUtil.getPlot(cluster.world, center));
final Location loc = manager.getSignLoc(plotworld, MainUtil.getPlotAbs(cluster.world, center));
toReturn.setY(loc.getY());
}
} else {
@ -124,13 +124,13 @@ public class ClusterManager {
final PlotManager manager = PS.get().getPlotManager(world);
final PlotWorld plotworld = PS.get().getPlotWorld(world);
final Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
final Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
return (bot.getX() < loc.getX()) && (bot.getZ() < loc.getZ()) && (top.getX() > loc.getX()) && (top.getZ() > loc.getZ());
final Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2());
return (bot.getX() <= loc.getX()) && (bot.getZ() <= loc.getZ()) && (top.getX() >= loc.getX()) && (top.getZ() >= loc.getZ());
}
public static HashSet<PlotCluster> getIntersects(final String world, final PlotClusterId id) {
if (!clusters.containsKey(world)) {
return new HashSet<>();
return new HashSet<>(0);
}
final HashSet<PlotCluster> list = new HashSet<PlotCluster>();
for (final PlotCluster cluster : clusters.get(world)) {
@ -236,7 +236,7 @@ public class ClusterManager {
}
public static PlotId estimatePlotId(final Location loc) {
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if (plot != null) {
return plot.id;
}

View File

@ -62,7 +62,7 @@ public abstract class EventUtil {
public abstract void callMember(final PlotPlayer initiator, final Plot plot, final UUID player, final boolean added);
public boolean checkPlayerBlockEvent(final PlotPlayer pp, final PlayerBlockEventType type, final Location loc, final LazyBlock block, final boolean notifyPerms) {
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
final UUID uuid = pp.getUUID();
if (plot == null) {
if (!MainUtil.isPlotAreaAbs(loc)) {

View File

@ -129,7 +129,7 @@ public class ExpireManager {
}
}
if (plot.isMerged()) {
MainUtil.unlinkPlot(plot, true);
MainUtil.unlinkPlot(plot, true, false);
}
plot.deletePlot(null);
expiredPlots.get(world).remove(plot);
@ -144,7 +144,7 @@ public class ExpireManager {
}
}
};
if (MainUtil.runners.containsKey(plot)) {
if (plot.getRunning() > 0) {
PS.debug("$2[&5Expire&dManager$2] &bSkipping plot in use: " + plot);
expiredPlots.get(world).remove(plot);
run();

File diff suppressed because it is too large Load Diff

View File

@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
@ -46,6 +47,7 @@ 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.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.schematic.PlotItem;
import com.plotsquared.object.schematic.StateWrapper;
@ -92,15 +94,6 @@ public abstract class SchematicHandler {
} else {
directory = outputDir.getPath();
}
final Location top = plot.getTop();
final Location bot = plot.getBottom();
final int area = ((1 + top.getX()) - bot.getX()) * ((1 + top.getZ()) - bot.getZ());
if (area > 4096) {
PS.debug("The plot is > 64 x 64 - Fast lossy schematic saving will be used");
}
// if (area <= 4096 && PS.get().worldEdit != null) {
// new WorldEditSchematic().saveSchematic(directory + File.separator + name + ".schematic", plot.world, plot.id);
// }
final Runnable THIS = this;
SchematicHandler.manager.getCompoundTag(plot.world, plot.id, new RunnableVal<CompoundTag>() {
@Override
@ -162,9 +155,8 @@ public abstract class SchematicHandler {
final int LENGTH = demensions.getZ();
final int HEIGHT = demensions.getY();
// Validate dimensions
final Location bottom = plot.getBottom();
final Location top = plot.getTop();
if ((((top.getX() - bottom.getX()) + 1) < WIDTH) || (((top.getZ() - bottom.getZ()) + 1) < LENGTH) || (HEIGHT > 256)) {
RegionWrapper region = MainUtil.getLargestRegion(plot);
if ((((region.maxX - region.minX + x_offset) + 1) < WIDTH) || (((region.maxZ - region.minZ + z_offset) + 1) < LENGTH) || (HEIGHT > 256)) {
PS.debug("Schematic is too large");
TaskManager.runTask(whenDone);
return;
@ -177,9 +169,10 @@ public abstract class SchematicHandler {
if (HEIGHT >= 256) {
y_offset = 0;
} else {
y_offset = MainUtil.getHeighestBlock(plot.world, bottom.getX() + 1, bottom.getZ() + 1);
y_offset = MainUtil.getHeighestBlock(plot.world, region.minX + 1, region.minZ + 1);
}
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1 + x_offset, y_offset - 1, 1 + z_offset);
final Location pos1 = new Location(plot.world, region.minX + x_offset, y_offset, region.minZ + z_offset);
// Location pos2 = new Location(plot.world, region.maxX, region.maxY, region.maxZ);
final Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1);
// TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate);
final int p1x = pos1.getX();
@ -369,14 +362,14 @@ public abstract class SchematicHandler {
if (items == null) {
return false;
}
Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
RegionWrapper region = MainUtil.getLargestRegion(plot);
Location l1 = new Location(plot.world, region.minX + x_offset, 1, region.minZ + z_offset);
// Location l1 = MainUtil.getPlotBottomLoc(plot.world, plot.getId());
final int sy = MainUtil.getHeighestBlock(plot.world, l1.getX() + 1, l1.getZ() + 1);
final Dimension demensions = schematic.getSchematicDimension();
final int HEIGHT = demensions.getY();
if ((HEIGHT < 255)) {
l1 = l1.add(1, sy - 1, 1);
} else {
l1 = l1.add(1, 0, 1);
l1 = l1.add(0, sy - 1, 0);
}
final int X = l1.getX() + x_offset;
final int Y = l1.getY();
@ -675,25 +668,11 @@ public abstract class SchematicHandler {
return new CompoundTag("Schematic", schematic);
}
/**
* Gets the schematic of a plot
*
* @param world to check
* @param id plot
*
* @return tag
*/
public void getCompoundTag(final String world, final PlotId id, final RunnableVal<CompoundTag> whenDone) {
if (PS.get().getPlot(world, id) == null) {
whenDone.run();
return;
}
final Location pos1 = MainUtil.getPlotBottomLoc(world, id).add(1, -1, 1);
final Location pos2 = MainUtil.getPlotTopLoc(world, id);
getCompoundTag(world, pos1, pos2, whenDone);
}
public abstract void getCompoundTag(final String world, Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone);
public abstract void getCompoundTag(final String world, final Location pos1, final Location pos2, final RunnableVal<CompoundTag> whenDone);
public void getCompoundTag(final String world, PlotId id, final RunnableVal<CompoundTag> whenDone) {
getCompoundTag(world, MainUtil.getRegions(MainUtil.getPlotAbs(world, id)), whenDone);
}
public boolean pastePart(final String world, final DataCollection[] blocks, final Location l1, final int x_offset, final int z_offset, final int i1, final int i2, final int WIDTH, final int LENGTH) {
int length = 0;

View File

@ -59,7 +59,6 @@ import com.plotsquared.bukkit.listeners.PlayerEvents;
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8;
import com.plotsquared.bukkit.listeners.PlayerEvents_1_8_3;
import com.plotsquared.bukkit.listeners.PlotPlusListener;
import com.plotsquared.bukkit.listeners.TNTListener;
import com.plotsquared.bukkit.listeners.WorldEvents;
import com.plotsquared.bukkit.listeners.worldedit.WEListener;
import com.plotsquared.bukkit.titles.DefaultTitle;
@ -520,7 +519,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Override
public void registerTNTListener() {
getServer().getPluginManager().registerEvents(new TNTListener(), this);
// No longer here
}
@Override

View File

@ -161,7 +161,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
final HashMap<PlotId, Plot> newplots = plots.get(world);
final Plot plot = newplots.get(entry2.getKey());
if (plot != null) {
plot.getSettings().setMerged(entry2.getValue());
plot.setMerged(entry2.getValue());
}
}
}

View File

@ -129,7 +129,7 @@ public class PlotMeConnector_017 extends APlotMeConnector {
final HashMap<PlotId, boolean[]> mergeMap = merges.get(plot.world);
if (mergeMap != null) {
if (mergeMap.containsKey(plot.id)) {
plot.getSettings().setMerged(mergeMap.get(plot.id));
plot.setMerged(mergeMap.get(plot.id));
}
}
}

View File

@ -51,7 +51,7 @@ public class AugmentedPopulator extends BlockPopulator {
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
final World bukkitWorld = Bukkit.getWorld(world);
if (cluster != null) {
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()).subtract(1, 0, 1);
final Location tl = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
bx = bl.getX();
bz = bl.getZ();

View File

@ -143,23 +143,23 @@ public class ChunkListener implements Listener {
final int x2 = x + 15;
final int z2 = z + 15;
Plot plot;
plot = MainUtil.getPlot(new Location(world, x, 1, z));
plot = MainUtil.getPlotAbs(new Location(world, x, 1, z));
if ((plot != null) && (plot.owner != null)) {
return false;
}
plot = MainUtil.getPlot(new Location(world, x2, 1, z2));
plot = MainUtil.getPlotAbs(new Location(world, x2, 1, z2));
if ((plot != null) && (plot.owner != null)) {
return false;
}
plot = MainUtil.getPlot(new Location(world, x2, 1, z));
plot = MainUtil.getPlotAbs(new Location(world, x2, 1, z));
if ((plot != null) && (plot.owner != null)) {
return false;
}
plot = MainUtil.getPlot(new Location(world, x, 1, z2));
plot = MainUtil.getPlotAbs(new Location(world, x, 1, z2));
if ((plot != null) && (plot.owner != null)) {
return false;
}
plot = MainUtil.getPlot(new Location(world, x + 7, 1, z + 7));
plot = MainUtil.getPlotAbs(new Location(world, x + 7, 1, z + 7));
if ((plot != null) && (plot.owner != null)) {
return false;
}

View File

@ -31,48 +31,46 @@ import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.bukkit.events.PlayerEnterPlotEvent;
import com.plotsquared.bukkit.util.BukkitPlayerFunctions;
import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil;
/**
*/
public class ForceFieldListener implements Listener {
private Set<Player> getNearbyPlayers(final Player player, final Plot plot) {
final Set<Player> players = new HashSet<>();
Player oPlayer;
private Set<PlotPlayer> getNearbyPlayers(final Player player, final Plot plot) {
final Set<PlotPlayer> players = new HashSet<>();
PlotPlayer pp;
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
if (!(entity instanceof Player) || ((oPlayer = (Player) entity) == null) || !BukkitPlayerFunctions.isInPlot(oPlayer) || !BukkitPlayerFunctions.getCurrentPlot(oPlayer).equals(plot)) {
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
continue;
}
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
if (!plot.isAdded(uuid)) {
players.add(oPlayer);
if (!plot.isAdded(pp.getUUID())) {
players.add(pp);
}
}
return players;
}
private Player hasNearbyPermitted(final Player player, final Plot plot) {
Player oPlayer;
private PlotPlayer hasNearbyPermitted(final Player player, final Plot plot) {
PlotPlayer pp;
for (final Entity entity : player.getNearbyEntities(5d, 5d, 5d)) {
if (!(entity instanceof Player) || ((oPlayer = (Player) entity) == null) || !BukkitPlayerFunctions.isInPlot(oPlayer) || !BukkitPlayerFunctions.getCurrentPlot(oPlayer).equals(plot)) {
if (!(entity instanceof Player) || ((pp = BukkitUtil.getPlayer((Player) entity)) == null) || !plot.equals(pp.getCurrentPlot())) {
continue;
}
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(oPlayer));
if (plot.isAdded(uuid)) {
return oPlayer;
if (plot.isAdded(pp.getUUID())) {
return pp;
}
}
return null;
}
public Vector calculateVelocity(final Player p, final Player e) {
final org.bukkit.Location playerLocation = p.getLocation();
final org.bukkit.Location oPlayerLocation = e.getLocation();
public Vector calculateVelocity(final PlotPlayer pp, final PlotPlayer e) {
Location playerLocation = pp.getLocationFull();
Location oPlayerLocation = e.getLocation();
final double playerX = playerLocation.getX(), playerY = playerLocation.getY(), playerZ = playerLocation.getZ(), oPlayerX = oPlayerLocation.getX(), oPlayerY = oPlayerLocation.getY(), oPlayerZ = oPlayerLocation
.getZ();
double x = 0d, y = 0d, z = 0d;
@ -98,7 +96,6 @@ public class ForceFieldListener implements Listener {
public void onPlotEntry(final PlayerEnterPlotEvent event) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
pp.getLocation();
final Plot plot = event.getPlot();
if (plot == null) {
return;
@ -107,16 +104,16 @@ public class ForceFieldListener implements Listener {
if (!FlagManager.isBooleanFlag(plot, "forcefield", false)) {
final UUID uuid = pp.getUUID();
if (plot.isAdded(uuid)) {
final Set<Player> players = getNearbyPlayers(player, plot);
for (final Player oPlayer : players) {
oPlayer.setVelocity(calculateVelocity(player, oPlayer));
final Set<PlotPlayer> players = getNearbyPlayers(player, plot);
for (final PlotPlayer oPlayer : players) {
((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer));
}
} else {
final Player oPlayer = hasNearbyPermitted(player, plot);
final PlotPlayer oPlayer = hasNearbyPermitted(player, plot);
if (oPlayer == null) {
return;
}
player.setVelocity(calculateVelocity(oPlayer, player));
player.setVelocity(calculateVelocity(oPlayer, pp));
}
}
}

View File

@ -32,6 +32,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.ThrownPotion;
import org.bukkit.entity.Vehicle;
@ -41,6 +42,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockDispenseEvent;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.block.BlockFadeEvent;
import org.bukkit.event.block.BlockFormEvent;
import org.bukkit.event.block.BlockFromToEvent;
@ -57,6 +60,7 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
@ -83,6 +87,10 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.help.HelpTopic;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.metadata.LazyMetadataValue;
import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin;
import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector;
@ -476,17 +484,17 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Set last location
pp.setMeta("location", BukkitUtil.getLocation(to));
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
final String worldname = to.getWorld().getName();
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
final PlotManager plotManager = PS.get().getPlotManager(worldname);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ()));
Plot now = MainUtil.getPlot(loc);
final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (now == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
@ -497,13 +505,12 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true);
return;
}
} else if ((lastPlot != null) && id.equals(lastPlot.id)) {
} else if ((lastPlot != null) && now.equals(lastPlot)) {
return;
} else {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plotEntry(pp, plot)) {
if (!plotEntry(pp, now)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
if (!now.equals(lastPlot)) {
player.teleport(from);
} else {
player.teleport(player.getWorld().getSpawnLocation());
@ -534,17 +541,17 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Set last location
pp.setMeta("location", BukkitUtil.getLocation(to));
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
final String worldname = to.getWorld().getName();
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
final PlotManager plotManager = PS.get().getPlotManager(worldname);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
Plot now = MainUtil.getPlot(loc);
final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (now == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
@ -555,13 +562,12 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true);
return;
}
} else if ((lastPlot != null) && id.equals(lastPlot.id)) {
} else if ((lastPlot != null) && now.equals(lastPlot)) {
return;
} else {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plotEntry(pp, plot)) {
if (!plotEntry(pp, now)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
if (!now.equals(lastPlot)) {
player.teleport(from);
} else {
player.teleport(player.getWorld().getSpawnLocation());
@ -656,7 +662,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
@ -682,13 +688,32 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (!PS.get().isPlotWorld(world)) {
return;
}
final Plot plot = MainUtil.getPlot(loc);
Plot plot = MainUtil.getPlot(loc);
if ((plot != null) && plot.hasOwner()) {
if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
List<MetadataValue> meta = event.getEntity().getMetadata("plot");
Plot origin;
if (meta.size() == 0) {
origin = plot;
}
else {
origin = (Plot) meta.get(0).value();
}
if (lastRadius != 0) {
final List<Entity> nearby = event.getEntity().getNearbyEntities(lastRadius, lastRadius, lastRadius);
for (final Entity near : nearby) {
if ((near instanceof TNTPrimed) || (near.getType() == EntityType.MINECART_TNT)) {
if (!near.hasMetadata("plot")) {
near.setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
}
}
}
lastRadius = 0;
}
final Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext()) {
final Block b = iter.next();
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) {
if (!origin.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) {
iter.remove();
}
}
@ -714,8 +739,8 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Delete last location
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location");
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot");
pp.deleteMeta("location");
pp.deleteMeta("lastplot");
if (BukkitMain.worldEdit != null) {
if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) {
@ -941,25 +966,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return;
}
}
if (!Settings.PISTON_FALLING_BLOCK_CHECK) {
return;
}
org.bukkit.Location lastLoc;
if (blocks.size() > 0) {
lastLoc = blocks.get(blocks.size() - 1).getLocation().add(relative);
} else {
lastLoc = event.getBlock().getLocation().add(relative);
}
final Entity[] ents = lastLoc.getChunk().getEntities();
for (final Entity entity : ents) {
if (entity instanceof FallingBlock) {
final org.bukkit.Location eloc = entity.getLocation();
if (eloc.distanceSquared(lastLoc) < 2) {
event.setCancelled(true);
return;
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@ -998,6 +1004,20 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDispense(final BlockDispenseEvent e) {
Material type = e.getItem().getType();
if (type != Material.WATER_BUCKET && type != Material.LAVA_BUCKET) {
return;
}
final Location loc = BukkitUtil.getLocation(e.getVelocity().toLocation(e.getBlock().getWorld()));
if (PS.get().isPlotWorld(loc.getWorld())) {
if (MainUtil.isPlotRoad(loc)) {
e.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onStructureGrow(final StructureGrowEvent e) {
if (!PS.get().isPlotWorld(e.getWorld().getName())) {
@ -1113,9 +1133,6 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
lb = new BukkitLazyBlock(block);
break;
}
// TODO calls both:
// redstone ore
lb = new BukkitLazyBlock(new PlotBlock((short) hand.getTypeId(), (byte) hand.getDurability()));
switch (hand.getType()) {
case MONSTER_EGG:
@ -1205,21 +1222,21 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
final Location loc = BukkitUtil.getLocation(event.getLocation());
final String world = loc.getWorld();
if (!PS.get().isPlotWorld(world)) {
final PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
return;
}
if (!MainUtil.isPlotArea(loc)) {
return;
}
final PlotWorld pW = PS.get().getPlotWorld(world);
final CreatureSpawnEvent.SpawnReason reason = event.getSpawnReason();
if (((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) || (reason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG)) && !pW.SPAWN_EGGS) {
if (((reason == CreatureSpawnEvent.SpawnReason.SPAWNER_EGG) || (reason == CreatureSpawnEvent.SpawnReason.DISPENSE_EGG)) && !plotworld.SPAWN_EGGS) {
event.setCancelled(true);
return;
} else if ((reason == CreatureSpawnEvent.SpawnReason.BREEDING) && !pW.SPAWN_BREEDING) {
} else if ((reason == CreatureSpawnEvent.SpawnReason.BREEDING) && !plotworld.SPAWN_BREEDING) {
event.setCancelled(true);
return;
} else if ((reason == CreatureSpawnEvent.SpawnReason.CUSTOM) && !pW.SPAWN_CUSTOM && !(event.getEntityType().getTypeId() == 30)) {
} else if ((reason == CreatureSpawnEvent.SpawnReason.CUSTOM) && !plotworld.SPAWN_CUSTOM && !(event.getEntityType().getTypeId() == 30)) {
event.setCancelled(true);
return;
}
@ -1227,6 +1244,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
final Plot plot = MainUtil.getPlot(loc);
if (checkEntity(entity, plot)) {
event.setCancelled(true);
return;
}
}
@ -1248,7 +1266,30 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
return;
}
if (event.getTo().hasGravity()) {
Entity entity = event.getEntity();
List<MetadataValue> meta = entity.getMetadata("plot");
if (meta.size() == 0) {
return;
}
Plot origin = (Plot) meta.get(0).value();
if (origin != null && !origin.equals(plot)) {
event.setCancelled(true);
entity.remove();
}
}
else if (event.getTo() == Material.AIR) {
event.getEntity().setMetadata("plot", new FixedMetadataValue((Plugin) PS.get().IMP, plot));
}
}
private float lastRadius;
@EventHandler
public void onPrime(final ExplosionPrimeEvent event) {
lastRadius = event.getRadius() + 1;
}
public boolean checkEntity(final Entity entity, final Plot plot) {
@ -1260,7 +1301,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (cap == 0) {
return true;
}
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
if (mobs[0] >= cap) {
return true;
}
@ -1273,7 +1314,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return true;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[3] >= cap) {
return true;
@ -1287,7 +1328,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return true;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[1] >= cap) {
return true;
@ -1301,7 +1342,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return true;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[2] >= cap) {
return true;
@ -1316,7 +1357,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
return true;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[4] >= cap) {
return true;
@ -1401,6 +1442,9 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
}
}
// To prevent recursion
private boolean tmp_teleport = true;
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(final PlayerTeleportEvent event) {
if ((event.getTo() == null) || (event.getFrom() == null)) {
@ -1414,54 +1458,68 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (MathMan.roundInt(from.getX()) != (x2 = MathMan.roundInt(to.getX()))) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Set last location
pp.setMeta("location", BukkitUtil.getLocation(to));
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
final String worldname = to.getWorld().getName();
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
final PlotManager plotManager = PS.get().getPlotManager(worldname);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, MathMan.roundInt(to.getZ()));
Plot now = MainUtil.getPlot(loc);
final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot)) {
if (now == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot) && tmp_teleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
tmp_teleport = false;
player.teleport(from);
tmp_teleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
tmp_teleport = false;
player.teleport(player.getWorld().getSpawnLocation());
tmp_teleport = true;
}
}
event.setCancelled(true);
return;
}
} else if ((lastPlot != null) && id.equals(lastPlot.id)) {
} else if ((lastPlot != null) && now.equals(lastPlot)) {
return;
} else {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plotEntry(pp, plot)) {
if (!plotEntry(pp, now) && tmp_teleport) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
if (!now.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
tmp_teleport = false;
player.teleport(from);
tmp_teleport = true;
} else {
Location spawn = BukkitUtil.getLocation(player.getWorld().getSpawnLocation());
if (spawn.getEuclideanDistanceSquared(pp.getLocation()) > 2) {
tmp_teleport = false;
player.teleport(player.getWorld().getSpawnLocation());
tmp_teleport = true;
}
}
event.setCancelled(true);
return;
}
}
final Integer border = MainUtil.worldBorder.get(worldname);
if (border != null) {
if (border != null && tmp_teleport) {
if (x2 > border) {
to.setX(border - 4);
tmp_teleport = false;
player.teleport(event.getTo());
tmp_teleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
} else if (x2 < -border) {
to.setX(-border + 4);
tmp_teleport = false;
player.teleport(event.getTo());
tmp_teleport = true;
MainUtil.sendMessage(pp, C.BORDER);
return;
}
@ -1472,19 +1530,17 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
if (MathMan.roundInt(from.getZ()) != (z2 = MathMan.roundInt(to.getZ()))) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
// Set last location
pp.setMeta("location", BukkitUtil.getLocation(to));
Location loc = BukkitUtil.getLocation(to);
pp.setMeta("location", loc);
final String worldname = to.getWorld().getName();
final PlotWorld plotworld = PS.get().getPlotWorld(worldname);
if (plotworld == null) {
return;
}
final PlotManager plotManager = PS.get().getPlotManager(worldname);
final PlotId id = plotManager.getPlotId(plotworld, x2, 0, z2);
Plot now = MainUtil.getPlot(loc);
final Plot lastPlot = (Plot) pp.getMeta("lastplot");
if (id == null) {
if (now == null) {
if ((lastPlot != null) && !plotExit(pp, lastPlot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_EXIT_DENIED);
if (lastPlot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
@ -1495,13 +1551,12 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true);
return;
}
} else if ((lastPlot != null) && id.equals(lastPlot.id)) {
} else if ((lastPlot != null) && now.equals(lastPlot)) {
return;
} else {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!plotEntry(pp, plot)) {
if (!plotEntry(pp, now)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(from)))) {
if (!now.equals(lastPlot)) {
player.teleport(from);
} else {
player.teleport(player.getWorld().getSpawnLocation());
@ -2056,7 +2111,7 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
event.setCancelled(true);
return;
}
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);

View File

@ -78,7 +78,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
return;
}
final Location l = BukkitUtil.getLocation(state.getLocation());
final Plot plot = MainUtil.getPlot(l);
final Plot plot = MainUtil.getPlotAbs(l);
final PlotPlayer pp = BukkitUtil.getPlayer(player);
boolean cancelled = false;
if (plot == null) {
@ -126,7 +126,7 @@ public class PlayerEvents_1_8 extends PlotListener implements Listener {
if (!PS.get().isPlotWorld(world)) {
return;
}
final Plot plot = MainUtil.getPlot(l);
final Plot plot = MainUtil.getPlotAbs(l);
final PlotPlayer pp = BukkitUtil.getPlayer(e.getPlayer());
if (plot == null) {
if (!MainUtil.isPlotArea(l)) {

View File

@ -24,13 +24,13 @@ public class PlayerEvents_1_8_3 implements Listener {
if (!PS.get().isPlotWorld(world)) {
return;
}
final Plot plot = MainUtil.getPlot(loc);
final Plot plot = MainUtil.getPlotAbs(loc);
if ((plot != null) && plot.hasOwner()) {
if (FlagManager.isPlotFlagTrue(plot, "explosion")) {
final Iterator<Block> iter = event.blockList().iterator();
while (iter.hasNext()) {
final Block b = iter.next();
if (!plot.equals(MainUtil.getPlot(BukkitUtil.getLocation(b.getLocation())))) {
if (!plot.equals(MainUtil.getPlotAbs(BukkitUtil.getLocation(b.getLocation())))) {
iter.remove();
}
}

View File

@ -109,7 +109,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
if (player.getGameMode() != GameMode.SURVIVAL) {
return;
}
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
final Plot plot = MainUtil.getPlotAbs(BukkitUtil.getLocation(player));
if (plot == null) {
return;
}
@ -124,7 +124,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
return;
}
final Player player = (Player) event.getEntity();
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
final Plot plot = MainUtil.getPlotAbs(BukkitUtil.getLocation(player));
if (plot == null) {
return;
}
@ -137,7 +137,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
public void onItemPickup(final PlayerPickupItemEvent event) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final Plot plot = MainUtil.getPlot(pp.getLocation());
final Plot plot = MainUtil.getPlotAbs(pp.getLocation());
if (plot == null) {
return;
}
@ -151,7 +151,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
public void onItemDrop(final PlayerDropItemEvent event) {
final Player player = event.getPlayer();
final PlotPlayer pp = BukkitUtil.getPlayer(player);
final Plot plot = MainUtil.getPlot(pp.getLocation());
final Plot plot = MainUtil.getPlotAbs(pp.getLocation());
if (plot == null) {
return;
}

View File

@ -1,120 +0,0 @@
package com.plotsquared.bukkit.listeners;
import java.util.List;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.util.Vector;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.util.BukkitUtil;
public class TNTListener implements Listener {
private double lastRadius;
@EventHandler
public void onPrime(final ExplosionPrimeEvent event) {
lastRadius = event.getRadius() + 1;
}
@EventHandler
public void onExplode(final EntityExplodeEvent event) {
final Entity entity = event.getEntity();
if (entity == null) {
return;
}
final World world = entity.getWorld();
final String worldname = world.getName();
if (!PS.get().isPlotWorld(worldname)) {
return;
}
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(entity));
if (plot == null) {
return;
}
if (!FlagManager.isPlotFlagTrue(plot, "explosion")) {
return;
}
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final List<Entity> nearby = entity.getNearbyEntities(lastRadius, lastRadius, lastRadius);
for (final Entity near : nearby) {
if ((near instanceof TNTPrimed) || (near.getType() == EntityType.MINECART_TNT)) {
final Vector velocity = near.getVelocity();
final Location loc = BukkitUtil.getLocation(near);
final Plot nearPlot = MainUtil.getPlot(loc);
if (!plot.equals(nearPlot)) {
near.setVelocity(new Vector(0, 0, 0));
continue;
}
final double vx = velocity.getX();
velocity.getX();
final double vz = velocity.getX();
int dx;
int dz;
if (vx > 0) {
dx = top.getX() - loc.getX();
} else {
dx = bot.getX() - loc.getX();
}
if (vz > 0) {
dz = top.getZ() - loc.getZ();
} else {
dz = bot.getZ() - loc.getZ();
}
final double s1 = dx / vx;
final double s2 = dz / vz;
final Vector v1 = new Vector(dx, 0, vz * s1);
final Vector v2 = new Vector(vx * s2, 0, dz);
Vector shortest;
if (v1.length() < v2.length()) {
shortest = v1;
} else {
shortest = v2;
}
final Location landing = loc.add(shortest.getBlockX() + 1, 0, shortest.getBlockZ() + 1);
final int ty = MainUtil.getHeighestBlock(worldname, landing.getX(), landing.getZ());
final int diff = ty - loc.getY();
final double calcDiff = getY(velocity, Math.sqrt((shortest.getBlockX() * shortest.getBlockX()) + (shortest.getBlockZ() * shortest.getBlockZ())));
if (calcDiff > diff) {
near.setVelocity(new Vector(0, 0, 0));
}
}
}
event.getEntity().setVelocity(new Vector(0, 0, 0));
}
public double getY(final Vector velocity, final double x) {
final double g = 16;
final double l1 = velocity.length();
final double l2 = Math.sqrt((velocity.getX() * velocity.getX()) + (velocity.getZ() * velocity.getZ()));
final double v = l1 * 20;
double theta = Math.acos(l2 / l1);
if (velocity.getY() < 0) {
theta = -theta;
}
final double cos = Math.cos(theta);
final double yDiff = (x * Math.tan(theta)) - ((g * x * x) / (2 * (v * v * cos * cos)));
return yDiff;
}
}

View File

@ -305,7 +305,7 @@ public class WEListener implements Listener {
}
}
if (restricted.contains(reduced)) {
final Plot plot = MainUtil.getPlot(pp.getLocation());
final Plot plot = MainUtil.getPlotAbs(pp.getLocation());
if ((plot != null) && plot.isAdded(pp.getUUID())) {
if (delay(p, message, false)) {
e.setCancelled(true);

View File

@ -177,10 +177,15 @@ public class BukkitPlayer extends PlotPlayer {
}
Permission perm = Bukkit.getServer().getPluginManager().getPermission(key);
if (perm == null) {
try {
perm = new Permission(key, PermissionDefault.FALSE);
Bukkit.getServer().getPluginManager().addPermission(perm);
Bukkit.getServer().getPluginManager().recalculatePermissionDefaults(perm);
}
catch (Exception e) {
e.printStackTrace();
}
}
return player.hasPermission(key);
}

View File

@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@ -67,11 +68,11 @@ import com.plotsquared.bukkit.object.entity.EntityWrapper;
public class BukkitChunkManager extends ChunkManager {
@Override
public ArrayList<ChunkLoc> getChunkChunks(final String world) {
public Set<ChunkLoc> getChunkChunks(final String world) {
final String directory = Bukkit.getWorldContainer() + File.separator + world + File.separator + "region";
final File folder = new File(directory);
final File[] regionFiles = folder.listFiles();
final ArrayList<ChunkLoc> chunks = new ArrayList<>();
final HashSet<ChunkLoc> chunks = new HashSet<>();
if (regionFiles == null) {
throw new RuntimeException("Could not find worlds folder.");
}
@ -107,7 +108,7 @@ public class BukkitChunkManager extends ChunkManager {
for (final Player player : worldObj.getPlayers()) {
final org.bukkit.Location locObj = player.getLocation();
if (((locObj.getBlockX() >> 4) == loc.x) && ((locObj.getBlockZ() >> 4) == loc.z) && !locObj.getBlock().isEmpty()) {
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(locObj));
final Plot plot = MainUtil.getPlotAbs(BukkitUtil.getLocation(locObj));
if (plot != null) {
final PlotPlayer pp = BukkitUtil.getPlayer(player);
pp.teleport(MainUtil.getDefaultHome(plot));
@ -167,12 +168,12 @@ public class BukkitChunkManager extends ChunkManager {
final int z2 = z1 + 15;
final Location bot = new Location(world, x1, 0, z1);
Plot plot;
plot = MainUtil.getPlot(bot);
plot = MainUtil.getPlotAbs(bot);
if ((plot != null) && (plot.owner != null)) {
return plot;
}
final Location top = new Location(world, x2, 0, z2);
plot = MainUtil.getPlot(top);
plot = MainUtil.getPlotAbs(top);
if ((plot != null) && (plot.owner != null)) {
return plot;
}
@ -198,9 +199,6 @@ public class BukkitChunkManager extends ChunkManager {
private static HashMap<BlockLoc, Byte> bannerBase;
private static HashSet<EntityWrapper> entities;
/**
* Copy a region to a new location (in the same world)
*/
@Override
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
final int relX = newPos.getX() - pos1.getX();
@ -254,7 +252,6 @@ public class BukkitChunkManager extends ChunkManager {
}, new Runnable() {
@Override
public void run() {
// TODO whenDone
TaskManager.runTask(whenDone);
}
}, 5);
@ -947,7 +944,7 @@ public class BukkitChunkManager extends ChunkManager {
return BukkitUtil.getWorld(world).unloadChunk(loc.x, loc.z, save, safe);
}
public static void swapChunk(final World world, final Chunk pos1, final Chunk pos2, final RegionWrapper r1, final RegionWrapper r2) {
public static void swapChunk(final World world1, final World world2, final Chunk pos1, final Chunk pos2, final RegionWrapper r1, final RegionWrapper r2) {
initMaps();
final int relX = (r2.minX - r1.minX);
final int relZ = (r2.minZ - r1.minZ);
@ -958,29 +955,27 @@ public class BukkitChunkManager extends ChunkManager {
final int sx = pos1.getX() << 4;
final int sz = pos1.getZ() << 4;
final int maxY = world.getMaxHeight();
for (int x = Math.max(r1.minX, sx); x <= Math.min(r1.maxX, sx + 15); x++) {
for (int z = Math.max(r1.minZ, sz); z <= Math.min(r1.maxZ, sz + 15); z++) {
saveBlocks(world, maxY, sx, sz, relX, relZ);
for (int y = 0; y < maxY; y++) {
final Block block1 = world.getBlockAt(x, y, z);
saveBlocks(world1, 256, sx, sz, relX, relZ);
for (int y = 0; y < 256; y++) {
final Block block1 = world1.getBlockAt(x, y, z);
final int id1 = block1.getTypeId();
final byte data1 = block1.getData();
final int xx = x + relX;
final int zz = z + relZ;
final Block block2 = world.getBlockAt(xx, y, zz);
final Block block2 = world2.getBlockAt(xx, y, zz);
final int id2 = block2.getTypeId();
final byte data2 = block2.getData();
if (id1 == 0) {
if (id2 != 0) {
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, 0, (byte) 0);
BukkitSetBlockManager.setBlockManager.set(world1, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world2, xx, y, zz, 0, (byte) 0);
}
} else if (id2 == 0) {
if (id1 != 0) {
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, 0, (byte) 0);
BukkitSetBlockManager.setBlockManager.set(world1, x, y, z, 0, (byte) 0);
BukkitSetBlockManager.setBlockManager.set(world2, xx, y, zz, id1, data1);
}
} else if (id1 == id2) {
if (data1 != data2) {
@ -988,52 +983,35 @@ public class BukkitChunkManager extends ChunkManager {
block2.setData(data1);
}
} else {
BukkitSetBlockManager.setBlockManager.set(world, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world, xx, y, zz, id1, data1);
BukkitSetBlockManager.setBlockManager.set(world1, x, y, z, id2, data2);
BukkitSetBlockManager.setBlockManager.set(world2, xx, y, zz, id1, data1);
}
}
}
}
restoreBlocks(world, 0, 0);
restoreEntities(world, 0, 0);
restoreBlocks(world1, 0, 0);
restoreEntities(world1, 0, 0);
}
@Override
public void swap(final String worldname, final PlotId pos1, final PlotId pos2) {
final Location bot1 = MainUtil.getPlotBottomLoc(worldname, pos1).add(1, 0, 1);
final Location top1 = MainUtil.getPlotTopLoc(worldname, pos1);
final Location bot2 = MainUtil.getPlotBottomLoc(worldname, pos2).add(1, 0, 1);
final Location top2 = MainUtil.getPlotTopLoc(worldname, pos2);
swap(worldname, bot1, top1, bot2, top2);
final Plot plot1 = MainUtil.getPlot(worldname, pos1);
final Plot plot2 = MainUtil.getPlot(worldname, pos2);
// TODO clear all entities
clearAllEntities(plot1.getBottom(), plot1.getTop());
clearAllEntities(plot2.getBottom(), plot2.getTop());
}
@Override
public void swap(final String worldname, final Location bot1, final Location top1, final Location bot2, final Location top2) {
public void swap(final Location bot1, final Location top1, final Location bot2, final Location top2, final Runnable whenDone) {
final RegionWrapper region1 = new RegionWrapper(bot1.getX(), top1.getX(), bot1.getZ(), top1.getZ());
final RegionWrapper region2 = new RegionWrapper(bot2.getX(), top2.getX(), bot2.getZ(), top2.getZ());
final World world = Bukkit.getWorld(bot1.getWorld());
final World world1 = Bukkit.getWorld(bot1.getWorld());
final World world2 = Bukkit.getWorld(bot2.getWorld());
final int relX = bot2.getX() - bot1.getX();
final int relZ = bot2.getZ() - bot1.getZ();
for (int x = bot1.getX() >> 4; x <= (top1.getX() >> 4); x++) {
for (int z = bot1.getZ() >> 4; z <= (top1.getZ() >> 4); z++) {
final Chunk chunk1 = world.getChunkAt(x, z);
final Chunk chunk2 = world.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
swapChunk(world, chunk1, chunk2, region1, region2);
final Chunk chunk1 = world1.getChunkAt(x, z);
final Chunk chunk2 = world2.getChunkAt(x + (relX >> 4), z + (relZ >> 4));
swapChunk(world1, world2, chunk1, chunk2, region1, region2);
}
}
// FIXME swap plots
TaskManager.runTaskLater(whenDone, 1);
}
@Override
@ -1041,8 +1019,8 @@ public class BukkitChunkManager extends ChunkManager {
final int[] count = new int[5];
final World world = BukkitUtil.getWorld(plot.world);
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final Location bot = MainUtil.getPlotBottomLocAbs(plot.world, plot.id);
final Location top = MainUtil.getPlotTopLocAbs(plot.world, plot.id);
final int bx = bot.getX() >> 4;
final int bz = bot.getZ() >> 4;

View File

@ -22,6 +22,7 @@ import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotAnalysis;
import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
@ -31,7 +32,7 @@ import com.intellectualcrafters.plot.util.TaskManager;
public class BukkitHybridUtils extends HybridUtils {
@Override
public void analyzePlot(final Plot plot, final RunnableVal<PlotAnalysis> whenDone) {
public void analyzeRegion(final String world, final RegionWrapper region, final RunnableVal<PlotAnalysis> whenDone) {
// int diff, int variety, int verticies, int rotation, int height_sd
/*
* diff: compare to base by looping through all blocks
@ -47,12 +48,12 @@ public class BukkitHybridUtils extends HybridUtils {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
final World world = Bukkit.getWorld(plot.world);
final ChunkGenerator gen = world.getGenerator();
final World worldObj = Bukkit.getWorld(world);
final ChunkGenerator gen = worldObj.getGenerator();
if (gen == null) {
return;
}
final BiomeGrid base = new BiomeGrid() {
final BiomeGrid nullBiomeGrid = new BiomeGrid() {
@Override
public void setBiome(final int a, final int b, final Biome c) {}
@ -61,8 +62,13 @@ public class BukkitHybridUtils extends HybridUtils {
return null;
}
};
final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final Location bot = new Location(world, region.minX, region.minY, region.minZ);
final Location top = new Location(world, region.maxX, region.maxY, region.maxZ);
// final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
// final Location top = MainUtil.getPlotTopLoc(plot.world, plot.id);
final int bx = bot.getX();
final int bz = bot.getZ();
final int tx = top.getX();
@ -87,10 +93,10 @@ public class BukkitHybridUtils extends HybridUtils {
ChunkManager.chunkTask(bot, top, new RunnableVal<int[]>() {
@Override
public void run() {
// TODO [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
// [chunkx, chunkz, pos1x, pos1z, pos2x, pos2z, isedge]
final int X = value[0];
final int Z = value[1];
final short[][] result = gen.generateExtBlockSections(world, r, X, Z, base);
final short[][] result = gen.generateExtBlockSections(worldObj, r, X, Z, nullBiomeGrid);
final int xb = ((X) << 4) - bx;
final int zb = ((Z) << 4) - bz;
for (int i = 0; i < result.length; i++) {
@ -202,21 +208,6 @@ public class BukkitHybridUtils extends HybridUtils {
analysis.data_sd = (int) (MathMan.getSD(data, analysis.data));
analysis.air_sd = (int) (MathMan.getSD(air, analysis.air));
analysis.variety_sd = (int) (MathMan.getSD(variety, analysis.variety));
final List<Integer> result = new ArrayList<>();
result.add(analysis.changes);
result.add(analysis.faces);
result.add(analysis.data);
result.add(analysis.air);
result.add(analysis.variety);
result.add(analysis.changes_sd);
result.add(analysis.faces_sd);
result.add(analysis.data_sd);
result.add(analysis.air_sd);
result.add(analysis.variety_sd);
final Flag flag = new Flag(FlagManager.getFlag("analysis"), result);
FlagManager.addPlotFlag(plot, flag);
System.gc();
System.gc();
whenDone.value = analysis;
@ -236,7 +227,7 @@ public class BukkitHybridUtils extends HybridUtils {
public void run() {
final int X = value[0];
final int Z = value[1];
world.loadChunk(X, Z);
worldObj.loadChunk(X, Z);
int minX;
int minZ;
int maxX;
@ -272,14 +263,14 @@ public class BukkitHybridUtils extends HybridUtils {
for (int z = minZ; z <= maxZ; z++) {
final int zz = cbz + z;
for (int y = 0; y < 256; y++) {
final Block block = world.getBlockAt(xx, y, zz);
final Block block = worldObj.getBlockAt(xx, y, zz);
final int xr = xb + x;
final int zr = zb + z;
newblocks[y][xr][zr] = (short) block.getTypeId();
}
}
}
world.unloadChunkRequest(X, Z, true);
worldObj.unloadChunkRequest(X, Z, true);
}
}, new Runnable() {
@Override

View File

@ -1,140 +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.plotsquared.bukkit.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.UUIDHandler;
/**
* Functions involving players, plots and locations.
*/
public class BukkitPlayerFunctions {
/*
* =========== NOTICE ================
* - We will try to move as many functions as we can out of this class and into the MainUtil class
*/
/**
* Clear a plot. Use null player if no player is present
* @param player
* @param world
* @param plot
* @param isDelete
*/
public static void clear(final Player player, final String world, final Plot plot, final boolean isDelete) {
final long start = System.currentTimeMillis();
final Runnable whenDone = new Runnable() {
@Override
public void run() {
if ((player != null) && player.isOnline()) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
}
}
};
if (!MainUtil.clearAsPlayer(plot, isDelete, whenDone)) {
MainUtil.sendMessage(null, C.WAIT_FOR_TIMER);
}
}
public static String getPlayerName(final UUID uuid) {
if (uuid == null) {
return "unknown";
}
final String name = UUIDHandler.getName(uuid);
if (name == null) {
return "unknown";
}
return name;
}
/**
* @param player player
*
* @return boolean
*/
public static boolean isInPlot(final Player player) {
return getCurrentPlot(player) != null;
}
public static ArrayList<PlotId> getMaxPlotSelectionIds(final String world, PlotId pos1, PlotId pos2) {
final Plot plot1 = PS.get().getPlot(world, pos1);
final Plot plot2 = PS.get().getPlot(world, pos2);
if (plot1 != null) {
pos1 = MainUtil.getBottomPlot(plot1).id;
}
if (plot2 != null) {
pos2 = MainUtil.getTopPlot(plot2).id;
}
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;
}
/**
* Returns the plot a player is currently in.
*
* @param player
*
* @return boolean
*/
public static Plot getCurrentPlot(final Player player) {
if (!PS.get().isPlotWorld(player.getWorld().getName())) {
return null;
}
final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(player));
final String world = player.getWorld().getName();
if (id == null) {
return null;
}
return MainUtil.getPlot(world, id);
}
/**
* Get the plots for a player
*
* @param plr
*
* @return boolean
*/
public static Set<Plot> getPlayerPlots(final String world, final Player plr) {
final Set<Plot> p = PS.get().getPlots(world, plr.getName());
if (p == null) {
return new HashSet<>();
}
return p;
}
}

View File

@ -20,11 +20,14 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.plotsquared.bukkit.util;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@ -41,8 +44,13 @@ import com.intellectualcrafters.jnbt.StringTag;
import com.intellectualcrafters.jnbt.Tag;
import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.RegionWrapper;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.SchematicHandler;
import com.intellectualcrafters.plot.util.StringMan;
import com.intellectualcrafters.plot.util.TaskManager;
import com.plotsquared.object.schematic.StateWrapper;
@ -53,32 +61,21 @@ import com.plotsquared.object.schematic.StateWrapper;
public class BukkitSchematicHandler extends SchematicHandler {
@Override
public void getCompoundTag(final String world, final Location pos1, final Location pos2, final RunnableVal<CompoundTag> whenDone) {
public void getCompoundTag(final String world, final Set<RegionWrapper> regions, final RunnableVal<CompoundTag> whenDone) {
// async
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
// Main positions
final int p1x = pos1.getX();
final int p1z = pos1.getZ();
final int p2x = pos2.getX();
final int p2z = pos2.getZ();
final int bcx = p1x >> 4;
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
final int sy = pos1.getY();
final int ey = pos2.getY();
final int width = (pos2.getX() - pos1.getX()) + 1;
final int height = (pos2.getY() - pos1.getY()) + 1;
final int length = (pos2.getZ() - pos1.getZ()) + 1;
Location[] corners = MainUtil.getCorners(world, regions);
final Location bot = corners[0];
final Location top = corners[1];
final int width = (top.getX() - bot.getX()) + 1;
final int height = (top.getY() - bot.getY()) + 1;
final int length = (top.getZ() - bot.getZ()) + 1;
// Main Schematic tag
final HashMap<String, Tag> schematic = new HashMap<>();
schematic.put("Width", new ShortTag("Width", (short) width));
schematic.put("Length", new ShortTag("Length", (short) length));
schematic.put("Height", new ShortTag("Height", (short) height));
@ -89,12 +86,47 @@ public class BukkitSchematicHandler extends SchematicHandler {
schematic.put("WEOffsetX", new IntTag("WEOffsetX", 0));
schematic.put("WEOffsetY", new IntTag("WEOffsetY", 0));
schematic.put("WEOffsetZ", new IntTag("WEOffsetZ", 0));
// Arrays of data types
final List<Tag> tileEntities = new ArrayList<Tag>();
final byte[] blocks = new byte[width * height * length];
final byte[] blockData = new byte[width * height * length];
// Queue
final ArrayDeque<RegionWrapper> queue = new ArrayDeque<>(regions);
TaskManager.runTask(new Runnable() {
@Override
public void run() {
if (queue.size() == 0) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
whenDone.value = new CompoundTag("Schematic", schematic);
TaskManager.runTask(whenDone);
System.gc();
System.gc();
}
});
return;
}
final Runnable regionTask = this;
RegionWrapper region = queue.poll();
Location pos1 = new Location(world, region.minX, region.minY, region.minZ);
Location pos2 = new Location(world, region.maxX, region.maxY, region.maxZ);
final int bx = bot.getX();
final int bz = bot.getZ();
final int p1x = pos1.getX();
final int p1z = pos1.getZ();
final int p2x = pos2.getX();
final int p2z = pos2.getZ();
final int bcx = p1x >> 4;
final int bcz = p1z >> 4;
final int tcx = p2x >> 4;
final int tcz = p2z >> 4;
final int sy = pos1.getY();
final int ey = pos2.getY();
// Generate list of chunks
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
for (int x = bcx; x <= tcx; x++) {
@ -102,7 +134,6 @@ public class BukkitSchematicHandler extends SchematicHandler {
chunks.add(new ChunkLoc(x, z));
}
}
final World worldObj = Bukkit.getWorld(world);
// Main thread
TaskManager.runTask(new Runnable() {
@ -112,12 +143,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
while ((chunks.size() > 0) && ((System.currentTimeMillis() - start) < 20)) {
// save schematics
final ChunkLoc chunk = chunks.remove(0);
final Chunk bc = worldObj.getChunkAt(chunk.x, chunk.z);
if (!bc.load(false)) {
continue;
}
final int X = chunk.x;
final int Z = chunk.z;
int xxb = X << 4;
@ -141,10 +170,10 @@ public class BukkitSchematicHandler extends SchematicHandler {
final int ry = y - sy;
final int i1 = (ry * width * length);
for (int z = zzb; z <= zzt; z++) {
final int rz = z - p1z;
final int rz = z - bz;
final int i2 = i1 + (rz * width);
for (int x = xxb; x <= xxt; x++) {
final int rx = x - p1x;
final int rx = x - bx;
final int index = i2 + rx;
final Block block = worldObj.getBlockAt(x, y, z);
final int id = block.getTypeId();
@ -292,26 +321,15 @@ public class BukkitSchematicHandler extends SchematicHandler {
}
}
}
}
if (chunks.size() != 0) {
TaskManager.runTaskLater(this, 1);
} else {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
schematic.put("Blocks", new ByteArrayTag("Blocks", blocks));
schematic.put("Data", new ByteArrayTag("Data", blockData));
schematic.put("Entities", new ListTag("Entities", CompoundTag.class, new ArrayList<Tag>()));
schematic.put("TileEntities", new ListTag("TileEntities", CompoundTag.class, tileEntities));
whenDone.value = new CompoundTag("Schematic", schematic);
TaskManager.runTask(whenDone);
System.gc();
System.gc();
regionTask.run();
}
}
});
}
}
});
}
});

View File

@ -64,7 +64,6 @@ public class SetBlockFast extends BukkitSetBlockManager {
@Override
public void run() {
// TODO Auto-generated method stub
update(toUpdate.values());
toUpdate = new HashMap<>();
}

View File

@ -29,6 +29,6 @@ public class SetBlockSlow extends BukkitSetBlockManager {
@Override
public void update(final Collection<Chunk> chunks) {
// TODO nothing
// nothing
}
}

View File

@ -1,35 +0,0 @@
package com.plotsquared.bukkit.util;
import java.io.File;
import org.bukkit.Bukkit;
import com.intellectualcrafters.plot.object.Location;
import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.bukkit.BukkitMain;
import com.sk89q.worldedit.CuboidClipboard;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.bukkit.BukkitWorld;
public class WorldEditSchematic {
public void saveSchematic(final String file, final String world, final PlotId id) {
final Location bot = MainUtil.getPlotBottomLoc(world, id).add(1, 0, 1);
final Location top = MainUtil.getPlotTopLoc(world, id);
final Vector size = new Vector((top.getX() - bot.getX()) + 1, top.getY() - bot.getY() - 1, (top.getZ() - bot.getZ()) + 1);
final Vector origin = new Vector(bot.getX(), bot.getY(), bot.getZ());
final CuboidClipboard clipboard = new CuboidClipboard(size, origin);
new Vector(bot.getX(), bot.getY(), bot.getZ());
new Vector(top.getX(), top.getY(), top.getZ());
final EditSession session = BukkitMain.worldEdit.getWorldEdit().getEditSessionFactory().getEditSession(new BukkitWorld(Bukkit.getWorld(world)), 999999999);
clipboard.copy(session);
try {
clipboard.saveSchematic(new File(file));
MainUtil.sendMessage(null, "&7 - &a success: " + id);
} catch (final Exception e) {
e.printStackTrace();
MainUtil.sendMessage(null, "&7 - Failed to save &c" + id);
}
}
}

View File

@ -60,7 +60,7 @@ public class PlotListener {
if ((last != null) && !last.id.equals(plot.id)) {
plotExit(pp, last);
}
pp.setMeta("lastplot", plot);
pp.setMeta("lastplot", MainUtil.getPlot(plot));
EventUtil.manager.callEntry(pp, plot);
if (plot.hasOwner()) {
final HashMap<String, Flag> flags = FlagManager.getPlotFlags(plot);

View File

@ -47,9 +47,7 @@ public class WEManager {
continue;
}
if (Settings.WE_ALLOW_HELPER ? plot.isAdded(uuid) : (plot.isOwner(uuid) || plot.getTrusted().contains(uuid))) {
final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
regions.add(new RegionWrapper(pos1.getX(), pos2.getX(), pos1.getY(), pos2.getY(), pos1.getZ(), pos2.getZ()));
regions.addAll(MainUtil.getRegions(plot));
}
}
return regions;

View File

@ -61,7 +61,7 @@ public class AugmentedPopulator implements Populator {
this.b = b;
o = (plotworld.TERRAIN == 1) || (plotworld.TERRAIN == 2);
if (cluster != null) {
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1());
final Location bl = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()).subtract(1, 0, 1);
final Location tl = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1, 0, 1);
bx = bl.getX();
bz = bl.getZ();

View File

@ -27,9 +27,6 @@ public class SpongeBasicGen extends SpongePlotGenerator {
/**
* Some generator specific variables (implementation dependent)
*
* TODO USE THESE
*
*/
public int plotsize;
public int pathsize;

View File

@ -93,6 +93,7 @@ public class MainListener {
* - HangingBreakEvent
* - Liquid flow
* - PVP
* - block dispense
* - PVE
* - VehicleDestroy
* - Projectile
@ -164,7 +165,7 @@ public class MainListener {
return;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[3] >= cap) {
event.setCancelled(true);
@ -180,7 +181,7 @@ public class MainListener {
return;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[1] >= cap) {
event.setCancelled(true);
@ -197,7 +198,7 @@ public class MainListener {
return;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[2] >= cap) {
event.setCancelled(true);
@ -216,7 +217,7 @@ public class MainListener {
return;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[4] >= cap) {
event.setCancelled(true);
@ -232,7 +233,7 @@ public class MainListener {
return;
}
if (mobs == null) {
mobs = ChunkManager.manager.countEntities(plot);
mobs = MainUtil.countEntities(plot);
}
if (mobs[0] >= cap) {
event.setCancelled(true);
@ -266,7 +267,6 @@ public class MainListener {
event.setCancelled(true);
}
}
// TODO
}
@Subscribe
@ -519,7 +519,7 @@ public class MainListener {
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
@ -570,7 +570,7 @@ public class MainListener {
}
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_DESTROY_OTHER);
event.setCancelled(true);
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getSettings().flags.containsKey("done")) {
} else if (Settings.DONE_RESTRICTS_BUILDING && plot.getFlags().containsKey("done")) {
if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER);
event.setCancelled(true);
@ -658,9 +658,6 @@ public class MainListener {
final UUID uuid = pp.getUUID();
UUIDHandler.add(name, uuid);
ExpireManager.dates.put(uuid, System.currentTimeMillis());
// TODO worldedit bypass
if ((PS.get().update != null) && pp.hasPermission("plots.admin")) {
TaskManager.runTaskLater(new Runnable() {
@Override
@ -740,7 +737,7 @@ public class MainListener {
final Plot plot = MainUtil.getPlot(worldname, id);
if (!PlotListener.plotEntry(pp, plot)) {
MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED);
if (!plot.equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
if (!plot.getBasePlot(false).equals(MainUtil.getPlot(SpongeUtil.getLocation(worldname, from)))) {
event.setNewLocation(from);
} else {
event.setNewLocation(world.getSpawnLocation());
@ -964,9 +961,6 @@ public class MainListener {
player.deleteMeta("location");
player.deleteMeta("lastplot");
// TODO worldedit mask
if (Settings.PERMISSION_CACHING) {
((SpongePlayer) player).hasPerm = new HashSet<>();
((SpongePlayer) player).noPerm = new HashSet<>();

View File

@ -1,7 +1,9 @@
package com.plotsquared.sponge.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.entity.living.Living;
@ -32,8 +34,8 @@ public class SpongeChunkManager extends ChunkManager {
@Override
public int[] countEntities(final Plot plot) {
final Location pos1 = plot.getBottom();
final Location pos2 = plot.getTop();
final Location pos1 = plot.getBottomAbs();
final Location pos2 = plot.getTopAbs();
final String worldname = pos1.getWorld();
final World world = SpongeUtil.getWorld(worldname);
@ -87,8 +89,8 @@ public class SpongeChunkManager extends ChunkManager {
}
@Override
public List<ChunkLoc> getChunkChunks(final String world) {
final ArrayList<ChunkLoc> chunks = new ArrayList<ChunkLoc>();
public Set<ChunkLoc> getChunkChunks(final String world) {
final HashSet<ChunkLoc> chunks = new HashSet<ChunkLoc>();
final World worldObj = SpongeUtil.getWorld(world);
final ChunkDataStream storage = worldObj.getWorldStorage().getGeneratedChunks();
while (storage.hasNext()) {

Some files were not shown because too many files have changed in this diff Show More