Add back api and server module

This commit is contained in:
len 2021-06-02 19:55:55 +02:00
parent b814a5b01b
commit 5d8d7b5dff
22 changed files with 100 additions and 61 deletions

View File

@ -154,18 +154,31 @@ public final class RegexConfig {
// REPLACEMENT = getString("replacement", REPLACEMENT); // REPLACEMENT = getString("replacement", REPLACEMENT);
// } // }
// Options:
// Filter: the regexstring
// replacements:
// exclusions: ["list", "of", "words"]
private void loadChatFilters() { private void loadChatFilters() {
Map<String, Object> chProps = new HashMap<>(); for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
config.getChildrenMap().forEach((key, value) -> { String name = entry.getKey().toString(); // the name in the config this filter has
if (value.hasMapChildren()) { String type = entry.getValue().getNode("type").getString(); // the type of filter, block or replace
for (Map.Entry<Object, ? extends ConfigurationNode> vl : value.getChildrenMap().entrySet()) { String regex = "";
chProps.put( vl.getKey().toString(), vl.getValue().getValue()); List<String> replacements = new ArrayList<>();
} List<String> exclusions = new ArrayList<>();
} else { Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
chProps.put(key.toString(), value.getValue()); if (options.containsKey("filter")) {
regex = options.get("filter").getString();
} }
}); if (options.containsKey("replacements")) {
//UCChannel ch = new UCChannel(chProps); options.get("replacements").getChildrenList().forEach(key -> {
//addChannel(ch); replacements.add(key.getString());
});
}
if (options.containsKey("exclusions")) {
options.get("exclusions").getChildrenList().forEach(key -> {
exclusions.add(key.getString());
});
}
}
} }
} }

View File

@ -1,9 +1,8 @@
package com.alttd.chat.database; package com.alttd.chat.database;
import com.alttd.chat.data.ChatUser; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.data.Party; import com.alttd.chat.objects.ChatUser;
import com.alttd.chat.data.ServerWrapper; import com.alttd.chat.objects.Party;
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;

View File

@ -1,9 +1,8 @@
package com.alttd.chat.handlers; package com.alttd.chat.managers;
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;

View File

@ -1,10 +1,4 @@
package com.alttd.chat.handlers; package com.alttd.chat.managers;
import com.alttd.chat.config.Config;
import com.alttd.chat.config.RegexConfig;
import com.alttd.chat.data.FilterType;
import com.google.common.collect.Lists;
import ninja.leaping.configurate.ConfigurationNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -20,16 +14,17 @@ public class RegexManager {
// IDEA: Regex object -> RegexPattern, shatteredPattern, replacement, replacements // IDEA: Regex object -> RegexPattern, shatteredPattern, replacement, replacements
public static void initRegex() { public static void initRegex() {
//RegexConfig.init(VelocityChat.getPlugin().getDataDirectory()); // TODO setup the dir
// LOAD REGEXES, sad way of doing it:( // LOAD REGEXES, sad way of doing it:(
// maiby a REGEXobject and a list<Regex> would be better here? // maiby a REGEXobject and a list<Regex> would be better here?
for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) { /*for(ConfigurationNode node : Config.REGEXNODE.getChildrenMap().values()) {
RegexConfig regexConfig = new RegexConfig(node.getString()); RegexConfig regexConfig = new RegexConfig(node.getString());
if (FilterType.getType(regexConfig.TYPE) == FilterType.BLOCK) { if (FilterType.getType(regexConfig.TYPE) == FilterType.BLOCK) {
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT)); cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
} else if (FilterType.getType(regexConfig.TYPE) == FilterType.REPLACE) { } else if (FilterType.getType(regexConfig.TYPE) == FilterType.REPLACE) {
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT); replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
} }
} }*/
//TODO load data from config (a regex string, and it's exceptions if there are any) //TODO load data from config (a regex string, and it's exceptions if there are any)
cancelRegex.put(Pattern.compile("\\b([R]+[^\\w]?[4A]+[^\\w]?[P]+(([^\\w]?[E3]+[^\\w]?[DT]*)|([^\\w]?[I!1]+[^\\w]?[S5]+[^\\w]?[T7]+)|([^\\w]?[I!1]+[^\\w]?[N]+[^\\w]?[G69]+)))\\b"), new ArrayList<>()); cancelRegex.put(Pattern.compile("\\b([R]+[^\\w]?[4A]+[^\\w]?[P]+(([^\\w]?[E3]+[^\\w]?[DT]*)|([^\\w]?[I!1]+[^\\w]?[S5]+[^\\w]?[T7]+)|([^\\w]?[I!1]+[^\\w]?[N]+[^\\w]?[G69]+)))\\b"), new ArrayList<>());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
package com.alttd.chat.util; package com.alttd.chat.util;
public class ALogger { public class ALogger {
// static abuse
private static org.slf4j.Logger logger; private static org.slf4j.Logger logger;
public ALogger(org.slf4j.Logger log) { public ALogger(org.slf4j.Logger log) {

View File

@ -1,6 +1,6 @@
package com.alttd.chat.util; package com.alttd.chat.util;
import com.alttd.chat.VelocityChat; import com.alttd.chat.ChatAPI;
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;
@ -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 = VelocityChat.getPlugin().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().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 = VelocityChat.getPlugin().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().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 = VelocityChat.getPlugin().getLuckPerms(); LuckPerms luckPerms = ChatAPI.get().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();

View File

@ -63,7 +63,7 @@
</dependency> </dependency>
</dependencies> </dependencies>
<properties> <properties>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
</properties> </properties>
</project> </project>

View File

@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
</properties> </properties>
<parent> <parent>

View File

@ -10,7 +10,6 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
// Todo this is only needed to get some special usecases eg [i] -> get and return the item the player is holding over a SYNCRONIZED connection:/
public class ChatPlugin extends JavaPlugin { public class ChatPlugin extends JavaPlugin {
private static ChatPlugin instance; private static ChatPlugin instance;

View File

@ -27,7 +27,43 @@ public class ChatHandler {
plugin = ChatPlugin.getInstance(); plugin = ChatPlugin.getInstance();
} }
public void globalChat(Player player, String message) {
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
if(user == null) return;
if(!user.isGcOn()) {
player.sendMessage();// GC IS OFF INFORM THEM ABOUT THIS and cancel
return;
}
// Check if the player has global chat enabled, if not warn them
String senderName, prefix = "";
senderName = player.getDisplayName(); // TODO this can be a component
// can also be cached in the chatuser object?
prefix = plugin.getChatAPI().getPrefix(player.getUniqueId());
MiniMessage miniMessage = MiniMessage.get();
message = Utility.parseColors(message);
if(!player.hasPermission("chat.format"))
message = miniMessage.stripTokens(message);
if(message.contains("[i]"))
message = message.replace("[i]", "<[i]>");
List<Template> templates = new ArrayList<>(List.of(
Template.of("sender", senderName),
Template.of("prefix", prefix),
Template.of("message", message),
Template.of("server", Bukkit.getServerName())/*,
Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/));
Component component = miniMessage.parse(Config.GCFORMAT, templates);
//todo make a method for this, it'll be used more then onc
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("globalchat");
out.writeUTF(miniMessage.serialize(component));
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
}
} }

View File

@ -10,12 +10,12 @@ public class PluginMessage implements PluginMessageListener {
@Override @Override
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) { public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
if(!channel.equals(Config.MESSAGECHANNEL)) { if (!channel.equals(Config.MESSAGECHANNEL)) {
return; return;
} }
ByteArrayDataInput in = ByteStreams.newDataInput(bytes); ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF(); String subChannel = in.readUTF();
switch(subChannel) { switch (subChannel) {
case "globalchat": case "globalchat":
break; break;
default: default:
@ -23,6 +23,7 @@ public class PluginMessage implements PluginMessageListener {
} }
} }
}
/* // todo implement AdvancedChatFilter for this like this /* // todo implement AdvancedChatFilter for this like this
// send pluginmessage to backend server and return a shatteredcomponent to be reparsed by proxy // send pluginmessage to backend server and return a shatteredcomponent to be reparsed by proxy
// Start - move these to util // Start - move these to util

View File

@ -24,7 +24,7 @@
</repository> </repository>
</distributionManagement> </distributionManagement>
<!--<build> <build>
<defaultGoal>install</defaultGoal> <defaultGoal>install</defaultGoal>
<finalName>${project.artifactId}</finalName> <finalName>${project.artifactId}</finalName>
<plugins> <plugins>
@ -43,10 +43,11 @@
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build>--> </build>
<modules> <modules>
<!--<module>api</module>--> <module>api</module>
<module>galaxy</module>
<module>velocity</module> <module>velocity</module>
</modules> </modules>

View File

@ -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>

View File

@ -3,15 +3,12 @@ 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;
import com.alttd.chat.listeners.PluginMessageListener; import com.alttd.chat.listeners.PluginMessageListener;
import com.alttd.chat.managers.RegexManager;
import com.alttd.chat.util.ALogger; import com.alttd.chat.util.ALogger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
@ -59,10 +56,10 @@ public class VelocityChat {
public void onProxyInitialization(ProxyInitializeEvent event) { public void onProxyInitialization(ProxyInitializeEvent event) {
new ALogger(logger); new ALogger(logger);
Config.init(getDataDirectory()); Config.init(getDataDirectory());
new DatabaseConnection(); //new DatabaseConnection();
Queries.createTables(); //Queries.createTables();
ChatUserManager.initialize(); // loads all the users from the db and adds them. //ChatUserManager.initialize(); // loads all the users from the db and adds them.
RegexManager.initRegex(); // load the filters and regexes from config RegexManager.initRegex(); // load the filters and regexes from config
serverHandler = new ServerHandler(); serverHandler = new ServerHandler();

View File

@ -2,12 +2,11 @@ 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.data.ChatUser; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.events.GlobalAdminChatEvent; 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.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;