Push progress
This commit is contained in:
parent
5d8d7b5dff
commit
198e80aa7a
|
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
|
@ -12,10 +13,6 @@ public interface ChatAPI {
|
||||||
|
|
||||||
LuckPerms getLuckPerms();
|
LuckPerms getLuckPerms();
|
||||||
|
|
||||||
String getPrefix(UUID uuid);
|
DatabaseConnection getDataBase();
|
||||||
|
|
||||||
String getPrefix(UUID uuid, boolean all);
|
|
||||||
|
|
||||||
String getStaffPrefix(UUID uuid);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,30 @@
|
||||||
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 java.util.UUID;
|
|
||||||
|
|
||||||
public class ChatImplementation implements ChatAPI{
|
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.initialize(); // load the filters and regexes from config
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatAPI get() {
|
public static ChatAPI get() {
|
||||||
|
|
@ -32,19 +41,10 @@ public class ChatImplementation implements ChatAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrefix(UUID uuid) {
|
public DatabaseConnection getDataBase() {
|
||||||
return "";
|
if(databaseConnection == null)
|
||||||
|
databaseConnection = new DatabaseConnection();
|
||||||
|
return databaseConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPrefix(UUID uuid, boolean all) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStaffPrefix(UUID uuid) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
@ -29,10 +30,10 @@ public final class Config {
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
||||||
public static void init(File path) {
|
public static File CONFIGPATH;
|
||||||
CONFIG_FILE = new File(path, "config.yml");;
|
public static void init() { // todo setup share for the config
|
||||||
// public static void init() { // todo setup share for the config
|
CONFIGPATH = new File(System.getProperty("user.home")+File.separator+"ChatPlugin");
|
||||||
// CONFIG_FILE = new File(new File(System.getProperty("user.home")+File.separator+"ChatPlugin"), "config.yml");;
|
CONFIG_FILE = new File(CONFIGPATH, "config.yml");;
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.setFile(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||||
|
|
@ -186,13 +187,16 @@ public final class Config {
|
||||||
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message>";
|
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message>";
|
||||||
public static String GCPERMISSION = "proxy.globalchat";
|
public static String GCPERMISSION = "proxy.globalchat";
|
||||||
public static List<String> GCALIAS = new ArrayList<>();
|
public static List<String> GCALIAS = new ArrayList<>();
|
||||||
public static String GCNOTENABLED = "You don't have global chat enabled.";
|
public static String GCNOTENABLED = "You don't have global chat enabled."; // todo mini message formatting
|
||||||
|
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again."; // todo mini message formatting
|
||||||
|
public static int GCCOOLDOWN = 30;
|
||||||
private static void globalChat() {
|
private static void globalChat() {
|
||||||
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
MESSAGERECIEVER = getString("commands.globalchat.format", MESSAGERECIEVER);
|
||||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||||
GCALIAS.clear();
|
GCALIAS.clear();
|
||||||
GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global"));
|
GCALIAS = getList("commands.globalchat.alias", Lists.newArrayList("gc", "global"));
|
||||||
GCNOTENABLED = getString("commands.globalchat.not-enabled", GCNOTENABLED);
|
GCNOTENABLED = getString("commands.globalchat.not-enabled", GCNOTENABLED);
|
||||||
|
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package com.alttd.chat.config;
|
package com.alttd.chat.config;
|
||||||
|
|
||||||
|
import com.alttd.chat.managers.RegexManager;
|
||||||
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import ninja.leaping.configurate.ConfigurationNode;
|
import ninja.leaping.configurate.ConfigurationNode;
|
||||||
import ninja.leaping.configurate.ConfigurationOptions;
|
import ninja.leaping.configurate.ConfigurationOptions;
|
||||||
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
import ninja.leaping.configurate.commented.CommentedConfigurationNode;
|
||||||
import ninja.leaping.configurate.hocon.HoconConfigurationLoader;
|
|
||||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||||
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
import ninja.leaping.configurate.yaml.YAMLConfigurationLoader;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
|
|
@ -35,8 +36,8 @@ public final class RegexConfig {
|
||||||
static int version;
|
static int version;
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
||||||
public static void init(File path) {
|
public static void init() {
|
||||||
CONFIG_FILE = new File(path, "filters.yml");;
|
CONFIG_FILE = new File(Config.CONFIGPATH, "filters.yml");;
|
||||||
configLoader = YAMLConfigurationLoader.builder()
|
configLoader = YAMLConfigurationLoader.builder()
|
||||||
.setFile(CONFIG_FILE)
|
.setFile(CONFIG_FILE)
|
||||||
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
.setFlowStyle(DumperOptions.FlowStyle.BLOCK)
|
||||||
|
|
@ -145,40 +146,43 @@ public final class RegexConfig {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public String REGEX = "REGEX";
|
|
||||||
// public String TYPE = "TYPE";
|
|
||||||
// public String REPLACEMENT = "REPLACEMENT";
|
|
||||||
// private void ServerSettings() {
|
|
||||||
// REGEX = getString("regex", REGEX);
|
|
||||||
// TYPE = getString("type", TYPE);
|
|
||||||
// REPLACEMENT = getString("replacement", REPLACEMENT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Options:
|
|
||||||
// Filter: the regexstring
|
|
||||||
// replacements:
|
|
||||||
// exclusions: ["list", "of", "words"]
|
|
||||||
private void loadChatFilters() {
|
private void loadChatFilters() {
|
||||||
for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
|
// for (Map.Entry<Object, ? extends ConfigurationNode> entry : config.getChildrenMap().entrySet()) {
|
||||||
String name = entry.getKey().toString(); // the name in the config this filter has
|
// 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 type = entry.getValue().getNode("type").getString(); // the type of filter, block or replace
|
||||||
String regex = "";
|
// String regex = "";
|
||||||
List<String> replacements = new ArrayList<>();
|
// List<String> replacements = new ArrayList<>();
|
||||||
List<String> exclusions = new ArrayList<>();
|
// List<String> exclusions = new ArrayList<>();
|
||||||
Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
|
// Map<Object, ? extends ConfigurationNode> options = entry.getValue().getNode("options").getChildrenMap();
|
||||||
if (options.containsKey("filter")) {
|
// if (options.containsKey("filter")) {
|
||||||
regex = options.get("filter").getString();
|
// regex = options.get("filter").getString();
|
||||||
|
// }
|
||||||
|
// 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());
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
Map<String, Object> properties = new HashMap<>();
|
||||||
|
config.getChildrenMap().forEach((key, value) -> {
|
||||||
|
if (value.hasMapChildren()) {
|
||||||
|
String rkey = key.toString();
|
||||||
|
properties.put("name", rkey);
|
||||||
|
for (Map.Entry<Object, ? extends ConfigurationNode> vl : value.getChildrenMap().entrySet()) {
|
||||||
|
properties.put(rkey + "." + vl.getKey(), vl.getValue().getValue());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
properties.put(key.toString(), value.getValue());
|
||||||
}
|
}
|
||||||
if (options.containsKey("replacements")) {
|
});
|
||||||
options.get("replacements").getChildrenList().forEach(key -> {
|
|
||||||
replacements.add(key.getString());
|
ChatFilter chatFilter = new ChatFilter(properties);
|
||||||
});
|
RegexManager.addFilter(chatFilter);
|
||||||
}
|
|
||||||
if (options.containsKey("exclusions")) {
|
|
||||||
options.get("exclusions").getChildrenList().forEach(key -> {
|
|
||||||
exclusions.add(key.getString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,52 @@
|
||||||
package com.alttd.chat.managers;
|
package com.alttd.chat.managers;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.alttd.chat.config.RegexConfig;
|
||||||
import java.util.HashMap;
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
import java.util.Map;
|
import com.alttd.chat.objects.FilterType;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
// TODO rebuild this class, All regexes go in a single list where we use the ChatFilter object and a matcher
|
|
||||||
public class RegexManager {
|
public class RegexManager {
|
||||||
|
|
||||||
private static final HashMap<Pattern, ArrayList<String>> cancelRegex = new HashMap<>();
|
private static List<ChatFilter> chatFilters;
|
||||||
private static final HashMap<String, String> replaceRegex = new HashMap<>();
|
|
||||||
|
|
||||||
// IDEA: Regex object -> RegexPattern, shatteredPattern, replacement, replacements
|
public static void initialize() {
|
||||||
public static void initRegex() {
|
chatFilters = new ArrayList<>();
|
||||||
//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()) {
|
|
||||||
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)
|
RegexConfig.init();
|
||||||
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<>());
|
|
||||||
//TODO load data from config (a regex string and what to replace it with)
|
|
||||||
replaceRegex.put(":pirate:", "pirate");
|
|
||||||
|
|
||||||
//TODO we might just be able to throw it all in one list and just go through it and check the type to see what to do if there is a match :eyes:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean violatesFilter(String text) {
|
public static void addFilter(ChatFilter filter) {
|
||||||
for (Map.Entry<Pattern, ArrayList<String>> entry : cancelRegex.entrySet()) {
|
chatFilters.add(filter);
|
||||||
Matcher matcher = entry.getKey().matcher(text);
|
}
|
||||||
while (matcher.find()) {
|
// public static boolean violatesFilter(String text) {
|
||||||
if (!entry.getValue().contains(matcher.group())) return true;
|
// for (Map.Entry<Pattern, ArrayList<String>> entry : cancelRegex.entrySet()) {
|
||||||
|
// Matcher matcher = entry.getKey().matcher(text);
|
||||||
|
// while (matcher.find()) {
|
||||||
|
// if (!entry.getValue().contains(matcher.group())) return true;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static String replaceText(String text) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||||
|
for(ChatFilter chatFilter : chatFilters) {
|
||||||
|
|
||||||
|
switch (chatFilter.getType()) {
|
||||||
|
case REPLACE:
|
||||||
|
text = chatFilter.replaceText(text);
|
||||||
|
break;
|
||||||
|
case BLOCK:
|
||||||
|
if(chatFilter.matches(text)) { // todo find a better way to do this?
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
// for (Map.Entry<String, String> entry : replaceRegex.entrySet()) {
|
||||||
}
|
// text = text.replaceAll(entry.getKey(), entry.getValue());
|
||||||
|
// }
|
||||||
public static String replaceText(String text) {
|
|
||||||
for (Map.Entry<String, String> entry : replaceRegex.entrySet()) {
|
|
||||||
text = text.replaceAll(entry.getKey(), entry.getValue());
|
|
||||||
}
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,63 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ChatFilter {
|
public class ChatFilter {
|
||||||
|
|
||||||
private final String regex;
|
private final Properties properties = new Properties();
|
||||||
private final FilterType type;
|
private final Pattern pattern;
|
||||||
private String replacement = "";
|
private final FilterType filterType;
|
||||||
|
|
||||||
public ChatFilter(String regex, FilterType type) {
|
public ChatFilter(Map<String, Object> props) {
|
||||||
this.regex = regex;
|
addDefaults();
|
||||||
this.type = type;
|
properties.keySet().stream().filter(props::containsKey).forEach((nkey) -> properties.put(nkey, props.get(nkey)));
|
||||||
|
pattern = Pattern.compile(getRegex());
|
||||||
|
filterType = FilterType.getType((String) properties.get("type"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatFilter(String regex, FilterType type, String replacement) {
|
private void addDefaults() {
|
||||||
this.regex = regex;
|
properties.put("name", "");
|
||||||
this.type = type;
|
properties.put("type", null);
|
||||||
this.replacement = replacement;
|
properties.put("regex", "");
|
||||||
|
properties.put("replacement", "");
|
||||||
|
properties.put("exclusions", new ArrayList<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRegex() {
|
public String getRegex() {
|
||||||
return regex;
|
return (String) properties.get("regex");
|
||||||
}
|
}
|
||||||
|
|
||||||
public FilterType getType() {
|
public FilterType getType() {
|
||||||
return type;
|
return filterType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getReplacement() {
|
public String getReplacement() {
|
||||||
return replacement;
|
return (String) properties.get("replacement");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public List<String> getExclusions() {
|
||||||
|
return (List<String>) properties.get("exclusions");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matches(String input) {
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
return matcher.matches();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String replaceText(String input) {
|
||||||
|
Matcher matcher = pattern.matcher(input);
|
||||||
|
while (matcher.find()) {
|
||||||
|
String group = matcher.group();
|
||||||
|
if(!getExclusions().contains(group)) { // doesn't work well with capitals, use a stream filter?
|
||||||
|
input = input.replace(group, getReplacement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ public class ChatUser {
|
||||||
private String prefixAll;
|
private String prefixAll;
|
||||||
private boolean toggleGc;
|
private boolean toggleGc;
|
||||||
private UUID replyTarget;
|
private UUID replyTarget;
|
||||||
|
private long gcCooldown;
|
||||||
|
|
||||||
private LinkedList<Mail> mails;
|
private LinkedList<Mail> mails;
|
||||||
|
|
||||||
|
|
@ -38,6 +39,7 @@ public class ChatUser {
|
||||||
|
|
||||||
toggleGc = toggle_Gc;
|
toggleGc = toggle_Gc;
|
||||||
replyTarget = null;
|
replyTarget = null;
|
||||||
|
gcCooldown = System.currentTimeMillis(); //
|
||||||
mails = new LinkedList<>(); // todo load mails
|
mails = new LinkedList<>(); // todo load mails
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,4 +124,8 @@ public class ChatUser {
|
||||||
public void addMail(Mail mail) {
|
public void addMail(Mail mail) {
|
||||||
mails.add(mail);
|
mails.add(mail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getGcCooldown() {
|
||||||
|
return gcCooldown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>15</source>
|
||||||
|
<target>15</target>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,10 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>15</source>
|
||||||
|
<target>15</target>
|
||||||
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
|
|
||||||
|
|
@ -12,36 +12,44 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.Template;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ChatHandler {
|
public class ChatHandler {
|
||||||
|
|
||||||
private ChatPlugin plugin;
|
private final ChatPlugin plugin;
|
||||||
|
|
||||||
|
private final MiniMessage miniMessage;
|
||||||
|
private final Component GCNOTENABLED;
|
||||||
|
|
||||||
public ChatHandler() {
|
public ChatHandler() {
|
||||||
plugin = ChatPlugin.getInstance();
|
plugin = ChatPlugin.getInstance();
|
||||||
|
miniMessage = MiniMessage.get();
|
||||||
|
GCNOTENABLED = miniMessage.parse(Config.GCNOTENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void globalChat(Player player, String message) {
|
public void globalChat(Player player, String message) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(user == null) return;
|
if(user == null) return;
|
||||||
if(!user.isGcOn()) {
|
if(!user.isGcOn()) {
|
||||||
player.sendMessage();// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
|
||||||
|
if(timeLeft <= Config.GCCOOLDOWN) { // player is on cooldown and should wait x seconds
|
||||||
|
player.sendMessage(miniMessage.parse(Config.GCONCOOLDOWN, Template.of("cooldown", timeLeft+"")));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Check if the player has global chat enabled, if not warn them
|
|
||||||
String senderName, prefix = "";
|
String senderName, prefix = "";
|
||||||
|
|
||||||
senderName = player.getDisplayName(); // TODO this can be a component
|
senderName = player.getDisplayName(); // TODO this can be a component
|
||||||
// can also be cached in the chatuser object?
|
// can also be cached in the chatuser object?
|
||||||
prefix = plugin.getChatAPI().getPrefix(player.getUniqueId());
|
prefix = user.getPrefix();
|
||||||
|
|
||||||
MiniMessage miniMessage = MiniMessage.get();
|
|
||||||
message = Utility.parseColors(message);
|
message = Utility.parseColors(message);
|
||||||
if(!player.hasPermission("chat.format"))
|
if(!player.hasPermission("chat.format"))
|
||||||
message = miniMessage.stripTokens(message);
|
message = miniMessage.stripTokens(message);
|
||||||
|
|
@ -52,18 +60,58 @@ public class ChatHandler {
|
||||||
Template.of("sender", senderName),
|
Template.of("sender", senderName),
|
||||||
Template.of("prefix", prefix),
|
Template.of("prefix", prefix),
|
||||||
Template.of("message", message),
|
Template.of("message", message),
|
||||||
Template.of("server", Bukkit.getServerName())/*,
|
Template.of("server", Bukkit.getServerName()),
|
||||||
Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/));
|
Template.of("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||||
|
|
||||||
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
Component component = miniMessage.parse(Config.GCFORMAT, templates);
|
||||||
|
|
||||||
//todo make a method for this, it'll be used more then onc
|
sendPluginMessage(player, "globalchat", component);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPluginMessage(Player player, String channel, Component component) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("globalchat");
|
out.writeUTF(channel);
|
||||||
out.writeUTF(miniMessage.serialize(component));
|
out.writeUTF(miniMessage.serialize(component)); // todo use a better component serializer ~ look into kyori
|
||||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start - move these to util
|
||||||
|
public Component itemComponent(ItemStack item) {
|
||||||
|
Component component = Component.text("[i]");
|
||||||
|
if(item.getType().equals(Material.AIR))
|
||||||
|
return component;
|
||||||
|
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||||
|
if(dname) {
|
||||||
|
component = component.append(item.getItemMeta().displayName());
|
||||||
|
} else {
|
||||||
|
component = Component.text(materialToName(item.getType()));
|
||||||
|
}
|
||||||
|
component = component.hoverEvent(item.asHoverEvent());
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String materialToName(Material m) {
|
||||||
|
if (m.equals(Material.TNT)) {
|
||||||
|
return "TNT";
|
||||||
|
}
|
||||||
|
String orig = m.toString().toLowerCase();
|
||||||
|
String[] splits = orig.split("_");
|
||||||
|
StringBuilder sb = new StringBuilder(orig.length());
|
||||||
|
int pos = 0;
|
||||||
|
for (String split : splits) {
|
||||||
|
sb.append(split);
|
||||||
|
int loc = sb.lastIndexOf(split);
|
||||||
|
char charLoc = sb.charAt(loc);
|
||||||
|
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
||||||
|
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on")))
|
||||||
|
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||||
|
if (pos != splits.length - 1)
|
||||||
|
sb.append(' ');
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
// end - move these to util
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ public class VelocityChat {
|
||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Path dataDirectory;
|
private final Path dataDirectory;
|
||||||
|
|
||||||
private LuckPerms luckPerms;
|
private ChatAPI chatAPI;
|
||||||
private ChatHandler chatHandler;
|
private ChatHandler chatHandler;
|
||||||
private ServerHandler serverHandler;
|
private ServerHandler serverHandler;
|
||||||
|
|
||||||
|
|
@ -55,12 +55,8 @@ public class VelocityChat {
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
new ALogger(logger);
|
new ALogger(logger);
|
||||||
Config.init(getDataDirectory());
|
//Config.init(getDataDirectory());
|
||||||
//new DatabaseConnection();
|
chatAPI = new ChatImplementation();
|
||||||
//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();
|
||||||
|
|
@ -96,12 +92,6 @@ public class VelocityChat {
|
||||||
// all (proxy)commands go here
|
// all (proxy)commands go here
|
||||||
}
|
}
|
||||||
|
|
||||||
public LuckPerms getLuckPerms() {
|
|
||||||
if(luckPerms == null)
|
|
||||||
luckPerms = LuckPermsProvider.get();
|
|
||||||
return luckPerms;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatHandler getChatHandler() {
|
public ChatHandler getChatHandler() {
|
||||||
return chatHandler;
|
return chatHandler;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
|
@ -25,7 +26,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().getLuckPerms();
|
LuckPerms luckPerms = ChatAPI.get().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?
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class ChatHandler {
|
||||||
// Template.of("prefix", user.getPrefix()),
|
// Template.of("prefix", user.getPrefix()),
|
||||||
// Template.of("message", message),
|
// Template.of("message", message),
|
||||||
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
// Template.of("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude")
|
||||||
// /*,Template.of("[i]", itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
// /*,Template.of("[i]" , itemComponent(sender.getInventory().getItemInMainHand()))*/ //Todo move this into ChatFilters
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
Map<String, String> map = new HashMap<>();
|
||||||
|
|
@ -91,6 +91,16 @@ public class ChatHandler {
|
||||||
recipient.sendMessage(receiverMessage);
|
recipient.sendMessage(receiverMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void globalAdminChat(String message) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.get();
|
||||||
|
|
||||||
|
Component component = miniMessage.parse(Config.GACFORMAT);
|
||||||
|
|
||||||
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.proxy.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||||
|
target.sendMessage(component);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public void globalAdminChat(CommandSource commandSource, String message) {
|
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||||
String senderName = Config.CONSOLENAME;
|
String senderName = Config.CONSOLENAME;
|
||||||
String serverName = "Altitude";
|
String serverName = "Altitude";
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,14 @@ package com.alttd.chat.handlers;
|
||||||
import com.alttd.chat.VelocityChat;
|
import com.alttd.chat.VelocityChat;
|
||||||
import com.alttd.chat.config.ServerConfig;
|
import com.alttd.chat.config.ServerConfig;
|
||||||
import com.alttd.chat.data.ServerWrapper;
|
import com.alttd.chat.data.ServerWrapper;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ServerHandler {
|
public class ServerHandler {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,9 @@ public class PluginMessageListener {
|
||||||
// todo this is obsolete
|
// todo this is obsolete
|
||||||
//VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
//VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF());
|
||||||
break;
|
break;
|
||||||
|
case "globaladminchat":
|
||||||
|
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user