001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.plot.comment;
020
021import com.plotsquared.core.database.DBFunc;
022import com.plotsquared.core.plot.Plot;
023import com.plotsquared.core.util.task.RunnableVal;
024import com.plotsquared.core.util.task.TaskManager;
025
026import java.util.List;
027
028public class InboxPublic extends CommentInbox {
029
030    @Override
031    public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) {
032        List<PlotComment> comments = plot.getPlotCommentContainer().getComments(toString());
033        if (!comments.isEmpty()) {
034            whenDone.value = comments;
035            TaskManager.runTask(whenDone);
036            return true;
037        }
038        DBFunc.getComments(plot, toString(), new RunnableVal<>() {
039            @Override
040            public void run(List<PlotComment> value) {
041                whenDone.value = value;
042                if (value != null) {
043                    for (PlotComment comment : value) {
044                        plot.getPlotCommentContainer().addComment(comment);
045                    }
046                }
047                TaskManager.runTask(whenDone);
048            }
049        });
050        return true;
051    }
052
053    @Override
054    public boolean addComment(Plot plot, PlotComment comment) {
055        plot.getPlotCommentContainer().addComment(comment);
056        DBFunc.setComment(plot, comment);
057        return true;
058    }
059
060    @Override
061    public String toString() {
062        return "public";
063    }
064
065
066}