2015-04-06 11:59:22 +02:00
|
|
|
package com.intellectualcrafters.plot.object.comment;
|
|
|
|
|
2015-05-14 12:34:08 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
2015-04-06 11:59:22 +02:00
|
|
|
import java.util.HashMap;
|
2015-05-14 12:34:08 +02:00
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
2015-04-06 11:59:22 +02:00
|
|
|
|
2015-05-14 12:34:08 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
2015-04-09 07:41:14 +02:00
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2015-05-14 12:34:08 +02:00
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
|
|
|
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
2015-04-09 07:41:14 +02:00
|
|
|
|
2015-04-06 11:59:22 +02:00
|
|
|
|
|
|
|
public class CommentManager {
|
|
|
|
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
|
|
|
|
|
2015-05-14 12:34:08 +02:00
|
|
|
public static void sendTitle(final PlotPlayer player, final Plot plot) {
|
|
|
|
if (!Settings.COMMENT_NOTIFICATIONS) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!plot.isOwner(player.getUUID())) {
|
|
|
|
return;
|
2015-04-09 07:41:14 +02:00
|
|
|
}
|
2015-05-14 12:34:08 +02:00
|
|
|
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) {
|
2015-06-05 14:47:23 +02:00
|
|
|
AbstractTitle.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total), ChatColor.GOLD, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
|
2015-05-14 12:34:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 20);
|
2015-04-09 07:41:14 +02:00
|
|
|
}
|
|
|
|
|
2015-05-14 12:34:08 +02:00
|
|
|
public static long getTimestamp(PlotPlayer player, String inbox) {
|
|
|
|
Object meta = player.getMeta("inbox:"+inbox);
|
|
|
|
if (meta == null) {
|
|
|
|
return player.getPreviousLogin();
|
|
|
|
}
|
|
|
|
return (Long) meta;
|
2015-04-09 07:41:14 +02:00
|
|
|
}
|
|
|
|
|
2015-04-06 11:59:22 +02:00
|
|
|
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());
|
|
|
|
}
|
2015-04-09 07:41:14 +02:00
|
|
|
}
|