Move all files! Hahah

This commit is contained in:
Sauilitired
2015-07-16 16:16:13 +02:00
parent 8a4e19ab40
commit cff47cbac0
318 changed files with 58 additions and 2 deletions

View File

@@ -0,0 +1,35 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
public abstract class CommentInbox {
@Override
public abstract String toString();
public abstract boolean canRead(Plot plot, PlotPlayer player);
public abstract boolean canWrite(Plot plot, PlotPlayer player);
public abstract boolean canModify(Plot plot, PlotPlayer player);
/**
* The plot may be null if the user is not standing in a plot. Return false if this is not a plot-less inbox.
* <br>
* The `whenDone` parameter should be executed when it's done fetching the comments.
* The value should be set to List of comments
*
* @param plot
* @param whenDone
* @return
*/
public abstract boolean getComments(Plot plot, RunnableVal whenDone);
public abstract boolean addComment(Plot plot, PlotComment comment);
public abstract boolean removeComment(Plot plot, PlotComment comment);
public abstract boolean clearInbox(Plot plot);
}

View File

@@ -0,0 +1,79 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.ChatColor;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.titles.AbstractTitle;
import com.intellectualcrafters.plot.util.TaskManager;
public class CommentManager {
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
public static void sendTitle(final PlotPlayer player, final Plot plot) {
if (!Settings.COMMENT_NOTIFICATIONS) {
return;
}
if (!plot.isOwner(player.getUUID())) {
return;
}
TaskManager.runTaskLaterAsync(new Runnable() {
@Override
public void run() {
Collection<CommentInbox> boxes = CommentManager.inboxes.values();
final AtomicInteger count = new AtomicInteger(0);
final AtomicInteger size = new AtomicInteger(boxes.size());
for (final CommentInbox inbox : inboxes.values()) {
inbox.getComments(plot, new RunnableVal() {
@Override
public void run() {
int total;
if (value != null) {
int num = 0;
for (PlotComment comment : (ArrayList<PlotComment>) value) {
if (comment.timestamp > getTimestamp(player, inbox.toString())) {
num++;
}
}
total = count.addAndGet(num);
}
else {
total = count.get();
}
if (size.decrementAndGet() == 0 && total > 0) {
AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total), ChatColor.GOLD, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
}
}
});
}
}
}, 20);
}
public static long getTimestamp(PlotPlayer player, String inbox) {
Object meta = player.getMeta("inbox:"+inbox);
if (meta == null) {
return player.getPreviousLogin();
}
return (Long) meta;
}
public static void addInbox(CommentInbox inbox) {
inboxes.put(inbox.toString().toLowerCase(), inbox);
}
public static void registerDefaultInboxes() {
addInbox(new InboxReport());
addInbox(new InboxPublic());
addInbox(new InboxOwner());
}
}

View File

@@ -0,0 +1,97 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxOwner extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "owner";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@@ -0,0 +1,97 @@
package com.intellectualcrafters.plot.object.comment;
import java.util.ArrayList;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxPublic extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
if (plot == null || plot.owner == null) {
return false;
}
ArrayList<PlotComment> comments = plot.settings.getComments(toString());
if (comments != null) {
whenDone.value = comments;
TaskManager.runTask(whenDone);
return true;
}
DBFunc.getComments(plot, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
if (value != null) {
for (PlotComment comment : (ArrayList<PlotComment>) value) {
plot.settings.addComment(comment);
}
}
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
plot.settings.addComment(comment);
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "public";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@@ -0,0 +1,80 @@
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.database.DBFunc;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotHandler;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.TaskManager;
public class InboxReport extends CommentInbox {
@Override
public boolean canRead(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.read." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.read." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.read." + toString() + ".other")));
}
@Override
public boolean canWrite(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.write." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.write." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.write." + toString() + ".other")));
}
@Override
public boolean canModify(Plot plot, PlotPlayer player) {
if (plot == null) {
return Permissions.hasPermission(player, "plots.inbox.modify." + toString());
}
return (Permissions.hasPermission(player, "plots.inbox.modify." + toString()) && (PlotHandler.isOwner(plot, player.getUUID()) || Permissions.hasPermission(player, "plots.inbox.modify." + toString() + ".other")));
}
@Override
public boolean getComments(final Plot plot, final RunnableVal whenDone) {
DBFunc.getComments(null, toString(), new RunnableVal() {
@Override
public void run() {
whenDone.value = value;
TaskManager.runTask(whenDone);
}
});
return true;
}
@Override
public boolean addComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.setComment(plot, comment);
return true;
}
@Override
public String toString() {
return "report";
}
@Override
public boolean removeComment(Plot plot, PlotComment comment) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.removeComment(plot, comment);
return false;
}
@Override
public boolean clearInbox(Plot plot) {
if (plot == null || plot.owner == null) {
return false;
}
DBFunc.clearInbox(plot, toString());
return false;
}
}

View File

@@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////////////////////////////////////////////
// PlotSquared - A plot manager and world generator for the Bukkit API /
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
// /
// This program is free software; you can redistribute it and/or modify /
// it under the terms of the GNU General Public License as published by /
// the Free Software Foundation; either version 3 of the License, or /
// (at your option) any later version. /
// /
// This program is distributed in the hope that it will be useful, /
// but WITHOUT ANY WARRANTY; without even the implied warranty of /
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /
// GNU General Public License for more details. /
// /
// You should have received a copy of the GNU General Public License /
// along with this program; if not, write to the Free Software Foundation, /
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
// /
// You can contact us via: support@intellectualsites.com /
////////////////////////////////////////////////////////////////////////////////////////////////////
package com.intellectualcrafters.plot.object.comment;
import com.intellectualcrafters.plot.object.PlotId;
/**
* @author Empire92
*/
public class PlotComment {
public final String comment;
public final String inbox;
public final String senderName;
public final PlotId id;
public final String world;
public final long timestamp;
public PlotComment(final String world, final PlotId id, final String comment, final String senderName, final String inbox, final long timestamp) {
this.world = world;
this.id = id;
this.comment = comment;
this.senderName = senderName;
this.inbox = inbox;
this.timestamp = timestamp;
}
}