Changed PartyUser to be ChatUser

This commit is contained in:
Teriuihi 2021-05-14 02:33:23 +02:00
parent cec31f675e
commit 2475197526
4 changed files with 116 additions and 59 deletions

View File

@ -1,7 +1,7 @@
package com.alttd.chat.database;
import com.alttd.chat.objects.Party;
import com.alttd.chat.objects.PartyUser;
import com.alttd.chat.objects.ChatUser;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -156,7 +156,7 @@ public class Queries {
e.printStackTrace();
}
getPartyUsers(parties); //TODO This parameter should be temporary, it should access the actual list of parties normally
getChatUsers(parties); //TODO This parameter should be temporary, it should access the actual list of parties normally
}
public static Party addParty(UUID partyOwner, String partyName, String password) {
@ -247,10 +247,10 @@ public class Queries {
//-----------------------------------------
//Party Users
//Chat Users
private static void getPartyUsers(HashMap<Integer, Party> parties) {
String query = "SELECT * FROM party_users";
private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere
String query = "SELECT * FROM chat_users";
try {
Connection connection = DatabaseConnection.getConnection();
@ -264,15 +264,19 @@ public class Queries {
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
boolean force_tp = resultSet.getInt("force_tp") == 1;
if (partyId == 0) {
continue;
}
Party party = parties.get(partyId);
if (party == null) {
//TODO log this properly
System.out.println("INCORRECT LOGGING: party was empty, the party id stored in the database with user " + uuid + " was invalid.");
continue;
}
party.addUser(new PartyUser(uuid, partyId, toggled_chat, force_tp));
party.addUser(new ChatUser(uuid, partyId, toggled_chat, force_tp));
}
} catch (SQLException e) {
@ -280,7 +284,7 @@ public class Queries {
}
}
public static void addUser(PartyUser user) {
public static void addUser(ChatUser user) {
String query = "INSERT INTO party_users (uuid, party_id, toggled_chat, force_tp) VALUES (?, ?, ?, ?)";
try {

View File

@ -0,0 +1,98 @@
package com.alttd.chat.objects;
import com.alttd.chat.database.Queries;
import java.util.UUID;
public class ChatUser {
private final UUID uuid;
private final int partyId;
private boolean toggledChat;
private boolean forceTp;
private String displayName;
private String prefix;
private String staffPrefix;
private String prefixAll;
private boolean toggleGc;
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp) {
this.uuid = uuid;
this.partyId = partyId;
this.toggledChat = toggled_chat;
this.forceTp = force_tp;
//TODO Get the user somehow and use that to check their prefixes
displayName = Queries.getNickname(uuid);
if (displayName == null) {
//TODO displayName = player.getName() or something
}
//TODO Get the user somehow and use that to check the toggleGc permission
}
public UUID getUuid() {
return uuid;
}
public int getPartyId() {
return partyId;
}
public boolean toggledChat() {
return toggledChat;
}
public void toggleChat() {
toggledChat = !toggledChat;
Queries.setChatState(toggledChat, uuid); //TODO: Async pls
}
public boolean ForceTp() {
return forceTp;
}
public void toggleForceTp() {
forceTp = !forceTp;
Queries.setForceTpState(forceTp, uuid); //TODO: Async pls
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getStaffPrefix() {
return staffPrefix;
}
public void setStaffPrefix(String staffPrefix) {
this.staffPrefix = staffPrefix;
}
public String getPrefixAll() {
return prefixAll;
}
public void setPrefixAll(String prefixAll) {
this.prefixAll = prefixAll;
}
public void toggleGc() {
toggleGc = !toggleGc;
}
public boolean isGcOn() {
return toggleGc;
}
}

View File

@ -11,7 +11,7 @@ public class Party {
private UUID ownerUuid;
private String partyName;
private String partyPassword;
private ArrayList<PartyUser> partyUsers; //TODO might need to be a map?
private ArrayList<ChatUser> partyUsers; //TODO might need to be a map?
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
this.partyId = partyId;
@ -21,16 +21,16 @@ public class Party {
partyUsers = new ArrayList<>();
}
public void addUser(ArrayList<PartyUser> partyUsers) {
public void addUser(ArrayList<ChatUser> partyUsers) {
this.partyUsers.addAll(partyUsers);
}
public void addUser(PartyUser partyUser) {
public void addUser(ChatUser partyUser) {
this.partyUsers.add(partyUser);
Queries.addUser(partyUser);
}
public void removeUser(PartyUser partyUser) {
public void removeUser(ChatUser partyUser) {
partyUsers.remove(partyUser);
Queries.removeUser(partyUser.getUuid());
}
@ -70,11 +70,11 @@ public class Party {
return !partyPassword.isEmpty();
}
public ArrayList<PartyUser> getPartyUsers() {
public ArrayList<ChatUser> getPartyUsers() {
return partyUsers;
}
public void setPartyUsers(ArrayList<PartyUser> partyUsers) {
public void setPartyUsers(ArrayList<ChatUser> partyUsers) {
this.partyUsers = partyUsers;
}
}

View File

@ -1,45 +0,0 @@
package com.alttd.chat.objects;
import com.alttd.chat.database.Queries;
import java.util.UUID;
public class PartyUser {
private final UUID uuid;
private final int partyId;
private boolean toggledChat;
private boolean forceTp;
public PartyUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp) {
this.uuid = uuid;
this.partyId = partyId;
this.toggledChat = toggled_chat;
this.forceTp = force_tp;
}
public UUID getUuid() {
return uuid;
}
public int getPartyId() {
return partyId;
}
public boolean toggledChat() {
return toggledChat;
}
public void toggleChat() {
toggledChat = !toggledChat;
Queries.setChatState(toggledChat, uuid); //TODO: Async pls
}
public boolean ForceTp() {
return forceTp;
}
public void toggleForceTp() {
forceTp = !forceTp;
Queries.setForceTpState(forceTp, uuid); //TODO: Async pls
}
}