mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Extract comment logic from the plot class
This commit is contained in:
parent
352136f0c6
commit
f391cfd432
@ -208,7 +208,7 @@ public class Inbox extends SubCommand {
|
|||||||
}
|
}
|
||||||
PlotComment comment = value.get(index - 1);
|
PlotComment comment = value.get(index - 1);
|
||||||
inbox.removeComment(plot, comment);
|
inbox.removeComment(plot, comment);
|
||||||
boolean success = plot.removeComment(comment);
|
boolean success = plot.getPlotCommentContainer().removeComment(comment);
|
||||||
if (success) {
|
if (success) {
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("comment.comment_removed_success"),
|
TranslatableCaption.of("comment.comment_removed_success"),
|
||||||
@ -231,9 +231,9 @@ public class Inbox extends SubCommand {
|
|||||||
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
|
player.sendMessage(TranslatableCaption.of("comment.no_perm_inbox_modify"));
|
||||||
}
|
}
|
||||||
inbox.clearInbox(plot);
|
inbox.clearInbox(plot);
|
||||||
List<PlotComment> comments = plot.getComments(inbox.toString());
|
List<PlotComment> comments = plot.getPlotCommentContainer().getComments(inbox.toString());
|
||||||
if (!comments.isEmpty()) {
|
if (!comments.isEmpty()) {
|
||||||
plot.removeComments(comments);
|
plot.getPlotCommentContainer().removeComments(comments);
|
||||||
}
|
}
|
||||||
player.sendMessage(
|
player.sendMessage(
|
||||||
TranslatableCaption.of("comment.comment_removed_success"),
|
TranslatableCaption.of("comment.comment_removed_success"),
|
||||||
|
@ -53,7 +53,6 @@ import com.plotsquared.core.location.PlotLoc;
|
|||||||
import com.plotsquared.core.permissions.Permission;
|
import com.plotsquared.core.permissions.Permission;
|
||||||
import com.plotsquared.core.player.ConsolePlayer;
|
import com.plotsquared.core.player.ConsolePlayer;
|
||||||
import com.plotsquared.core.player.PlotPlayer;
|
import com.plotsquared.core.player.PlotPlayer;
|
||||||
import com.plotsquared.core.plot.comment.PlotComment;
|
|
||||||
import com.plotsquared.core.plot.expiration.ExpireManager;
|
import com.plotsquared.core.plot.expiration.ExpireManager;
|
||||||
import com.plotsquared.core.plot.expiration.PlotAnalysis;
|
import com.plotsquared.core.plot.expiration.PlotAnalysis;
|
||||||
import com.plotsquared.core.plot.flag.FlagContainer;
|
import com.plotsquared.core.plot.flag.FlagContainer;
|
||||||
@ -153,6 +152,10 @@ public class Plot {
|
|||||||
* Plot flag container
|
* Plot flag container
|
||||||
*/
|
*/
|
||||||
private final FlagContainer flagContainer = new FlagContainer(null);
|
private final FlagContainer flagContainer = new FlagContainer(null);
|
||||||
|
/**
|
||||||
|
* Utility used to manage plot comments
|
||||||
|
*/
|
||||||
|
private final PlotCommentContainer plotCommentContainer = new PlotCommentContainer(this);
|
||||||
/**
|
/**
|
||||||
* Has the plot changed since the last save cycle?
|
* Has the plot changed since the last save cycle?
|
||||||
*/
|
*/
|
||||||
@ -323,7 +326,9 @@ public class Plot {
|
|||||||
* @param message If a message should be sent to the player if a plot cannot be found
|
* @param message If a message should be sent to the player if a plot cannot be found
|
||||||
* @return The plot if only 1 result is found, or null
|
* @return The plot if only 1 result is found, or null
|
||||||
*/
|
*/
|
||||||
@Nullable public static Plot getPlotFromString(PlotPlayer<?> player, String arg, boolean message) {
|
@Nullable public static Plot getPlotFromString(@Nullable final PlotPlayer<?> player,
|
||||||
|
@Nullable final String arg,
|
||||||
|
final boolean message) {
|
||||||
if (arg == null) {
|
if (arg == null) {
|
||||||
if (player == null) {
|
if (player == null) {
|
||||||
if (message) {
|
if (message) {
|
||||||
@ -365,13 +370,13 @@ public class Plot {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (message) {
|
if (message && player != null) {
|
||||||
player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id"));
|
player.sendMessage(TranslatableCaption.of("invalid.not_valid_plot_id"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (area == null) {
|
if (area == null) {
|
||||||
if (message) {
|
if (message && player != null) {
|
||||||
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
|
player.sendMessage(TranslatableCaption.of("errors.invalid_plot_world"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -386,8 +391,8 @@ public class Plot {
|
|||||||
* @param string plot id/area + id
|
* @param string plot id/area + id
|
||||||
* @return New or existing plot object
|
* @return New or existing plot object
|
||||||
*/
|
*/
|
||||||
public static Plot fromString(PlotArea defaultArea, String string) {
|
@Nullable public static Plot fromString(@Nullable final PlotArea defaultArea, @Nonnull final String string) {
|
||||||
String[] split = string.split(";|,");
|
final String[] split = string.split(";|,");
|
||||||
if (split.length == 2) {
|
if (split.length == 2) {
|
||||||
if (defaultArea != null) {
|
if (defaultArea != null) {
|
||||||
PlotId id = PlotId.fromString(split[0] + ';' + split[1]);
|
PlotId id = PlotId.fromString(split[0] + ';' + split[1]);
|
||||||
@ -416,8 +421,8 @@ public class Plot {
|
|||||||
* @return plot at location or null
|
* @return plot at location or null
|
||||||
* @see PlotPlayer#getCurrentPlot() if a player is expected here.
|
* @see PlotPlayer#getCurrentPlot() if a player is expected here.
|
||||||
*/
|
*/
|
||||||
public static Plot getPlot(Location location) {
|
@Nullable public static Plot getPlot(@Nullable final Location location) {
|
||||||
PlotArea pa = location.getPlotArea();
|
final PlotArea pa = location.getPlotArea();
|
||||||
if (pa != null) {
|
if (pa != null) {
|
||||||
return pa.getPlot(location);
|
return pa.getPlot(location);
|
||||||
}
|
}
|
||||||
@ -3452,26 +3457,6 @@ public class Plot {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeComment(PlotComment comment) {
|
|
||||||
return getSettings().removeComment(comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeComments(List<PlotComment> comments) {
|
|
||||||
getSettings().removeComments(comments);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PlotComment> getComments(String inbox) {
|
|
||||||
return getSettings().getComments(inbox);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addComment(PlotComment comment) {
|
|
||||||
getSettings().addComment(comment);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setComments(List<PlotComment> list) {
|
|
||||||
getSettings().setComments(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getMerged(Direction direction) {
|
public boolean getMerged(Direction direction) {
|
||||||
return getMerged(direction.getIndex());
|
return getMerged(direction.getIndex());
|
||||||
}
|
}
|
||||||
@ -3627,8 +3612,9 @@ public class Plot {
|
|||||||
* - The index corresponds to the index of the category in the config
|
* - The index corresponds to the index of the category in the config
|
||||||
*
|
*
|
||||||
* @return Average ratings in each category
|
* @return Average ratings in each category
|
||||||
|
* @see Settings.Ratings#CATEGORIES Rating categories
|
||||||
*/
|
*/
|
||||||
public double[] getAverageRatings() {
|
@Nonnull public double[] getAverageRatings() {
|
||||||
Map<UUID, Integer> rating;
|
Map<UUID, Integer> rating;
|
||||||
if (this.getSettings().getRatings() != null) {
|
if (this.getSettings().getRatings() != null) {
|
||||||
rating = this.getSettings().getRatings();
|
rating = this.getSettings().getRatings();
|
||||||
@ -3662,8 +3648,23 @@ public class Plot {
|
|||||||
return ratings;
|
return ratings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the plot flag container
|
||||||
|
*
|
||||||
|
* @return Flag container
|
||||||
|
*/
|
||||||
@Nonnull public FlagContainer getFlagContainer() {
|
@Nonnull public FlagContainer getFlagContainer() {
|
||||||
return this.flagContainer;
|
return this.flagContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the plot comment container. This can be used to manage
|
||||||
|
* and access plot comments
|
||||||
|
*
|
||||||
|
* @return Plot comment container
|
||||||
|
*/
|
||||||
|
@Nonnull public PlotCommentContainer getPlotCommentContainer() {
|
||||||
|
return this.plotCommentContainer;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.plotsquared.core.plot;
|
||||||
|
|
||||||
|
import com.plotsquared.core.plot.comment.PlotComment;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Container for {@link com.plotsquared.core.plot.Plot} comments
|
||||||
|
*/
|
||||||
|
public final class PlotCommentContainer {
|
||||||
|
|
||||||
|
private final Plot plot;
|
||||||
|
|
||||||
|
PlotCommentContainer(@Nonnull final Plot plot) {
|
||||||
|
this.plot = plot;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a comment from the plot
|
||||||
|
*
|
||||||
|
* @param comment Comment to remove
|
||||||
|
* @return {@code true} if the comment was removed, {@code false} if not
|
||||||
|
*/
|
||||||
|
public boolean removeComment(@Nonnull final PlotComment comment) {
|
||||||
|
return this.getSettings().removeComment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a list of comments from the plot
|
||||||
|
*
|
||||||
|
* @param comments Comments to remove
|
||||||
|
*/
|
||||||
|
public void removeComments(@Nonnull final List<PlotComment> comments) {
|
||||||
|
this.getSettings().removeComments(comments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all comments in a specific inbox
|
||||||
|
*
|
||||||
|
* @param inbox Inbox
|
||||||
|
* @return List of comments
|
||||||
|
*/
|
||||||
|
@Nonnull public List<PlotComment> getComments(@Nonnull final String inbox) {
|
||||||
|
return this.getSettings().getComments(inbox);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a comment to the plot
|
||||||
|
*
|
||||||
|
* @param comment Comment to add
|
||||||
|
*/
|
||||||
|
public void addComment(@Nonnull final PlotComment comment) {
|
||||||
|
this.getSettings().addComment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the plot comments
|
||||||
|
*
|
||||||
|
* @param list New comments
|
||||||
|
*/
|
||||||
|
public void setComments(@Nonnull final List<PlotComment> list) {
|
||||||
|
this.getSettings().setComments(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull private PlotSettings getSettings() {
|
||||||
|
if (this.plot.getSettings() == null) {
|
||||||
|
throw new IllegalStateException("Cannot access comments for unowned plots");
|
||||||
|
}
|
||||||
|
return this.plot.getSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -37,7 +37,7 @@ public class InboxOwner extends CommentInbox {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||||
List<PlotComment> comments = plot.getComments(toString());
|
List<PlotComment> comments = plot.getPlotCommentContainer().getComments(toString());
|
||||||
if (!comments.isEmpty()) {
|
if (!comments.isEmpty()) {
|
||||||
whenDone.value = comments;
|
whenDone.value = comments;
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -48,10 +48,10 @@ public class InboxOwner extends CommentInbox {
|
|||||||
whenDone.value = value;
|
whenDone.value = value;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
for (PlotComment comment : value) {
|
for (PlotComment comment : value) {
|
||||||
plot.addComment(comment);
|
plot.getPlotCommentContainer().addComment(comment);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
plot.setComments(new ArrayList<>());
|
plot.getPlotCommentContainer().setComments(new ArrayList<>());
|
||||||
}
|
}
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ public class InboxOwner extends CommentInbox {
|
|||||||
if (plot.getOwner() == null) {
|
if (plot.getOwner() == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
plot.addComment(comment);
|
plot.getPlotCommentContainer().addComment(comment);
|
||||||
DBFunc.setComment(plot, comment);
|
DBFunc.setComment(plot, comment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class InboxPublic extends CommentInbox {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
|
||||||
List<PlotComment> comments = plot.getComments(toString());
|
List<PlotComment> comments = plot.getPlotCommentContainer().getComments(toString());
|
||||||
if (!comments.isEmpty()) {
|
if (!comments.isEmpty()) {
|
||||||
whenDone.value = comments;
|
whenDone.value = comments;
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -47,7 +47,7 @@ public class InboxPublic extends CommentInbox {
|
|||||||
whenDone.value = value;
|
whenDone.value = value;
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
for (PlotComment comment : value) {
|
for (PlotComment comment : value) {
|
||||||
plot.addComment(comment);
|
plot.getPlotCommentContainer().addComment(comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TaskManager.runTask(whenDone);
|
TaskManager.runTask(whenDone);
|
||||||
@ -57,7 +57,7 @@ public class InboxPublic extends CommentInbox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean addComment(Plot plot, PlotComment comment) {
|
@Override public boolean addComment(Plot plot, PlotComment comment) {
|
||||||
plot.addComment(comment);
|
plot.getPlotCommentContainer().addComment(comment);
|
||||||
DBFunc.setComment(plot, comment);
|
DBFunc.setComment(plot, comment);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user