diff --git a/api/pom.xml b/api/pom.xml index 28100ff..2eb8b2a 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -29,6 +29,7 @@ net.kyori adventure-text-minimessage 4.1.0-SNAPSHOT + provided com.velocitypowered @@ -42,17 +43,6 @@ 5.3 provided - - com.alttd.chat - velocity-chat - 1.0 - compile - - - net.kyori - adventure-text-minimessage - 4.1.0-SNAPSHOT - \ No newline at end of file diff --git a/api/src/main/java/com/alttd/chat/ChatAPI.java b/api/src/main/java/com/alttd/chat/ChatAPI.java index 254e8ea..f135e04 100644 --- a/api/src/main/java/com/alttd/chat/ChatAPI.java +++ b/api/src/main/java/com/alttd/chat/ChatAPI.java @@ -7,7 +7,9 @@ import java.util.UUID; public interface ChatAPI { - ChatAPI get(); + static ChatAPI get() { + return ChatImplementation.get(); + } LuckPerms getLuckPerms(); diff --git a/api/src/main/java/com/alttd/chat/ChatImplementation.java b/api/src/main/java/com/alttd/chat/ChatImplementation.java index cb30b33..bcca7ca 100644 --- a/api/src/main/java/com/alttd/chat/ChatImplementation.java +++ b/api/src/main/java/com/alttd/chat/ChatImplementation.java @@ -1,13 +1,11 @@ package com.alttd.chat; import com.alttd.chat.config.Config; -import com.alttd.chat.config.RegexConfig; import com.alttd.chat.database.DatabaseConnection; import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPermsProvider; import net.luckperms.api.model.group.Group; import net.luckperms.api.model.user.User; -import ninja.leaping.configurate.ConfigurationNode; import java.util.Collection; import java.util.Comparator; @@ -15,7 +13,7 @@ import java.util.UUID; public class ChatImplementation implements ChatAPI{ - private ChatAPI instance; + private static ChatAPI instance; private LuckPerms luckPerms; private DatabaseConnection databaseConnection; @@ -25,11 +23,10 @@ public class ChatImplementation implements ChatAPI{ Config.init(); luckPerms = getLuckPerms(); - //databaseConnection = getDataBase(); // TODO fix database on proxy, shade sql, add defaults to config + databaseConnection = getDataBase(); } - @Override - public ChatAPI get() { + public static ChatAPI get() { if(instance == null) instance = new ChatImplementation(); return instance; diff --git a/api/src/main/java/com/alttd/chat/database/Queries.java b/api/src/main/java/com/alttd/chat/database/Queries.java index b6cfdf6..370ff1a 100644 --- a/api/src/main/java/com/alttd/chat/database/Queries.java +++ b/api/src/main/java/com/alttd/chat/database/Queries.java @@ -20,7 +20,7 @@ public class Queries { List tables = new ArrayList<>(); tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))"); tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))"); - tables.add("CREATE TABLE IF NOT EXISTS party_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', PRIMARY KEY (`uuid`), FOREIGN KEY (party_id) REFERENCES parties(id) ON DELETE CASCADE)"); + tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', `toggled_gc` BIT(1) DEFAULT b'0', PRIMARY KEY (`uuid`), FOREIGN KEY (party_id) REFERENCES parties(id) ON DELETE CASCADE)"); try { Connection connection = DatabaseConnection.getConnection(); @@ -38,7 +38,7 @@ public class Queries { //Nicknames public static String getNickname(UUID uuid) { - //TODO use separate connection so it actually uses the nickname db... + // View has been created. String query = "SELECT nickname FROM nicknames WHERE uuid = ?"; try { @@ -263,6 +263,7 @@ public class Queries { 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; if (partyId == 0) { continue; @@ -276,7 +277,7 @@ public class Queries { continue; } - party.addUser(new ChatUser(uuid, partyId, toggled_chat, force_tp)); + party.addUser(new ChatUser(uuid, partyId, toggled_chat, force_tp, toggle_Gc)); } } catch (SQLException e) { @@ -285,7 +286,7 @@ public class Queries { } 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, toggled_gc) VALUES (?, ?, ?, ?, ?)"; try { Connection connection = DatabaseConnection.getConnection(); @@ -295,6 +296,7 @@ public class Queries { statement.setInt(2, user.getPartyId()); statement.setInt(3, user.toggledChat() ? 1 : 0); statement.setInt(4, user.ForceTp() ? 1 : 0); + statement.setInt(5, user.isGcOn() ? 1 : 0); statement.execute(); } catch (SQLException e) { diff --git a/api/src/main/java/com/alttd/chat/objects/ChatUser.java b/api/src/main/java/com/alttd/chat/objects/ChatUser.java index 52560a1..1075d89 100644 --- a/api/src/main/java/com/alttd/chat/objects/ChatUser.java +++ b/api/src/main/java/com/alttd/chat/objects/ChatUser.java @@ -16,7 +16,7 @@ public class ChatUser { private String prefixAll; private boolean toggleGc; - public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp) { + public ChatUser(UUID uuid, int partyId, boolean toggled_chat, boolean force_tp, boolean toggle_Gc) { this.uuid = uuid; this.partyId = partyId; this.toggledChat = toggled_chat; @@ -31,8 +31,8 @@ public class ChatUser { staffPrefix = Utility.getStaffPrefix(uuid); prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api - - toggleGc = Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is... + // 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... } public UUID getUuid() { @@ -95,7 +95,6 @@ public class ChatUser { public void toggleGc() { toggleGc = !toggleGc; - Utility.setPermission(uuid, "chat.gc", toggleGc); //TODO put the actual permission here, I don't know what it is... } public boolean isGcOn() { diff --git a/api/src/main/java/com/alttd/chat/util/Utility.java b/api/src/main/java/com/alttd/chat/util/Utility.java index b22607b..87792b4 100644 --- a/api/src/main/java/com/alttd/chat/util/Utility.java +++ b/api/src/main/java/com/alttd/chat/util/Utility.java @@ -1,6 +1,7 @@ package com.alttd.chat.util; -import com.alttd.chat.ChatPlugin; +import com.alttd.chat.ChatAPI; +import com.alttd.chat.ChatImplementation; import com.alttd.chat.config.Config; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; @@ -18,7 +19,7 @@ public class Utility { public static String getPrefix(UUID uuid, boolean highest) { StringBuilder prefix = new StringBuilder(); - LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms(); + LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); User user = luckPerms.getUserManager().getUser(uuid); if(user == null) return ""; if(!highest) { @@ -37,9 +38,10 @@ public class Utility { return prefix.toString(); } + // @teri you don't reference the plugin instance from the API instance, this creates a circular reference and breaks on compile and will never run public static String getStaffPrefix(UUID uuid) { StringBuilder prefix = new StringBuilder(); - LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms(); + LuckPerms luckPerms = ChatAPI.get().getLuckPerms(); User user = luckPerms.getUserManager().getUser(uuid); if(user == null) return ""; if(!Config.STAFFGROUPS.contains(user.getPrimaryGroup())) return ""; @@ -48,25 +50,13 @@ public class Utility { return prefix.toString(); } - public static boolean checkPermission(UUID uuid, String permission) { - ProxyServer proxy = ChatPlugin.getPlugin().getProxy(); - if (proxy.getPlayer(uuid).isEmpty()) return false; - Player player = proxy.getPlayer(uuid).get(); - - return player.hasPermission(permission); - } - public static String getDisplayName(UUID uuid) { - ProxyServer proxy = ChatPlugin.getPlugin().getProxy(); + // todo add a PlayerWrapper @Destro + /*ProxyServer proxy = ChatPlugin.getPlugin().getProxy(); if (proxy.getPlayer(uuid).isEmpty()) return ""; Player player = proxy.getPlayer(uuid).get(); - return player.getUsername(); + return player.getUsername();*/ + return ""; } - public static void setPermission(UUID uuid, String permission, boolean toggleGc) { - LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms(); - luckPerms.getUserManager().modifyUser(uuid, user -> { - user.data().add(Node.builder(permission).value(toggleGc).build()); - }); - } } diff --git a/galaxy/dependency-reduced-pom.xml b/galaxy/dependency-reduced-pom.xml index e8d6a64..76463a9 100644 --- a/galaxy/dependency-reduced-pom.xml +++ b/galaxy/dependency-reduced-pom.xml @@ -61,6 +61,12 @@ 1.16.5-R0.1-SNAPSHOT compile + + net.kyori + adventure-text-minimessage + 4.1.0-SNAPSHOT + provided + 11 diff --git a/galaxy/pom.xml b/galaxy/pom.xml index e182c6b..27ecb5a 100644 --- a/galaxy/pom.xml +++ b/galaxy/pom.xml @@ -87,5 +87,11 @@ configurate-yaml 3.7.1 + + net.kyori + adventure-text-minimessage + 4.1.0-SNAPSHOT + provided + \ No newline at end of file diff --git a/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java b/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java index 6e9c0ba..bce9157 100644 --- a/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java +++ b/galaxy/src/main/java/com/alttd/chat/ChatPlugin.java @@ -5,14 +5,10 @@ import com.alttd.chat.config.Config; import com.alttd.chat.handler.ChatHandler; import com.alttd.chat.listeners.PlayerListener; import com.alttd.chat.listeners.PluginMessage; -import ninja.leaping.configurate.ConfigurationNode; -import ninja.leaping.configurate.commented.CommentedConfigurationNode; import org.bukkit.command.CommandExecutor; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -import java.util.Map; - public class ChatPlugin extends JavaPlugin { private static ChatPlugin instance; diff --git a/velocity/dependency-reduced-pom.xml b/velocity/dependency-reduced-pom.xml index 775683b..92d7f5f 100644 --- a/velocity/dependency-reduced-pom.xml +++ b/velocity/dependency-reduced-pom.xml @@ -71,6 +71,12 @@ 4.1.0 provided + + net.kyori + adventure-text-minimessage + 4.1.0-SNAPSHOT + provided + 11 diff --git a/velocity/pom.xml b/velocity/pom.xml index ac5badb..70990df 100644 --- a/velocity/pom.xml +++ b/velocity/pom.xml @@ -98,6 +98,12 @@ 5.1.49 runtime + + net.kyori + adventure-text-minimessage + 4.1.0-SNAPSHOT + provided +