From 34291d5b4dcad44cbb2cd58d1c2de96b7310cd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 18 Feb 2020 20:43:46 +0100 Subject: [PATCH] Clean up PlotSettings --- .../plotsquared/plot/commands/Like.java | 6 +-- .../plotsquared/plot/commands/Rate.java | 12 ++--- .../plotsquared/plot/object/Plot.java | 17 +++---- .../plotsquared/plot/object/PlotSettings.java | 45 +++++-------------- .../plot/object/worlds/SinglePlotArea.java | 2 +- .../plotsquared/plot/util/MainUtil.java | 6 +-- .../plot/util/expiry/PlotAnalysis.java | 2 +- 7 files changed, 33 insertions(+), 57 deletions(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java index 4e1ae61d8..86c6868ac 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Like.java @@ -104,15 +104,15 @@ public class Like extends SubCommand { } } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java index a2de17560..ab29f3b4b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java @@ -145,15 +145,15 @@ public class Rate extends SubCommand { inventory.openInventory(); } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; @@ -186,15 +186,15 @@ public class Rate extends SubCommand { sendMessage(player, Captions.RATING_APPLIED, plot.getId().toString()); } }; - if (plot.getSettings().ratings == null) { + if (plot.getSettings().getRatings() == null) { if (!Settings.Enabled_Components.RATING_CACHE) { TaskManager.runTaskAsync(() -> { - plot.getSettings().ratings = DBFunc.getRatings(plot); + plot.getSettings().setRatings(DBFunc.getRatings(plot)); run.run(); }); return true; } - plot.getSettings().ratings = new HashMap<>(); + plot.getSettings().setRatings(new HashMap<>()); } run.run(); return true; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index b0f78192e..37f170c1e 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -542,9 +542,8 @@ public class Plot { * Gets or create plot settings. * * @return PlotSettings - * @deprecated use equivalent plot method; please file github issue if one does not exist. */ - @Deprecated public PlotSettings getSettings() { + public PlotSettings getSettings() { if (this.settings == null) { this.settings = new PlotSettings(); } @@ -1099,7 +1098,7 @@ public class Plot { /** * Sets a flag for this plot * - * @param flag Flag to set + * @param flag Flag to set */ public boolean setFlag(PlotFlag flag) { if (!EventUtil.manager.callFlagAdd(flag, origin)) { @@ -1135,12 +1134,14 @@ public class Plot { return this.removeFlag(getFlagContainer().queryLocal(flag)); } - public Collection> getApplicableFlags(final boolean plotOnly, final boolean ignorePluginFlags) { + public Collection> getApplicableFlags(final boolean plotOnly, + final boolean ignorePluginFlags) { if (!hasOwner()) { return Collections.emptyList(); } final Map, PlotFlag> flags = new HashMap<>(); - if (!plotOnly && getArea() != null && !getArea().getFlagContainer().getFlagMap().isEmpty()) { + if (!plotOnly && getArea() != null && !getArea().getFlagContainer().getFlagMap() + .isEmpty()) { final Map, PlotFlag> flagMap = getArea().getFlagContainer().getFlagMap(); flags.putAll(flagMap); } @@ -1478,9 +1479,9 @@ public class Plot { public void clearRatings() { Plot base = this.getBasePlot(false); PlotSettings baseSettings = base.getSettings(); - if (baseSettings.ratings != null && !baseSettings.getRatings().isEmpty()) { + if (baseSettings.getRatings() != null && !baseSettings.getRatings().isEmpty()) { DBFunc.deleteRatings(base); - baseSettings.ratings = null; + baseSettings.setRatings(null); } } @@ -1511,7 +1512,7 @@ public class Plot { public boolean hasRatings() { Plot base = this.getBasePlot(false); - return base.settings != null && base.settings.ratings != null; + return base.settings != null && base.settings.getRatings() != null; } /** diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java index 29d208487..a89f7ddbd 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotSettings.java @@ -2,6 +2,8 @@ package com.github.intellectualsites.plotsquared.plot.object; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.google.common.collect.ImmutableList; +import lombok.Getter; +import lombok.Setter; import java.util.ArrayList; import java.util.Collections; @@ -19,29 +21,24 @@ public class PlotSettings { /** * Merged plots. - * - * @deprecated Raw access */ - @Deprecated public boolean[] merged = new boolean[] {false, false, false, false}; + @Getter private boolean[] merged = new boolean[] {false, false, false, false}; /** * Plot alias. - * - * @deprecated Raw access */ - @Deprecated public String alias = ""; + @Getter @Setter private String alias = ""; /** * The ratings for a plot. - * - * @deprecated Raw access */ - @Deprecated public HashMap ratings; - private List comments = null; + @Setter private HashMap ratings; + /** + * Plot comments. + */ + @Setter private List comments = null; /** * Home Position. - * - * @deprecated Raw access */ - @Deprecated private BlockLoc position; + private BlockLoc position; /** * Check if the plot is merged in a direction
0 = North
1 = East
2 = South
3 = West
@@ -53,10 +50,6 @@ public class PlotSettings { return this.merged[direction]; } - public boolean[] getMerged() { - return this.merged; - } - public void setMerged(boolean[] merged) { this.merged = merged; } @@ -64,7 +57,6 @@ public class PlotSettings { public Map getRatings() { if (this.ratings == null) { this.ratings = new HashMap<>(); - } return this.ratings; } @@ -103,19 +95,6 @@ public class PlotSettings { this.position = position; } - public String getAlias() { - return this.alias; - } - - /** - * Set the plot alias. - * - * @param alias alias to be used - */ - public void setAlias(String alias) { - this.alias = alias; - } - @SuppressWarnings({"UnstableApiUsage"}) public List getComments(String inbox) { if (this.comments == null) { return Collections.emptyList(); @@ -125,10 +104,6 @@ public class PlotSettings { .collect(ImmutableList.toImmutableList()); } - void setComments(List comments) { - this.comments = comments; - } - boolean removeComment(PlotComment comment) { if (this.comments == null) { return false; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java index c1c6635c5..ba3003d6b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/worlds/SinglePlotArea.java @@ -171,7 +171,7 @@ public class SinglePlotArea extends GridPlotWorld { final FlagContainer oldContainer = p.getFlagContainer(); p = new SinglePlot(p.getId(), p.owner, p.getTrusted(), p.getMembers(), p.getDenied(), - s.alias, s.getPosition(), null, this, s.merged, p.getTimestamp(), p.temp); + s.getAlias(), s.getPosition(), null, this, s.getMerged(), p.getTimestamp(), p.temp); p.getFlagContainer().addAll(oldContainer); return p; diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java index e8e570949..35bd8bcf9 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/MainUtil.java @@ -681,9 +681,9 @@ public class MainUtil { * @return */ public static double[] getAverageRatings(Plot plot) { - HashMap rating; - if (plot.getSettings().ratings != null) { - rating = plot.getSettings().ratings; + Map rating; + if (plot.getSettings().getRatings() != null) { + rating = plot.getSettings().getRatings(); } else if (Settings.Enabled_Components.RATING_CACHE) { rating = new HashMap<>(); } else { diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java index 22a60ca02..c426d7fee 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/util/expiry/PlotAnalysis.java @@ -84,7 +84,7 @@ public class PlotAnalysis { " - $1Reducing " + plots.size() + " plots to those with sufficient data"); while (iterator.hasNext()) { Plot plot = iterator.next(); - if (plot.getSettings().ratings == null || plot.getSettings().getRatings() + if (plot.getSettings().getRatings() == null || plot.getSettings().getRatings() .isEmpty()) { iterator.remove(); } else {