Lazy initialization

This commit is contained in:
boy0001
2015-07-22 04:31:12 +10:00
parent 59c672d9a8
commit 95ad199f52
37 changed files with 263 additions and 207 deletions

View File

@ -72,7 +72,7 @@ public class Add extends SubCommand {
return false;
}
if (plot.members.contains(uuid)) {
if (plot.getMembers().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
@ -80,11 +80,11 @@ public class Add extends SubCommand {
plot.addMember(uuid);
}
else {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.denied.contains(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
plot.addMember(uuid);

View File

@ -176,7 +176,7 @@ 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.settings.isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
if (MainUtil.canClaim(plr, current) && (current.getSettings().isMerged() == false) && cluster.equals(ClusterManager.getCluster(current))) {
Claim.claimPlot(plr, current, true, true);
return true;
}

View File

@ -47,7 +47,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.settings.isMerged()) {
if (plot.hasOwner() || plot.getSettings().isMerged()) {
return false;
}
final boolean result = EventUtil.manager.callClaim(player, plot, false);

View File

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

View File

@ -221,9 +221,9 @@ public class DebugUUID extends SubCommand {
if (value != null) {
plot.owner = value;
}
plot.trusted = new HashSet<>();
plot.members = new HashSet<>();
plot.denied = new HashSet<>();
plot.getTrusted().clear();
plot.getMembers().clear();
plot.getDenied().clear();
}
MainUtil.sendConsoleMessage("&7 - Deleting database");

View File

@ -75,7 +75,7 @@ public class Deny extends SubCommand {
return false;
}
if (plot.denied.contains(uuid)) {
if (plot.getDenied().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}

View File

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

View File

@ -38,7 +38,7 @@ public class Home extends SubCommand {
private Plot isAlias(final String a) {
for (final Plot p : PS.get().getPlots()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
}

View File

@ -156,7 +156,7 @@ public class Inbox extends SubCommand {
}
PlotComment comment = comments.get(index - 1);
inbox.removeComment(plot, comment);
plot.settings.removeComment(comment);
plot.getSettings().removeComment(comment);
MainUtil.sendMessage(player, C.COMMENT_REMOVED, comment.comment);
}
})) {
@ -170,9 +170,9 @@ public class Inbox extends SubCommand {
sendMessage(player, C.NO_PERM_INBOX_MODIFY);
}
inbox.clearInbox(plot);
ArrayList<PlotComment> comments = plot.settings.getComments(inbox.toString());
ArrayList<PlotComment> comments = plot.getSettings().getComments(inbox.toString());
if (comments != null) {
plot.settings.removeComments(comments);
plot.getSettings().removeComments(comments);
}
MainUtil.sendMessage(player, C.COMMENT_REMOVED, "*");
return true;

View File

@ -144,8 +144,8 @@ public class Info extends SubCommand {
boolean trustedEveryone;
// Wildcard player {added}
{
containsEveryone = (plot.trusted != null) && plot.trusted.contains(DBFunc.everyone);
trustedEveryone = (plot.members != null) && plot.members.contains(DBFunc.everyone);
containsEveryone = (plot.getTrusted() != null) && plot.getTrusted().contains(DBFunc.everyone);
trustedEveryone = (plot.getMembers() != null) && plot.getMembers().contains(DBFunc.everyone);
}
// Unclaimed?
if (!hasOwner && !containsEveryone && !trustedEveryone) {
@ -198,18 +198,18 @@ public class Info extends SubCommand {
final PlotId id = plot.id;
final PlotId id2 = MainUtil.getTopPlot(plot).id;
final int num = MainUtil.getPlotSelectionIds(id, id2).size();
final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : C.NONE.s();
final String alias = plot.getSettings().getAlias().length() > 0 ? plot.getSettings().getAlias() : C.NONE.s();
Location top = MainUtil.getPlotTopLoc(world, plot.id);
Location bot = MainUtil.getPlotBottomLoc(world, plot.id).add(1, 0, 1);
final String biome = BlockManager.manager.getBiome(bot.add((top.getX() - bot.getX()) / 2, 0, (top.getX() - bot.getX()) / 2));
final String trusted = getPlayerList(plot.trusted);
final String members = getPlayerList(plot.members);
final String denied = getPlayerList(plot.denied);
final String trusted = getPlayerList(plot.getTrusted());
final String members = getPlayerList(plot.getMembers());
final String denied = getPlayerList(plot.getDenied());
Flag descriptionFlag = FlagManager.getPlotFlag(plot, "description");
final String description = descriptionFlag == null ? C.NONE.s() : descriptionFlag.getValueString();
final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.settings, true).values(), "$1, $2") : C.NONE.s()), C.replacements);
final String flags = StringMan.replaceFromMap("$2" + (StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "").length() > 0 ? StringUtils.join(FlagManager.getPlotFlags(plot.world, plot.getSettings(), true).values(), "$1, $2") : C.NONE.s()), C.replacements);
final boolean build = (player == null) || plot.isAdded(player.getUUID());
String owner = plot.owner == null ? "unowned" : getPlayerList(plot.getOwners());

View File

@ -63,12 +63,12 @@ public class Rate extends SubCommand {
public int compare(Plot p1, Plot p2) {
double v1 = 0;
double v2 = 0;
if (p1.settings.ratings != null) {
if (p1.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
v1 -= 11 - entry.getValue().getAverageRating();
}
}
if (p2.settings.ratings != null) {
if (p2.getSettings().ratings != null) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
v2 -= 11 - entry.getValue().getAverageRating();
}
@ -78,7 +78,7 @@ public class Rate extends SubCommand {
});
UUID uuid = player.getUUID();
for (Plot p : plots) {
if ((p.settings.ratings == null || !p.settings.ratings.containsKey(uuid)) && !p.isAdded(uuid)) {
if ((p.getSettings().ratings == null || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) {
MainUtil.teleportPlayer(player, player.getLocation(), p);
MainUtil.sendMessage(player, C.RATE_THIS);
return true;
@ -105,7 +105,7 @@ public class Rate extends SubCommand {
final Runnable run = new Runnable() {
@Override
public void run() {
if (plot.settings.ratings.containsKey(player.getUUID())) {
if (plot.getSettings().ratings.containsKey(player.getUUID())) {
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
@ -127,7 +127,7 @@ public class Rate extends SubCommand {
// get new rating
rV = rateEvent.getRating();
// set rating
plot.settings.ratings.put(player.getUUID(), rV);
plot.getSettings().ratings.put(player.getUUID(), rV);
DBFunc.setRating(plot, player.getUUID(), rV);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
@ -149,11 +149,11 @@ public class Rate extends SubCommand {
inventory.openInventory();
}
};
if (plot.settings.ratings == null) {
if (plot.getSettings().ratings == null) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
plot.settings.ratings = DBFunc.getRatings(plot);
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}
});
@ -187,20 +187,20 @@ public class Rate extends SubCommand {
final Runnable run = new Runnable() {
@Override
public void run() {
if (plot.settings.ratings.containsKey(uuid)) {
if (plot.getSettings().ratings.containsKey(uuid)) {
sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return;
}
plot.settings.ratings.put(uuid, rating);
plot.getSettings().ratings.put(uuid, rating);
DBFunc.setRating(plot, uuid, rating);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
}
};
if (plot.settings.ratings == null) {
if (plot.getSettings().ratings == null) {
TaskManager.runTaskAsync(new Runnable() {
@Override
public void run() {
plot.settings.ratings = DBFunc.getRatings(plot);
plot.getSettings().ratings = DBFunc.getRatings(plot);
run.run();
}
});

View File

@ -60,9 +60,9 @@ public class Remove extends SubCommand {
if (args[0].equals("unknown")) {
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
all.addAll(plot.members);
all.addAll(plot.trusted);
all.addAll(plot.denied);
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
@ -78,9 +78,9 @@ public class Remove extends SubCommand {
else if (args[0].equals("*")){
ArrayList<UUID> toRemove = new ArrayList<>();
HashSet<UUID> all = new HashSet<>();
all.addAll(plot.members);
all.addAll(plot.trusted);
all.addAll(plot.denied);
all.addAll(plot.getMembers());
all.addAll(plot.getTrusted());
all.addAll(plot.getDenied());
for (UUID uuid : all) {
toRemove.add(uuid);
count++;
@ -94,17 +94,17 @@ public class Remove extends SubCommand {
else {
UUID uuid = UUIDHandler.getUUID(args[0]);
if (uuid != null) {
if (plot.trusted.contains(uuid)) {
if (plot.getTrusted().contains(uuid)) {
if (plot.removeTrusted(uuid)) {
count++;
}
}
else if (plot.members.contains(uuid)) {
else if (plot.getMembers().contains(uuid)) {
if (plot.removeMember(uuid)) {
count++;
}
}
else if (plot.denied.contains(uuid)) {
else if (plot.getDenied().contains(uuid)) {
if (plot.removeDenied(uuid)) {
count++;
}

View File

@ -123,10 +123,9 @@ public class SchematicCmd extends SubCommand {
if (!(schematic.getSchematicDimension().getY() == BukkitUtil.getMaxHeight(loc.getWorld()))) {
l1 = bot.add(0, sy - 1, 0);
}
else {
else {
l1 = bot;
}
}
final int blen = b.length - 1;
SchematicCmd.this.task = TaskManager.runTaskRepeat(new Runnable() {
@Override

View File

@ -207,7 +207,7 @@ public class Set extends SubCommand {
return false;
}
for (final Plot p : PS.get().getPlots(plr.getLocation().getWorld()).values()) {
if (p.settings.getAlias().equalsIgnoreCase(alias)) {
if (p.getSettings().getAlias().equalsIgnoreCase(alias)) {
MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN);
return false;
}

View File

@ -94,7 +94,7 @@ public class TP extends SubCommand {
return null;
}
for (final Plot p : PS.get().getPlots(world).values()) {
if ((p.settings.getAlias().length() > 0) && p.settings.getAlias().equalsIgnoreCase(a)) {
if ((p.getSettings().getAlias().length() > 0) && p.getSettings().getAlias().equalsIgnoreCase(a)) {
return p;
}
}

View File

@ -72,7 +72,7 @@ public class Trust extends SubCommand {
return false;
}
if (plot.trusted.contains(uuid)) {
if (plot.getTrusted().contains(uuid)) {
MainUtil.sendMessage(plr, C.ALREADY_ADDED);
return false;
}
@ -80,11 +80,11 @@ public class Trust extends SubCommand {
plot.addTrusted(uuid);
}
else {
if (plot.members.size() + plot.trusted.size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
if (plot.getMembers().size() + plot.getTrusted().size() >= PS.get().getPlotWorld(plot.world).MAX_PLOT_MEMBERS) {
MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS);
return false;
}
if (plot.denied.contains(uuid)) {
if (plot.getDenied().contains(uuid)) {
plot.removeDenied(uuid);
}
plot.addTrusted(uuid);

View File

@ -58,7 +58,7 @@ public class Undeny extends SubCommand {
int count = 0;
if (args[0].equals("unknown")) {
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.denied) {
for (UUID uuid : plot.getDenied()) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
}
@ -69,7 +69,7 @@ public class Undeny extends SubCommand {
}
}
else if (args[0].equals("*")){
for (UUID uuid : new ArrayList<>(plot.denied)) {
for (UUID uuid : new ArrayList<>(plot.getDenied())) {
plot.removeDenied(uuid);
count++;
}

View File

@ -58,7 +58,7 @@ public class Untrust extends SubCommand {
int count = 0;
if (args[0].equals("unknown")) {
ArrayList<UUID> toRemove = new ArrayList<>();
for (UUID uuid : plot.trusted) {
for (UUID uuid : plot.getTrusted()) {
if (UUIDHandler.getName(uuid) == null) {
toRemove.add(uuid);
}
@ -69,7 +69,7 @@ public class Untrust extends SubCommand {
}
}
else if (args[0].equals("*")){
for (UUID uuid : new ArrayList<>(plot.trusted)) {
for (UUID uuid : new ArrayList<>(plot.getTrusted())) {
plot.removeTrusted(uuid);
count++;
}

View File

@ -171,7 +171,7 @@ public class list extends SubCommand {
}
plots = new ArrayList<Plot>();
for (Plot plot : PS.get().getPlots()) {
if (plot.trusted.contains(plr.getUUID()) || plot.members.contains(plr.getUUID())) {
if (plot.getTrusted().contains(plr.getUUID()) || plot.getMembers().contains(plr.getUUID())) {
plots.add(plot);
}
}
@ -208,9 +208,9 @@ public class list extends SubCommand {
public int compare(Plot p1, Plot p2) {
double v1 = 0;
double v2 = 0;
int p1s = p1.settings.ratings != null ? p1.settings.ratings.size() : 0;
int p2s = p2.settings.ratings != null ? p2.settings.ratings.size() : 0;
if (p1.settings.ratings != null && p1s > 0) {
int p1s = p1.getSettings().ratings != null ? p1.getSettings().ratings.size() : 0;
int p2s = p2.getSettings().ratings != null ? p2.getSettings().ratings.size() : 0;
if (p1.getSettings().ratings != null && p1s > 0) {
for (Entry<UUID, Rating> entry : p1.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
v1 += av * av;
@ -218,7 +218,7 @@ public class list extends SubCommand {
v1 /= p1s;
v1 += p1s;
}
if (p2.settings.ratings != null && p2s > 0) {
if (p2.getSettings().ratings != null && p2s > 0) {
for (Entry<UUID, Rating> entry : p2.getRatings().entrySet()) {
double av = entry.getValue().getAverageRating();
v2 += av * av;
@ -353,7 +353,7 @@ public class list extends SubCommand {
int i = page * pageSize;
for (Plot plot : subList) {
if (plot.settings.isMerged()) {
if (plot.getSettings().isMerged()) {
if (!MainUtil.getBottomPlot(plot).equals(plot)) {
continue;
}
@ -380,16 +380,16 @@ public class list extends SubCommand {
new FancyMessage(
ChatColor.stripColor(
ChatColor.translateAlternateColorCodes('&',
C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.trusted)))))
C.PLOT_INFO_TRUSTED.s().replaceAll("%trusted%", Info.getPlayerList(plot.getTrusted())))))
.color(ChatColor.GOLD);
FancyMessage members =
new FancyMessage(
ChatColor.stripColor(
ChatColor.translateAlternateColorCodes('&',
C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.members)))))
C.PLOT_INFO_MEMBERS.s().replaceAll("%members%", Info.getPlayerList(plot.getMembers())))))
.color(ChatColor.GOLD);
String strFlags = StringUtils.join(plot.settings.flags.values(), ",");
String strFlags = StringUtils.join(plot.getSettings().flags.values(), ",");
if (strFlags.length() == 0) {
strFlags = C.NONE.s();
}