Add PartyUser implement it into Party

This commit is contained in:
destro174
2021-08-08 22:07:47 +02:00
parent aaaa46e97f
commit 0ace870550
7 changed files with 108 additions and 51 deletions
@@ -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;
}
}
@@ -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;
}
}