Add base for Mailing
This commit is contained in:
parent
d9e00094dd
commit
4d25f4e8cb
|
|
@ -2,9 +2,12 @@ package com.alttd.chat.managers;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.alttd.chat.objects.Mail;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public final class ChatUserManager {
|
public final class ChatUserManager {
|
||||||
|
|
||||||
|
|
@ -28,4 +31,10 @@ public final class ChatUserManager {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Mail> getUnReadMail(ChatUser user) {
|
||||||
|
return user.getMails().stream()
|
||||||
|
.filter(Mail::isUnRead)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.alttd.chat.objects;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatUser {
|
public class ChatUser {
|
||||||
|
|
@ -15,8 +16,13 @@ public class ChatUser {
|
||||||
private String staffPrefix;
|
private String staffPrefix;
|
||||||
private String prefixAll;
|
private String prefixAll;
|
||||||
private boolean toggleGc;
|
private boolean toggleGc;
|
||||||
private UUID replytarget;
|
private UUID replyTarget;
|
||||||
|
|
||||||
|
private LinkedList<Mail> mails;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Not all of the objects are relevant to proxy or server, so the saving should only update if the value has been changed?
|
||||||
|
*/
|
||||||
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) {
|
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.partyId = partyId;
|
this.partyId = partyId;
|
||||||
|
|
@ -34,7 +40,8 @@ public class ChatUser {
|
||||||
prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api
|
prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api
|
||||||
// a boolean is lighter then a permission check, it's what I'd suggest doing here
|
// a boolean is lighter then a permission check, it's what I'd suggest doing here
|
||||||
toggleGc = toggle_Gc;//Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is...
|
toggleGc = toggle_Gc;//Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is...
|
||||||
replytarget = null;
|
replyTarget = null;
|
||||||
|
mails = new LinkedList<>(); // todo load mails
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
|
|
@ -103,11 +110,15 @@ public class ChatUser {
|
||||||
return toggleGc;
|
return toggleGc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getReplytarget() {
|
public UUID getReplyTarget() {
|
||||||
return replytarget;
|
return replyTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplytarget(UUID replytarget) {
|
public void setReplyTarget(UUID replyTarget) {
|
||||||
this.replytarget = replytarget;
|
this.replyTarget = replyTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedList<Mail> getMails() {
|
||||||
|
return mails;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
54
api/src/main/java/com/alttd/chat/objects/Mail.java
Normal file
54
api/src/main/java/com/alttd/chat/objects/Mail.java
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Mail {
|
||||||
|
|
||||||
|
private final UUID uuid; // the player
|
||||||
|
private final UUID sender; // the sender
|
||||||
|
private boolean read;
|
||||||
|
private final long sendTime; // any other option for this? does the db store recordcreation and edit time?
|
||||||
|
private long readTime; // any other option for this?
|
||||||
|
private final String message; // do we want staff to edit this after being send but being unread?
|
||||||
|
|
||||||
|
public Mail(UUID player, UUID sender, Boolean read, long sendTime, long readTime, String message) {
|
||||||
|
this.uuid = player;
|
||||||
|
this.sender = sender;
|
||||||
|
this.read = read;
|
||||||
|
this.sendTime = sendTime;
|
||||||
|
this.readTime = readTime;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getSender() {
|
||||||
|
return sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUnRead() {
|
||||||
|
return read;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRead(boolean read) {
|
||||||
|
this.read = read;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSendTime() {
|
||||||
|
return sendTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getReadTime() {
|
||||||
|
return readTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReadTime(long readTime) {
|
||||||
|
this.readTime = readTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,12 +51,11 @@ public class Utility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDisplayName(UUID uuid) {
|
public static String getDisplayName(UUID uuid) {
|
||||||
// todo add a <T> PlayerWrapper<T> @Destro
|
StringBuilder prefix = new StringBuilder();
|
||||||
/*ProxyServer proxy = ChatPlugin.getPlugin().getProxy();
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||||
if (proxy.getPlayer(uuid).isEmpty()) return "";
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
Player player = proxy.getPlayer(uuid).get();
|
if(user == null) return "";
|
||||||
return player.getUsername();*/
|
return user.getUsername();
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
67
velocity/src/main/java/com/alttd/chat/commands/SendMail.java
Normal file
67
velocity/src/main/java/com/alttd/chat/commands/SendMail.java
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.api.GlobalAdminChatEvent;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public class SendMail {
|
||||||
|
|
||||||
|
public SendMail(ProxyServer proxyServer) {
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("mail")
|
||||||
|
.requires(ctx -> ctx.hasPermission("command.proxy.mail"))// TODO permission system? load permissions from config?
|
||||||
|
.then(LiteralArgumentBuilder.<CommandSource>literal("send")
|
||||||
|
.then(RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||||
|
.suggests((context, builder) -> {
|
||||||
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
|
for (Player player : proxyServer.getAllPlayers()) {
|
||||||
|
possibleValues.add(player.getGameProfile().getName());
|
||||||
|
}
|
||||||
|
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||||
|
String remaining = builder.getRemaining().toLowerCase();
|
||||||
|
for (String str : possibleValues) {
|
||||||
|
if (str.toLowerCase().startsWith(remaining)) {
|
||||||
|
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.then(RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
|
.executes(context -> {
|
||||||
|
// todo construct the mail and notify the player if online?
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> 0)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.executes(context -> 0)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
|
/*for (String alias : Config.MAILCOMMANDALIASES) {
|
||||||
|
metaBuilder.aliases(alias);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user