Chat/api/src/main/java/com/alttd/chat/objects/ChatUser.java

167 lines
5.3 KiB
Java
Raw Normal View History

2021-06-02 17:55:55 +00:00
package com.alttd.chat.objects;
2021-05-14 00:33:23 +00:00
import com.alttd.chat.database.Queries;
import com.alttd.chat.objects.channels.Channel;
import com.alttd.chat.util.Utility;
2021-07-17 22:48:55 +00:00
import net.kyori.adventure.text.Component;
2021-05-14 00:33:23 +00:00
2021-07-28 18:42:09 +00:00
import java.util.ArrayList;
import java.util.List;
2021-05-14 00:33:23 +00:00
import java.util.UUID;
2022-01-29 22:21:35 +00:00
import java.util.stream.Collectors;
2021-05-14 00:33:23 +00:00
public class ChatUser {
2021-06-07 08:51:00 +00:00
private final UUID uuid; // player uuid
private int partyId; // the party they are in
private Channel toggledChannel;
2021-07-17 22:48:55 +00:00
private String name; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
private Component displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
2021-07-27 16:46:58 +00:00
// private Component prefix; // doesn't need saving, we get this from luckperms
// private Component staffPrefix; // doesn't need saving, we get this from luckperms
// private Component prefixAll; // doesn't need saving, we get this from luckperms
2021-07-30 01:16:41 +00:00
//private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
2021-06-23 19:44:04 +00:00
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
2021-06-07 08:51:00 +00:00
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
2021-08-22 08:47:39 +00:00
private boolean spy;
2021-07-28 18:42:09 +00:00
private List<Mail> mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message
private List<UUID> ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player?
private List<UUID> ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player?
2022-01-05 14:25:17 +00:00
private boolean isMuted;
2021-05-15 22:28:47 +00:00
public ChatUser(UUID uuid, int partyId, Channel toggledChannel) {
2021-05-14 00:33:23 +00:00
this.uuid = uuid;
this.partyId = partyId;
this.toggledChannel = toggledChannel;
2021-05-14 00:33:23 +00:00
name = Queries.getDisplayName(uuid);
2021-07-17 22:48:55 +00:00
if (name == null) {
name = Utility.getDisplayName(uuid, "");
}
2021-07-17 22:48:55 +00:00
setDisplayName(name);
2021-05-14 00:33:23 +00:00
2021-07-27 16:46:58 +00:00
// prefix = Utility.getPrefix(uuid, true); // TODO we need to update this, so cache and update when needed or always request it?
// staffPrefix = Utility.getStaffPrefix(uuid);
//
// prefixAll = Utility.getPrefix(uuid, false);
2021-05-22 18:34:32 +00:00
2021-05-15 22:28:47 +00:00
replyTarget = null;
2021-06-07 08:38:38 +00:00
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
2021-07-27 16:46:58 +00:00
mails = Queries.getMails(uuid);
ignoredPlayers = Queries.getIgnoredUsers(uuid);
2021-07-28 18:42:09 +00:00
ignoredBy = new ArrayList<>(); // todo load ignoredPlayers
2021-08-22 08:47:39 +00:00
spy = true;
2022-01-05 14:25:17 +00:00
isMuted = false; // TODO load from db
2021-05-14 00:33:23 +00:00
}
public UUID getUuid() {
return uuid;
}
public int getPartyId() {
return partyId;
}
public void setPartyId(int partyId) {
this.partyId = partyId;
}
public Channel getToggledChannel() {
return toggledChannel;
2021-05-14 00:33:23 +00:00
}
public void setToggledChannel(Channel channel) {
toggledChannel = channel;
Queries.setToggledChannel(toggledChannel, uuid); //TODO: Async pls - no CompleteableFuture<>!
2021-05-14 00:33:23 +00:00
}
2021-07-17 22:48:55 +00:00
public Component getDisplayName() {
2021-05-14 00:33:23 +00:00
return displayName;
}
public void setDisplayName(String displayName) {
2021-07-17 22:48:55 +00:00
this.displayName = Utility.applyColor(displayName);
2021-05-14 00:33:23 +00:00
}
2021-07-17 22:48:55 +00:00
public Component getPrefix() {
2021-07-27 16:46:58 +00:00
//return prefix;
return Utility.getPrefix(uuid, true); // No longer cache this data
2021-05-14 00:33:23 +00:00
}
2021-07-17 22:48:55 +00:00
public Component getStaffPrefix() {
2021-07-27 16:46:58 +00:00
//return staffPrefix;
return Utility.getStaffPrefix(uuid);
2021-05-14 00:33:23 +00:00
}
2021-07-17 22:48:55 +00:00
public Component getPrefixAll() {
2021-07-27 16:46:58 +00:00
//return prefixAll;
return Utility.getPrefix(uuid, false);
2021-05-14 00:33:23 +00:00
}
2021-06-23 19:44:04 +00:00
public String getReplyTarget() {
2021-05-15 22:28:47 +00:00
return replyTarget;
}
2021-06-23 19:44:04 +00:00
public void setReplyTarget(String replyTarget) {
2021-05-15 22:28:47 +00:00
this.replyTarget = replyTarget;
2021-05-15 19:16:01 +00:00
}
2021-07-28 18:42:09 +00:00
public List<Mail> getMails() {
2021-05-15 22:28:47 +00:00
return mails;
2021-05-15 19:16:01 +00:00
}
2021-05-22 18:34:32 +00:00
2022-01-29 22:21:35 +00:00
public List<Mail> getUnReadMail() {
return getMails().stream()
.filter(Mail::isUnRead)
.collect(Collectors.toList());
}
2021-05-22 18:34:32 +00:00
public void addMail(Mail mail) {
mails.add(mail);
}
2021-06-06 19:32:13 +00:00
2021-07-28 18:42:09 +00:00
public List<UUID> getIgnoredPlayers() {
2021-06-07 08:38:38 +00:00
return ignoredPlayers;
}
public void addIgnoredPlayers(UUID uuid) {
ignoredPlayers.add(uuid);
}
2021-07-27 16:46:58 +00:00
public void removeIgnoredPlayers(UUID uuid) {
ignoredPlayers.remove(uuid);
}
2021-07-28 18:42:09 +00:00
public List<UUID> getIgnoredBy() {
2021-06-07 08:51:00 +00:00
return ignoredBy;
}
public void addIgnoredBy(UUID uuid) {
ignoredBy.add(uuid);
}
2021-06-06 19:32:13 +00:00
public long getGcCooldown() {
return gcCooldown;
}
2021-06-07 08:38:38 +00:00
public void setGcCooldown(long time) {
this.gcCooldown = time;
}
2021-08-22 08:47:39 +00:00
public boolean isSpy() {
return spy;
}
public void toggleSpy() {
this.spy = !spy;
}
2022-01-05 14:25:17 +00:00
public boolean isMuted() {
return isMuted;
}
public void setMuted(boolean muted) {
this.isMuted = muted;
}
2021-05-14 00:33:23 +00:00
}