merge api into velocity
This commit is contained in:
parent
0d0c4a13e5
commit
d8a4490358
|
|
@ -1,6 +1,5 @@
|
||||||
package com.alttd.chat;
|
package com.alttd.chat;
|
||||||
|
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -13,8 +12,6 @@ public interface ChatAPI {
|
||||||
|
|
||||||
LuckPerms getLuckPerms();
|
LuckPerms getLuckPerms();
|
||||||
|
|
||||||
DatabaseConnection getDataBase();
|
|
||||||
|
|
||||||
String getPrefix(UUID uuid);
|
String getPrefix(UUID uuid);
|
||||||
|
|
||||||
String getPrefix(UUID uuid, boolean all);
|
String getPrefix(UUID uuid, boolean all);
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,8 @@
|
||||||
package com.alttd.chat;
|
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.LuckPerms;
|
||||||
import net.luckperms.api.LuckPermsProvider;
|
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;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatImplementation implements ChatAPI{
|
public class ChatImplementation implements ChatAPI{
|
||||||
|
|
@ -19,18 +10,12 @@ public class ChatImplementation implements ChatAPI{
|
||||||
private static ChatAPI instance;
|
private static ChatAPI instance;
|
||||||
|
|
||||||
private LuckPerms luckPerms;
|
private LuckPerms luckPerms;
|
||||||
private DatabaseConnection databaseConnection; // todo this isn't needed can be removed
|
|
||||||
|
|
||||||
public ChatImplementation() {
|
public ChatImplementation() {
|
||||||
instance = this;
|
instance = this;
|
||||||
Config.init();
|
|
||||||
|
|
||||||
luckPerms = getLuckPerms();
|
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() {
|
public static ChatAPI get() {
|
||||||
|
|
@ -46,37 +31,14 @@ public class ChatImplementation implements ChatAPI{
|
||||||
return luckPerms;
|
return luckPerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public DatabaseConnection getDataBase() {
|
|
||||||
if(databaseConnection == null)
|
|
||||||
databaseConnection = new DatabaseConnection();
|
|
||||||
return databaseConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrefix(UUID uuid) {
|
public String getPrefix(UUID uuid) {
|
||||||
return getPrefix(uuid, false);
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrefix(UUID uuid, boolean all) {
|
public String getPrefix(UUID uuid, boolean all) {
|
||||||
// TODO cache these components on load, and return them here?
|
return "";
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -80,12 +80,12 @@
|
||||||
<version>5.3</version>
|
<version>5.3</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<!--<dependency>
|
||||||
<groupId>com.alttd.chat</groupId>
|
<groupId>com.alttd.chat</groupId>
|
||||||
<artifactId>chat-api</artifactId>
|
<artifactId>chat-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.inject</groupId>
|
<groupId>com.google.inject</groupId>
|
||||||
<artifactId>guice</artifactId>
|
<artifactId>guice</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,11 @@ package com.alttd.chat;
|
||||||
import com.alttd.chat.commands.GlobalAdminChat;
|
import com.alttd.chat.commands.GlobalAdminChat;
|
||||||
import com.alttd.chat.commands.GlobalChat;
|
import com.alttd.chat.commands.GlobalChat;
|
||||||
import com.alttd.chat.config.Config;
|
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.ChatHandler;
|
||||||
|
import com.alttd.chat.handlers.ChatUserManager;
|
||||||
|
import com.alttd.chat.handlers.RegexManager;
|
||||||
import com.alttd.chat.handlers.ServerHandler;
|
import com.alttd.chat.handlers.ServerHandler;
|
||||||
import com.alttd.chat.listeners.ChatListener;
|
import com.alttd.chat.listeners.ChatListener;
|
||||||
import com.alttd.chat.listeners.ProxyPlayerListener;
|
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.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
@ -35,7 +41,7 @@ public class VelocityChat {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Path dataDirectory;
|
private final Path dataDirectory;
|
||||||
|
|
||||||
private ChatAPI chatAPI;
|
private LuckPerms luckPerms;
|
||||||
private ChatHandler chatHandler;
|
private ChatHandler chatHandler;
|
||||||
private ServerHandler serverHandler;
|
private ServerHandler serverHandler;
|
||||||
|
|
||||||
|
|
@ -52,7 +58,11 @@ public class VelocityChat {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
new ALogger(logger);
|
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();
|
serverHandler = new ServerHandler();
|
||||||
chatHandler = new ChatHandler();
|
chatHandler = new ChatHandler();
|
||||||
|
|
@ -88,8 +98,10 @@ public class VelocityChat {
|
||||||
// all (proxy)commands go here
|
// all (proxy)commands go here
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatAPI API() {
|
public LuckPerms getLuckPerms() {
|
||||||
return chatAPI;
|
if(luckPerms == null)
|
||||||
|
luckPerms = LuckPermsProvider.get();
|
||||||
|
return luckPerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatHandler getChatHandler() {
|
public ChatHandler getChatHandler() {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ public class GlobalChatToggle {
|
||||||
.then(RequiredArgumentBuilder
|
.then(RequiredArgumentBuilder
|
||||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
LuckPerms luckPerms = VelocityChat.getPlugin().API().getLuckPerms();
|
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
|
||||||
Player player = (Player) context;
|
Player player = (Player) context;
|
||||||
luckPerms.getUserManager().modifyUser(player.getUniqueId(), user -> {
|
luckPerms.getUserManager().modifyUser(player.getUniqueId(), user -> {
|
||||||
if(player.hasPermission(Config.GCPERMISSION)) { //TODO THIS MUST BE A CONSTANT FROM CONFIG?
|
if(player.hasPermission(Config.GCPERMISSION)) { //TODO THIS MUST BE A CONSTANT FROM CONFIG?
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.data;
|
||||||
|
|
||||||
public class ChatFilter {
|
public class ChatFilter {
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.data;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.data;
|
||||||
|
|
||||||
public enum FilterType {
|
public enum FilterType {
|
||||||
REPLACE("replace"),
|
REPLACE("replace"),
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.data;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.data;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
|
|
||||||
|
|
@ -10,7 +10,7 @@ import java.sql.SQLException;
|
||||||
public class DatabaseConnection {
|
public class DatabaseConnection {
|
||||||
|
|
||||||
private static DatabaseConnection instance;
|
private static DatabaseConnection instance;
|
||||||
private Connection connection;
|
private static Connection connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets information for the database and opens the connection.
|
* Sets information for the database and opens the connection.
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.chat.database;
|
||||||
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.data.ChatUser;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.data.Party;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.data.ServerWrapper;
|
||||||
|
import com.alttd.chat.handlers.ChatUserManager;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
@ -2,9 +2,7 @@ package com.alttd.chat.handlers;
|
||||||
|
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.data.ChatUser;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
|
||||||
import com.alttd.chat.objects.ChatUser;
|
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
|
||||||
|
|
@ -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.database.Queries;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
|
||||||
import com.alttd.chat.objects.Mail;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -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.Config;
|
||||||
import com.alttd.chat.config.RegexConfig;
|
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 com.google.common.collect.Lists;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
package com.alttd.chat.util;
|
package com.alttd.chat.util;
|
||||||
|
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
|
@ -17,18 +17,18 @@ public class Utility {
|
||||||
public static HashMap<String, String> colors;
|
public static HashMap<String, String> colors;
|
||||||
static { // this might be in minimessage already?
|
static { // this might be in minimessage already?
|
||||||
colors = new HashMap<>(); // todo map all colors to minimessage
|
colors = new HashMap<>(); // todo map all colors to minimessage
|
||||||
colors.put("&0", "<black"); // and confirm these are correct
|
colors.put("&0", "<black>"); // and confirm these are correct
|
||||||
colors.put("&1", "<dark_blue"); // could also add some default hex colors here?
|
colors.put("&1", "<dark_blue>"); // could also add some default hex colors here?
|
||||||
colors.put("&2", "<dark_green");
|
colors.put("&2", "<dark_green>");
|
||||||
colors.put("&3", "<dark_aqua");
|
colors.put("&3", "<dark_aqua>");
|
||||||
colors.put("&4", "<dark_red");
|
colors.put("&4", "<dark_red>");
|
||||||
colors.put("&5", "<dark_purple");
|
colors.put("&5", "<dark_purple>");
|
||||||
colors.put("&6", "<gold");
|
colors.put("&6", "<gold>");
|
||||||
colors.put("&7", "<gray");
|
colors.put("&7", "<gray>");
|
||||||
colors.put("&8", "<dark_gray");
|
colors.put("&8", "<dark_gray>");
|
||||||
colors.put("&9", "<blue");
|
colors.put("&9", "<blue>");
|
||||||
colors.put("&a", "<green");
|
colors.put("&a", "<green>");
|
||||||
colors.put("&b", "<aqua");
|
colors.put("&b", "<aqua>");
|
||||||
colors.put("&c", "<red>");
|
colors.put("&c", "<red>");
|
||||||
colors.put("&d", "<light_purple>");
|
colors.put("&d", "<light_purple>");
|
||||||
colors.put("&e", "<yellow>");
|
colors.put("&e", "<yellow>");
|
||||||
|
|
@ -49,7 +49,7 @@ public class Utility {
|
||||||
|
|
||||||
public static String getPrefix(UUID uuid, boolean highest) {
|
public static String getPrefix(UUID uuid, boolean highest) {
|
||||||
StringBuilder prefix = new StringBuilder();
|
StringBuilder prefix = new StringBuilder();
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return "";
|
if(user == null) return "";
|
||||||
if(!highest) {
|
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
|
// @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) {
|
public static String getStaffPrefix(UUID uuid) {
|
||||||
StringBuilder prefix = new StringBuilder();
|
StringBuilder prefix = new StringBuilder();
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return prefix.toString();
|
if(user == null) return prefix.toString();
|
||||||
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
||||||
|
|
@ -82,7 +82,7 @@ public class Utility {
|
||||||
|
|
||||||
public static String getDisplayName(UUID uuid) {
|
public static String getDisplayName(UUID uuid) {
|
||||||
StringBuilder prefix = new StringBuilder();
|
StringBuilder prefix = new StringBuilder();
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return "";
|
if(user == null) return "";
|
||||||
return user.getUsername();
|
return user.getUsername();
|
||||||
Loading…
Reference in New Issue
Block a user