Add PartyUser implement it into Party
This commit is contained in:
parent
aaaa46e97f
commit
0ace870550
|
|
@ -5,6 +5,7 @@ import com.alttd.chat.managers.PartyManager;
|
|||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
|
||||
|
|
@ -176,19 +177,18 @@ public class Queries {
|
|||
while (resultSet.next()) {
|
||||
int id = resultSet.getInt("party_id");
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
// String displayName = resultSet.getString("nickname");
|
||||
// if (displayName == null || displayName.isEmpty()) {
|
||||
// displayName = resultSet.getString("Username");
|
||||
// }
|
||||
String displayName = resultSet.getString("Username"); // FIXME: 08/08/2021 only using display name till we can fix nickname colors
|
||||
String displayName = resultSet.getString("nickname");
|
||||
if (displayName == null || displayName.isEmpty()) {
|
||||
displayName = resultSet.getString("Username");
|
||||
}
|
||||
String playerName = resultSet.getString("Username");
|
||||
|
||||
Party party = PartyManager.getParty(id);
|
||||
if (party == null) {
|
||||
ALogger.warn("Unable to retrieve party: " + id);
|
||||
continue;
|
||||
}
|
||||
|
||||
party.putUser(uuid, displayName);
|
||||
party.putPartyUser(new PartyUser(uuid, displayName, playerName));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
@ -218,13 +218,13 @@ public class Queries {
|
|||
party.resetPartyUsers();
|
||||
while (resultSet.next()) {
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
// String displayName = resultSet.getString("nickname");
|
||||
// if (displayName == null || displayName.isEmpty()) {
|
||||
// displayName = resultSet.getString("Username");
|
||||
// }
|
||||
String displayName = resultSet.getString("Username"); // FIXME: 08/08/2021 only using display name till we can fix nickname colors
|
||||
String displayName = resultSet.getString("nickname");
|
||||
if (displayName == null || displayName.isEmpty()) {
|
||||
displayName = resultSet.getString("Username");
|
||||
}
|
||||
String playerName = resultSet.getString("Username");
|
||||
|
||||
party.putUser(uuid, displayName);
|
||||
party.putPartyUser(new PartyUser(uuid, displayName, playerName));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class PartyManager {
|
|||
|
||||
public static Party getParty(UUID uuid) {
|
||||
for(Party party : parties) {
|
||||
if(party.getPartyUsers().containsKey(uuid)) {
|
||||
if(party.getPartyUsersUuid().contains(uuid)) {
|
||||
return party;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alttd.chat.managers.PartyManager;
|
|||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Party {
|
||||
|
||||
|
|
@ -13,27 +14,27 @@ public class Party {
|
|||
private UUID ownerUuid;
|
||||
private String partyName;
|
||||
private String partyPassword;
|
||||
private final HashMap<UUID, String> partyUsers; //TODO might need to be a map?
|
||||
private static ArrayList<PartyUser> partyUsers; //TODO might need to be a map?
|
||||
|
||||
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
|
||||
this.partyId = partyId;
|
||||
this.ownerUuid = ownerUuid;
|
||||
this.partyName = partyName;
|
||||
this.partyPassword = partyPassword;
|
||||
partyUsers = new HashMap<>();
|
||||
partyUsers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void putUser(UUID uuid, String displayName) {
|
||||
this.partyUsers.put(uuid, displayName);
|
||||
public void putPartyUser(PartyUser partyUser) {
|
||||
partyUsers.add(partyUser);
|
||||
}
|
||||
|
||||
public void addUser(ChatUser partyUser, String displayName) {
|
||||
public void addUser(ChatUser chatUser, String playerName) {
|
||||
// this.partyUsers.put(partyUser.getUuid(), PlainComponentSerializer.plain().serialize(partyUser.getDisplayName()));
|
||||
// partyUser.setPartyId(getPartyId());
|
||||
// Queries.addPartyUser(partyUser);
|
||||
this.partyUsers.put(partyUser.getUuid(), displayName);
|
||||
partyUser.setPartyId(getPartyId());
|
||||
Queries.addPartyUser(partyUser);
|
||||
partyUsers.add(new PartyUser(chatUser.getUuid(), chatUser.getDisplayName(), playerName));
|
||||
chatUser.setPartyId(getPartyId());
|
||||
Queries.addPartyUser(chatUser);
|
||||
}
|
||||
|
||||
public void removeUser(UUID uuid) {
|
||||
|
|
@ -54,7 +55,7 @@ public class Party {
|
|||
}
|
||||
|
||||
public UUID newOwner() {
|
||||
UUID uuid = partyUsers.keySet().iterator().next();
|
||||
UUID uuid = partyUsers.iterator().next().getUuid();
|
||||
setOwnerUuid(uuid);
|
||||
return uuid;
|
||||
}
|
||||
|
|
@ -86,7 +87,7 @@ public class Party {
|
|||
return !partyPassword.isEmpty();
|
||||
}
|
||||
|
||||
public HashMap<UUID, String> getPartyUsers() {
|
||||
public List<PartyUser> getPartyUsers() {
|
||||
return partyUsers;
|
||||
}
|
||||
|
||||
|
|
@ -96,14 +97,19 @@ public class Party {
|
|||
}
|
||||
|
||||
public List<UUID> getPartyUsersUuid() {
|
||||
return new ArrayList<>(partyUsers.keySet());
|
||||
}
|
||||
|
||||
public String getUserDisplayName(UUID uuid) {
|
||||
return partyUsers.get(uuid);
|
||||
return partyUsers.stream().map(PartyUser::getUuid).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void resetPartyUsers() { // FIXME: 08/08/2021 This is a temp solution until bungee messages take over updating parties
|
||||
partyUsers.clear();
|
||||
}
|
||||
|
||||
public PartyUser getPartyUser(UUID uuid) {
|
||||
for(PartyUser user : partyUsers) {
|
||||
if(uuid.equals(user.getUuid())) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
36
api/src/main/java/com/alttd/chat/objects/PartyUser.java
Normal file
36
api/src/main/java/com/alttd/chat/objects/PartyUser.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package com.alttd.chat.objects;
|
||||
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartyUser {
|
||||
|
||||
protected UUID uuid;
|
||||
protected Component displayName;
|
||||
protected String playerName;
|
||||
|
||||
public PartyUser(UUID uuid, String displayName, String playerName) {
|
||||
this(uuid, Utility.applyColor(displayName), playerName);
|
||||
}
|
||||
|
||||
public PartyUser(UUID uuid, Component displayName, String playerName) {
|
||||
this.uuid = uuid;
|
||||
this.displayName = displayName;
|
||||
this.playerName = playerName;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,11 +7,13 @@ import com.alttd.chat.managers.ChatUserManager;
|
|||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -41,6 +43,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MiniMessage miniMessage = MiniMessage.get();
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "create" -> {
|
||||
if (args.length < 3 || !args[1].matches("[\\w]{3,16}") || !args[2].matches("[\\w]{3,16}")) {
|
||||
|
|
@ -119,7 +122,7 @@ public class ChatParty implements CommandExecutor, TabCompleter {
|
|||
sender.sendMessage(MiniMessage.get().parse("<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>"));
|
||||
ChatPlugin.getInstance().getChatHandler().partyMessage(party, player, "<dark_aqua>" +
|
||||
player.getName() +
|
||||
" left the chat party, the new party owner is " + party.getUserDisplayName(uuid));
|
||||
" left the chat party, the new party owner is " + party.getPartyUser(uuid).getPlayerName());
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
|
|
@ -169,19 +172,24 @@ public class ChatParty implements CommandExecutor, TabCompleter {
|
|||
break;
|
||||
}
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<gold><bold>Chat party info</bold>:\n</gold>")
|
||||
.append("<green>Name: <dark_aqua>").append(party.getPartyName()).append("</dark_aqua>\n")
|
||||
.append(party.getOwnerUuid().equals(player.getUniqueId()) ? "Password: <dark_aqua>" + party.getPartyPassword() + "</dark_aqua>\n" : "")
|
||||
.append("Owner: ").append(party.getUserDisplayName(party.getOwnerUuid())).append("\n")
|
||||
.append("Members: ");
|
||||
for (String displayName : party.getPartyUsers().values()) {
|
||||
stringBuilder.append(displayName).append(", ");
|
||||
String message = "<gold><bold>Chat party info</bold>:\n</gold>"
|
||||
+ "<green>Name: <dark_aqua><partyname></dark_aqua>\n"
|
||||
+ (party.getOwnerUuid().equals(player.getUniqueId()) ? "Password: <dark_aqua><password></dark_aqua>\n" : "")
|
||||
+ "Owner: <ownername>\n"
|
||||
+ "Members: <members>";
|
||||
List<Component> displayNames = new ArrayList<>();
|
||||
for (PartyUser partyUser : party.getPartyUsers()) {
|
||||
displayNames.add(partyUser.getDisplayName());
|
||||
}
|
||||
|
||||
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
|
||||
List<Template> templates = new ArrayList<>(List.of(
|
||||
Template.of("partyname", party.getPartyName()),
|
||||
Template.of("password", party.getPartyPassword()),
|
||||
Template.of("ownername", party.getPartyUser(party.getOwnerUuid()).getDisplayName()),
|
||||
Template.of("members", Component.join(Component.text(", "), displayNames)),
|
||||
Template.of("message", message)));
|
||||
|
||||
sender.sendMessage(Utility.applyColor(stringBuilder.toString()));
|
||||
sender.sendMessage(miniMessage.parse("<message>", templates));
|
||||
}
|
||||
// TODO: 08/08/2021 add a way to change the password and owner (and name?)
|
||||
default -> {
|
||||
|
|
|
|||
|
|
@ -192,7 +192,7 @@ public class ChatHandler {
|
|||
|
||||
Component spyMessage = miniMessage.parse(Config.PARTY_SPY, templates);
|
||||
for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsers().containsKey(pl.getUniqueId())) { // todo add a toggle for social spy
|
||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) { // todo add a toggle for social spy
|
||||
pl.sendMessage(spyMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import com.alttd.chat.database.Queries;
|
|||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
|
|
@ -98,12 +99,15 @@ public class PluginMessage implements PluginMessageListener {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Component component = MiniMessage.get().parse("<dark_aqua>* " + party.getPartyUsers().get(uuid) + " logged in to Altitude.");
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if(user != null) {
|
||||
Component component = MiniMessage.get().parse("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsers().containsKey(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
break;
|
||||
|
|
@ -119,12 +123,15 @@ public class PluginMessage implements PluginMessageListener {
|
|||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Component component = MiniMessage.get().parse("<dark_aqua>* " + party.getPartyUsers().get(uuid) + " logged out of Altitude.");
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if(user != null) {
|
||||
Component component = MiniMessage.get().parse("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsers().containsKey(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user