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

@ -52,11 +52,11 @@ public class InfoInventory implements InventoryHolder {
public InfoInventory build() {
final UUID uuid = UUIDHandler.getUUID(BukkitUtil.getPlayer(this.player));
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner), "&cAlias: &6" + this.plot.settings.getAlias(), "&cBiome: &6" + this.plot.settings.getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.trusted.size(), "&8Click to view a list of the trusted users");
final ItemStack members = getItem(Material.EMERALD, "&cMembers", "&cAmount: &6" + this.plot.members.size(), "&8Click to view a list of plot members");
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.denied.size(), "&8Click to view a list of denied players");
final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.settings.flags.size(), "&8Click to view a list of plot flags");
final ItemStack generalInfo = getItem(Material.EMERALD, "&cPlot Info", "&cID: &6" + this.plot.getId().toString(), "&cOwner: &6" + getName(this.plot.owner), "&cAlias: &6" + this.plot.getSettings().getAlias(), "&cBiome: &6" + this.plot.getSettings().getBiome().toString().replaceAll("_", "").toLowerCase(), "&cCan Build: &6" + this.plot.isAdded(uuid), "&cIs Denied: &6" + this.plot.isDenied(uuid));
final ItemStack trusted = getItem(Material.EMERALD, "&cTrusted", "&cAmount: &6" + this.plot.getTrusted().size(), "&8Click to view a list of the trusted users");
final ItemStack members = getItem(Material.EMERALD, "&cMembers", "&cAmount: &6" + this.plot.getMembers().size(), "&8Click to view a list of plot members");
final ItemStack denied = getItem(Material.EMERALD, "&cDenied", "&cAmount: &6" + this.plot.getDenied().size(), "&8Click to view a list of denied players");
final ItemStack flags = getItem(Material.EMERALD, "&cFlags", "&cAmount: &6" + this.plot.getSettings().flags.size(), "&8Click to view a list of plot flags");
this.inventory.setItem(2, generalInfo);
this.inventory.setItem(3, trusted);
this.inventory.setItem(4, members);

View File

@ -92,10 +92,6 @@ public class Plot implements Cloneable {
this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new HashSet<>();
this.members = new HashSet<>();
this.denied = new HashSet<>();
this.temp = false;
}
@ -111,10 +107,6 @@ public class Plot implements Cloneable {
this.world = world;
this.id = id;
this.owner = owner;
this.settings = new PlotSettings(this);
this.trusted = new HashSet<>();
this.members = new HashSet<>();
this.denied = new HashSet<>();
this.temp = temp;
}
@ -186,7 +178,7 @@ public class Plot implements Cloneable {
* @return boolean false if the player is allowed to enter
*/
public boolean isDenied(final UUID uuid) {
return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid)));
return (this.getDenied() != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid)));
}
/**
@ -195,6 +187,69 @@ public class Plot implements Cloneable {
public PlotId getId() {
return this.id;
}
/**
* Get or create plot settings
* @return PlotSettings
*/
public PlotSettings getSettings() {
if (settings == null) {
settings = new PlotSettings(this);
}
return settings;
}
public boolean isMerged() {
if (settings == null) {
return false;
}
return settings.getMerged(0) || settings.getMerged(2) || settings.getMerged(1) || settings.getMerged(3);
}
/**
* Get if the plot is merged in a direction
* @param direction
* @return
*/
public boolean getMerged(int direction) {
if (settings == null) {
return false;
}
return settings.getMerged(direction);
}
/**
* Get the denied users
* @return
*/
public HashSet<UUID> getDenied() {
if (this.denied == null) {
this.denied = new HashSet<>();
}
return this.denied;
}
/**
* Get the trusted users
* @return
*/
public HashSet<UUID> getTrusted() {
if (this.trusted == null) {
this.trusted = new HashSet<>();
}
return this.trusted;
}
/**
* Get the members
* @return
*/
public HashSet<UUID> getMembers() {
if (this.members == null) {
this.members = new HashSet<>();
}
return this.members;
}
/**
* Get a clone of the plot
@ -216,7 +271,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public void addDenied(final UUID uuid) {
if (this.denied.add(uuid)) DBFunc.setDenied(this, uuid);
if (this.getDenied().add(uuid)) DBFunc.setDenied(this, uuid);
}
/**
@ -225,7 +280,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public void addTrusted(final UUID uuid) {
if (this.trusted.add(uuid)) DBFunc.setTrusted(this, uuid);
if (this.getTrusted().add(uuid)) DBFunc.setTrusted(this, uuid);
}
/**
@ -234,7 +289,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public void addMember(final UUID uuid) {
if (this.members.add(uuid)) DBFunc.setMember(this, uuid);
if (this.getMembers().add(uuid)) DBFunc.setMember(this, uuid);
}
/**
@ -332,10 +387,10 @@ public class Plot implements Cloneable {
*/
public HashMap<UUID, Rating> getRatings() {
HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
if (settings.ratings == null) {
if (getSettings().ratings == null) {
return map;
}
for (Entry<UUID, Integer> entry : settings.ratings.entrySet()) {
for (Entry<UUID, Integer> entry : getSettings().ratings.entrySet()) {
map.put(entry.getKey(), new Rating(entry.getValue()));
}
return map;
@ -346,16 +401,16 @@ public class Plot implements Cloneable {
* @param loc
*/
public void setHome(BlockLoc loc) {
BlockLoc pos = this.settings.getPosition();
BlockLoc pos = this.getSettings().getPosition();
if ((pos == null && loc == null) || (pos != null && pos.equals(loc))) {
return;
}
this.settings.setPosition(loc);
if (this.settings.getPosition() == null) {
this.getSettings().setPosition(loc);
if (this.getSettings().getPosition() == null) {
DBFunc.setPosition(this, "");
}
else {
DBFunc.setPosition(this, this.settings.getPosition().toString());
DBFunc.setPosition(this, this.getSettings().getPosition().toString());
}
}
@ -364,14 +419,14 @@ public class Plot implements Cloneable {
* @param alias
*/
public void setAlias(String alias) {
String name = this.settings.getAlias();
String name = this.getSettings().getAlias();
if (alias == null) {
alias = "";
}
if (name.equals(alias)) {
return;
}
this.settings.setAlias(alias);
this.getSettings().setAlias(alias);
DBFunc.setAlias(this, alias);
}
@ -499,7 +554,7 @@ public class Plot implements Cloneable {
*/
@Override
public String toString() {
if (this.settings.getAlias().length() > 1) {
if (this.settings != null && this.settings.getAlias().length() > 1) {
return this.settings.getAlias();
}
return this.world + ";" + this.getId().x + ";" + this.getId().y;
@ -511,7 +566,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public boolean removeDenied(final UUID uuid) {
if (this.denied.remove(uuid)) {
if (this.getDenied().remove(uuid)) {
DBFunc.removeDenied(this, uuid);
return true;
}
@ -524,7 +579,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public boolean removeTrusted(final UUID uuid) {
if (this.trusted.remove(uuid)) {
if (this.getTrusted().remove(uuid)) {
DBFunc.removeTrusted(this, uuid);
return true;
}
@ -537,7 +592,7 @@ public class Plot implements Cloneable {
* @param uuid
*/
public boolean removeMember(final UUID uuid) {
if (this.members.remove(uuid)) {
if (this.getMembers().remove(uuid)) {
DBFunc.removeMember(this, uuid);
return true;
}

View File

@ -105,7 +105,7 @@ public class PlotAnalysis {
PS.log(" - $1Reducing " + plots.size() + " plots to those with sufficient data");
while (iter.hasNext()) {
Plot plot = iter.next();
if (plot.settings.ratings == null || plot.settings.ratings.size() == 0) {
if (plot.getSettings().ratings == null || plot.getSettings().ratings.size() == 0) {
iter.remove();
}
else {
@ -147,7 +147,7 @@ public class PlotAnalysis {
for (;mi.intValue() < plots.size(); mi.increment()) {
int i = mi.intValue();
Plot plot = plots.get(i);
ratings[i] = (int) ((plot.getAverageRating() + plot.settings.ratings.size()) * 100);
ratings[i] = (int) ((plot.getAverageRating() + plot.getSettings().ratings.size()) * 100);
PS.log(" | " + plot + " (rating) " + (ratings[i]));
}
}

View File

@ -14,7 +14,7 @@ public class PlotHandler {
if (plot.owner == null) {
return new HashSet<UUID>();
}
if (plot.settings.isMerged()) {
if (plot.isMerged()) {
HashSet<UUID> owners = new HashSet<UUID>();
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
@ -33,7 +33,7 @@ public class PlotHandler {
if (plot.owner == null) {
return false;
}
if (plot.settings.isMerged()) {
if (plot.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
@ -50,7 +50,7 @@ public class PlotHandler {
if (plot.owner == null) {
return false;
}
if (plot.settings.isMerged()) {
if (plot.isMerged()) {
Plot top = MainUtil.getTopPlot(plot);
ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
for (PlotId id : ids) {
@ -82,13 +82,13 @@ public class PlotHandler {
if (isOwner(plot, uuid)) {
return true;
}
if (plot.denied.contains(uuid)) {
if (plot.getDenied().contains(uuid)) {
return false;
}
if (plot.trusted.contains(uuid) || plot.trusted.contains(DBFunc.everyone)) {
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) {
return true;
}
if (plot.members.contains(uuid) || plot.members.contains(DBFunc.everyone)) {
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone)) {
if (PlotHandler.isOnline(plot)) {
return true;
}

View File

@ -41,7 +41,7 @@ public class InboxOwner extends CommentInbox {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
@ -53,7 +53,7 @@ public class InboxOwner extends CommentInbox {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
plot.getSettings().addComment(comment);
}
}
TaskManager.runTask(whenDone);
@ -67,7 +67,7 @@ public class InboxOwner extends CommentInbox {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
plot.getSettings().addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}

View File

@ -41,7 +41,7 @@ public class InboxPublic extends CommentInbox {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
ArrayList<PlotComment> comments = plot.getSettings().getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
@ -53,7 +53,7 @@ public class InboxPublic extends CommentInbox {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
plot.getSettings().addComment(comment);
}
}
TaskManager.runTask(whenDone);
@ -67,7 +67,7 @@ public class InboxPublic extends CommentInbox {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
plot.getSettings().addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}