mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 15:16:45 +01:00
Comment notifications
This commit is contained in:
parent
f3777bd8c5
commit
9cb06d625d
@ -583,10 +583,6 @@ public class PlotSquared {
|
|||||||
ExpireManager.runTask();
|
ExpireManager.runTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.COMMENT_NOTIFICATION_INTERVAL > 0) {
|
|
||||||
CommentManager.runTask();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy files
|
// Copy files
|
||||||
copyFile("town.template", "templates");
|
copyFile("town.template", "templates");
|
||||||
copyFile("skyblock.template", "templates");
|
copyFile("skyblock.template", "templates");
|
||||||
@ -878,7 +874,7 @@ public class PlotSquared {
|
|||||||
options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES);
|
options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES);
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
options.put("comments.notifications.interval", Settings.COMMENT_NOTIFICATION_INTERVAL);
|
options.put("comments.notifications.enabled", Settings.COMMENT_NOTIFICATIONS);
|
||||||
|
|
||||||
// Plot limits
|
// Plot limits
|
||||||
options.put("global_limit", Settings.GLOBAL_LIMIT);
|
options.put("global_limit", Settings.GLOBAL_LIMIT);
|
||||||
@ -954,7 +950,7 @@ public class PlotSquared {
|
|||||||
Settings.CHUNK_PROCESSOR_MAX_ENTITIES= config.getInt("chunk-processor.max-entities");
|
Settings.CHUNK_PROCESSOR_MAX_ENTITIES= config.getInt("chunk-processor.max-entities");
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
Settings.COMMENT_NOTIFICATION_INTERVAL = config.getInt("comments.notifications.interval");
|
Settings.COMMENT_NOTIFICATIONS = config.getBoolean("comments.notifications.enabled");
|
||||||
|
|
||||||
// Plot limits
|
// Plot limits
|
||||||
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
|
Settings.MAX_AUTO_SIZE = config.getInt("claim.max-auto-area");
|
||||||
|
@ -92,7 +92,7 @@ public class Inbox extends SubCommand {
|
|||||||
int unread = 0;
|
int unread = 0;
|
||||||
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
for (PlotComment comment : (ArrayList<PlotComment>) value) {
|
||||||
total++;
|
total++;
|
||||||
if (comment.timestamp > player.getPreviousLogin()) {
|
if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) {
|
||||||
unread++;
|
unread++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,6 +122,7 @@ public class Inbox extends SubCommand {
|
|||||||
sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", "));
|
sendMessage(player, C.INVALID_INBOX, StringUtils.join(CommentManager.inboxes.keySet(),", "));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
player.setMeta("inbox:" + inbox.toString(), System.currentTimeMillis());
|
||||||
final int page;
|
final int page;
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
switch (args[1].toLowerCase()) {
|
switch (args[1].toLowerCase()) {
|
||||||
|
@ -109,6 +109,7 @@ public enum C {
|
|||||||
/*
|
/*
|
||||||
* Comment
|
* Comment
|
||||||
*/
|
*/
|
||||||
|
INBOX_NOTIFICATION("%s unread messages. Use /plot inbox", "Comment"),
|
||||||
NOT_VALID_INBOX_INDEX("$2No comment at index %s", "Comment"),
|
NOT_VALID_INBOX_INDEX("$2No comment at index %s", "Comment"),
|
||||||
INBOX_ITEM("$2 - $4%s", "Comment"),
|
INBOX_ITEM("$2 - $4%s", "Comment"),
|
||||||
COMMENT_SYNTAX("$2Use /plots comment [X;Z] <%s> <comment>", "Comment"),
|
COMMENT_SYNTAX("$2Use /plots comment [X;Z] <%s> <comment>", "Comment"),
|
||||||
|
@ -46,7 +46,7 @@ public class Settings {
|
|||||||
/**
|
/**
|
||||||
* Comment system
|
* Comment system
|
||||||
*/
|
*/
|
||||||
public static int COMMENT_NOTIFICATION_INTERVAL = -1;
|
public static boolean COMMENT_NOTIFICATIONS = false;
|
||||||
/**
|
/**
|
||||||
* Chunk processor
|
* Chunk processor
|
||||||
*/
|
*/
|
||||||
|
@ -39,7 +39,9 @@ import com.intellectualcrafters.plot.flag.FlagManager;
|
|||||||
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
import com.intellectualcrafters.plot.object.Plot;
|
import com.intellectualcrafters.plot.object.Plot;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.comment.CommentManager;
|
||||||
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,13 +124,14 @@ public class PlotListener extends APlotListener {
|
|||||||
final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + "").replaceAll("%greeting%", greeting);
|
final String sTitleMain = C.TITLE_ENTERED_PLOT.s().replaceAll("%x%", plot.id.x + "").replaceAll("%z%", plot.id.y + "").replaceAll("%world%", plot.world + "").replaceAll("%greeting%", greeting);
|
||||||
final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner)).replaceAll("%greeting%", greeting);
|
final String sTitleSub = C.TITLE_ENTERED_PLOT_SUB.s().replaceFirst("%s", getName(plot.owner)).replaceAll("%greeting%", greeting);
|
||||||
if (AbstractTitle.TITLE_CLASS != null) {
|
if (AbstractTitle.TITLE_CLASS != null) {
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, sTitleMain, sTitleSub, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s()), ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
|
AbstractTitle.TITLE_CLASS.sendTitle(pp, sTitleMain, sTitleSub, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_COLOR.s()), ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
final PlayerEnterPlotEvent callEvent = new PlayerEnterPlotEvent(player, plot);
|
final PlayerEnterPlotEvent callEvent = new PlayerEnterPlotEvent(player, plot);
|
||||||
Bukkit.getPluginManager().callEvent(callEvent);
|
Bukkit.getPluginManager().callEvent(callEvent);
|
||||||
}
|
}
|
||||||
|
CommentManager.sendTitle(pp, plot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,36 +1,71 @@
|
|||||||
package com.intellectualcrafters.plot.object.comment;
|
package com.intellectualcrafters.plot.object.comment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.mutable.MutableInt;
|
||||||
|
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.PlotPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.RunnableVal;
|
||||||
|
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||||
|
import com.intellectualcrafters.plot.util.TaskManager;
|
||||||
|
|
||||||
|
|
||||||
public class CommentManager {
|
public class CommentManager {
|
||||||
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
|
public static HashMap<String, CommentInbox> inboxes = new HashMap<>();
|
||||||
|
|
||||||
private static HashMap<String, Long> timestamps = new HashMap<>();
|
public static void sendTitle(final PlotPlayer player, final Plot plot) {
|
||||||
|
if (!Settings.COMMENT_NOTIFICATIONS) {
|
||||||
public static void runTask() {
|
return;
|
||||||
// TaskManager.runTaskRepeat(new Runnable() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void run() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
// }, Settings.COMMENT_NOTIFICATION_INTERVAL * 1200);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getTimestamp(PlotPlayer player) {
|
|
||||||
Long time = timestamps.get(player.getName());
|
|
||||||
if (time == null) {
|
|
||||||
time = player.getPreviousLogin();
|
|
||||||
timestamps.put(player.getName(), time);
|
|
||||||
}
|
}
|
||||||
return time;
|
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.TITLE_CLASS.sendTitle(player, "", C.INBOX_NOTIFICATION.s().replaceAll("%s", "" + total), ChatColor.GOLD, ChatColor.valueOf(C.TITLE_ENTERED_PLOT_SUB_COLOR.s()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTime(PlotPlayer player) {
|
public static long getTimestamp(PlotPlayer player, String inbox) {
|
||||||
timestamps.put(player.getName(), System.currentTimeMillis());
|
Object meta = player.getMeta("inbox:"+inbox);
|
||||||
|
if (meta == null) {
|
||||||
|
return player.getPreviousLogin();
|
||||||
|
}
|
||||||
|
return (Long) meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addInbox(CommentInbox inbox) {
|
public static void addInbox(CommentInbox inbox) {
|
||||||
|
@ -3,8 +3,10 @@ package com.intellectualcrafters.plot.titles;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
public abstract class AbstractTitle {
|
public abstract class AbstractTitle {
|
||||||
public static AbstractTitle TITLE_CLASS;
|
public static AbstractTitle TITLE_CLASS;
|
||||||
|
|
||||||
public abstract void sendTitle(Player player, String head, String sub, ChatColor head_color, ChatColor sub_color);
|
public abstract void sendTitle(PlotPlayer player, String head, String sub, ChatColor head_color, ChatColor sub_color);
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,17 @@ package com.intellectualcrafters.plot.titles;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
public class DefaultTitle extends AbstractTitle {
|
public class DefaultTitle extends AbstractTitle {
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(final Player player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
||||||
try {
|
try {
|
||||||
final DefaultTitleManager title = new DefaultTitleManager(head, sub, 1, 2, 1);
|
final DefaultTitleManager title = new DefaultTitleManager(head, sub, 1, 2, 1);
|
||||||
title.setTitleColor(head_color);
|
title.setTitleColor(head_color);
|
||||||
title.setSubtitleColor(sub_color);
|
title.setSubtitleColor(sub_color);
|
||||||
title.send(player);
|
title.send(((BukkitPlayer) player).player);
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
|
AbstractTitle.TITLE_CLASS = new DefaultTitle_183();
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color);
|
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color);
|
||||||
|
@ -3,14 +3,17 @@ package com.intellectualcrafters.plot.titles;
|
|||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
public class DefaultTitle_183 extends AbstractTitle {
|
public class DefaultTitle_183 extends AbstractTitle {
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(final Player player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
||||||
try {
|
try {
|
||||||
final DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, 1, 2, 1);
|
final DefaultTitleManager_183 title = new DefaultTitleManager_183(head, sub, 1, 2, 1);
|
||||||
title.setTitleColor(head_color);
|
title.setTitleColor(head_color);
|
||||||
title.setSubtitleColor(sub_color);
|
title.setSubtitleColor(sub_color);
|
||||||
title.send(player);
|
title.send(((BukkitPlayer) player).player);
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
AbstractTitle.TITLE_CLASS = new HackTitle();
|
AbstractTitle.TITLE_CLASS = new HackTitle();
|
||||||
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color);
|
AbstractTitle.TITLE_CLASS.sendTitle(player, head, sub, head_color, sub_color);
|
||||||
|
@ -5,15 +5,17 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
|
import com.intellectualcrafters.plot.object.BukkitPlayer;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
|
|
||||||
public class HackTitle extends AbstractTitle {
|
public class HackTitle extends AbstractTitle {
|
||||||
@Override
|
@Override
|
||||||
public void sendTitle(final Player player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
public void sendTitle(final PlotPlayer player, final String head, final String sub, final ChatColor head_color, final ChatColor sub_color) {
|
||||||
try {
|
try {
|
||||||
final HackTitleManager title = new HackTitleManager(head, sub, 1, 2, 1);
|
final HackTitleManager title = new HackTitleManager(head, sub, 1, 2, 1);
|
||||||
title.setTitleColor(head_color);
|
title.setTitleColor(head_color);
|
||||||
title.setSubtitleColor(sub_color);
|
title.setSubtitleColor(sub_color);
|
||||||
title.send(player);
|
title.send(((BukkitPlayer) player).player);
|
||||||
} catch (final Throwable e) {
|
} catch (final Throwable e) {
|
||||||
PlotSquared.log("&cYour server version does not support titles!");
|
PlotSquared.log("&cYour server version does not support titles!");
|
||||||
Settings.TITLES = false;
|
Settings.TITLES = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user