Start of ChatUserManager
This commit is contained in:
@@ -2,6 +2,7 @@ package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
@@ -16,7 +17,7 @@ public class ChatImplementation implements ChatAPI{
|
||||
private static ChatAPI instance;
|
||||
|
||||
private LuckPerms luckPerms;
|
||||
private DatabaseConnection databaseConnection;
|
||||
private DatabaseConnection databaseConnection; // todo this isn't needed can be removed
|
||||
|
||||
public ChatImplementation() {
|
||||
instance = this;
|
||||
@@ -24,6 +25,8 @@ public class ChatImplementation implements ChatAPI{
|
||||
|
||||
luckPerms = getLuckPerms();
|
||||
databaseConnection = getDataBase();
|
||||
|
||||
ChatUserManager.initialize(); // loads all the users from the db and adds them.
|
||||
}
|
||||
|
||||
public static ChatAPI get() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alttd.chat.database;
|
||||
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
@@ -249,7 +250,7 @@ public class Queries {
|
||||
//-----------------------------------------
|
||||
|
||||
//Chat Users
|
||||
|
||||
//@teri what's this?
|
||||
private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere
|
||||
String query = "SELECT * FROM chat_users";
|
||||
|
||||
@@ -287,6 +288,30 @@ public class Queries {
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadChatUsers() { //TODO Get parties from cache somewhere
|
||||
String query = "SELECT * FROM chat_users";
|
||||
|
||||
try {
|
||||
Connection connection = DatabaseConnection.getConnection();
|
||||
|
||||
ResultSet resultSet = connection.prepareStatement(query).executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
|
||||
UUID uuid = UUID.fromString(resultSet.getString("uuid"));
|
||||
int partyId = resultSet.getInt("party_id");
|
||||
boolean toggled_chat = resultSet.getInt("toggled_chat") == 1;
|
||||
boolean force_tp = resultSet.getInt("force_tp") == 1;
|
||||
boolean toggle_Gc = resultSet.getInt("toggled_gc") == 1;
|
||||
// could do a constructor for chatuser to accept the record?
|
||||
ChatUserManager.addUser(new ChatUser(uuid, partyId, toggled_chat, force_tp, toggle_Gc));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
String query = "INSERT INTO chat_users (uuid, party_id, toggled_chat, force_tp, toggled_gc) VALUES (?, ?, ?, ?, ?)";
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.alttd.chat.managers;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public final class ChatUserManager {
|
||||
|
||||
private static CopyOnWriteArraySet<ChatUser> chatUsers;// not sure on this, could cause errors later on
|
||||
|
||||
public static void initialize() {
|
||||
chatUsers = new CopyOnWriteArraySet<>();
|
||||
Queries.loadChatUsers();
|
||||
}
|
||||
|
||||
public static void addUser(ChatUser user) {
|
||||
if(getChatUser(user.getUuid()) != null)
|
||||
chatUsers.add(user);
|
||||
}
|
||||
|
||||
public static ChatUser getChatUser(UUID uuid) {
|
||||
for(ChatUser user : chatUsers) {
|
||||
if(user.getUuid() == uuid) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public class ChatUser {
|
||||
private String staffPrefix;
|
||||
private String prefixAll;
|
||||
private boolean toggleGc;
|
||||
private UUID replytarget;
|
||||
|
||||
public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) {
|
||||
this.uuid = uuid;
|
||||
@@ -33,6 +34,7 @@ public class ChatUser {
|
||||
prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api
|
||||
// a boolean is lighter then a permission check, it's what I'd suggest doing here
|
||||
toggleGc = toggle_Gc;//Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is...
|
||||
replytarget = null;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
@@ -100,4 +102,12 @@ public class ChatUser {
|
||||
public boolean isGcOn() {
|
||||
return toggleGc;
|
||||
}
|
||||
|
||||
public UUID getReplytarget() {
|
||||
return replytarget;
|
||||
}
|
||||
|
||||
public void setReplytarget(UUID replytarget) {
|
||||
this.replytarget = replytarget;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user