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.ArrayList; 027import java.util.List; 028 029public class InboxOwner extends CommentInbox { 030 031 @Override 032 public boolean getComments(final Plot plot, final RunnableVal<List<PlotComment>> whenDone) { 033 List<PlotComment> comments = plot.getPlotCommentContainer().getComments(toString()); 034 if (!comments.isEmpty()) { 035 whenDone.value = comments; 036 TaskManager.runTask(whenDone); 037 return true; 038 } 039 DBFunc.getComments(plot, toString(), new RunnableVal<>() { 040 @Override 041 public void run(List<PlotComment> value) { 042 whenDone.value = value; 043 if (value != null) { 044 for (PlotComment comment : value) { 045 plot.getPlotCommentContainer().addComment(comment); 046 } 047 } else { 048 plot.getPlotCommentContainer().setComments(new ArrayList<>()); 049 } 050 TaskManager.runTask(whenDone); 051 } 052 }); 053 return true; 054 } 055 056 @Override 057 public boolean addComment(Plot plot, PlotComment comment) { 058 if (plot.getOwner() == null) { 059 return false; 060 } 061 plot.getPlotCommentContainer().addComment(comment); 062 DBFunc.setComment(plot, comment); 063 return true; 064 } 065 066 @Override 067 public String toString() { 068 return "owner"; 069 } 070 071}