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.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class ChatUserManager {
|
||||
|
||||
|
|
@ -28,4 +31,10 @@ public final class ChatUserManager {
|
|||
}
|
||||
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.util.Utility;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatUser {
|
||||
|
|
@ -15,8 +16,13 @@ public class ChatUser {
|
|||
private String staffPrefix;
|
||||
private String prefixAll;
|
||||
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) {
|
||||
this.uuid = uuid;
|
||||
this.partyId = partyId;
|
||||
|
|
@ -34,7 +40,8 @@ public class ChatUser {
|
|||
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
|
||||
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() {
|
||||
|
|
@ -103,11 +110,15 @@ public class ChatUser {
|
|||
return toggleGc;
|
||||
}
|
||||
|
||||
public UUID getReplytarget() {
|
||||
return replytarget;
|
||||
public UUID getReplyTarget() {
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
public void setReplytarget(UUID replytarget) {
|
||||
this.replytarget = replytarget;
|
||||
public void setReplyTarget(UUID 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) {
|
||||
// todo add a <T> PlayerWrapper<T> @Destro
|
||||
/*ProxyServer proxy = ChatPlugin.getPlugin().getProxy();
|
||||
if (proxy.getPlayer(uuid).isEmpty()) return "";
|
||||
Player player = proxy.getPlayer(uuid).get();
|
||||
return player.getUsername();*/
|
||||
return "";
|
||||
StringBuilder prefix = new StringBuilder();
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return "";
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
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