Merge remote-tracking branch 'origin/database' into main
This commit is contained in:
commit
71e77ce870
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.chat.database;
|
||||||
|
|
||||||
import com.alttd.chat.objects.Party;
|
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.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
|
@ -156,7 +156,7 @@ public class Queries {
|
||||||
e.printStackTrace();
|
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) {
|
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) {
|
private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere
|
||||||
String query = "SELECT * FROM party_users";
|
String query = "SELECT * FROM chat_users";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
@ -264,15 +264,19 @@ public class Queries {
|
||||||
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
||||||
boolean force_tp = resultSet.getInt("force_tp") == 1;
|
boolean force_tp = resultSet.getInt("force_tp") == 1;
|
||||||
|
|
||||||
|
if (partyId == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Party party = parties.get(partyId);
|
Party party = parties.get(partyId);
|
||||||
|
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
//TODO log this properly
|
//TODO log this properly
|
||||||
System.out.println("INCORRECT LOGGING: party was empty, the party id stored in the database with user " + uuid + " was invalid.");
|
System.out.println("INCORRECT LOGGING: party was empty, the party id stored in the database with user " + uuid + " was invalid.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
party.addUser(new PartyUser(uuid, partyId, toggled_chat, force_tp));
|
party.addUser(new ChatUser(uuid, partyId, toggled_chat, force_tp));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} 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 (?, ?, ?, ?)";
|
String query = "INSERT INTO party_users (uuid, party_id, toggled_chat, force_tp) VALUES (?, ?, ?, ?)";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
98
api/src/main/java/com/alttd/chat/objects/ChatUser.java
Normal file
98
api/src/main/java/com/alttd/chat/objects/ChatUser.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ public class Party {
|
||||||
private UUID ownerUuid;
|
private UUID ownerUuid;
|
||||||
private String partyName;
|
private String partyName;
|
||||||
private String partyPassword;
|
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) {
|
public Party(int partyId, UUID ownerUuid, String partyName, String partyPassword) {
|
||||||
this.partyId = partyId;
|
this.partyId = partyId;
|
||||||
|
|
@ -21,16 +21,16 @@ public class Party {
|
||||||
partyUsers = new ArrayList<>();
|
partyUsers = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(ArrayList<PartyUser> partyUsers) {
|
public void addUser(ArrayList<ChatUser> partyUsers) {
|
||||||
this.partyUsers.addAll(partyUsers);
|
this.partyUsers.addAll(partyUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addUser(PartyUser partyUser) {
|
public void addUser(ChatUser partyUser) {
|
||||||
this.partyUsers.add(partyUser);
|
this.partyUsers.add(partyUser);
|
||||||
Queries.addUser(partyUser);
|
Queries.addUser(partyUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeUser(PartyUser partyUser) {
|
public void removeUser(ChatUser partyUser) {
|
||||||
partyUsers.remove(partyUser);
|
partyUsers.remove(partyUser);
|
||||||
Queries.removeUser(partyUser.getUuid());
|
Queries.removeUser(partyUser.getUuid());
|
||||||
}
|
}
|
||||||
|
|
@ -70,11 +70,11 @@ public class Party {
|
||||||
return !partyPassword.isEmpty();
|
return !partyPassword.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<PartyUser> getPartyUsers() {
|
public ArrayList<ChatUser> getPartyUsers() {
|
||||||
return partyUsers;
|
return partyUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPartyUsers(ArrayList<PartyUser> partyUsers) {
|
public void setPartyUsers(ArrayList<ChatUser> partyUsers) {
|
||||||
this.partyUsers = partyUsers;
|
this.partyUsers = partyUsers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user