Add back api and server module
This commit is contained in:
parent
b814a5b01b
commit
5d8d7b5dff
|
|
@ -154,18 +154,31 @@ public final class RegexConfig {
|
|||
// REPLACEMENT = getString("replacement", REPLACEMENT);
|
||||
// }
|
||||
|
||||
// Options:
|
||||
// Filter: the regexstring
|
||||
// replacements:
|
||||
// exclusions: ["list", "of", "words"]
|
||||
private void loadChatFilters() {
|
||||
Map<String, Object> chProps = new HashMap<>();
|
||||
config.getChildrenMap().forEach((key, value) -> {
|
||||
if (value.hasMapChildren()) {
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> vl : value.getChildrenMap().entrySet()) {
|
||||
chProps.put( vl.getKey().toString(), vl.getValue().getValue());
|
||||
}
|
||||
} else {
|
||||
chProps.put(key.toString(), value.getValue());
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
|
||||
String name = entry.getKey().toString(); // the name in the config this filter has
|
||||
String type = entry.getValue().getNode("type").getString(); // the type of filter, block or replace
|
||||
String regex = "";
|
||||
List<String> replacements = new ArrayList<>();
|
||||
List<String> exclusions = new ArrayList<>();
|
||||
Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
|
||||
if (options.containsKey("filter")) {
|
||||
regex = options.get("filter").getString();
|
||||
}
|
||||
});
|
||||
//UCChannel ch = new UCChannel(chProps);
|
||||
//addChannel(ch);
|
||||
if (options.containsKey("replacements")) {
|
||||
options.get("replacements").getChildrenList().forEach(key -> {
|
||||
replacements.add(key.getString());
|
||||
});
|
||||
}
|
||||
if (options.containsKey("exclusions")) {
|
||||
options.get("exclusions").getChildrenList().forEach(key -> {
|
||||
exclusions.add(key.getString());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,8 @@
|
|||
package com.alttd.chat.database;
|
||||
|
||||
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.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
|
@ -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.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
|
@ -1,10 +1,4 @@
|
|||
package com.alttd.chat.handlers;
|
||||
|
||||
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;
|
||||
package com.alttd.chat.managers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -20,16 +14,17 @@ public class RegexManager {
|
|||
|
||||
// IDEA: Regex object -> RegexPattern, shatteredPattern, replacement, replacements
|
||||
public static void initRegex() {
|
||||
//RegexConfig.init(VelocityChat.getPlugin().getDataDirectory()); // TODO setup the dir
|
||||
// LOAD REGEXES, sad way of doing it:(
|
||||
// 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());
|
||||
if (FilterType.getType(regexConfig.TYPE) == FilterType.BLOCK) {
|
||||
cancelRegex.put(Pattern.compile(regexConfig.REGEX), Lists.newArrayList(regexConfig.REPLACEMENT));
|
||||
} else if (FilterType.getType(regexConfig.TYPE) == FilterType.REPLACE) {
|
||||
replaceRegex.put(regexConfig.REGEX, regexConfig.REPLACEMENT);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
//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<>());
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.chat.data;
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
public class ChatFilter {
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.chat.data;
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.util.Utility;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.chat.data;
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
public enum FilterType {
|
||||
REPLACE("replace"),
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.chat.data;
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.alttd.chat.data;
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import com.alttd.chat.database.Queries;
|
||||
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
package com.alttd.chat.util;
|
||||
|
||||
public class ALogger {
|
||||
// static abuse
|
||||
|
||||
private static org.slf4j.Logger logger;
|
||||
|
||||
public ALogger(org.slf4j.Logger log) {
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.alttd.chat.util;
|
||||
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.config.Config;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
|
|
@ -49,7 +49,7 @@ public class Utility {
|
|||
|
||||
public static String getPrefix(UUID uuid, boolean highest) {
|
||||
StringBuilder prefix = new StringBuilder();
|
||||
LuckPerms luckPerms = VelocityChat.getPlugin().getLuckPerms();
|
||||
LuckPerms luckPerms = ChatAPI.get().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 = VelocityChat.getPlugin().getLuckPerms();
|
||||
LuckPerms luckPerms = ChatAPI.get().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 = VelocityChat.getPlugin().getLuckPerms();
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return "";
|
||||
return user.getUsername();
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import org.bukkit.command.CommandExecutor;
|
|||
import org.bukkit.event.Listener;
|
||||
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 {
|
||||
|
||||
private static ChatPlugin instance;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,43 @@ public class ChatHandler {
|
|||
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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ public class PluginMessage implements PluginMessageListener {
|
|||
|
||||
@Override
|
||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
||||
if(!channel.equals(Config.MESSAGECHANNEL)) {
|
||||
if (!channel.equals(Config.MESSAGECHANNEL)) {
|
||||
return;
|
||||
}
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
String subChannel = in.readUTF();
|
||||
switch(subChannel) {
|
||||
switch (subChannel) {
|
||||
case "globalchat":
|
||||
break;
|
||||
default:
|
||||
|
|
@ -23,6 +23,7 @@ public class PluginMessage implements PluginMessageListener {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* // todo implement AdvancedChatFilter for this like this
|
||||
// send pluginmessage to backend server and return a shatteredcomponent to be reparsed by proxy
|
||||
// Start - move these to util
|
||||
|
|
|
|||
7
pom.xml
7
pom.xml
|
|
@ -24,7 +24,7 @@
|
|||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<!--<build>
|
||||
<build>
|
||||
<defaultGoal>install</defaultGoal>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
|
|
@ -43,10 +43,11 @@
|
|||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>-->
|
||||
</build>
|
||||
|
||||
<modules>
|
||||
<!--<module>api</module>-->
|
||||
<module>api</module>
|
||||
<module>galaxy</module>
|
||||
<module>velocity</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -3,15 +3,12 @@ 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;
|
||||
import com.alttd.chat.listeners.PluginMessageListener;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
|
@ -59,10 +56,10 @@ public class VelocityChat {
|
|||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
new ALogger(logger);
|
||||
Config.init(getDataDirectory());
|
||||
new DatabaseConnection();
|
||||
Queries.createTables();
|
||||
//new DatabaseConnection();
|
||||
//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
|
||||
|
||||
serverHandler = new ServerHandler();
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@ package com.alttd.chat.handlers;
|
|||
|
||||
import com.alttd.chat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.data.ChatUser;
|
||||
import com.alttd.chat.events.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
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 net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user