merge api into velocity

This commit is contained in:
len 2021-05-24 10:10:02 +02:00
parent 0d0c4a13e5
commit d8a4490358
19 changed files with 54 additions and 83 deletions

View File

@ -1,6 +1,5 @@
package com.alttd.chat;
import com.alttd.chat.database.DatabaseConnection;
import net.luckperms.api.LuckPerms;
import java.util.UUID;
@ -13,8 +12,6 @@ public interface ChatAPI {
LuckPerms getLuckPerms();
DatabaseConnection getDataBase();
String getPrefix(UUID uuid);
String getPrefix(UUID uuid, boolean all);

View File

@ -1,17 +1,8 @@
package com.alttd.chat;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
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 java.util.Collection;
import java.util.Comparator;
import java.util.UUID;
public class ChatImplementation implements ChatAPI{
@ -19,18 +10,12 @@ public class ChatImplementation implements ChatAPI{
private static ChatAPI instance;
private LuckPerms luckPerms;
private DatabaseConnection databaseConnection; // todo this isn't needed can be removed
public ChatImplementation() {
instance = this;
Config.init();
luckPerms = getLuckPerms();
databaseConnection = getDataBase();
Queries.createTables();
ChatUserManager.initialize(); // loads all the users from the db and adds them.
RegexManager.initRegex(); // load the filters and regexes from config
}
public static ChatAPI get() {
@ -46,37 +31,14 @@ public class ChatImplementation implements ChatAPI{
return luckPerms;
}
@Override
public DatabaseConnection getDataBase() {
if(databaseConnection == null)
databaseConnection = new DatabaseConnection();
return databaseConnection;
}
@Override
public String getPrefix(UUID uuid) {
return getPrefix(uuid, false);
return "";
}
@Override
public String getPrefix(UUID uuid, boolean all) {
// TODO cache these components on load, and return them here?
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return "";
if(all) {
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
inheritedGroups.stream()
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
.forEach(group -> {
if (Config.PREFIXGROUPS.contains(group.getName())) {
prefix.append("<white>[").append(group.getCachedData().getMetaData().getPrefix()).append("]</white>");
}
});
}
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
return prefix.toString();
return "";
}
@Override

View File

@ -80,12 +80,12 @@
<version>5.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<!--<dependency>
<groupId>com.alttd.chat</groupId>
<artifactId>chat-api</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
</dependency>-->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>

View File

@ -3,7 +3,11 @@ package com.alttd.chat;
import com.alttd.chat.commands.GlobalAdminChat;
import com.alttd.chat.commands.GlobalChat;
import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.database.Queries;
import com.alttd.chat.handlers.ChatHandler;
import com.alttd.chat.handlers.ChatUserManager;
import com.alttd.chat.handlers.RegexManager;
import com.alttd.chat.handlers.ServerHandler;
import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.ProxyPlayerListener;
@ -18,6 +22,8 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import org.slf4j.Logger;
import java.io.File;
@ -35,7 +41,7 @@ public class VelocityChat {
private final Logger logger;
private final Path dataDirectory;
private ChatAPI chatAPI;
private LuckPerms luckPerms;
private ChatHandler chatHandler;
private ServerHandler serverHandler;
@ -52,7 +58,11 @@ public class VelocityChat {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
new ALogger(logger);
chatAPI = new ChatImplementation(getDataDirectory());
Config.init(getDataDirectory());
Queries.createTables();
ChatUserManager.initialize(); // loads all the users from the db and adds them.
RegexManager.initRegex(); // load the filters and regexes from config
serverHandler = new ServerHandler();
chatHandler = new ChatHandler();
@ -88,8 +98,10 @@ public class VelocityChat {
// all (proxy)commands go here
}
public ChatAPI API() {
return chatAPI;
public LuckPerms getLuckPerms() {
if(luckPerms == null)
luckPerms = LuckPermsProvider.get();
return luckPerms;
}
public ChatHandler getChatHandler() {

View File

@ -25,7 +25,7 @@ public class GlobalChatToggle {
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
LuckPerms luckPerms = VelocityChat.getPlugin().API().getLuckPerms();
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
Player player = (Player) context;
luckPerms.getUserManager().modifyUser(player.getUniqueId(), user -> {
if(player.hasPermission(Config.GCPERMISSION)) { //TODO THIS MUST BE A CONSTANT FROM CONFIG?

View File

@ -1,4 +1,4 @@
package com.alttd.chat.objects;
package com.alttd.chat.data;
public class ChatFilter {

View File

@ -1,4 +1,4 @@
package com.alttd.chat.objects;
package com.alttd.chat.data;
import com.alttd.chat.database.Queries;
import com.alttd.chat.util.Utility;

View File

@ -1,4 +1,4 @@
package com.alttd.chat.objects;
package com.alttd.chat.data;
public enum FilterType {
REPLACE("replace"),

View File

@ -1,4 +1,4 @@
package com.alttd.chat.objects;
package com.alttd.chat.data;
import java.util.UUID;

View File

@ -1,4 +1,4 @@
package com.alttd.chat.objects;
package com.alttd.chat.data;
import com.alttd.chat.database.Queries;

View File

@ -10,7 +10,7 @@ import java.sql.SQLException;
public class DatabaseConnection {
private static DatabaseConnection instance;
private Connection connection;
private static Connection connection;
/**
* Sets information for the database and opens the connection.

View File

@ -1,8 +1,9 @@
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.data.ChatUser;
import com.alttd.chat.data.Party;
import com.alttd.chat.data.ServerWrapper;
import com.alttd.chat.handlers.ChatUserManager;
import com.alttd.chat.util.ALogger;
import java.sql.Connection;

View File

@ -2,9 +2,7 @@ package com.alttd.chat.handlers;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.data.ChatUser;
import com.alttd.chat.util.Utility;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;

View File

@ -1,8 +1,9 @@
package com.alttd.chat.managers;
package com.alttd.chat.handlers;
import com.alttd.chat.data.ChatUser;
import com.alttd.chat.data.Mail;
import com.alttd.chat.data.ServerWrapper;
import com.alttd.chat.database.Queries;
import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.objects.Mail;
import java.util.List;
import java.util.UUID;

View File

@ -1,8 +1,8 @@
package com.alttd.chat.managers;
package com.alttd.chat.handlers;
import com.alttd.chat.config.Config;
import com.alttd.chat.config.RegexConfig;
import com.alttd.chat.objects.FilterType;
import com.alttd.chat.data.FilterType;
import com.google.common.collect.Lists;
import ninja.leaping.configurate.ConfigurationNode;

View File

@ -1,6 +1,6 @@
package com.alttd.chat.util;
import com.alttd.chat.ChatAPI;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
@ -17,18 +17,18 @@ public class Utility {
public static HashMap<String, String> colors;
static { // this might be in minimessage already?
colors = new HashMap<>(); // todo map all colors to minimessage
colors.put("&0", "<black"); // and confirm these are correct
colors.put("&1", "<dark_blue"); // could also add some default hex colors here?
colors.put("&2", "<dark_green");
colors.put("&3", "<dark_aqua");
colors.put("&4", "<dark_red");
colors.put("&5", "<dark_purple");
colors.put("&6", "<gold");
colors.put("&7", "<gray");
colors.put("&8", "<dark_gray");
colors.put("&9", "<blue");
colors.put("&a", "<green");
colors.put("&b", "<aqua");
colors.put("&0", "<black>"); // and confirm these are correct
colors.put("&1", "<dark_blue>"); // could also add some default hex colors here?
colors.put("&2", "<dark_green>");
colors.put("&3", "<dark_aqua>");
colors.put("&4", "<dark_red>");
colors.put("&5", "<dark_purple>");
colors.put("&6", "<gold>");
colors.put("&7", "<gray>");
colors.put("&8", "<dark_gray>");
colors.put("&9", "<blue>");
colors.put("&a", "<green>");
colors.put("&b", "<aqua>");
colors.put("&c", "<red>");
colors.put("&d", "<light_purple>");
colors.put("&e", "<yellow>");
@ -49,7 +49,7 @@ public class Utility {
public static String getPrefix(UUID uuid, boolean highest) {
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return "";
if(!highest) {
@ -71,7 +71,7 @@ public class Utility {
// @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 = ChatAPI.get().getLuckPerms();
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return prefix.toString();
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
@ -82,7 +82,7 @@ public class Utility {
public static String getDisplayName(UUID uuid) {
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return "";
return user.getUsername();