Minor cleanup

This commit is contained in:
boy0001 2015-07-04 16:37:33 +10:00
parent 289527b8e5
commit 483be4e2f0
28 changed files with 613 additions and 340 deletions

View File

@ -70,6 +70,7 @@ public class PS {
* @param imp_class * @param imp_class
*/ */
protected PS(final IPlotMain imp_class) { protected PS(final IPlotMain imp_class) {
instance = this;
SetupUtils.generators = new HashMap<>(); SetupUtils.generators = new HashMap<>();
IMP = imp_class; IMP = imp_class;
try { try {
@ -529,7 +530,11 @@ public class PS {
if (callEvent) { if (callEvent) {
EventUtil.manager.callDelete(world, id); EventUtil.manager.callDelete(world, id);
} }
Plot plot = plots.get(world).remove(id); HashMap<PlotId, Plot> allPlots = plots.get(world);
if (allPlots == null) {
return false;
}
Plot plot = allPlots.remove(id);
if (MainUtil.lastPlot.containsKey(world)) { if (MainUtil.lastPlot.containsKey(world)) {
final PlotId last = MainUtil.lastPlot.get(world); final PlotId last = MainUtil.lastPlot.get(world);
final int last_max = Math.max(last.x, last.y); final int last_max = Math.max(last.x, last.y);

View File

@ -67,34 +67,29 @@ public class Add extends SubCommand {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
if (!plot.members.contains(uuid)) { if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER);
MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false;
return false; }
}
if (plot.trusted.contains(uuid)) { if (plot.members.contains(uuid)) {
plot.trusted.remove(uuid);
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
}
if (plot.denied.contains(uuid)) {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
plot.denied.remove(uuid);
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
}
plot.addMember(uuid);
DBFunc.setMember(loc.getWorld(), plot, uuid);
EventUtil.manager.callMember(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false; return false;
} }
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.removeTrusted(uuid)) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); plot.addMember(uuid);
return false;
} }
else {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.denied.contains(uuid)) {
plot.removeDenied(uuid);
}
plot.addMember(uuid);
}
EventUtil.manager.callMember(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.MEMBER_ADDED); MainUtil.sendMessage(plr, C.MEMBER_ADDED);
return true; return true;
} }

View File

@ -62,7 +62,7 @@ public class Clear extends SubCommand {
Runnable runnable = new Runnable() { Runnable runnable = new Runnable() {
@Override @Override
public void run() { public void run() {
MainUtil.clear(world, plot, plot.owner == null, null); MainUtil.clear(plot, plot.owner == null, null);
PS.log("Plot " + plot.getId().toString() + " cleared."); PS.log("Plot " + plot.getId().toString() + " cleared.");
} }
}; };

View File

@ -187,7 +187,7 @@ public class Cluster extends SubCommand {
} }
} }
for (final Plot plot : toRemove) { for (final Plot plot : toRemove) {
DBFunc.delete(plot.world, plot); plot.unclaim();
} }
} }
DBFunc.delete(cluster); DBFunc.delete(cluster);
@ -361,11 +361,11 @@ public class Cluster extends SubCommand {
if (player != null) { if (player != null) {
MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName());
} }
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld(), uuid)) { for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
DBFunc.delete(world, plot); plot.unclaim();
} }
} }
MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER); MainUtil.sendMessage(plr, C.CLUSTER_KICKED_USER);
@ -411,11 +411,11 @@ public class Cluster extends SubCommand {
cluster.invited.remove(uuid); cluster.invited.remove(uuid);
DBFunc.removeInvited(cluster, uuid); DBFunc.removeInvited(cluster, uuid);
MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName()); MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName());
for (final Plot plot : PS.get().getPlots(plr.getLocation().getWorld(), uuid)) { for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) {
final PlotCluster current = ClusterManager.getCluster(plot); final PlotCluster current = ClusterManager.getCluster(plot);
if ((current != null) && current.equals(cluster)) { if ((current != null) && current.equals(cluster)) {
final String world = plr.getLocation().getWorld(); final String world = plr.getLocation().getWorld();
DBFunc.delete(world, plot); plot.unclaim();
} }
} }
return true; return true;

View File

@ -66,7 +66,7 @@ public class DebugFixFlags extends SubCommand {
} }
} }
if (changed) { if (changed) {
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
} }
} }
MainUtil.sendMessage(plr, "&aDone!"); MainUtil.sendMessage(plr, "&aDone!");

View File

@ -76,7 +76,7 @@ public class Delete extends SubCommand {
if (!result) { if (!result) {
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER); MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
} }
DBFunc.delete(loc.getWorld(), plot); DBFunc.delete(plot);
} }
}; };
if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) { if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {

View File

@ -67,26 +67,19 @@ public class Deny extends SubCommand {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
if (!plot.denied.contains(uuid)) { if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER);
MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false;
return false; }
}
if (plot.trusted.contains(uuid)) { if (plot.denied.contains(uuid)) {
plot.trusted.remove(uuid);
DBFunc.removeTrusted(loc.getWorld(), plot, uuid);
}
if (plot.members.contains(uuid)) {
plot.members.remove(uuid);
DBFunc.removeMember(loc.getWorld(), plot, uuid);
}
plot.addDenied(uuid);
DBFunc.setDenied(loc.getWorld(), plot, uuid);
EventUtil.manager.callDenied(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false; return false;
} }
plot.removeMember(uuid);
plot.removeTrusted(uuid);
plot.addDenied(uuid);
EventUtil.manager.callDenied(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.DENIED_ADDED); MainUtil.sendMessage(plr, C.DENIED_ADDED);
if (!uuid.equals(DBFunc.everyone)) { if (!uuid.equals(DBFunc.everyone)) {
PS.get().IMP.handleKick(uuid, C.YOU_GOT_DENIED); PS.get().IMP.handleKick(uuid, C.YOU_GOT_DENIED);

View File

@ -159,7 +159,7 @@ public class FlagCmd extends SubCommand {
if ((args.length == 3) && flag.getAbstractFlag().isList()) { if ((args.length == 3) && flag.getAbstractFlag().isList()) {
final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " "); final String value = StringUtils.join(Arrays.copyOfRange(args, 2, args.length), " ");
((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value); ((FlagValue.ListValue) flag.getAbstractFlag().value).remove(flag.getValue(), value);
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
} else { } else {
final boolean result = FlagManager.removePlotFlag(plot, flag.getKey()); final boolean result = FlagManager.removePlotFlag(plot, flag.getKey());
if (!result) { if (!result) {
@ -206,7 +206,7 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.FLAG_NOT_ADDED); MainUtil.sendMessage(player, C.FLAG_NOT_ADDED);
return false; return false;
} }
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
MainUtil.sendMessage(player, C.FLAG_ADDED); MainUtil.sendMessage(player, C.FLAG_ADDED);
APlotListener.manager.plotEntry(player, plot); APlotListener.manager.plotEntry(player, plot);
return true; return true;

View File

@ -20,6 +20,8 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@ -58,74 +60,56 @@ public class Remove extends SubCommand {
} }
int count = 0; int count = 0;
if (args[0].equals("unknown")) { if (args[0].equals("unknown")) {
Iterator<UUID> i = plot.members.iterator(); ArrayList<UUID> toRemove = new ArrayList<>();
while (i.hasNext()) { HashSet<UUID> all = new HashSet<>();
UUID uuid = i.next(); all.addAll(plot.members);
all.addAll(plot.trusted);
all.addAll(plot.denied);
for (UUID uuid : all) {
if (UUIDHandler.getName(uuid) == null) { if (UUIDHandler.getName(uuid) == null) {
DBFunc.removeMember(plot.world, plot, uuid); toRemove.add(uuid);
i.remove();
count++; count++;
} }
} }
i = plot.trusted.iterator(); for (UUID uuid : toRemove) {
while (i.hasNext()) { plot.removeDenied(uuid);
UUID uuid = i.next(); plot.removeTrusted(uuid);
if (UUIDHandler.getName(uuid) == null) { plot.removeMember(uuid);
DBFunc.removeTrusted(plot.world, plot, uuid);
i.remove();
count++;
}
}
i = plot.denied.iterator();
while (i.hasNext()) {
UUID uuid = i.next();
if (UUIDHandler.getName(uuid) == null) {
DBFunc.removeDenied(plot.world, plot, uuid);
i.remove();
count++;
}
} }
} }
else if (args[0].equals("*")){ else if (args[0].equals("*")){
Iterator<UUID> i = plot.members.iterator(); ArrayList<UUID> toRemove = new ArrayList<>();
while (i.hasNext()) { HashSet<UUID> all = new HashSet<>();
UUID uuid = i.next(); all.addAll(plot.members);
DBFunc.removeMember(plot.world, plot, uuid); all.addAll(plot.trusted);
i.remove(); all.addAll(plot.denied);
for (UUID uuid : all) {
toRemove.add(uuid);
count++; count++;
} }
i = plot.trusted.iterator(); for (UUID uuid : toRemove) {
while (i.hasNext()) { plot.removeDenied(uuid);
UUID uuid = i.next(); plot.removeTrusted(uuid);
DBFunc.removeTrusted(plot.world, plot, uuid); plot.removeMember(uuid);
i.remove();
count++;
}
i = plot.denied.iterator();
while (i.hasNext()) {
UUID uuid = i.next();
DBFunc.removeDenied(plot.world, plot, uuid);
i.remove();
count++;
} }
} }
else { else {
UUID uuid = UUIDHandler.getUUID(args[0]); UUID uuid = UUIDHandler.getUUID(args[0]);
if (uuid != null) { if (uuid != null) {
if (plot.trusted.contains(uuid)) { if (plot.trusted.contains(uuid)) {
DBFunc.removeTrusted(plot.world, plot, uuid); if (plot.removeTrusted(uuid)) {
plot.trusted.remove(uuid); count++;
count++; }
} }
else if (plot.members.contains(uuid)) { else if (plot.members.contains(uuid)) {
DBFunc.removeMember(plot.world, plot, uuid); if (plot.removeMember(uuid)) {
plot.members.remove(uuid); count++;
count++; }
} }
else if (plot.denied.contains(uuid)) { else if (plot.denied.contains(uuid)) {
DBFunc.removeDenied(plot.world, plot, uuid); if (plot.removeDenied(uuid)) {
plot.denied.remove(uuid); count++;
count++; }
} }
} }
} }

View File

@ -141,8 +141,7 @@ public class Set extends SubCommand {
} }
if (args.length > 1) { if (args.length > 1) {
if (args[1].equalsIgnoreCase("none")) { if (args[1].equalsIgnoreCase("none")) {
plot.settings.setPosition(null); plot.setHome(null);
DBFunc.setPosition(loc.getWorld(), plot, "");
return true; return true;
} }
return MainUtil.sendMessage(plr, C.HOME_ARGUMENT); return MainUtil.sendMessage(plr, C.HOME_ARGUMENT);
@ -153,8 +152,7 @@ public class Set extends SubCommand {
base.setY(0); base.setY(0);
final Location relative = plr.getLocation().subtract(base.getX(), base.getY(), base.getZ()); 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()); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ(), relative.getYaw(), relative.getPitch());
plot.settings.setPosition(blockloc); plot.setHome(blockloc);
DBFunc.setPosition(loc.getWorld(), plot, blockloc.toString());
return MainUtil.sendMessage(plr, C.POSITION_SET); return MainUtil.sendMessage(plr, C.POSITION_SET);
} }
if (args[0].equalsIgnoreCase("alias")) { if (args[0].equalsIgnoreCase("alias")) {
@ -181,7 +179,7 @@ public class Set extends SubCommand {
return false; return false;
} }
} }
DBFunc.setAlias(loc.getWorld(), plot, alias); plot.setAlias(alias);
MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias)); MainUtil.sendMessage(plr, C.ALIAS_SET_TO.s().replaceAll("%alias%", alias));
return true; return true;
} }
@ -211,7 +209,7 @@ public class Set extends SubCommand {
MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList())); MainUtil.sendMessage(plr, getBiomeList(BlockManager.manager.getBiomeList()));
return true; return true;
} }
MainUtil.setBiome(plr.getLocation().getWorld(), plot, args[1].toUpperCase()); plot.setBiome(args[1].toUpperCase());
MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase()); MainUtil.sendMessage(plr, C.BIOME_SET_TO.s() + args[1].toLowerCase());
return true; return true;
} }

View File

@ -67,34 +67,29 @@ public class Trust extends SubCommand {
MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]);
return false; return false;
} }
if (!plot.trusted.contains(uuid)) { if (plot.isOwner(uuid)) {
if (plot.isOwner(uuid)) { MainUtil.sendMessage(plr, C.ALREADY_OWNER);
MainUtil.sendMessage(plr, C.ALREADY_OWNER); return false;
return false; }
}
if (plot.members.contains(uuid)) { if (plot.trusted.contains(uuid)) {
plot.members.remove(uuid);
DBFunc.removeMember(loc.getWorld(), plot, uuid);
}
if (plot.denied.contains(uuid)) {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
plot.denied.remove(uuid);
DBFunc.removeDenied(loc.getWorld(), plot, uuid);
}
plot.addTrusted(uuid);
DBFunc.setTrusted(loc.getWorld(), plot, uuid);
EventUtil.manager.callTrusted(plr, plot, uuid, true);
} else {
MainUtil.sendMessage(plr, C.ALREADY_ADDED); MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false; return false;
} }
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) { if (plot.removeMember(uuid)) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); plot.addTrusted(uuid);
return false;
} }
else {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.denied.contains(uuid)) {
plot.removeDenied(uuid);
}
plot.addTrusted(uuid);
}
EventUtil.manager.callTrusted(plr, plot, uuid, true);
MainUtil.sendMessage(plr, C.TRUSTED_ADDED); MainUtil.sendMessage(plr, C.TRUSTED_ADDED);
return true; return true;
} }

View File

@ -60,10 +60,7 @@ public class Unclaim extends SubCommand {
} }
final boolean result = PS.get().removePlot(loc.getWorld(), plot.id, true); final boolean result = PS.get().removePlot(loc.getWorld(), plot.id, true);
if (result) { if (result) {
final String worldname = plr.getLocation().getWorld(); plot.unclaim();
PS.get().getPlotManager(worldname).unclaimPlot(pWorld, plot);
DBFunc.delete(worldname, plot);
// TODO set wall block
} else { } else {
MainUtil.sendMessage(plr, "Plot removal has been denied."); MainUtil.sendMessage(plr, "Plot removal has been denied.");
} }

View File

@ -20,6 +20,7 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@ -58,33 +59,28 @@ public class Undeny extends SubCommand {
} }
int count = 0; int count = 0;
if (args[0].equals("unknown")) { if (args[0].equals("unknown")) {
Iterator<UUID> i = plot.denied.iterator(); ArrayList<UUID> toRemove = new ArrayList<>();
i = plot.denied.iterator(); for (UUID uuid : plot.denied) {
while (i.hasNext()) {
UUID uuid = i.next();
if (UUIDHandler.getName(uuid) == null) { if (UUIDHandler.getName(uuid) == null) {
DBFunc.removeDenied(plot.world, plot, uuid); toRemove.add(uuid);
i.remove();
count++;
} }
} }
for (UUID uuid : toRemove) {
plot.removeDenied(uuid);
count++;
}
} }
else if (args[0].equals("*")){ else if (args[0].equals("*")){
Iterator<UUID> i = plot.denied.iterator(); for (UUID uuid : new ArrayList<>(plot.denied)) {
while (i.hasNext()) { plot.removeDenied(uuid);
UUID uuid = i.next();
DBFunc.removeDenied(plot.world, plot, uuid);
i.remove();
count++; count++;
} }
} }
else { else {
UUID uuid = UUIDHandler.getUUID(args[0]); UUID uuid = UUIDHandler.getUUID(args[0]);
if (uuid != null) { if (uuid != null) {
if (plot.denied.contains(uuid)) { if (plot.removeDenied(uuid)) {
DBFunc.removeDenied(plot.world, plot, uuid); count++;
plot.denied.remove(uuid);
count++;
} }
} }
} }

View File

@ -20,6 +20,7 @@
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.commands; package com.intellectualcrafters.plot.commands;
import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.UUID; import java.util.UUID;
@ -58,33 +59,28 @@ public class Untrust extends SubCommand {
} }
int count = 0; int count = 0;
if (args[0].equals("unknown")) { if (args[0].equals("unknown")) {
Iterator<UUID> i = plot.trusted.iterator(); ArrayList<UUID> toRemove = new ArrayList<>();
i = plot.trusted.iterator(); for (UUID uuid : plot.trusted) {
while (i.hasNext()) {
UUID uuid = i.next();
if (UUIDHandler.getName(uuid) == null) { if (UUIDHandler.getName(uuid) == null) {
DBFunc.removeTrusted(plot.world, plot, uuid); toRemove.add(uuid);
i.remove();
count++;
} }
} }
for (UUID uuid : toRemove) {
plot.removeTrusted(uuid);
count++;
}
} }
else if (args[0].equals("*")){ else if (args[0].equals("*")){
Iterator<UUID> i = plot.trusted.iterator(); for (UUID uuid : new ArrayList<>(plot.trusted)) {
while (i.hasNext()) { plot.removeTrusted(uuid);
UUID uuid = i.next();
DBFunc.removeTrusted(plot.world, plot, uuid);
i.remove();
count++; count++;
} }
} }
else { else {
UUID uuid = UUIDHandler.getUUID(args[0]); UUID uuid = UUIDHandler.getUUID(args[0]);
if (uuid != null) { if (uuid != null) {
if (plot.trusted.contains(uuid)) { if (plot.removeTrusted(uuid)) {
DBFunc.removeTrusted(plot.world, plot, uuid); count++;
plot.trusted.remove(uuid);
count++;
} }
} }
} }

View File

@ -84,7 +84,7 @@ public interface AbstractDB {
* *
* @param plot Plot that should be deleted * @param plot Plot that should be deleted
*/ */
public void delete(final String world, final Plot plot); public void delete(final Plot plot);
public void delete(final PlotCluster cluster); public void delete(final PlotCluster cluster);
@ -133,7 +133,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param merged boolean[] * @param merged boolean[]
*/ */
public void setMerged(final String world, final Plot plot, final boolean[] merged); public void setMerged(final Plot plot, final boolean[] merged);
/** /**
* Swap the settings, helpers etc. of two plots * Swap the settings, helpers etc. of two plots
@ -149,7 +149,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param flags flags to set (flag[]) * @param flags flags to set (flag[])
*/ */
public void setFlags(final String world, final Plot plot, final Collection<Flag> flags); public void setFlags(final Plot plot, final Collection<Flag> flags);
/** /**
* Set cluster flags * Set cluster flags
@ -170,7 +170,7 @@ public interface AbstractDB {
* @param plot Plot for which the alias should be set * @param plot Plot for which the alias should be set
* @param alias Plot Alias * @param alias Plot Alias
*/ */
public void setAlias(final String world, final Plot plot, final String alias); public void setAlias(final Plot plot, final String alias);
/** /**
* Purgle a plot * Purgle a plot
@ -193,7 +193,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param position Plot Home Position * @param position Plot Home Position
*/ */
public void setPosition(final String world, final Plot plot, final String position); public void setPosition(final Plot plot, final String position);
/** /**
* *
@ -220,7 +220,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be removed * @param uuid Player that should be removed
*/ */
public void removeTrusted(final String world, final Plot plot, final UUID uuid); public void removeTrusted(final Plot plot, final UUID uuid);
/** /**
* @param cluster PlotCluster Object * @param cluster PlotCluster Object
@ -232,7 +232,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be removed * @param uuid Player that should be removed
*/ */
public void removeMember(final String world, final Plot plot, final UUID uuid); public void removeMember(final Plot plot, final UUID uuid);
/** /**
* *
@ -245,7 +245,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be removed * @param uuid Player that should be removed
*/ */
public void setTrusted(final String world, final Plot plot, final UUID uuid); public void setTrusted(final Plot plot, final UUID uuid);
/** /**
* @param cluster PlotCluster Object * @param cluster PlotCluster Object
@ -257,7 +257,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player that should be added * @param uuid Player that should be added
*/ */
public void setMember(final String world, final Plot plot, final UUID uuid); public void setMember(final Plot plot, final UUID uuid);
/** /**
* *
@ -265,19 +265,19 @@ public interface AbstractDB {
* @param cluster * @param cluster
* @param uuid * @param uuid
*/ */
public void setInvited(final String world, final PlotCluster cluster, final UUID uuid); public void setInvited(final PlotCluster cluster, final UUID uuid);
/** /**
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player uuid * @param uuid Player uuid
*/ */
public void removeDenied(final String world, final Plot plot, final UUID uuid); public void removeDenied(final Plot plot, final UUID uuid);
/** /**
* @param plot Plot Object * @param plot Plot Object
* @param uuid Player uuid that should be added * @param uuid Player uuid that should be added
*/ */
public void setDenied(final String world, final Plot plot, final UUID uuid); public void setDenied(final Plot plot, final UUID uuid);
/** /**
* Get Plots ratings * Get Plots ratings
@ -303,7 +303,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param comment Comment to remove * @param comment Comment to remove
*/ */
public void removeComment(final String world, final Plot plot, final PlotComment comment); public void removeComment(final Plot plot, final PlotComment comment);
/** /**
* Clear an inbox * Clear an inbox
@ -319,7 +319,7 @@ public interface AbstractDB {
* @param plot Plot Object * @param plot Plot Object
* @param comment Comment to add * @param comment Comment to add
*/ */
public void setComment(final String world, final Plot plot, final PlotComment comment); public void setComment(final Plot plot, final PlotComment comment);
/** /**
* Get Plot Comments * Get Plot Comments
@ -330,7 +330,7 @@ public interface AbstractDB {
* *
* @return Plot Comments within the specified tier * @return Plot Comments within the specified tier
*/ */
public void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone); public void getComments(final Plot plot, final String inbox, RunnableVal whenDone);
public void createPlotAndSettings(Plot plot); public void createPlotAndSettings(Plot plot);

View File

@ -56,6 +56,9 @@ public class DBFunc {
public static AbstractDB dbManager; public static AbstractDB dbManager;
public static void movePlot(final Plot originalPlot, final Plot newPlot) { public static void movePlot(final Plot originalPlot, final Plot newPlot) {
if (originalPlot.temp || newPlot.temp) {
return;
}
dbManager.movePlot(originalPlot, newPlot); dbManager.movePlot(originalPlot, newPlot);
} }
/** /**
@ -87,6 +90,9 @@ public class DBFunc {
* @param uuid New Owner * @param uuid New Owner
*/ */
public static void setOwner(final Plot plot, final UUID uuid) { public static void setOwner(final Plot plot, final UUID uuid) {
if (plot.temp) {
return;
}
dbManager.setOwner(plot, uuid); dbManager.setOwner(plot, uuid);
} }
@ -105,6 +111,9 @@ public class DBFunc {
* @param plot Plot to create * @param plot Plot to create
*/ */
public static void createPlot(final Plot plot) { public static void createPlot(final Plot plot) {
if (plot.temp) {
return;
}
dbManager.createPlot(plot); dbManager.createPlot(plot);
} }
@ -114,6 +123,9 @@ public class DBFunc {
* @param plot Plot to create * @param plot Plot to create
*/ */
public static void createPlotAndSettings(final Plot plot) { public static void createPlotAndSettings(final Plot plot) {
if (plot.temp) {
return;
}
dbManager.createPlotAndSettings(plot); dbManager.createPlotAndSettings(plot);
} }
@ -131,8 +143,11 @@ public class DBFunc {
* *
* @param plot Plot to delete * @param plot Plot to delete
*/ */
public static void delete(final String world, final Plot plot) { public static void delete(final Plot plot) {
dbManager.delete(world, plot); if (plot.temp) {
return;
}
dbManager.delete(plot);
} }
public static void delete(final PlotCluster toDelete) { public static void delete(final PlotCluster toDelete) {
@ -146,6 +161,9 @@ public class DBFunc {
* @param plot Plot Object * @param plot Plot Object
*/ */
public static void createPlotSettings(final int id, final Plot plot) { public static void createPlotSettings(final int id, final Plot plot) {
if (plot.temp) {
return;
}
dbManager.createPlotSettings(id, plot); dbManager.createPlotSettings(id, plot);
} }
@ -158,7 +176,7 @@ public class DBFunc {
* @return ID * @return ID
*/ */
/* /*
* public static int getId(String world, PlotId id2) { Statement stmt = * public static int getId(String plotId id2) { Statement stmt =
* null; try { stmt = connection.createStatement(); ResultSet r = * null; try { stmt = connection.createStatement(); ResultSet r =
* stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x * stmt.executeQuery("SELECT `id` FROM `plot` WHERE `plot_id_x` = '" + id2.x
* + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world + * + "' AND `plot_id_z` = '" + id2.y + "' AND `world` = '" + world +
@ -178,12 +196,18 @@ public class DBFunc {
return dbManager.getPlots(); return dbManager.getPlots();
} }
public static void setMerged(final String world, final Plot plot, final boolean[] merged) { public static void setMerged(final Plot plot, final boolean[] merged) {
dbManager.setMerged(world, plot, merged); if (plot.temp) {
return;
}
dbManager.setMerged(plot, merged);
} }
public static void setFlags(final String world, final Plot plot, final Collection<Flag> flags) { public static void setFlags(final Plot plot, final Collection<Flag> flags) {
dbManager.setFlags(world, plot, flags); if (plot.temp) {
return;
}
dbManager.setFlags(plot, flags);
} }
public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags) { public static void setFlags(final PlotCluster cluster, final Collection<Flag> flags) {
@ -194,8 +218,11 @@ public class DBFunc {
* @param plot * @param plot
* @param alias * @param alias
*/ */
public static void setAlias(final String world, final Plot plot, final String alias) { public static void setAlias(final Plot plot, final String alias) {
dbManager.setAlias(world, plot, alias); if (plot.temp) {
return;
}
dbManager.setAlias(plot, alias);
} }
public static void purgeIds(final String world, final Set<Integer> uniqueIds) { public static void purgeIds(final String world, final Set<Integer> uniqueIds) {
@ -210,8 +237,11 @@ public class DBFunc {
* @param plot * @param plot
* @param position * @param position
*/ */
public static void setPosition(final String world, final Plot plot, final String position) { public static void setPosition(final Plot plot, final String position) {
dbManager.setPosition(world, plot, position); if (plot.temp) {
return;
}
dbManager.setPosition(plot, position);
} }
/** /**
@ -227,11 +257,17 @@ public class DBFunc {
* @param plot * @param plot
* @param comment * @param comment
*/ */
public static void removeComment(final String world, final Plot plot, final PlotComment comment) { public static void removeComment(final Plot plot, final PlotComment comment) {
dbManager.removeComment(world, plot, comment); if (plot.temp) {
return;
}
dbManager.removeComment(plot, comment);
} }
public static void clearInbox(final Plot plot, final String inbox) { public static void clearInbox(final Plot plot, final String inbox) {
if (plot.temp) {
return;
}
dbManager.clearInbox(plot, inbox); dbManager.clearInbox(plot, inbox);
} }
@ -239,23 +275,32 @@ public class DBFunc {
* @param plot * @param plot
* @param comment * @param comment
*/ */
public static void setComment(final String world, final Plot plot, final PlotComment comment) { public static void setComment(final Plot plot, final PlotComment comment) {
dbManager.setComment(world, plot, comment); if (plot.temp) {
return;
}
dbManager.setComment(plot, comment);
} }
/** /**
* @param plot * @param plot
*/ */
public static void getComments(final String world, final Plot plot, final String inbox, RunnableVal whenDone) { public static void getComments(final Plot plot, final String inbox, RunnableVal whenDone) {
dbManager.getComments(world, plot, inbox, whenDone); if (plot.temp) {
return;
}
dbManager.getComments(plot, inbox, whenDone);
} }
/** /**
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void removeTrusted(final String world, final Plot plot, final UUID uuid) { public static void removeTrusted(final Plot plot, final UUID uuid) {
dbManager.removeTrusted(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.removeTrusted(plot, uuid);
} }
/** /**
@ -286,8 +331,11 @@ public class DBFunc {
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void removeMember(final String world, final Plot plot, final UUID uuid) { public static void removeMember(final Plot plot, final UUID uuid) {
dbManager.removeMember(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.removeMember(plot, uuid);
} }
/** /**
@ -304,8 +352,11 @@ public class DBFunc {
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void setTrusted(final String world, final Plot plot, final UUID uuid) { public static void setTrusted(final Plot plot, final UUID uuid) {
dbManager.setTrusted(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.setTrusted(plot, uuid);
} }
public static void setHelper(final PlotCluster cluster, final UUID uuid) { public static void setHelper(final PlotCluster cluster, final UUID uuid) {
@ -317,12 +368,15 @@ public class DBFunc {
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void setMember(final String world, final Plot plot, final UUID uuid) { public static void setMember(final Plot plot, final UUID uuid) {
dbManager.setMember(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.setMember(plot, uuid);
} }
public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) { public static void setInvited(final String world, final PlotCluster cluster, final UUID uuid) {
dbManager.setInvited(world, cluster, uuid); dbManager.setInvited(cluster, uuid);
} }
/** /**
@ -330,8 +384,11 @@ public class DBFunc {
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void removeDenied(final String world, final Plot plot, final UUID uuid) { public static void removeDenied(final Plot plot, final UUID uuid) {
dbManager.removeDenied(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.removeDenied(plot, uuid);
} }
/** /**
@ -339,8 +396,11 @@ public class DBFunc {
* @param plot * @param plot
* @param uuid * @param uuid
*/ */
public static void setDenied(final String world, final Plot plot, final UUID uuid) { public static void setDenied(final Plot plot, final UUID uuid) {
dbManager.setDenied(world, plot, uuid); if (plot.temp) {
return;
}
dbManager.setDenied(plot, uuid);
} }
public static HashMap<UUID, Integer> getRatings(final Plot plot) { public static HashMap<UUID, Integer> getRatings(final Plot plot) {
@ -348,6 +408,9 @@ public class DBFunc {
} }
public static void setRating(Plot plot, UUID rater, int value) { public static void setRating(Plot plot, UUID rater, int value) {
if (plot.temp) {
return;
}
dbManager.setRating(plot, rater, value); dbManager.setRating(plot, rater, value);
} }

View File

@ -683,13 +683,13 @@ public class SQLManager implements AbstractDB {
* @param plot * @param plot
*/ */
@Override @Override
public void delete(final String world, final Plot plot) { public void delete(final Plot plot) {
PS.get().removePlot(world, plot.id, false); PS.get().removePlot(plot.world, plot.id, false);
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
PreparedStatement stmt = null; PreparedStatement stmt = null;
final int id = getId(world, plot.id); final int id = getId(plot.world, plot.id);
try { try {
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_settings` WHERE `plot_plot_id` = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
@ -708,7 +708,7 @@ public class SQLManager implements AbstractDB {
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_comments` WHERE `world` = ? AND `hashcode` = ?");
stmt.setString(1, world); stmt.setString(1, plot.world);
stmt.setInt(2, plot.hashCode()); stmt.setInt(2, plot.hashCode());
stmt.executeUpdate(); stmt.executeUpdate();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot` WHERE `id` = ?");
@ -1039,7 +1039,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setMerged(final String world, final Plot plot, final boolean[] merged) { public void setMerged(final Plot plot, final boolean[] merged) {
plot.settings.setMerged(merged); plot.settings.setMerged(merged);
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
@ -1051,7 +1051,7 @@ public class SQLManager implements AbstractDB {
} }
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?"); final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `merged` = ? WHERE `plot_plot_id` = ?");
stmt.setInt(1, n); stmt.setInt(1, n);
stmt.setInt(2, getId(world, plot.id)); stmt.setInt(2, getId(plot.world, plot.id));
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
@ -1118,7 +1118,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setFlags(final String world, final Plot plot, final Collection<Flag> flags) { public void setFlags(final Plot plot, final Collection<Flag> flags) {
final StringBuilder flag_string = new StringBuilder(); final StringBuilder flag_string = new StringBuilder();
int i = 0; int i = 0;
for (final Flag flag : flags) { for (final Flag flag : flags) {
@ -1134,7 +1134,7 @@ public class SQLManager implements AbstractDB {
try { try {
final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?"); final PreparedStatement stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `flags` = ? WHERE `plot_plot_id` = ?");
stmt.setString(1, flag_string.toString()); stmt.setString(1, flag_string.toString());
stmt.setInt(2, getId(world, plot.id)); stmt.setInt(2, getId(plot.world, plot.id));
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
@ -1165,8 +1165,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setAlias(final String world, final Plot plot, final String alias) { public void setAlias(final Plot plot, final String alias) {
plot.settings.setAlias(alias);
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1174,7 +1173,7 @@ public class SQLManager implements AbstractDB {
try { try {
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?"); stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `alias` = ? WHERE `plot_plot_id` = ?");
stmt.setString(1, alias); stmt.setString(1, alias);
stmt.setInt(2, getId(world, plot.id)); stmt.setInt(2, getId(plot.world, plot.id));
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
@ -1259,7 +1258,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setPosition(final String world, final Plot plot, final String position) { public void setPosition(final Plot plot, final String position) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1267,7 +1266,7 @@ public class SQLManager implements AbstractDB {
try { try {
stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?"); stmt = SQLManager.this.connection.prepareStatement("UPDATE `" + SQLManager.this.prefix + "plot_settings` SET `position` = ? WHERE `plot_plot_id` = ?");
stmt.setString(1, position); stmt.setString(1, position);
stmt.setInt(2, getId(world, plot.id)); stmt.setInt(2, getId(plot.world, plot.id));
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
@ -1327,7 +1326,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void removeComment(final String world, final Plot plot, final PlotComment comment) { public void removeComment(final Plot plot, final PlotComment comment) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1383,7 +1382,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void getComments(final String world, final Plot plot, final String inbox, final RunnableVal whenDone) { public void getComments(final Plot plot, final String inbox, final RunnableVal whenDone) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1429,7 +1428,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setComment(final String world, final Plot plot, final PlotComment comment) { public void setComment(final Plot plot, final PlotComment comment) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -1452,13 +1451,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void removeTrusted(final String world, final Plot plot, final UUID uuid) { public void removeTrusted(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_helpers` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -1471,13 +1470,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void removeMember(final String world, final Plot plot, final UUID uuid) { public void removeMember(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_trusted` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -1490,13 +1489,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setTrusted(final String world, final Plot plot, final UUID uuid) { public void setTrusted(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_helpers` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -1527,13 +1526,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setMember(final String world, final Plot plot, final UUID uuid) { public void setMember(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_trusted` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -1546,13 +1545,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void removeDenied(final String world, final Plot plot, final UUID uuid) { public void removeDenied(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("DELETE FROM `" + SQLManager.this.prefix + "plot_denied` WHERE `plot_plot_id` = ? AND `user_uuid` = ?");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -1565,13 +1564,13 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setDenied(final String world, final Plot plot, final UUID uuid) { public void setDenied(final Plot plot, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)"); final PreparedStatement statement = SQLManager.this.connection.prepareStatement("INSERT INTO `" + SQLManager.this.prefix + "plot_denied` (`plot_plot_id`, `user_uuid`) VALUES(?,?)");
statement.setInt(1, getId(world, plot.id)); statement.setInt(1, getId(plot.world, plot.id));
statement.setString(2, uuid.toString()); statement.setString(2, uuid.toString());
statement.executeUpdate(); statement.executeUpdate();
statement.close(); statement.close();
@ -2098,7 +2097,7 @@ public class SQLManager implements AbstractDB {
} }
@Override @Override
public void setInvited(final String world, final PlotCluster cluster, final UUID uuid) { public void setInvited(final PlotCluster cluster, final UUID uuid) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTaskAsync(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -175,7 +175,7 @@ public class ClassicPlotMeConnector extends APlotMeConnector {
else { else {
UUIDHandler.add(new StringWrapper(name), owner); UUIDHandler.add(new StringWrapper(name), owner);
} }
final Plot plot = new Plot(id, owner, new ArrayList<UUID>(), new ArrayList<UUID>(), world); final Plot plot = new Plot(world, id, owner);
plots.get(world).put(id, plot); plots.get(world).put(id, plot);
} }

View File

@ -196,7 +196,7 @@ public class FlagManager {
return false; return false;
} }
plot.settings.flags.put(flag.getKey(), flag); plot.settings.flags.put(flag.getKey(), flag);
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
return true; return true;
} }
@ -249,7 +249,7 @@ public class FlagManager {
plot.settings.flags.put(id, flag); plot.settings.flags.put(id, flag);
return false; return false;
} }
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
return true; return true;
} }
@ -280,7 +280,7 @@ public class FlagManager {
else { else {
plot.settings.flags.clear(); plot.settings.flags.clear();
} }
DBFunc.setFlags(plot.world, plot, plot.settings.flags.values()); DBFunc.setFlags(plot, plot.settings.flags.values());
} }
public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) { public static void setClusterFlags(final PlotCluster cluster, final Set<Flag> flags) {

View File

@ -1132,10 +1132,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) { if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) {
final Collection<Plot> plots = PS.get().getPlots(pp.getName()).values(); final Collection<Plot> plots = PS.get().getPlots(pp.getName()).values();
for (final Plot plot : plots) { for (final Plot plot : plots) {
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world); plot.delete();
final PlotManager manager = PS.get().getPlotManager(plot.world);
manager.clearPlot(plotworld, plot, true, null);
DBFunc.delete(plot.world, plot);
PS.log(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), event.getPlayer().getName())); PS.log(String.format("&cPlot &6%s &cwas deleted + cleared due to &6%s&c getting banned", plot.getId(), event.getPlayer().getName()));
} }
} }

View File

@ -27,8 +27,11 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.Flag;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
/** /**
* The plot class * The plot class
@ -50,10 +53,6 @@ public class Plot implements Cloneable {
* plot owner * plot owner
*/ */
public UUID owner; public UUID owner;
/**
* Deny Entry
*/
public boolean deny_entry;
/** /**
* List of trusted (with plot permissions) * List of trusted (with plot permissions)
*/ */
@ -70,40 +69,56 @@ public class Plot implements Cloneable {
* External settings class * External settings class
*/ */
public PlotSettings settings; public PlotSettings settings;
/**
* Delete on next save cycle?
*/
public boolean delete;
/** /**
* Has the plot changed since the last save cycle? * Has the plot changed since the last save cycle?
*/ */
public boolean hasChanged = false; public boolean hasChanged = false;
public boolean countsTowardsMax = true; public boolean countsTowardsMax = true;
/**
* If this plot is temporary i.e. not stored in the DB
*/
public final boolean temp;
/** /**
* Primary constructor * Constructor for a new plot
* *
* @param world
* @param id * @param id
* @param owner * @param owner
* @param trusted
* @param denied
*/ */
public Plot(final PlotId id, final UUID owner, final ArrayList<UUID> trusted, final ArrayList<UUID> denied, final String world) { public Plot(String world, PlotId id, UUID owner) {
this.id = id;
this.settings = new PlotSettings(this);
this.owner = owner;
this.deny_entry = this.owner == null;
this.trusted = trusted;
this.denied = denied;
this.members = new ArrayList<>();
this.settings.setAlias("");
this.delete = false;
this.settings.flags = new HashMap<>();
this.world = world; this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new ArrayList<>();
this.members = new ArrayList<>();
this.denied = new ArrayList<>();
this.temp = false;
} }
/** /**
* Constructor for saved plots * Constructor for a temporary plot
*
* @param world
* @param id
* @param owner
* @param temp
*/
public Plot(String world, PlotId id, UUID owner, boolean temp) {
this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new ArrayList<>();
this.members = new ArrayList<>();
this.denied = new ArrayList<>();
this.temp = temp;
}
/**
* Constructor for a saved plots
* *
* @param id * @param id
* @param owner * @param owner
@ -115,21 +130,19 @@ public class Plot implements Cloneable {
this.id = id; this.id = id;
this.settings = new PlotSettings(this); this.settings = new PlotSettings(this);
this.owner = owner; this.owner = owner;
this.deny_entry = this.owner != null;
this.members = members; this.members = members;
this.trusted = trusted; this.trusted = trusted;
this.denied = denied; this.denied = denied;
this.settings.setAlias(alias); this.settings.setAlias(alias);
this.settings.setPosition(position); this.settings.setPosition(position);
this.settings.setMerged(merged); this.settings.setMerged(merged);
this.delete = false;
this.settings.flags = new HashMap<>();
if (flags != null) { if (flags != null) {
for (Flag flag : flags) { for (Flag flag : flags) {
this.settings.flags.put(flag.getKey(), flag); this.settings.flags.put(flag.getKey(), flag);
} }
} }
this.world = world; this.world = world;
this.temp = false;
} }
/** /**
@ -202,7 +215,7 @@ public class Plot implements Cloneable {
* @param uuid * @param uuid
*/ */
public void addDenied(final UUID uuid) { public void addDenied(final UUID uuid) {
this.denied.add(uuid); if (this.denied.add(uuid)) DBFunc.setDenied(this, uuid);
} }
/** /**
@ -211,7 +224,7 @@ public class Plot implements Cloneable {
* @param uuid * @param uuid
*/ */
public void addTrusted(final UUID uuid) { public void addTrusted(final UUID uuid) {
this.trusted.add(uuid); if (this.trusted.add(uuid)) DBFunc.setTrusted(this, uuid);
} }
/** /**
@ -220,9 +233,223 @@ public class Plot implements Cloneable {
* @param uuid * @param uuid
*/ */
public void addMember(final UUID uuid) { public void addMember(final UUID uuid) {
this.members.add(uuid); if (this.members.add(uuid)) DBFunc.setMember(this, uuid);
} }
/**
* Set the plot owner
* @param owner
*/
public void setOwner(final UUID owner) {
if (!this.owner.equals(owner)) {
this.owner = owner;
DBFunc.setOwner(this, owner);
}
}
/**
* Clear a plot
* @see MainUtil#clear(Plot, boolean, Runnable)
* @see MainUtil#clearAsPlayer(Plot, boolean, Runnable)
* @see #delete() to clear and delete a plot
* @param whenDone A runnable to execute when clearing finishes, or null
*/
public void clear(Runnable whenDone) {
MainUtil.clear(this, false, whenDone);
}
/**
* Delete a plot
* @see PS#removePlot(String, PlotId, boolean)
* @see #clear(Runnable) to simply clear a plot
*/
public void delete() {
MainUtil.removeSign(this);
MainUtil.clear(this, true, new Runnable() {
@Override
public void run() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
}
}
});
}
public void unclaim() {
if (PS.get().removePlot(world, id, true)) {
DBFunc.delete(Plot.this);
}
}
/**
* Unlink a plot and remove the roads
* @see MainUtil#unlinkPlot(Plot)
* @return true if plot was linked
*/
public boolean unlink() {
return MainUtil.unlinkPlot(this);
}
/**
* Return the home location for the plot
* @see MainUtil#getPlotHome(Plot)
* @return Home location
*/
public Location getHome() {
return MainUtil.getPlotHome(this);
}
/**
* Set the home location
* @param loc
*/
public void setHome(BlockLoc loc) {
BlockLoc pos = this.settings.getPosition();
if ((pos == null && loc == null) || (pos != null && pos.equals(loc))) {
return;
}
this.settings.setPosition(loc);
if (this.settings.getPosition() == null) {
DBFunc.setPosition(this, "");
}
else {
DBFunc.setPosition(this, this.settings.getPosition().toString());
}
}
/**
* Set the plot alias
* @param alias
*/
public void setAlias(String alias) {
String name = this.settings.getAlias();
if (alias == null) {
alias = "";
}
if (name.equals(alias)) {
return;
}
this.settings.setAlias(alias);
DBFunc.setAlias(this, alias);
}
/**
* Resend all chunks inside the plot to nearby players<br>
* This should not need to be called
* @see MainUtil#update(Plot)
*/
public void refreshChunks() {
MainUtil.update(this);
}
/**
* Remove the plot sign if it is set
*/
public void removeSign() {
MainUtil.removeSign(this);
}
/**
* Set the plot sign if plot signs are enabled
*/
public void setSign() {
MainUtil.setSign(this);
}
/**
* Register a plot and create it in the database<br>
* - The plot will not be created if the owner is null<br>
* - This will not save any trusted etc in the DB, those should be set after plot creation
* @return true if plot was created successfully
*/
public boolean create() {
return MainUtil.createPlot(owner, this);
}
/**
* Auto merge the plot with any adjacent plots of the same owner
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
*/
public void autoMerge() {
MainUtil.autoMerge(this, owner);
}
/**
* Set the plot biome
*/
public void setBiome(String biome) {
MainUtil.setBiome(this, biome);
}
/**
* Return the top location for the plot
* @return
*/
public Location getTop() {
return MainUtil.getPlotTopLoc(world, id);
}
/**
* Return the bottom location for the plot
* @return
*/
public Location getBottom() {
return MainUtil.getPlotBottomLoc(world, id);
}
/**
* Get the top plot, or this plot if it is not part of a mega plot
* @return The bottom plot
*/
public Plot getTopPlot() {
return MainUtil.getTopPlot(this);
}
/**
* Get the bottom plot, or this plot if it is not part of a mega plot
* @return The bottom plot
*/
public Plot getBottomPlot() {
return MainUtil.getBottomPlot(this);
}
/**
* Swap the plot contents and settings with another location<br>
* - The destination must correspond to a valid plot of equal dimensions
* @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 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(PlotId destination, Runnable whenDone) {
return MainUtil.swap(world, id, destination, whenDone);
}
/**
* Move the plot to an empty location<br>
* - The location must be empty
* @param destination Where to move the plot
* @param whenDone A task to run when done, or null
* @return if the move was successful
*/
public boolean move(Plot destination, Runnable whenDone) {
return MainUtil.move(this, destination, whenDone);
}
/**
* Copy the plot contents and settings to another location<br>
* - The destination must correspond to an empty location
* @param destination The location to copy to
* @param whenDone The task to run when done
* @return If the copy was successful
*/
public boolean copy(PlotId destination, Runnable whenDone) {
return MainUtil.copy(world, id, destination, whenDone);
}
/** /**
* Get plot display name * Get plot display name
* *
@ -241,8 +468,12 @@ public class Plot implements Cloneable {
* *
* @param uuid * @param uuid
*/ */
public void removeDenied(final UUID uuid) { public boolean removeDenied(final UUID uuid) {
this.denied.remove(uuid); if (this.denied.remove(uuid)) {
DBFunc.removeDenied(this, uuid);
return true;
}
return false;
} }
/** /**
@ -250,8 +481,12 @@ public class Plot implements Cloneable {
* *
* @param uuid * @param uuid
*/ */
public void removeHelper(final UUID uuid) { public boolean removeTrusted(final UUID uuid) {
this.trusted.remove(uuid); if (this.trusted.remove(uuid)) {
DBFunc.removeTrusted(this, uuid);
return true;
}
return false;
} }
/** /**
@ -259,8 +494,12 @@ public class Plot implements Cloneable {
* *
* @param uuid * @param uuid
*/ */
public void removeTrusted(final UUID uuid) { public boolean removeMember(final UUID uuid) {
this.members.remove(uuid); if (this.members.remove(uuid)) {
DBFunc.removeMember(this, uuid);
return true;
}
return false;
} }
@Override @Override

View File

@ -79,6 +79,7 @@ public class PlotSettings {
public PlotSettings(final Plot plot) { public PlotSettings(final Plot plot) {
this.alias = ""; this.alias = "";
this.plot = plot; this.plot = plot;
this.flags = new HashMap<>();
} }
/** /**

View File

@ -47,7 +47,7 @@ public class InboxOwner extends CommentInbox {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true; return true;
} }
DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
whenDone.value = value; whenDone.value = value;
@ -68,7 +68,7 @@ public class InboxOwner extends CommentInbox {
return false; return false;
} }
plot.settings.addComment(comment); plot.settings.addComment(comment);
DBFunc.setComment(plot.world, plot, comment); DBFunc.setComment(plot, comment);
return true; return true;
} }
@ -82,7 +82,7 @@ public class InboxOwner extends CommentInbox {
if (plot == null || plot.owner == null) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.removeComment(plot.world, plot, comment); DBFunc.removeComment(plot, comment);
return false; return false;
} }

View File

@ -47,7 +47,7 @@ public class InboxPublic extends CommentInbox {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return true; return true;
} }
DBFunc.getComments(plot.world, plot, toString(), new RunnableVal() { DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
whenDone.value = value; whenDone.value = value;
@ -68,7 +68,7 @@ public class InboxPublic extends CommentInbox {
return false; return false;
} }
plot.settings.addComment(comment); plot.settings.addComment(comment);
DBFunc.setComment(plot.world, plot, comment); DBFunc.setComment(plot, comment);
return true; return true;
} }
@ -82,7 +82,7 @@ public class InboxPublic extends CommentInbox {
if (plot == null || plot.owner == null) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.removeComment(plot.world, plot, comment); DBFunc.removeComment(plot, comment);
return false; return false;
} }

View File

@ -36,7 +36,7 @@ public class InboxReport extends CommentInbox {
@Override @Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) { public boolean getComments(final Plot plot, final RunnableVal whenDone) {
DBFunc.getComments(null, null, toString(), new RunnableVal() { DBFunc.getComments(null, toString(), new RunnableVal() {
@Override @Override
public void run() { public void run() {
whenDone.value = value; whenDone.value = value;
@ -51,7 +51,7 @@ public class InboxReport extends CommentInbox {
if (plot == null || plot.owner == null) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.setComment(plot.world, plot, comment); DBFunc.setComment(plot, comment);
return true; return true;
} }
@ -65,7 +65,7 @@ public class InboxReport extends CommentInbox {
if (plot == null || plot.owner == null) { if (plot == null || plot.owner == null) {
return false; return false;
} }
DBFunc.removeComment(plot.world, plot, comment); DBFunc.removeComment(plot, comment);
return false; return false;
} }

View File

@ -132,10 +132,7 @@ public class ExpireManager {
if (plot.settings.isMerged()) { if (plot.settings.isMerged()) {
MainUtil.unlinkPlot(plot); MainUtil.unlinkPlot(plot);
} }
manager.clearPlot(plotworld, plot, false, null); plot.delete();
MainUtil.removeSign(plot);
DBFunc.delete(world, plot);
PS.get().removePlot(world, plot.id, false);
expiredPlots.get(world).remove(plot); expiredPlots.get(world).remove(plot);
PS.log("&7[&5Expire&dManager&7] &cDeleted expired plot: " + plot.id + (changed != -1 ? " (changed " + value + ")" : "")); PS.log("&7[&5Expire&dManager&7] &cDeleted expired plot: " + plot.id + (changed != -1 ? " (changed " + value + ")" : ""));
PS.log("&3 - World: " + plot.world); PS.log("&3 - World: " + plot.world);

View File

@ -175,9 +175,8 @@ public class MainUtil {
if (plot.denied != null) { if (plot.denied != null) {
myplot.denied = plot.denied; myplot.denied = plot.denied;
} }
myplot.deny_entry = plot.deny_entry;
myplot.settings.setMerged(new boolean[] { false, false, false, false }); myplot.settings.setMerged(new boolean[] { false, false, false, false });
DBFunc.setMerged(world, myplot, myplot.settings.getMerged()); DBFunc.setMerged(myplot, myplot.settings.getMerged());
} }
if (plotworld.TERRAIN != 3) { if (plotworld.TERRAIN != 3) {
for (int x = pos1.x; x <= pos2.x; x++) { for (int x = pos1.x; x <= pos2.x; x++) {
@ -345,7 +344,7 @@ public class MainUtil {
if (result) { if (result) {
final Location location; final Location location;
if (PS.get().getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) { if (PS.get().getPlotWorld(plot.world).HOME_ALLOW_NONMEMBER || plot.isAdded(player.getUUID())) {
location = MainUtil.getPlotHome(bot.world, bot); location = MainUtil.getPlotHome(bot);
} }
else { else {
location = getDefaultHome(plot); location = getDefaultHome(plot);
@ -532,7 +531,7 @@ public class MainUtil {
for (int y = pos1.y; y <= pos2.y; y++) { for (int y = pos1.y; y <= pos2.y; y++) {
final PlotId id = new PlotId(x, y); final PlotId id = new PlotId(x, y);
final Plot plot = PS.get().getPlots(world).get(id); final Plot plot = PS.get().getPlots(world).get(id);
DBFunc.setMerged(world, plot, plot.settings.getMerged()); DBFunc.setMerged(plot, plot.settings.getMerged());
} }
} }
manager.finishPlotMerge(plotworld, plotIds); manager.finishPlotMerge(plotworld, plotIds);
@ -633,6 +632,14 @@ public class MainUtil {
final Location loc = manager.getSignLoc(plotworld, p); final Location loc = manager.getSignLoc(plotworld, p);
BlockManager.setBlocks(world, new int[] { loc.getX() }, new int[] { loc.getY() }, new int[] { loc.getZ() }, new int[] { 0 }, new byte[] { 0 }); BlockManager.setBlocks(world, new int[] { loc.getX() }, new int[] { loc.getY() }, new int[] { loc.getZ() }, new int[] { 0 }, new byte[] { 0 });
} }
public static void setSign(final Plot p) {
if (p.owner == null) {
setSign(null, p);
return;
}
setSign(UUIDHandler.getName(p.owner), p);
}
public static void setSign(String name, final Plot p) { public static void setSign(String name, final Plot p) {
if (name == null) { if (name == null) {
@ -655,7 +662,7 @@ public class MainUtil {
return string; return string;
} }
public static void autoMerge(final String world, final Plot plot, final UUID uuid) { public static void autoMerge(final Plot plot, final UUID uuid) {
if (plot == null) { if (plot == null) {
return; return;
} }
@ -676,32 +683,32 @@ public class MainUtil {
final PlotId bot = getBottomPlot(plot).id; final PlotId bot = getBottomPlot(plot).id;
final PlotId top = getTopPlot(plot).id; final PlotId top = getTopPlot(plot).id;
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, uuid, 0)) { if (ownsPlots(plot.world, plots, uuid, 0)) {
final boolean result = mergePlots(world, plots, true); final boolean result = mergePlots(plot.world, plots, true);
if (result) { if (result) {
merge = true; merge = true;
continue; continue;
} }
} }
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
if (ownsPlots(world, plots, uuid, 1)) { if (ownsPlots(plot.world, plots, uuid, 1)) {
final boolean result = mergePlots(world, plots, true); final boolean result = mergePlots(plot.world, plots, true);
if (result) { if (result) {
merge = true; merge = true;
continue; continue;
} }
} }
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
if (ownsPlots(world, plots, uuid, 2)) { if (ownsPlots(plot.world, plots, uuid, 2)) {
final boolean result = mergePlots(world, plots, true); final boolean result = mergePlots(plot.world, plots, true);
if (result) { if (result) {
merge = true; merge = true;
continue; continue;
} }
} }
plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
if (ownsPlots(world, plots, uuid, 3)) { if (ownsPlots(plot.world, plots, uuid, 3)) {
final boolean result = mergePlots(world, plots, true); final boolean result = mergePlots(plot.world, plots, true);
if (result) { if (result) {
merge = true; merge = true;
continue; continue;
@ -757,9 +764,12 @@ public class MainUtil {
updateWorldBorder(plot); updateWorldBorder(plot);
} }
final Plot p = createPlotAbs(uuid, plot); final Plot p = createPlotAbs(uuid, plot);
if (p == null) {
return false;
}
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world); final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
if (plotworld.AUTO_MERGE) { if (plotworld.AUTO_MERGE) {
autoMerge(plot.world, p, uuid); autoMerge(p, uuid);
} }
return true; return true;
} }
@ -769,7 +779,15 @@ public class MainUtil {
*/ */
public static Plot createPlotAbs(final UUID uuid, final Plot plot) { public static Plot createPlotAbs(final UUID uuid, final Plot plot) {
final String w = plot.world; final String w = plot.world;
final Plot p = new Plot(plot.id, uuid, new ArrayList<UUID>(), new ArrayList<UUID>(), w); HashMap<PlotId, Plot> plots = PS.get().getPlots(plot.world);
Plot p = plots.get(plot.id);
if (p != null) {
return p;
}
p = new Plot(w, plot.id, uuid);
if (p.owner == null) {
return null;
}
PS.get().updatePlot(p); PS.get().updatePlot(p);
DBFunc.createPlotAndSettings(p); DBFunc.createPlotAndSettings(p);
return p; return p;
@ -803,24 +821,24 @@ public class MainUtil {
return false; return false;
} }
ChunkManager.manager.clearAllEntities(plot); ChunkManager.manager.clearAllEntities(plot);
clear(plot.world, plot, isDelete, whenDone); clear(plot, isDelete, whenDone);
removeSign(plot); removeSign(plot);
return true; return true;
} }
public static void clear(final String world, final Plot plot, final boolean isDelete, final Runnable whenDone) { public static void clear(final Plot plot, final boolean isDelete, final Runnable whenDone) {
final PlotManager manager = PS.get().getPlotManager(world); final PlotManager manager = PS.get().getPlotManager(plot.world);
final Location pos1 = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1); final Location pos1 = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1);
final int prime = 31; final int prime = 31;
int h = 1; int h = 1;
h = (prime * h) + pos1.getX(); h = (prime * h) + pos1.getX();
h = (prime * h) + pos1.getZ(); h = (prime * h) + pos1.getZ();
state = h; state = h;
System.currentTimeMillis(); System.currentTimeMillis();
final PlotWorld plotworld = PS.get().getPlotWorld(world); final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
runners.put(plot, 1); runners.put(plot, 1);
if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) { if (plotworld.TERRAIN != 0 || Settings.FAST_CLEAR) {
final Location pos2 = MainUtil.getPlotTopLoc(world, plot.id); final Location pos2 = MainUtil.getPlotTopLoc(plot.world, plot.id);
ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() { ChunkManager.manager.regenerateRegion(pos1, pos2, new Runnable() {
@Override @Override
public void run() { public void run() {
@ -919,12 +937,12 @@ public class MainUtil {
} }
} }
public static void setBiome(final String world, final Plot plot, final String biome) { public static void setBiome(final Plot plot, final String biome) {
final int bottomX = getPlotBottomLoc(world, plot.id).getX() + 1; final int bottomX = getPlotBottomLoc(plot.world, plot.id).getX() + 1;
final int topX = getPlotTopLoc(world, plot.id).getX(); final int topX = getPlotTopLoc(plot.world, plot.id).getX();
final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1; final int bottomZ = getPlotBottomLoc(plot.world, plot.id).getZ() + 1;
final int topZ = getPlotTopLoc(world, plot.id).getZ(); final int topZ = getPlotTopLoc(plot.world, plot.id).getZ();
BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome); BukkitUtil.setBiome(plot.world, bottomX, bottomZ, topX, topZ, biome);
update(plot); update(plot);
} }
@ -967,8 +985,8 @@ public class MainUtil {
* *
* @see #getPlotHome(String, Plot) * @see #getPlotHome(String, Plot)
*/ */
public static Location getPlotHome(final String w, final Plot plot) { public static Location getPlotHome(final Plot plot) {
return getPlotHome(w, plot.id); return getPlotHome(plot.world, plot.id);
} }
/** /**
@ -1160,7 +1178,7 @@ public class MainUtil {
} }
final Plot pos1 = getBottomPlot(plot1); final Plot pos1 = getBottomPlot(plot1);
final Plot pos2 = getTopPlot(plot1); final Plot pos2 = getTopPlot(plot1);
final PlotId size = MainUtil.getSize(plot1.world, plot1); final PlotId size = MainUtil.getSize(plot1);
if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) {
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return false; return false;
@ -1190,7 +1208,7 @@ public class MainUtil {
} }
final Plot pos1 = getBottomPlot(plot1); final Plot pos1 = getBottomPlot(plot1);
final Plot pos2 = getTopPlot(plot1); final Plot pos2 = getTopPlot(plot1);
final PlotId size = MainUtil.getSize(plot1.world, plot1); final PlotId size = MainUtil.getSize(plot1);
if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) { if (!MainUtil.isUnowned(plot2.world, plot2.id, new PlotId((plot2.id.x + size.x) - 1, (plot2.id.y + size.y) - 1))) {
return false; return false;
} }
@ -1230,7 +1248,7 @@ public class MainUtil {
} }
final Plot pos1 = getBottomPlot(currentPlot); final Plot pos1 = getBottomPlot(currentPlot);
final Plot pos2 = getTopPlot(currentPlot); final Plot pos2 = getTopPlot(currentPlot);
final PlotId size = MainUtil.getSize(world, currentPlot); final PlotId size = MainUtil.getSize(currentPlot);
if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) { if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return false; return false;
@ -1244,28 +1262,28 @@ public class MainUtil {
Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y))); Plot plot = createPlotAbs(currentPlot.owner, getPlot(world, new PlotId(x, y)));
if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) { if (currentPlot.settings.flags != null && currentPlot.settings.flags.size() > 0) {
plot.settings.flags = currentPlot.settings.flags; plot.settings.flags = currentPlot.settings.flags;
DBFunc.setFlags(world, plot, currentPlot.settings.flags.values()); DBFunc.setFlags(plot, currentPlot.settings.flags.values());
} }
if (currentPlot.settings.isMerged()) { if (currentPlot.settings.isMerged()) {
plot.settings.setMerged(currentPlot.settings.getMerged()); plot.settings.setMerged(currentPlot.settings.getMerged());
DBFunc.setMerged(world, plot, currentPlot.settings.getMerged()); DBFunc.setMerged(plot, currentPlot.settings.getMerged());
} }
if (currentPlot.members != null && currentPlot.members.size() > 0) { if (currentPlot.members != null && currentPlot.members.size() > 0) {
plot.members = currentPlot.members; plot.members = currentPlot.members;
for (UUID member : plot.members) { for (UUID member : plot.members) {
DBFunc.setMember(world, plot, member); DBFunc.setMember(plot, member);
} }
} }
if (currentPlot.trusted != null && currentPlot.trusted.size() > 0) { if (currentPlot.trusted != null && currentPlot.trusted.size() > 0) {
plot.members = currentPlot.trusted; plot.members = currentPlot.trusted;
for (UUID trusted : plot.trusted) { for (UUID trusted : plot.trusted) {
DBFunc.setTrusted(world, plot, trusted); DBFunc.setTrusted(plot, trusted);
} }
} }
if (currentPlot.denied != null && currentPlot.denied.size() > 0) { if (currentPlot.denied != null && currentPlot.denied.size() > 0) {
plot.members = currentPlot.denied; plot.members = currentPlot.denied;
for (UUID denied : plot.denied) { for (UUID denied : plot.denied) {
DBFunc.setDenied(world, plot, denied); DBFunc.setDenied(plot, denied);
} }
} }
PS.get().getPlots(world).put(plot.id, plot); PS.get().getPlots(world).put(plot.id, plot);
@ -1470,7 +1488,7 @@ public class MainUtil {
} }
public static PlotId getSize(final String world, final Plot plot) { public static PlotId getSize(final Plot plot) {
final PlotSettings settings = plot.settings; final PlotSettings settings = plot.settings;
if (!settings.isMerged()) { if (!settings.isMerged()) {
return new PlotId(1, 1); return new PlotId(1, 1);
@ -1490,7 +1508,7 @@ public class MainUtil {
if (PS.get().getPlots(world).containsKey(id)) { if (PS.get().getPlots(world).containsKey(id)) {
return PS.get().getPlots(world).get(id); return PS.get().getPlots(world).get(id);
} }
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world); return new Plot(world, id, null);
} }
/** /**

View File

@ -121,7 +121,7 @@ public class BukkitPlayerFunctions {
if (PS.get().getPlots(world).containsKey(id)) { if (PS.get().getPlots(world).containsKey(id)) {
return PS.get().getPlots(world).get(id); return PS.get().getPlots(world).get(id);
} }
return new Plot(id, null, new ArrayList<UUID>(), new ArrayList<UUID>(), world); return new Plot(world, id, null);
} }
/** /**