Compare commits
42
Commits
ignore_fix
...
matrix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
636ee3c57e | ||
|
|
7cc7cca129 | ||
|
|
3bfd358e78 | ||
|
|
eb30750134 | ||
|
|
fc7860145f | ||
|
|
1dd19f0543 | ||
|
|
bbd421c423 | ||
|
|
5fe5a305a5 | ||
|
|
bbfc9c407c | ||
|
|
880108d344 | ||
|
|
61e705b088 | ||
|
|
38228ea585 | ||
|
|
b65fcdb1c7 | ||
|
|
e74361a7b7 | ||
|
|
769859a617 | ||
|
|
cb0bda8d5b | ||
|
|
5212954946 | ||
|
|
f1b8af6136 | ||
|
|
bfc9af69d0 | ||
|
|
ea705c879f | ||
|
|
f5c0a0676c | ||
|
|
9bd9e21321 | ||
|
|
1c570fd524 | ||
|
|
131ea6da9d | ||
|
|
3275db13d0 | ||
|
|
a908e32d0b | ||
|
|
8393d12c6d | ||
|
|
782c7df4ef | ||
|
|
a876a9f77b | ||
|
|
f3147b3256 | ||
|
|
65503a02f3 | ||
|
|
7140a0cd78 | ||
|
|
187f71d6c3 | ||
|
|
3b2aa84164 | ||
|
|
0fb497c2f1 | ||
|
|
192fca3a89 | ||
|
|
d6135f2456 | ||
|
|
c057c69653 | ||
|
|
c25767e473 | ||
|
|
37aa9fdf4c | ||
|
|
ed2ba74772 | ||
|
|
44d6e994cc |
@@ -40,3 +40,5 @@ target/
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid
|
||||
!gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
*.bat
|
||||
|
||||
Vendored
+4
-1
@@ -1,9 +1,12 @@
|
||||
pipeline {
|
||||
agent any
|
||||
environment {
|
||||
NEXUS_CREDS = credentials('alttd-snapshot-user')
|
||||
}
|
||||
stages {
|
||||
stage('Gradle') {
|
||||
steps {
|
||||
sh './gradlew build'
|
||||
sh './gradlew build -PalttdSnapshotUsername=$NEXUS_CREDS_USR -PalttdSnapshotPassword=$NEXUS_CREDS_PSW'
|
||||
}
|
||||
}
|
||||
stage('Archive') {
|
||||
|
||||
@@ -3,12 +3,12 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
|
||||
// exclude("net.kyori")
|
||||
// }
|
||||
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
// Cosmos
|
||||
compileOnly("com.alttd.cosmos:cosmos-api:1.21.10-R0.1-SNAPSHOT") {
|
||||
isChanging = true
|
||||
}
|
||||
compileOnly("org.spongepowered:configurate-yaml:4.2.0") // Configurate
|
||||
compileOnly("net.luckperms:api:5.5") // Luckperms
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
||||
@@ -15,9 +15,9 @@ public abstract interface ChatAPI {
|
||||
|
||||
DatabaseConnection getDataBase();
|
||||
|
||||
void ReloadConfig();
|
||||
void reloadConfig();
|
||||
|
||||
void ReloadChatFilters();
|
||||
void reloadChatFilters();
|
||||
|
||||
HashMap<String, String> getPrefixes();
|
||||
|
||||
|
||||
@@ -5,15 +5,12 @@ import com.alttd.chat.config.PrefixConfig;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ChatImplementation implements ChatAPI{
|
||||
|
||||
@@ -26,7 +23,7 @@ public class ChatImplementation implements ChatAPI{
|
||||
|
||||
public ChatImplementation() {
|
||||
instance = this;
|
||||
ReloadConfig();
|
||||
reloadConfig();
|
||||
|
||||
luckPerms = getLuckPerms();
|
||||
databaseConnection = getDataBase();
|
||||
@@ -57,13 +54,13 @@ public class ChatImplementation implements ChatAPI{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ReloadConfig() {
|
||||
public void reloadConfig() {
|
||||
Config.init();
|
||||
loadPrefixes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ReloadChatFilters() {
|
||||
public void reloadChatFilters() {
|
||||
RegexManager.initialize();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.alttd.chat.config;
|
||||
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.ConfigurationOptions;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
@@ -19,6 +20,7 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Config {
|
||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||
private static final String HEADER = "";
|
||||
@@ -31,6 +33,7 @@ public final class Config {
|
||||
static boolean verbose;
|
||||
|
||||
public static File CONFIGPATH;
|
||||
|
||||
public static void init() {
|
||||
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "ChatPlugin");
|
||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||
@@ -49,14 +52,14 @@ public final class Config {
|
||||
return;
|
||||
}
|
||||
} catch (IOException error) {
|
||||
error.printStackTrace();
|
||||
ALogger.error(error.getMessage(), error);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
verbose = getBoolean("verbose", true);
|
||||
@@ -66,7 +69,7 @@ public final class Config {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ public final class Config {
|
||||
method.setAccessible(true);
|
||||
method.invoke(instance);
|
||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||
ex.printStackTrace();
|
||||
ALogger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,7 +89,7 @@ public final class Config {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
ALogger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +97,7 @@ public final class Config {
|
||||
try {
|
||||
configLoader.save(config);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
ALogger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,17 +110,18 @@ public final class Config {
|
||||
try {
|
||||
config.node(splitPath(path)).set(def);
|
||||
} catch (SerializationException e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setString(String path, String def) {
|
||||
try {
|
||||
if(config.node(splitPath(path)).virtual())
|
||||
if (config.node(splitPath(path)).virtual()) {
|
||||
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
|
||||
}
|
||||
} catch (SerializationException ex) {
|
||||
ex.printStackTrace();
|
||||
ALogger.error(ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +155,7 @@ public final class Config {
|
||||
set(path, def);
|
||||
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
|
||||
} catch (SerializationException ex) {
|
||||
ex.printStackTrace();
|
||||
ALogger.error(ex.getMessage(), ex);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -164,7 +168,9 @@ public final class Config {
|
||||
return config.node(splitPath(path));
|
||||
}
|
||||
|
||||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||
/**
|
||||
* ONLY EDIT ANYTHING BELOW THIS LINE
|
||||
**/
|
||||
public static List<String> PREFIXGROUPS = new ArrayList<>();
|
||||
public static List<String> CONFLICTINGPREFIXGROUPS = new ArrayList<>();
|
||||
public static List<String> STAFFGROUPS = new ArrayList<>();
|
||||
@@ -173,9 +179,11 @@ public final class Config {
|
||||
public static UUID CONSOLEUUID = UUID.randomUUID();
|
||||
public static int EMOTELIMIT = 3;
|
||||
public static String MENTIONPLAYERTAG = "<aqua>@</aqua>";
|
||||
|
||||
private static void settings() {
|
||||
PREFIXGROUPS = getList("settings.prefix-groups",
|
||||
Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch", "developer"));
|
||||
Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch",
|
||||
"developer"));
|
||||
CONFLICTINGPREFIXGROUPS = getList("settings.prefix-conflicts-groups",
|
||||
Lists.newArrayList("eventteam", "eventleader"));
|
||||
STAFFGROUPS = getList("settings.staff-groups",
|
||||
@@ -189,10 +197,13 @@ public final class Config {
|
||||
|
||||
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
||||
public static List<String> REPLYCOMMANDALIASES = new ArrayList<>();
|
||||
public static String MESSAGESENDER = "<hover:show_text:Click to reply><click:suggest_command:/msg <receivername> ><light_purple>(Me -> <gray><receiver></gray>)</hover> <message>";
|
||||
public static String MESSAGERECIEVER = "<hover:show_text:Click to reply><click:suggest_command:/msg <sendername> ><light_purple>(<gray><sender></gray> on <server> -> Me)</hover> <message>";
|
||||
public static String MESSAGESENDER =
|
||||
"<hover:show_text:Click to reply><click:suggest_command:/msg <receivername> ><light_purple>(Me -> <gray><receiver></gray>)</hover> <message>";
|
||||
public static String MESSAGERECIEVER =
|
||||
"<hover:show_text:Click to reply><click:suggest_command:/msg <sendername> ><light_purple>(<gray><sender></gray> on <server> -> Me)</hover> <message>";
|
||||
public static String MESSAGESPY = "<gray>(<gray><sendername></gray> -> <receivername>) <message>";
|
||||
public static String RECEIVER_DOES_NOT_EXIST = "<red><player> is not a valid player.</red>";
|
||||
|
||||
private static void messageCommand() {
|
||||
MESSAGECOMMANDALIASES.clear();
|
||||
REPLYCOMMANDALIASES.clear();
|
||||
@@ -204,12 +215,14 @@ public final class Config {
|
||||
RECEIVER_DOES_NOT_EXIST = getString("commands.message.receiver-does-not-exist", RECEIVER_DOES_NOT_EXIST);
|
||||
}
|
||||
|
||||
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 List<String> GCALIAS = new ArrayList<>();
|
||||
public static String GCNOTENABLED = "You don't have global chat enabled.";
|
||||
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again.";
|
||||
public static int GCCOOLDOWN = 30;
|
||||
|
||||
private static void globalChat() {
|
||||
GCFORMAT = getString("commands.globalchat.format", GCFORMAT);
|
||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||
@@ -219,26 +232,32 @@ public final class Config {
|
||||
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
||||
}
|
||||
|
||||
public static String CHATFORMAT = "<white><light_purple><prefixall> <gray><hover:show_text:Click to message <sendername>><click:suggest_command:/msg <sendername> ><sender></hover>: <white><message>";
|
||||
public static String CHATFORMAT =
|
||||
"<white><light_purple><prefixall> <gray><hover:show_text:Click to message <sendername>><click:suggest_command:/msg <sendername> ><sender></hover>: <white><message>";
|
||||
public static String URLFORMAT = "<click:OPEN_URL:<clickurl>><url></click>";
|
||||
|
||||
private static void Chat() {
|
||||
CHATFORMAT = getString("chat.format", CHATFORMAT);
|
||||
URLFORMAT = getString("chat.urlformat", URLFORMAT);
|
||||
}
|
||||
|
||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
||||
public static String GACFORMAT = "<hover:show_text:Click to reply><click:suggest_command:/acg ><yellow>(<sender> on <server> -> Team)</hover> <message>";
|
||||
public static String GACFORMAT =
|
||||
"<hover:show_text:Click to reply><click:suggest_command:/acg ><yellow>(<sender> on <server> -> Team)</hover> <message>";
|
||||
|
||||
private static void globalAdminChat() {
|
||||
GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg"));
|
||||
GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT);
|
||||
}
|
||||
|
||||
public static String MESSAGECHANNEL = "altitude:chatplugin";
|
||||
|
||||
private static void messageChannels() {
|
||||
MESSAGECHANNEL = getString("settings.message-channel", MESSAGECHANNEL);
|
||||
}
|
||||
|
||||
public static ConfigurationNode REGEXNODE = null;
|
||||
|
||||
private static void RegexNOde() {
|
||||
REGEXNODE = getNode("regex-settings");
|
||||
}
|
||||
@@ -247,6 +266,7 @@ public final class Config {
|
||||
public static String SERVERSWTICHMESSAGETO = "<gray>* <player> leaves to <to_server>...";
|
||||
public static String SERVERJOINMESSAGE = "<green>* <player> appears from thin air...";
|
||||
public static String SERVERLEAVEMESSAGE = "<red>* <player> vanishes in the mist...";
|
||||
|
||||
private static void JoinLeaveMessages() {
|
||||
SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM);
|
||||
SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO);
|
||||
@@ -255,8 +275,10 @@ public final class Config {
|
||||
|
||||
}
|
||||
|
||||
public static String PARTY_FORMAT = "<dark_aqua>(<gray><sender></gray><hover:show_text:\"on <server>\"> → <party></hover>) <message>";
|
||||
public static String PARTY_SPY = "<i><gray>PC:</gray><dark_gray> <dark_gray><username></dark_gray>: <dark_gray><party></dark_gray> <message></dark_gray></i>";
|
||||
public static String PARTY_FORMAT =
|
||||
"<dark_aqua>(<gray><sender></gray><hover:show_text:\"on <server>\"> → <party></hover>) <message>";
|
||||
public static String PARTY_SPY =
|
||||
"<i><gray>PC:</gray><dark_gray> <dark_gray><username></dark_gray>: <dark_gray><party></dark_gray> <message></dark_gray></i>";
|
||||
public static String NO_PERMISSION = "<red>You don't have permission to use this command.</red>";
|
||||
public static String NO_CONSOLE = "<red>This command can not be used by console</red>";
|
||||
public static String CREATED_PARTY = "<green>You created a chat party called: " +
|
||||
@@ -270,9 +292,11 @@ public final class Config {
|
||||
public static String INVALID_PASSWORD = "<red>Invalid password.</red>";
|
||||
public static String JOINED_PARTY = "<green>You joined <party_name>!</green>";
|
||||
public static String PLAYER_JOINED_PARTY = "<green><player_name> joined <party_name>!</green>";
|
||||
public static String NOTIFY_FINDING_NEW_OWNER = "<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>";
|
||||
public static String NOTIFY_FINDING_NEW_OWNER =
|
||||
"<dark_aqua>Since you own this chat party a new party owner will be chosen.<dark_aqua>";
|
||||
public static String LEFT_PARTY = "<green>You have left the chat party!</green>";
|
||||
public static String OWNER_LEFT_PARTY = "<dark_aqua>[ChatParty]: <old_owner> left the chat party, the new party owner is <new_owner></dark_aqua>";
|
||||
public static String OWNER_LEFT_PARTY =
|
||||
"<dark_aqua>[ChatParty]: <old_owner> left the chat party, the new party owner is <new_owner></dark_aqua>";
|
||||
public static String PLAYER_LEFT_PARTY = "<dark_aqua>[ChatParty]: <player_name> left the chat party!</dark_aqua>";
|
||||
public static String NEW_PARTY_OWNER = "<dark_aqua>[ChatParty]: <old_owner> transferred the party to <new_owner>!";
|
||||
public static String CANT_REMOVE_PARTY_OWNER = "<red>You can't remove yourself, please leave instead.</red>";
|
||||
@@ -286,20 +310,23 @@ public final class Config {
|
||||
"<dark_aqua>You received an invite to join <party>, click this message to accept.</dark_aqua></click>";
|
||||
public static String PARTY_MEMBER_LOGGED_ON = "<dark_aqua>[ChatParty] <player> joined Altitude...</dark_aqua>";
|
||||
public static String PARTY_MEMBER_LOGGED_OFF = "<dark_aqua>[ChatParty] <player> left Altitude...</dark_aqua>";
|
||||
public static String RENAMED_PARTY = "<dark_aqua>[ChatParty] <owner> changed the party name from <old_name> to <new_name>!</dark_aqua>";
|
||||
public static String RENAMED_PARTY =
|
||||
"<dark_aqua>[ChatParty] <owner> changed the party name from <old_name> to <new_name>!</dark_aqua>";
|
||||
public static String CHANGED_PASSWORD = "<green>Password was set to <password></green>";
|
||||
public static String DISBAND_PARTY_CONFIRM = "<green><bold>Are you sure you want to disband your party?</bold> " +
|
||||
"Type <gold>/party disband confirm <party></gold> to confirm.";
|
||||
public static String DISBANDED_PARTY = "<dark_aqua>[ChatParty] <owner> has disbanded <party>, everyone has been removed.</dark_aqua>";
|
||||
public static String DISBANDED_PARTY =
|
||||
"<dark_aqua>[ChatParty] <owner> has disbanded <party>, everyone has been removed.</dark_aqua>";
|
||||
public static String PARTY_INFO = """
|
||||
<gold><bold>Chat party info</bold>:
|
||||
</gold><green>Name: <dark_aqua><party></dark_aqua>
|
||||
Password: <dark_aqua><password></dark_aqua>
|
||||
Owner: <owner>
|
||||
Members: <members>""";
|
||||
public static Component ONLINE_PREFIX = null;
|
||||
public static Component OFFLINE_PREFIX = null;
|
||||
public static ComponentLike ONLINE_PREFIX = null;
|
||||
public static ComponentLike OFFLINE_PREFIX = null;
|
||||
public static String PARTY_TOGGLED = "<dark_aqua>Party chat toggled <status>.</dark_aqua>";
|
||||
|
||||
private static void party() {
|
||||
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
||||
PARTY_SPY = getString("party.spy", PARTY_SPY);
|
||||
@@ -338,17 +365,27 @@ public final class Config {
|
||||
|
||||
public static String PARTY_HELP_WRAPPER = "<gold>ChatParty help:\n<commands></gold>";
|
||||
public static String PARTY_HELP_HELP = "<green>Show this menu: <gold>/party help</gold></green>";
|
||||
public static String PARTY_HELP_CREATE = "<green>Create a party: <gold>/party create <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_INFO = "<green>Show info about your current party: <gold>/party info</gold></green>";
|
||||
public static String PARTY_HELP_INVITE = "<green>Invite a user to your party: <gold>/party invite <username></gold></green>";
|
||||
public static String PARTY_HELP_JOIN = "<green>Join a party: <gold>/party join <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_CREATE =
|
||||
"<green>Create a party: <gold>/party create <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_INFO =
|
||||
"<green>Show info about your current party: <gold>/party info</gold></green>";
|
||||
public static String PARTY_HELP_INVITE =
|
||||
"<green>Invite a user to your party: <gold>/party invite <username></gold></green>";
|
||||
public static String PARTY_HELP_JOIN =
|
||||
"<green>Join a party: <gold>/party join <party_name> <party_password></gold></green>";
|
||||
public static String PARTY_HELP_LEAVE = "<green>Leave your current party: <gold>/party leave</gold></green>";
|
||||
public static String PARTY_HELP_NAME = "<green>Change the name of your party: <gold>/party name <new_name></gold></green>";
|
||||
public static String PARTY_HELP_OWNER = "<green>Change the owner of your party: <gold>/party owner <new_owner_name></gold></green>";
|
||||
public static String PARTY_HELP_PASSWORD = "<green>Change the password of your party: <gold>/party password <new_password></gold></green>";
|
||||
public static String PARTY_HELP_REMOVE = "<green>Remove a member from your party: <gold>/party remove <member_name></gold></green>";
|
||||
public static String PARTY_HELP_DISBAND = "<green>Remove everyone from your party and disband it: <gold>/party disband</gold></green>";
|
||||
public static String PARTY_HELP_NAME =
|
||||
"<green>Change the name of your party: <gold>/party name <new_name></gold></green>";
|
||||
public static String PARTY_HELP_OWNER =
|
||||
"<green>Change the owner of your party: <gold>/party owner <new_owner_name></gold></green>";
|
||||
public static String PARTY_HELP_PASSWORD =
|
||||
"<green>Change the password of your party: <gold>/party password <new_password></gold></green>";
|
||||
public static String PARTY_HELP_REMOVE =
|
||||
"<green>Remove a member from your party: <gold>/party remove <member_name></gold></green>";
|
||||
public static String PARTY_HELP_DISBAND =
|
||||
"<green>Remove everyone from your party and disband it: <gold>/party disband</gold></green>";
|
||||
public static String PARTY_HELP_CHAT = "<green>Talk in party chat: <gold>/p <message></gold></green>";
|
||||
|
||||
private static void partyHelp() {
|
||||
PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER);
|
||||
PARTY_HELP_HELP = getString("party.help.help", PARTY_HELP_HELP);
|
||||
@@ -366,12 +403,17 @@ public final class Config {
|
||||
}
|
||||
|
||||
public static String CUSTOM_CHANNEL_TOGGLED = "<yellow>Toggled <channel> <status>.</yellow>";
|
||||
public static Component TOGGLED_ON = null;
|
||||
public static Component TOGGLED_OFF = null;
|
||||
public static ComponentLike TOGGLED_ON = null;
|
||||
public static ComponentLike TOGGLED_OFF = null;
|
||||
public static double LOCAL_DISTANCE;
|
||||
public static String CHANNEL_SPY =
|
||||
"<i><gray>SPY:</gray> <dark_gray>(<dark_gray><sender> → <channel>) <message></dark_gray>";
|
||||
|
||||
private static void chatChannels() {
|
||||
ConfigurationNode node = getNode("chat-channels");
|
||||
if (node.empty()) {
|
||||
getString("chat-channels.ac.format", "<white><gray><sender></gray> <hover:show_text:on <server>><yellow>to <channel></yellow></hover><gray>: <message>");
|
||||
getString("chat-channels.ac.format",
|
||||
"<white><gray><sender></gray> <hover:show_text:on <server>><yellow>to <channel></yellow></hover><gray>: <message>");
|
||||
getList("chat-channels.ac.servers", List.of("lobby"));
|
||||
getBoolean("chat-channels.ac.proxy", false);
|
||||
node = getNode("chat-channels");
|
||||
@@ -383,16 +425,23 @@ public final class Config {
|
||||
new CustomChannel(channelName,
|
||||
getString(key + "format", ""),
|
||||
getList(key + "servers", Collections.EMPTY_LIST),
|
||||
getBoolean(key + "proxy", false));
|
||||
getList(key + "alias", Collections.EMPTY_LIST),
|
||||
getBoolean(key + "proxy", false),
|
||||
getBoolean(key + "local", false)
|
||||
);
|
||||
}
|
||||
|
||||
CUSTOM_CHANNEL_TOGGLED = getString("chat-channels-messages.channel-toggled", CUSTOM_CHANNEL_TOGGLED);
|
||||
TOGGLED_ON = Utility.parseMiniMessage(getString("chat-channels-messages.channel-on", "<green>on</green><gray>"));
|
||||
TOGGLED_ON =
|
||||
Utility.parseMiniMessage(getString("chat-channels-messages.channel-on", "<green>on</green><gray>"));
|
||||
TOGGLED_OFF = Utility.parseMiniMessage(getString("chat-channels-messages.channel-off", "<red>off</red><gray>"));
|
||||
LOCAL_DISTANCE = getDouble("chat-channels-messages.local-distance", 200.0);
|
||||
CHANNEL_SPY = getString("chat-channels-messages.spy", CHANNEL_SPY);
|
||||
}
|
||||
|
||||
public static String SERVERMUTEPERMISSION = "chat.command.mute-server";
|
||||
public static String SPYPERMISSION = "chat.socialspy";
|
||||
|
||||
private static void permissions() {
|
||||
SERVERMUTEPERMISSION = getString("permissions.server-mute", SERVERMUTEPERMISSION);
|
||||
SPYPERMISSION = getString("permissions.spy-permission", SPYPERMISSION);
|
||||
@@ -403,6 +452,7 @@ public final class Config {
|
||||
public static String DATABASE = "database";
|
||||
public static String USERNAME = "root";
|
||||
public static String PASSWORD = "root";
|
||||
|
||||
private static void database() {
|
||||
IP = getString("database.ip", IP);
|
||||
PORT = getString("database.port", PORT);
|
||||
@@ -412,18 +462,25 @@ public final class Config {
|
||||
}
|
||||
|
||||
public static String NOTIFICATIONFORMAT = "<red>[<prefix>] <displayname> <target> <input>";
|
||||
|
||||
private static void notificationSettings() {
|
||||
NOTIFICATIONFORMAT = getString("settings.blockedmessage-notification", NOTIFICATIONFORMAT);
|
||||
}
|
||||
|
||||
public static String mailHeader = "===== List Mails ====='";
|
||||
public static String mailBody = "<white>From:</white> [<staffprefix>] <sender> <white><hover:show_text:'<date>'><time_ago> day(s) ago</hover>: </white><message>";
|
||||
public static String mailBody =
|
||||
"<white>From:</white> [<staffprefix>] <sender> <white><hover:show_text:'<date>'><time_ago> day(s) ago</hover>: </white><message>";
|
||||
public static String mailFooter = "======================";
|
||||
public static String mailNoUser = "<red>A player with this name hasn't logged in recently.";
|
||||
public static String mailReceived = "<yellow><click:run_command:/mail list unread>New mail from <sender>, click to view</click></yellow>";
|
||||
public static String mailUnread = "<green><click:run_command:/mail list unread>You have <amount> unread mail, click to view it.</click></green>";
|
||||
public static String mailSent = "<green>Successfully send mail to <player_name></green>: <#2e8b57><message></#2e8b57>";
|
||||
public static String mailReceived =
|
||||
"<yellow><click:run_command:/mail list unread>New mail from <sender>, click to view</click></yellow>";
|
||||
public static String mailUnread =
|
||||
"<green><click:run_command:/mail list unread>You have <amount> unread mail, click to view it.</click></green>";
|
||||
public static String mailSent =
|
||||
"<green>Successfully send mail to <player_name></green>: <#2e8b57><message></#2e8b57>";
|
||||
public static List<String> mailCommandAlias = new ArrayList<>();
|
||||
public static int mailDisplayDelay = 5;
|
||||
|
||||
private static void mailSettings() {
|
||||
mailHeader = getString("settings.mail.header", mailHeader);
|
||||
mailBody = getString("settings.mail.message", mailBody);
|
||||
@@ -432,11 +489,15 @@ public final class Config {
|
||||
mailReceived = getString("settings.mail.mail-received", mailReceived);
|
||||
mailUnread = getString("settings.mail.mail-unread", mailUnread);
|
||||
mailSent = getString("settings.mail.mail-sent", mailSent);
|
||||
mailDisplayDelay = getInt("settings.mail.delay", mailDisplayDelay);
|
||||
}
|
||||
|
||||
public static HashMap<String, Long> serverChannelId = new HashMap<>();
|
||||
public static String REPORT_SENT = "<green>Your report was sent, staff will contact you asap to help resolve your issue!</green>";
|
||||
public static String REPORT_TOO_SHORT = "<red>Please ensure your report is descriptive. We require at least 3 words per report</red>";
|
||||
public static String REPORT_SENT =
|
||||
"<green>Your report was sent, staff will contact you asap to help resolve your issue!</green>";
|
||||
public static String REPORT_TOO_SHORT =
|
||||
"<red>Please ensure your report is descriptive. We require at least 3 words per report</red>";
|
||||
|
||||
private static void loadChannelIds() {
|
||||
serverChannelId.clear();
|
||||
serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1));
|
||||
@@ -444,8 +505,9 @@ public final class Config {
|
||||
Map<Object, ? extends ConfigurationNode> objectMap = node.childrenMap();
|
||||
for (Object o : objectMap.keySet()) {
|
||||
String key = (String) o;
|
||||
if (key.equalsIgnoreCase("general"))
|
||||
if (key.equalsIgnoreCase("general")) {
|
||||
continue;
|
||||
}
|
||||
ConfigurationNode configurationNode = objectMap.get(o);
|
||||
long channelId = configurationNode.getLong();
|
||||
serverChannelId.put(key.toLowerCase(), channelId);
|
||||
@@ -469,7 +531,9 @@ public final class Config {
|
||||
}
|
||||
|
||||
public static String HELP_REPORT = "<red>/report <message></red>";
|
||||
public static String FIRST_JOIN = "<green>* Welcome <light_purple><player></light_purple> to Altitude! They've joined for the first time.</green>";
|
||||
public static String FIRST_JOIN =
|
||||
"<green>* Welcome <light_purple><player></light_purple> to Altitude! They've joined for the first time.</green>";
|
||||
|
||||
private static void loadMessages() {
|
||||
HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT);
|
||||
FIRST_JOIN = getString("settings.first-join.message", FIRST_JOIN);
|
||||
@@ -477,7 +541,9 @@ public final class Config {
|
||||
|
||||
public static String EMOTELIST_HEADER = "<bold>Available Chat Emotes</bold><newline>";
|
||||
public static String EMOTELIST_ITEM = "<insert:\"<regex>\"><gold><regex></gold> : <emote></insert><newline>";
|
||||
public static String EMOTELIST_FOOTER = "<green>----<< <gray>Prev</gray> <page> <gray>/</gray> <pages> <gray>Next</gray> >>----";
|
||||
public static String EMOTELIST_FOOTER =
|
||||
"<green>----<< <gray>Prev</gray> <page> <gray>/</gray> <pages> <gray>Next</gray> >>----";
|
||||
|
||||
private static void emoteListCommand() {
|
||||
EMOTELIST_HEADER = getString("commands.emotelist.header", EMOTELIST_HEADER);
|
||||
EMOTELIST_ITEM = getString("commands.emotelist.item", EMOTELIST_ITEM);
|
||||
@@ -488,31 +554,42 @@ public final class Config {
|
||||
public static String NICK_CHANGED = "<yellow>Your nickname was changed to <nickname><yellow>.";
|
||||
public static String NICK_NOT_CHANGED = "<yellow>Your nickname request was denied.";
|
||||
public static String NICK_RESET = "<yellow>Nickname changed back to normal.";
|
||||
public static String NICK_CHANGED_OTHERS = "<gold><targetplayer><yellow>'s nickname was changed to <nickname><yellow>.";
|
||||
public static String NICK_TARGET_NICK_CHANGE = "<yellow>Your nickname was changed to <nickname> <yellow>by <sendernick><yellow>";
|
||||
public static String NICK_CHANGED_OTHERS =
|
||||
"<gold><targetplayer><yellow>'s nickname was changed to <nickname><yellow>.";
|
||||
public static String NICK_TARGET_NICK_CHANGE =
|
||||
"<yellow>Your nickname was changed to <nickname> <yellow>by <sendernick><yellow>";
|
||||
public static String NICK_RESET_OTHERS = "<gold><player><gold>'s <yellow>nickname was reset back to normal.";
|
||||
public static String NICK_INVALID_CHARACTERS = "<yellow>You can only use letters and numbers in nicknames.";
|
||||
public static String NICK_INVALID_LENGTH = "<yellow>Nicknames need to be between 3 to 16 characters long.";
|
||||
public static String NICK_PLAYER_NOT_ONLINE = "<red>That player is not online.";
|
||||
public static String NICK_BLOCKED_COLOR_CODES = "<yellow>You have blocked color codes in that nickname.";
|
||||
public static String NICK_USER_NOT_FOUND = "<red>Failed to set nickname from player, try again from a server this player has been on before.";
|
||||
public static String NICK_ACCEPTED = "<green>You accepted <targetplayer><green>'s nickname. They are now called <newnick><green>.";
|
||||
public static String NICK_DENIED = "<green>You denied <targetplayer><green>'s nickname. They are still called <oldnick><green>.";
|
||||
public static String NICK_USER_NOT_FOUND =
|
||||
"<red>Failed to set nickname from player, try again from a server this player has been on before.";
|
||||
public static String NICK_ACCEPTED =
|
||||
"<green>You accepted <targetplayer><green>'s nickname. They are now called <newnick><green>.";
|
||||
public static String NICK_DENIED =
|
||||
"<green>You denied <targetplayer><green>'s nickname. They are still called <oldnick><green>.";
|
||||
public static String NICK_ALREADY_HANDLED = "<red><targetplayer><red>'s nickname was already accepted or denied.";
|
||||
public static String NICK_NO_LUCKPERMS = "<red>Due to an issue with LuckPerms /nick try won't work at the moment.";
|
||||
public static String NICK_TOO_SOON = "<red>Please wait <time><red> until requesting a new nickname";
|
||||
public static String NICK_REQUEST_PLACED = "<green>Replaced your previous request <oldrequestednick><green> with <newrequestednick><green>.";
|
||||
public static String NICK_REQUEST_PLACED =
|
||||
"<green>Replaced your previous request <oldrequestednick><green> with <newrequestednick><green>.";
|
||||
public static String NICK_REQUEST_NEW = "<green>New nickname request by <player><green>!";
|
||||
public static String NICK_TRYOUT = "<white><prefix><white> <nick><gray>: <white>Hi, this is what my new nickname could look like!";
|
||||
public static String NICK_REQUESTED = "<green>Your requested to be nicknamed <nick><green> has been received. Staff will accept or deny this request asap!";
|
||||
public static String NICK_TRYOUT =
|
||||
"<white><prefix><white> <nick><gray>: <white><click:suggest_command:/nick request <nickrequest>>Hi, this is what my new nickname could look like! Click this message to request.";
|
||||
public static String NICK_REQUESTED =
|
||||
"<green>Your requested to be nicknamed <nick><green> has been received. Staff will accept or deny this request asap!";
|
||||
public static String NICK_REVIEW_WAITING = "<green>There are <amount> nicknames waiting for review!";
|
||||
public static String NICK_TAKEN = "<red>Someone else already has this nickname, or has this name as their username.";
|
||||
public static String NICK_TAKEN =
|
||||
"<red>Someone else already has this nickname, or has this name as their username.";
|
||||
public static String NICK_REQUESTS_ON_LOGIN = "<green>Current nick requests: <amount>";
|
||||
public static long NICK_WAIT_TIME = 86400000;
|
||||
public static List<String> NICK_ITEM_LORE = new ArrayList<>();
|
||||
public static List<String> NICK_BLOCKED_COLOR_CODESLIST = new ArrayList<>();
|
||||
public static List<String> NICK_ALLOWED_COLOR_CODESLIST = new ArrayList<>();
|
||||
public static String NICK_CURRENT = "<gold>Current nickname: <nickname><white>(<insert:\"<currentnickname>\"><currentnickname></insert>)";
|
||||
public static String NICK_CURRENT =
|
||||
"<gold>Current nickname: <nickname><white>(<insert:\"<currentnickname>\"><currentnickname></insert>)";
|
||||
|
||||
private static void nicknameSettings() {
|
||||
NICK_CHANGED = getString("nicknames.messages.nick-changed", NICK_CHANGED);
|
||||
NICK_NOT_CHANGED = getString("nicknames.messages.nick-not-changed", NICK_NOT_CHANGED);
|
||||
@@ -538,9 +615,13 @@ public final class Config {
|
||||
NICK_TAKEN = getString("nicknames.messages.nick-taken", NICK_TAKEN);
|
||||
NICK_REQUESTS_ON_LOGIN = getString("nicknames.messages.nick-reauests-on-login", NICK_REQUESTS_ON_LOGIN);
|
||||
NICK_WAIT_TIME = getLong("nicknames.wait-time", NICK_WAIT_TIME);
|
||||
NICK_ITEM_LORE = getList("nicknames.item-lore", List.of("<aqua>New nick: <newnick>", "<aqua>Old nick: <oldnick>", "<aqua>Last changed: <lastchanged>", "<green>Left click to Accept <light_purple>| <red>Right click to Deny"));
|
||||
NICK_ITEM_LORE = getList("nicknames.item-lore",
|
||||
List.of("<aqua>New nick: <newnick>", "<aqua>Old nick: <oldnick>", "<aqua>Last changed: <lastchanged>",
|
||||
"<green>Left click to Accept <light_purple>| <red>Right click to Deny"));
|
||||
NICK_BLOCKED_COLOR_CODESLIST = getList("nicknames.blocked-color-codes", List.of("&k", "&l", "&n", "&m", "&o"));
|
||||
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes", List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f", "&r"));
|
||||
NICK_ALLOWED_COLOR_CODESLIST = getList("nicknames.allowed-color-codes",
|
||||
List.of("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "&f",
|
||||
"&r"));
|
||||
NICK_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
||||
}
|
||||
|
||||
@@ -549,7 +630,8 @@ public final class Config {
|
||||
|
||||
private static void deathMessagesSettings() {
|
||||
DEATH_MESSAGES_MAX_PER_PERIOD = getInt("death-messages.max-per-period", DEATH_MESSAGES_MAX_PER_PERIOD);
|
||||
DEATH_MESSAGES_LIMIT_PERIOD_MINUTES = getInt("death-messages.limit-period-minutes", DEATH_MESSAGES_LIMIT_PERIOD_MINUTES);
|
||||
DEATH_MESSAGES_LIMIT_PERIOD_MINUTES =
|
||||
getInt("death-messages.limit-period-minutes", DEATH_MESSAGES_LIMIT_PERIOD_MINUTES);
|
||||
}
|
||||
|
||||
public static long CHAT_LOG_DELETE_OLDER_THAN_DAYS = 31;
|
||||
@@ -559,4 +641,14 @@ public final class Config {
|
||||
CHAT_LOG_DELETE_OLDER_THAN_DAYS = getLong("chat-log.delete-older-than-days", CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
||||
CHAT_LOG_SAVE_DELAY_MINUTES = getLong("chat-log.save-delay-minutes", CHAT_LOG_SAVE_DELAY_MINUTES);
|
||||
}
|
||||
|
||||
public static String MATRIX_SERVER = "http://127.0.0.1:8008";
|
||||
public static String MATRIX_AS_TOKEN = "<token>";
|
||||
public static String MATRIX_HS_TOKEN = "<token>";
|
||||
|
||||
private static void matrixSettings() {
|
||||
MATRIX_SERVER = getString("matrix.server", MATRIX_SERVER);
|
||||
MATRIX_AS_TOKEN = getString("matrix.as_token", MATRIX_AS_TOKEN);
|
||||
MATRIX_HS_TOKEN = getString("matrix.hs_token", MATRIX_HS_TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.alttd.chat.objects;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -13,9 +13,9 @@ import java.util.stream.Collectors;
|
||||
public class ChatUser {
|
||||
private final UUID uuid; // player uuid
|
||||
private int partyId; // the party they are in
|
||||
private Channel toggledChannel;
|
||||
private final Channel toggledChannel;
|
||||
private String name; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||
private Component displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||
private ComponentLike displayName; // the nickname, doesn't need to be saved with the chatuser object, could be saved but we can get it from the nicknamesview
|
||||
// private Component prefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component staffPrefix; // doesn't need saving, we get this from luckperms
|
||||
// private Component prefixAll; // doesn't need saving, we get this from luckperms
|
||||
@@ -24,9 +24,9 @@ public class ChatUser {
|
||||
private String replyContinueTarget; // reply target for use in /c
|
||||
private long gcCooldown; // the time when they last used gc, is used for the cooldown, i wouldn't save this, but setting this to the login time means they can't use gc for 30 seconds after logging in
|
||||
private boolean spy;
|
||||
private List<Mail> mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message
|
||||
private List<UUID> ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player?
|
||||
private List<UUID> ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player?
|
||||
private final List<Mail> mails; // mails aren't finalized yet, so for now a table sender, reciever, sendtime, readtime(if emtpy mail isn't read yet?, could also do a byte to control this), the actual message
|
||||
private final List<UUID> ignoredPlayers; // a list of UUID, a new table non unique, where one is is the player select * from ignores where ignoredby = thisplayer? where the result is the uuid of the player ignored by this player?
|
||||
private final List<UUID> ignoredBy; // a list of UUID, same table as above but select * from ignores where ignored = thisplayer? result should be the other user that ignored this player?
|
||||
private boolean isMuted;
|
||||
|
||||
public ChatUser(UUID uuid, int partyId, Channel toggledChannel) {
|
||||
@@ -71,12 +71,7 @@ public class ChatUser {
|
||||
return toggledChannel;
|
||||
}
|
||||
|
||||
public void setToggledChannel(Channel channel) {
|
||||
toggledChannel = channel;
|
||||
Queries.setToggledChannel(toggledChannel, uuid); //TODO: Async pls - no CompleteableFuture<>!
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
public ComponentLike getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@@ -84,17 +79,17 @@ public class ChatUser {
|
||||
this.displayName = Utility.applyColor(displayName);
|
||||
}
|
||||
|
||||
public Component getPrefix() {
|
||||
public ComponentLike getPrefix() {
|
||||
//return prefix;
|
||||
return Utility.getPrefix(uuid, true); // No longer cache this data
|
||||
}
|
||||
|
||||
public Component getStaffPrefix() {
|
||||
public ComponentLike getStaffPrefix() {
|
||||
//return staffPrefix;
|
||||
return Utility.getStaffPrefix(uuid);
|
||||
}
|
||||
|
||||
public Component getPrefixAll() {
|
||||
public ComponentLike getPrefixAll() {
|
||||
//return prefixAll;
|
||||
return Utility.getPrefix(uuid, false);
|
||||
}
|
||||
@@ -145,10 +140,6 @@ public class ChatUser {
|
||||
return ignoredBy;
|
||||
}
|
||||
|
||||
public void addIgnoredBy(UUID uuid) {
|
||||
ignoredBy.add(uuid);
|
||||
}
|
||||
|
||||
public long getGcCooldown() {
|
||||
return gcCooldown;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -25,7 +25,8 @@ public class EmoteList {
|
||||
}
|
||||
|
||||
private int page;
|
||||
public Component showEmotePage() {
|
||||
|
||||
public ComponentLike showEmotePage() {
|
||||
int startIndex = page * pageSize;
|
||||
int pages = RegexManager.getEmoteFilters().size() / pageSize;
|
||||
int endIndex = Math.min(startIndex + pageSize, RegexManager.getEmoteFilters().size());
|
||||
@@ -33,7 +34,7 @@ public class EmoteList {
|
||||
Placeholder.unparsed("page", String.valueOf(page)),
|
||||
Placeholder.unparsed("pages", String.valueOf(pages))
|
||||
);
|
||||
Component list = Utility.parseMiniMessage(Config.EMOTELIST_HEADER, placeholders);
|
||||
Component list = Utility.parseMiniMessage(Config.EMOTELIST_HEADER, placeholders).asComponent();
|
||||
|
||||
for (int i = startIndex; i < endIndex; i++) {
|
||||
ChatFilter emote = RegexManager.getEmoteFilters().get(i);
|
||||
@@ -60,5 +61,4 @@ public class EmoteList {
|
||||
this.page = Math.max(page - 1, 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,10 +3,6 @@ package com.alttd.chat.objects;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
|
||||
import javax.annotation.RegEx;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ModifiableString {
|
||||
private Component text;
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
package com.alttd.chat.objects;
|
||||
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartyUser {
|
||||
|
||||
protected UUID uuid;
|
||||
protected Component displayName;
|
||||
protected ComponentLike displayName;
|
||||
protected String playerName;
|
||||
|
||||
public PartyUser(UUID uuid, String displayName, String playerName) {
|
||||
this(uuid, Utility.applyColor(displayName), playerName);
|
||||
}
|
||||
|
||||
public PartyUser(UUID uuid, Component displayName, String playerName) {
|
||||
public PartyUser(UUID uuid, ComponentLike displayName, String playerName) {
|
||||
this.uuid = uuid;
|
||||
this.displayName = displayName;
|
||||
this.playerName = playerName;
|
||||
@@ -25,7 +25,7 @@ public class PartyUser {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public Component getDisplayName() {
|
||||
public ComponentLike getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ public class Channel {
|
||||
protected String channelName;
|
||||
protected String format;
|
||||
protected boolean proxy;
|
||||
protected boolean local;
|
||||
|
||||
public Channel(String channelName, String format, boolean proxy) {
|
||||
public Channel(String channelName, String format, boolean proxy, boolean local) {
|
||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||
this.channelName = channelName;
|
||||
this.format = format;
|
||||
this.proxy = proxy;
|
||||
this.local = local;
|
||||
channels.put(channelName.toLowerCase(), this);
|
||||
}
|
||||
|
||||
@@ -39,6 +41,10 @@ public class Channel {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public boolean isLocal() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public static Channel getChatChannel(String channelName) {
|
||||
return channels.get(channelName.toLowerCase());
|
||||
}
|
||||
|
||||
@@ -1,20 +1,27 @@
|
||||
package com.alttd.chat.objects.channels;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomChannel extends Channel {
|
||||
private final List<String> servers;
|
||||
private final List<String> aliases;
|
||||
|
||||
public CustomChannel(String channelName, String format, List<String> servers, boolean proxy) {
|
||||
super(channelName, format, proxy);
|
||||
public CustomChannel(String channelName, String format, List<String> servers, List<String> aliases, boolean proxy,
|
||||
boolean local) {
|
||||
super(channelName, format, proxy, local);
|
||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||
this.channelName = channelName;
|
||||
this.format = format;
|
||||
this.servers = servers;
|
||||
this.proxy = proxy;
|
||||
channels.put(channelName.toLowerCase(), this);
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public List<String> getServers() {
|
||||
return servers;
|
||||
}
|
||||
|
||||
public List<String> getAliases() {
|
||||
return aliases;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,6 @@ package com.alttd.chat.objects.channels;
|
||||
|
||||
public abstract class DefaultChannel extends Channel{
|
||||
public DefaultChannel(String channelName, String format, boolean proxy) {
|
||||
super(channelName, format, proxy);
|
||||
super(channelName, format, proxy, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,32 +3,30 @@ package com.alttd.chat.util;
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.config.Config;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import net.luckperms.api.model.user.User;
|
||||
import net.luckperms.api.node.Node;
|
||||
import org.bukkit.permissions.Permission;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Utility {
|
||||
|
||||
private static final List<String> EMPTY_LIST = new ArrayList<>();
|
||||
static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
||||
static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(https?://)?[-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)");
|
||||
|
||||
private static MiniMessage miniMessage = null;
|
||||
|
||||
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||
public static HashMap<String, String> colors;
|
||||
private static LegacyComponentSerializer legacySerializer;
|
||||
|
||||
static { // this might be in minimessage already?
|
||||
colors = new HashMap<>();
|
||||
colors.put("&0", "<black>");
|
||||
@@ -50,6 +48,7 @@ public class Utility {
|
||||
}
|
||||
|
||||
public static HashMap<String, Pair<TagResolver, List<String>>> formattingPerms = new HashMap<>();
|
||||
|
||||
static {
|
||||
formattingPerms.put("chat.format.color",
|
||||
new Pair<>(StandardTags.color(), colors.values().stream().toList()));
|
||||
@@ -82,7 +81,9 @@ public class Utility {
|
||||
}
|
||||
|
||||
public static String parseColors(String message) {
|
||||
if (message == null) return "";
|
||||
if (message == null) {
|
||||
return "";
|
||||
}
|
||||
// split string in sections and check those vs looping hashmap?:/
|
||||
// think this is better, but will check numbers on this
|
||||
for (String key : colors.keySet()) {
|
||||
@@ -93,15 +94,17 @@ public class Utility {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static Component getPrefix(UUID uuid, boolean single) {
|
||||
public static ComponentLike getPrefix(UUID uuid, boolean single) {
|
||||
StringBuilder prefix = new StringBuilder();
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
List<String> prefixGroups = Config.PREFIXGROUPS;
|
||||
if(user == null) return Component.empty();
|
||||
if (user == null) {
|
||||
return Component.empty();
|
||||
}
|
||||
if (!single) {
|
||||
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
||||
if(inheritedGroups.stream().map(Group::getName).collect(Collectors.toList()).contains("eventleader")) {
|
||||
if (inheritedGroups.stream().anyMatch(group -> group.getName().equals("eventleader"))) {
|
||||
prefixGroups.remove("eventteam"); // hardcoded for now, new prefix system would load this from config
|
||||
}
|
||||
inheritedGroups.stream()
|
||||
@@ -113,20 +116,22 @@ public class Utility {
|
||||
});
|
||||
}
|
||||
prefix.append(getUserPrefix(user));
|
||||
// prefix.append(user.getCachedData().getMetaData().getPrefix());
|
||||
|
||||
return applyColor(prefix.toString());
|
||||
}
|
||||
|
||||
public static Component getStaffPrefix(UUID uuid) {
|
||||
public static ComponentLike getStaffPrefix(UUID uuid) {
|
||||
StringBuilder prefix = new StringBuilder();
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return Component.empty();
|
||||
if (user == null) {
|
||||
return Component.empty();
|
||||
}
|
||||
if (user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
||||
Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
|
||||
if(group != null)
|
||||
if (group != null) {
|
||||
prefix.append(getGroupPrefix(group));
|
||||
}
|
||||
// prefix.append(group.getCachedData().getMetaData().getPrefix());
|
||||
}
|
||||
return applyColor(prefix.toString());
|
||||
@@ -138,26 +143,32 @@ public class Utility {
|
||||
if (group == null) {
|
||||
return "";
|
||||
}
|
||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", user.getCachedData().getMetaData().getPrefix());
|
||||
}
|
||||
|
||||
public static String getGroupPrefix(String groupName) {
|
||||
Group group = ChatAPI.get().getLuckPerms().getGroupManager().getGroup(groupName);
|
||||
if (group == null) {
|
||||
String prefix = user.getCachedData().getMetaData().getPrefix();
|
||||
if (prefix == null) {
|
||||
ALogger.warn("User " + user.getUsername() + " has no prefix set!");
|
||||
return "";
|
||||
}
|
||||
return getGroupPrefix(group);
|
||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", prefix);
|
||||
}
|
||||
|
||||
public static String getGroupPrefix(Group group) {
|
||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", group.getCachedData().getMetaData().getPrefix());
|
||||
String prefix = group.getCachedData().getMetaData().getPrefix();
|
||||
if (prefix == null) {
|
||||
ALogger.warn("Group " + group.getName() + " has no prefix set!");
|
||||
return "";
|
||||
}
|
||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", prefix);
|
||||
}
|
||||
|
||||
public static String getDisplayName(UUID uuid, String playerName) {
|
||||
if (!playerName.isBlank()) return playerName;
|
||||
if (!playerName.isBlank()) {
|
||||
return playerName;
|
||||
}
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return "";
|
||||
if (user == null) {
|
||||
return "";
|
||||
}
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@@ -172,13 +183,15 @@ public class Utility {
|
||||
public static boolean hasPermission(UUID uuid, String permission) {
|
||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||
User user = luckPerms.getUserManager().getUser(uuid);
|
||||
if(user == null) return false;
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
}
|
||||
|
||||
public static Component applyColor(String message) {
|
||||
public static ComponentLike applyColor(String message) {
|
||||
String hexColor1 = "";
|
||||
String hexColor2 = "";
|
||||
String hexColor2;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
message = parseColors(message);
|
||||
boolean startsWithColor = false;
|
||||
@@ -245,7 +258,7 @@ public class Utility {
|
||||
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
|
||||
}
|
||||
}
|
||||
return stringBuilder.length() == 0 ? Utility.parseMiniMessage(message)
|
||||
return stringBuilder.isEmpty() ? Utility.parseMiniMessage(message)
|
||||
: Utility.parseMiniMessage(stringBuilder.toString());
|
||||
}
|
||||
|
||||
@@ -291,32 +304,29 @@ public class Utility {
|
||||
}
|
||||
|
||||
public static String formatText(String message) {
|
||||
/*
|
||||
.match(pattern)
|
||||
.replacement(url -> {
|
||||
String clickUrl = url.content();
|
||||
if (!URL_SCHEME_PATTERN.matcher(clickUrl).find()) {
|
||||
clickUrl = "http://" + clickUrl;
|
||||
}
|
||||
return (style == null ? url : url.style(style)).clickEvent(ClickEvent.openUrl(clickUrl));
|
||||
})
|
||||
.build();
|
||||
*/
|
||||
Matcher matcher = DEFAULT_URL_PATTERN.matcher(message);
|
||||
while (matcher.find()) {
|
||||
String url = matcher.group();
|
||||
String clickUrl = url;
|
||||
String urlFormat = Config.URLFORMAT;
|
||||
message = message.replace(url, urlFormat.replaceAll("<url>", url).replaceAll("<clickurl>", clickUrl));
|
||||
message = message.replace(url, urlFormat
|
||||
.replaceAll("<url>", "<u>" + url + "</u>")
|
||||
.replaceAll("<clickurl>", formatUrl(url)));
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static Component parseMiniMessage(String message) {
|
||||
private static String formatUrl(String url) {
|
||||
if (url.startsWith("http://") || url.startsWith("https://")) {
|
||||
return url;
|
||||
}
|
||||
return "https://" + url;
|
||||
}
|
||||
|
||||
public static ComponentLike parseMiniMessage(String message) {
|
||||
return getMiniMessage().deserialize(message);
|
||||
}
|
||||
|
||||
public static Component parseMiniMessage(String message, TagResolver placeholders) {
|
||||
public static ComponentLike parseMiniMessage(String message, TagResolver placeholders) {
|
||||
if (placeholders == null) {
|
||||
return getMiniMessage().deserialize(message);
|
||||
} else {
|
||||
@@ -324,7 +334,7 @@ public class Utility {
|
||||
}
|
||||
}
|
||||
|
||||
public static Component parseMiniMessage(String message, TagResolver ... placeholders) {
|
||||
public static ComponentLike parseMiniMessage(String message, TagResolver... placeholders) {
|
||||
if (placeholders == null) {
|
||||
return getMiniMessage().deserialize(message);
|
||||
} else {
|
||||
@@ -337,7 +347,9 @@ public class Utility {
|
||||
}
|
||||
|
||||
public static MiniMessage getMiniMessage() {
|
||||
if (miniMessage == null) miniMessage = MiniMessage.miniMessage();
|
||||
if (miniMessage == null) {
|
||||
miniMessage = MiniMessage.miniMessage();
|
||||
}
|
||||
return miniMessage;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
id("io.github.goooler.shadow") version "8.1.8"
|
||||
id("com.github.ben-manes.versions") version "0.52.0"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
@@ -5,11 +5,12 @@ plugins {
|
||||
|
||||
dependencies {
|
||||
implementation(project(":api")) // API
|
||||
// compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") // Galaxy
|
||||
compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT")
|
||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
||||
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
|
||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||
compileOnly("com.alttd.cosmos:cosmos-api:1.21.10-R0.1-SNAPSHOT") {
|
||||
isChanging = true
|
||||
}
|
||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.6.1") // move to proxy
|
||||
compileOnly("org.apache.commons:commons-lang3:3.17.0") // needs an alternative, already removed from upstream api and will be removed in server
|
||||
compileOnly("net.luckperms:api:5.5") // Luckperms
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
||||
@@ -12,14 +12,14 @@ import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ChatPlugin extends JavaPlugin {
|
||||
|
||||
@@ -28,7 +28,6 @@ public class ChatPlugin extends JavaPlugin {
|
||||
private ChatAPI chatAPI;
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
private String messageChannel;
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
@Override
|
||||
@@ -38,7 +37,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||
chatAPI = new ChatImplementation();
|
||||
chatHandler = new ChatHandler();
|
||||
DatabaseConnection.initialize();
|
||||
serverConfig = new ServerConfig(Bukkit.getServer().getName());
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
||||
if (serverConfig.GLOBALCHAT) {
|
||||
@@ -53,15 +52,16 @@ public class ChatPlugin extends JavaPlugin {
|
||||
registerCommand("muteserver", new MuteServer());
|
||||
registerCommand("spy", new Spy());
|
||||
registerCommand("chatclear", new ChatClear());
|
||||
// registerCommand("chatparty", new ChatParty());
|
||||
registerCommand("p", new PartyChat());
|
||||
registerCommand("emotes", new Emotes());
|
||||
for (Channel channel : Channel.getChannels()) {
|
||||
if (!(channel instanceof CustomChannel customChannel)) continue;
|
||||
if (!(channel instanceof CustomChannel customChannel)) {
|
||||
continue;
|
||||
}
|
||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(customChannel));
|
||||
}
|
||||
|
||||
messageChannel = Config.MESSAGECHANNEL;
|
||||
String messageChannel = Config.MESSAGECHANNEL;
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, messageChannel);
|
||||
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
||||
|
||||
@@ -83,23 +83,13 @@ public class ChatPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void registerCommand(String commandName, CommandExecutor commandExecutor) {
|
||||
getCommand(commandName).setExecutor(commandExecutor);
|
||||
}
|
||||
|
||||
public void registerCommand(String commandName, CommandExecutor commandExecutor, List<String> aliases) {
|
||||
PluginCommand command = getCommand(commandName);
|
||||
command.setAliases(aliases);
|
||||
command.setExecutor(commandExecutor);
|
||||
Objects.requireNonNull(getCommand(commandName)).setExecutor(commandExecutor);
|
||||
}
|
||||
|
||||
public static ChatPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ChatAPI getChatAPI() {
|
||||
return chatAPI;
|
||||
}
|
||||
|
||||
public ChatHandler getChatHandler() {
|
||||
return chatHandler;
|
||||
}
|
||||
@@ -116,11 +106,11 @@ public class ChatPlugin extends JavaPlugin {
|
||||
serverConfig.MUTED = !serverConfig.MUTED;
|
||||
}
|
||||
|
||||
public void ReloadConfig() {
|
||||
chatAPI.ReloadConfig();
|
||||
chatAPI.ReloadChatFilters();
|
||||
serverConfig = new ServerConfig(Bukkit.getServer().getName());
|
||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
|
||||
public void reloadConfig() {
|
||||
chatAPI.reloadConfig();
|
||||
chatAPI.reloadChatFilters();
|
||||
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config.").asComponent(), "command.chat.reloadchat");
|
||||
ALogger.info("Reloaded ChatPlugin config.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,15 @@ import org.bukkit.command.defaults.BukkitCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChatChannel extends BukkitCommand {
|
||||
|
||||
CustomChannel channel;
|
||||
String command;
|
||||
ToggleableForCustomChannel toggleableForCustomChannel;
|
||||
private static List<ChatChannel> activeCommands = new ArrayList<>();
|
||||
private static final List<ChatChannel> activeCommands = new ArrayList<>();
|
||||
|
||||
public ChatChannel(CustomChannel channel) {
|
||||
super(channel.getChannelName().toLowerCase());
|
||||
@@ -26,7 +27,7 @@ public class ChatChannel extends BukkitCommand {
|
||||
this.command = channel.getChannelName().toLowerCase();
|
||||
this.description = "Chat channel named " + channel.getChannelName() + ".";
|
||||
this.usageMessage = "/" + command + " <message>";
|
||||
this.setAliases(Collections.emptyList());
|
||||
this.setAliases(channel.getAliases());
|
||||
activeCommands.add(this);
|
||||
this.toggleableForCustomChannel = new ToggleableForCustomChannel(channel);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
@@ -9,21 +8,24 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChatClear implements CommandExecutor {
|
||||
|
||||
private static final Component component = MiniMessage.miniMessage().deserialize("\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n\n \n");
|
||||
private static final Component component = MiniMessage.miniMessage().deserialize("\n".repeat(100));
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!sender.hasPermission("chat.command.clear-chat")) {
|
||||
sender.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this command.</red>"));
|
||||
sender.sendRichMessage("<red>You don't have permission to use this command.</red>");
|
||||
return true;
|
||||
}
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
if (!player.hasPermission("chat.clear-bypass"))
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.hasPermission("chat.clear-bypass")) {
|
||||
player.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
Bukkit.getServer().sendMessage(miniMessage.deserialize(
|
||||
"<gold><player> cleared chat.</gold>",
|
||||
|
||||
@@ -8,17 +8,22 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Continue implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user.getReplyContinueTarget() == null) return false;
|
||||
if(args.length == 0) return false; // todo error message or command info
|
||||
if (user.getReplyContinueTarget() == null) {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().continuePrivateMessage(player, user.getReplyContinueTarget(), message);
|
||||
|
||||
@@ -7,15 +7,18 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class GlobalChat implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length == 0) return false;
|
||||
if (args.length == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
|
||||
|
||||
@@ -5,19 +5,17 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ignore implements CommandExecutor {
|
||||
@@ -29,11 +27,13 @@ public class Ignore implements CommandExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
if (args.length > 1) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
String targetName = args[0];
|
||||
if (targetName.equals("?")) {
|
||||
new BukkitRunnable() {
|
||||
@@ -44,7 +44,7 @@ public class Ignore implements CommandExecutor {
|
||||
StringBuilder ignoredMessage = new StringBuilder();
|
||||
|
||||
if (userNames.isEmpty()) {
|
||||
player.sendMessage(Utility.parseMiniMessage("You don't have anyone ignored!")); //TODO load from config
|
||||
player.sendRichMessage("You don't have anyone ignored!"); //TODO load from config
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public class Ignore implements CommandExecutor {
|
||||
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
|
||||
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
|
||||
|
||||
player.sendMessage(Utility.parseMiniMessage(ignoredMessage.toString()));
|
||||
player.sendRichMessage(ignoredMessage.toString());
|
||||
}
|
||||
}.runTaskAsynchronously(plugin);
|
||||
return false;
|
||||
@@ -76,7 +76,7 @@ public class Ignore implements CommandExecutor {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (!chatUser.getIgnoredPlayers().contains(target)) {
|
||||
chatUser.addIgnoredPlayers(target);
|
||||
Queries.ignoreUser(((Player) sender).getUniqueId(), target);
|
||||
Queries.ignoreUser(player.getUniqueId(), target);
|
||||
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
||||
sendPluginMessage("ignore", player, target);
|
||||
} else {
|
||||
|
||||
@@ -8,15 +8,18 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Message implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
if(args.length < 2) return false; // todo error message or command info
|
||||
if (args.length < 2) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setReplyContinueTarget(args[0]);
|
||||
|
||||
@@ -3,21 +3,21 @@ package com.alttd.chat.commands;
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MuteServer implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
@@ -26,13 +26,13 @@ public class MuteServer implements CommandExecutor {
|
||||
public void run() {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this command.</red>"));
|
||||
sender.sendRichMessage("<red>You don't have permission to use this command.</red>");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatPlugin.getInstance().toggleServerMuted();
|
||||
|
||||
Component component;
|
||||
ComponentLike component;
|
||||
if (ChatPlugin.getInstance().serverMuted()) {
|
||||
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
||||
} else {
|
||||
|
||||
@@ -8,18 +8,22 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Reply implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user.getReplyTarget() == null) return false;
|
||||
if(args.length == 0) return false; // todo error message or command info
|
||||
if (user.getReplyTarget() == null) {
|
||||
return false;
|
||||
}
|
||||
if (args.length == 0) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
|
||||
String message = StringUtils.join(args, " ", 0, args.length);
|
||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, user.getReplyTarget(), message);
|
||||
|
||||
@@ -1,30 +1,29 @@
|
||||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Spy implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) {
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
UUID uuid = player.getUniqueId();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
user.toggleSpy();
|
||||
sender.sendMessage(Utility.parseMiniMessage("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
|
||||
@@ -2,38 +2,31 @@ package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import jdk.jshell.execution.Util;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ToggleGlobalChat implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(!(sender instanceof Player)) { // must be a player
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return true;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
UUID uuid = ((Player) sender).getUniqueId();
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
//chatUser.toggleGc();
|
||||
ChatUserManager.getChatUser(uuid);
|
||||
Utility.flipPermission(uuid, Config.GCPERMISSION);
|
||||
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
||||
sender.sendMessage(Utility.parseMiniMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
||||
sender.sendRichMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
return false;
|
||||
|
||||
@@ -3,21 +3,17 @@ package com.alttd.chat.commands;
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.listeners.PluginMessage;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -30,17 +26,15 @@ public class Unignore implements CommandExecutor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
if (!(sender instanceof Player player)) { // must be a player
|
||||
return true;
|
||||
}
|
||||
if(args.length > 1) return false; // todo error message or command info
|
||||
if (args.length > 1) {
|
||||
return false; // todo error message or command info
|
||||
}
|
||||
String targetName = args[0];
|
||||
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
||||
if(target == null) {
|
||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||
return false;
|
||||
}
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -8,11 +8,14 @@ import com.alttd.chat.objects.ChatFilter;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -20,11 +23,15 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -32,7 +39,7 @@ public class ChatHandler {
|
||||
|
||||
private final ChatPlugin plugin;
|
||||
|
||||
private final Component GCNOTENABLED;
|
||||
private final ComponentLike GCNOTENABLED;
|
||||
|
||||
public ChatHandler() {
|
||||
plugin = ChatPlugin.getInstance();
|
||||
@@ -49,9 +56,9 @@ public class ChatHandler {
|
||||
Placeholder.parsed("receivername", target)
|
||||
);
|
||||
|
||||
Component component = Utility.parseMiniMessage("<message>", placeholders);
|
||||
ComponentLike component = Utility.parseMiniMessage("<message>", placeholders);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
ModifiableString modifiableString = new ModifiableString(component.asComponent());
|
||||
// todo a better way for this
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||
GalaxyUtility.sendBlockedNotification("DM Language",
|
||||
@@ -63,8 +70,8 @@ public class ChatHandler {
|
||||
|
||||
component = modifiableString.component();
|
||||
|
||||
sendPrivateMessage(player, target, "privatemessage", component);
|
||||
Component spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
sendPrivateMessage(player, target, "privatemessage", component.asComponent());
|
||||
ComponentLike spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
pl.sendMessage(spymessage);
|
||||
@@ -99,7 +106,7 @@ public class ChatHandler {
|
||||
// .replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand())).build());
|
||||
|
||||
sendPrivateMessage(player, target, "privatemessage", messageComponent);
|
||||
Component spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
ComponentLike spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||
pl.sendMessage(spymessage);
|
||||
@@ -120,21 +127,20 @@ public class ChatHandler {
|
||||
|
||||
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
|
||||
if (timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.GCONCOOLDOWN, Placeholder.parsed("cooldown", Config.GCCOOLDOWN-timeLeft+"")));
|
||||
player.sendRichMessage(Config.GCONCOOLDOWN, Placeholder.parsed("cooldown", Config.GCCOOLDOWN - timeLeft + ""));
|
||||
return;
|
||||
}
|
||||
|
||||
Component senderName = user.getDisplayName();
|
||||
Component prefix = user.getPrefix();
|
||||
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
ComponentLike prefix = user.getPrefix();
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", Bukkit.getServer().getName())
|
||||
Placeholder.parsed("server", ServerName.getServerName())
|
||||
);
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
|
||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders).asComponent();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
// todo a better way for this
|
||||
@@ -153,22 +159,25 @@ public class ChatHandler {
|
||||
|
||||
public void chatChannel(Player player, CustomChannel channel, String message) {
|
||||
if (!player.hasPermission(channel.getPermission())) {
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>You don't have permission to use this channel.</red>"));
|
||||
player.sendRichMessage("<red>You don't have permission to use this channel.</red>");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) return;
|
||||
if (isMuted(player, message, "[" + channel.getChannelName() + " Muted] ")) {
|
||||
ALogger.info("Refusing to send message by muted user");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
Component senderName = user.getDisplayName();
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.component("message", parseMessageContent(player, message)),
|
||||
Placeholder.parsed("server", Bukkit.getServer().getName()),
|
||||
Placeholder.parsed("server", ServerName.getServerName()),
|
||||
Placeholder.parsed("channel", channel.getChannelName())
|
||||
);
|
||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
|
||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders).asComponent();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(component);
|
||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
|
||||
@@ -176,15 +185,16 @@ public class ChatHandler {
|
||||
player,
|
||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||
"");
|
||||
return; // the message was blocked
|
||||
ALogger.info("Refusing to send blocked chat message");
|
||||
return;
|
||||
}
|
||||
|
||||
component = modifiableString.component();
|
||||
|
||||
if (channel.isProxy()) {
|
||||
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component);
|
||||
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component, message);
|
||||
} else {
|
||||
sendChatChannelMessage(channel, player.getUniqueId(), component);
|
||||
sendChatChannelMessage(channel, player.getUniqueId(), component, message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +208,6 @@ public class ChatHandler {
|
||||
));
|
||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||
|
||||
|
||||
// if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||
//
|
||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
@@ -237,22 +246,51 @@ public class ChatHandler {
|
||||
// }
|
||||
}
|
||||
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
|
||||
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
|
||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, ComponentLike component, String message) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
ALogger.warn("Failed to send chat message from non existent player");
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
if (player == null) {
|
||||
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||
player.sendRichMessage("<red>Unable to send messages to <channel> in this server.</red>",
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()));
|
||||
ALogger.info(String.format("Not sending chat message due to [%s] not being in this channels config",
|
||||
ServerName.getServerName()));
|
||||
return;
|
||||
}
|
||||
|
||||
Stream<? extends Player> stream = Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.filter(p -> p.hasPermission(chatChannel.getPermission()));
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid) && !p.hasPermission("chat.ignorebypass"));
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
stream.forEach(p -> p.sendMessage(component));
|
||||
if (chatChannel.isLocal()) {
|
||||
Location location = player.getLocation();
|
||||
stream = stream.filter(receiver -> {
|
||||
Player receiverPlayer = Bukkit.getPlayer(receiver.getUniqueId());
|
||||
if (receiverPlayer == null) {
|
||||
return false;
|
||||
}
|
||||
if (!location.getWorld().getUID().equals(receiverPlayer.getLocation().getWorld().getUID())) {
|
||||
return false;
|
||||
}
|
||||
return !(receiverPlayer.getLocation().distance(location) > Config.LOCAL_DISTANCE);
|
||||
});
|
||||
}
|
||||
List<? extends Player> recipientPlayers = stream.toList();
|
||||
recipientPlayers.forEach(p -> p.sendMessage(component));
|
||||
|
||||
List<UUID> recipientUUIDs = recipientPlayers.stream().map(Entity::getUniqueId).toList();
|
||||
Bukkit.getServer().getOnlinePlayers().stream()
|
||||
.filter(onlinePlayer -> onlinePlayer.hasPermission(Config.SPYPERMISSION))
|
||||
.filter(onlinePlayer -> !recipientUUIDs.contains(onlinePlayer.getUniqueId()))
|
||||
.forEach(onlinePlayer -> onlinePlayer.sendRichMessage(Config.CHANNEL_SPY,
|
||||
Placeholder.component("sender", player.name()),
|
||||
Placeholder.parsed("channel", chatChannel.getChannelName()),
|
||||
Placeholder.parsed("message", message)));
|
||||
}
|
||||
|
||||
private void sendPluginMessage(Player player, String channel, Component component) {
|
||||
@@ -272,7 +310,7 @@ public class ChatHandler {
|
||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||
}
|
||||
|
||||
public void sendChatChannelMessage(Player player, String chatChannelName, String channel, Component component) {
|
||||
public void sendChatChannelMessage(Player player, String chatChannelName, String channel, Component component, String ignored) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF(channel);
|
||||
out.writeUTF(chatChannelName);
|
||||
@@ -285,7 +323,9 @@ public class ChatHandler {
|
||||
|
||||
private boolean isMuted(Player player, String message, String prefix) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
if (user == null) return false;
|
||||
if (user == null) {
|
||||
return false;
|
||||
}
|
||||
if (user.isMuted() || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
// if (Database.get().isPlayerMuted(player.getUniqueId(), null) || (ChatPlugin.getInstance().serverMuted() && !player.hasPermission("chat.bypass-server-muted"))) {
|
||||
GalaxyUtility.sendBlockedNotification(prefix, player, Utility.parseMiniMessage(Utility.stripTokens(message)), "");
|
||||
@@ -296,11 +336,12 @@ public class ChatHandler {
|
||||
|
||||
public static Component itemComponent(ItemStack item) {
|
||||
Component component = Component.text("[i]", NamedTextColor.AQUA);
|
||||
if(item.getType().equals(Material.AIR))
|
||||
if (item.getType().equals(Material.AIR)) {
|
||||
return component.color(NamedTextColor.WHITE);
|
||||
}
|
||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||
if (dname) {
|
||||
component = component.append(item.getItemMeta().displayName());
|
||||
component = component.append(Objects.requireNonNull(item.getItemMeta().displayName()));
|
||||
} else {
|
||||
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
|
||||
}
|
||||
@@ -322,10 +363,12 @@ public class ChatHandler {
|
||||
int loc = sb.lastIndexOf(split);
|
||||
char charLoc = sb.charAt(loc);
|
||||
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
||||
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on")))
|
||||
split.equalsIgnoreCase("with") || split.equalsIgnoreCase("on"))) {
|
||||
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||
if (pos != splits.length - 1)
|
||||
}
|
||||
if (pos != splits.length - 1) {
|
||||
sb.append(' ');
|
||||
}
|
||||
++pos;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.alttd.chat.objects.*;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.GalaxyUtility;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -16,6 +17,7 @@ import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -46,28 +48,32 @@ public class ChatListener implements Listener {
|
||||
this.chatLogHandler = chatLogHandler;
|
||||
}
|
||||
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onChatCommandDecorate(AsyncChatCommandDecorateEvent event) {
|
||||
if (event.player() == null) return;
|
||||
if (event.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
Component message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||
public void onChatDecorate(AsyncChatDecorateEvent event) {
|
||||
if (event.player() == null) return;
|
||||
if (event.player() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Component formatComponent = Component.text("%message%");
|
||||
Component message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
ComponentLike message = parseMessageContent(event.player(), plainTextComponentSerializer.serialize(event.originalMessage()));
|
||||
|
||||
event.result(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||
}
|
||||
|
||||
private final Component mention = MiniMessage.miniMessage().deserialize(Config.MENTIONPLAYERTAG);
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerChat(AsyncChatEvent event) {
|
||||
event.setCancelled(true); //Always cancel the event because we do not want to deal with Microsoft's stupid bans
|
||||
@@ -85,9 +91,9 @@ public class ChatListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
|
||||
Component input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(input);
|
||||
ModifiableString modifiableString = new ModifiableString(input.asComponent());
|
||||
|
||||
// todo a better way for this
|
||||
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||
@@ -106,7 +112,7 @@ public class ChatListener implements Listener {
|
||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||
modifiableString.component(),
|
||||
"");
|
||||
chatLogHandler.addChatLog(uuid, player.getServer().getName(), PlainTextComponentSerializer.plainText().serialize(input), true);
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input.asComponent()), true);
|
||||
return; // the message was blocked
|
||||
}
|
||||
|
||||
@@ -115,7 +121,7 @@ public class ChatListener implements Listener {
|
||||
|
||||
if (!player.hasPermission("chat.ignorebypass")) {
|
||||
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||
&& !receiver.hasPermission("chat.ignorebypass"));
|
||||
|| receiver.hasPermission("chat.ignorebypass"));
|
||||
}
|
||||
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||
|
||||
@@ -129,8 +135,8 @@ public class ChatListener implements Listener {
|
||||
for (Player pingPlayer : playersToPing) {
|
||||
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||
}
|
||||
chatLogHandler.addChatLog(uuid, player.getServer().getName(), modifiableString.string(), false);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input));
|
||||
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
||||
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input.asComponent()));
|
||||
}
|
||||
|
||||
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
||||
@@ -158,9 +164,11 @@ public class ChatListener implements Listener {
|
||||
// String substring = a.group().substring(1);
|
||||
// return ;
|
||||
// });
|
||||
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||
modifiableString.replace(TextReplacementConfig.builder()
|
||||
.once()
|
||||
@@ -168,13 +176,14 @@ public class ChatListener implements Listener {
|
||||
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||
.build());
|
||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||
&& !player.hasPermission("chat.ignorebypass"))
|
||||
|| player.hasPermission("chat.ignorebypass")) {
|
||||
playersToPing.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public @NotNull Component render(@NotNull Player player, @NotNull Component message) {
|
||||
public @NotNull ComponentLike render(@NotNull Player player, @NotNull Component message) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", user.getDisplayName()),
|
||||
@@ -188,7 +197,7 @@ public class ChatListener implements Listener {
|
||||
return Utility.parseMiniMessage(Config.CHATFORMAT, placeholders);
|
||||
}
|
||||
|
||||
private Component parseMessageContent(Player player, String rawMessage) {
|
||||
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
||||
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||
|
||||
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||
@@ -198,7 +207,7 @@ public class ChatListener implements Listener {
|
||||
});
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||
Component component = miniMessage.deserialize(rawMessage);
|
||||
Component component = miniMessage.deserialize(Utility.formatText(rawMessage));
|
||||
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||
component = component.replaceText(
|
||||
TextReplacementConfig.builder()
|
||||
|
||||
@@ -5,16 +5,18 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.objects.PartyUser;
|
||||
import com.alttd.chat.objects.channels.Channel;
|
||||
import com.alttd.chat.objects.channels.CustomChannel;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.ServerName;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
@@ -35,7 +37,7 @@ public class PluginMessage implements PluginMessageListener {
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
String subChannel = in.readUTF();
|
||||
switch (subChannel) {
|
||||
case "privatemessagein": {
|
||||
case "privatemessagein" -> {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String target = in.readUTF();
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
@@ -47,13 +49,15 @@ public class PluginMessage implements PluginMessageListener {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (isTargetNotIgnored(chatUser, targetuuid)) {
|
||||
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1,
|
||||
1); // todo load this from config
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
if (!user.getReplyContinueTarget().equalsIgnoreCase(target))
|
||||
if (!user.getReplyContinueTarget().equalsIgnoreCase(target)) {
|
||||
user.setReplyTarget(target);
|
||||
}
|
||||
}
|
||||
case "privatemessageout": {
|
||||
}
|
||||
case "privatemessageout" -> {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String target = in.readUTF();
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
@@ -69,10 +73,11 @@ public class PluginMessage implements PluginMessageListener {
|
||||
// ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
// user.setReplyTarget(target);
|
||||
}
|
||||
}
|
||||
case "globalchat" -> {
|
||||
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) {
|
||||
break;
|
||||
}
|
||||
case "globalchat": {
|
||||
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) break;
|
||||
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
String message = in.readUTF();
|
||||
@@ -83,29 +88,27 @@ public class PluginMessage implements PluginMessageListener {
|
||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "ignore": {
|
||||
case "ignore" -> {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
||||
UUID targetUUID = UUID.fromString(in.readUTF());
|
||||
|
||||
if (!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
||||
chatUser.addIgnoredPlayers(targetUUID);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "unignore": {
|
||||
case "unignore" -> {
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
||||
chatUser.removeIgnoredPlayers(UUID.fromString(in.readUTF()));
|
||||
}
|
||||
case "chatchannel" -> {
|
||||
if (ChatPlugin.getInstance().serverMuted()) {
|
||||
break;
|
||||
}
|
||||
case "chatchannel": {
|
||||
if (ChatPlugin.getInstance().serverMuted()) break;
|
||||
|
||||
chatChannel(in);
|
||||
break;
|
||||
}
|
||||
case "tmppartyupdate" : {
|
||||
case "tmppartyupdate" -> {
|
||||
int id = Integer.parseInt(in.readUTF());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
@@ -113,9 +116,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||
Queries.loadPartyUsers(id);
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
break;
|
||||
}
|
||||
case "partylogin": {
|
||||
case "partylogin" -> {
|
||||
int id = Integer.parseInt(in.readUTF());
|
||||
Party party = PartyManager.getParty(id);
|
||||
if (party == null) {
|
||||
@@ -128,18 +130,19 @@ public class PluginMessage implements PluginMessageListener {
|
||||
public void run() {
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if (user != null) {
|
||||
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
|
||||
ComponentLike component = Utility.parseMiniMessage(
|
||||
"<dark_aqua>* " + user.getPlayerName() + " logged in to Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers()
|
||||
.contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
break;
|
||||
}
|
||||
case "partylogout": {
|
||||
case "partylogout" -> {
|
||||
int id = Integer.parseInt(in.readUTF());
|
||||
Party party = PartyManager.getParty(id);
|
||||
if (party == null) {
|
||||
@@ -152,29 +155,30 @@ public class PluginMessage implements PluginMessageListener {
|
||||
public void run() {
|
||||
PartyUser user = party.getPartyUser(uuid);
|
||||
if (user != null) {
|
||||
Component component = Utility.parseMiniMessage("<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
|
||||
ComponentLike component = Utility.parseMiniMessage(
|
||||
"<dark_aqua>* " + user.getPlayerName() + " logged out of Altitude.");
|
||||
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers()
|
||||
.contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
break;
|
||||
}
|
||||
case "reloadconfig":
|
||||
ChatPlugin.getInstance().ReloadConfig();
|
||||
break;
|
||||
case "chatpunishments":
|
||||
case "reloadconfig" -> ChatPlugin.getInstance().reloadConfig();
|
||||
case "chatpunishments" -> {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
boolean mute = in.readBoolean();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
if (user == null) return;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
user.setMuted(mute);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
default -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,15 +190,15 @@ public class PluginMessage implements PluginMessageListener {
|
||||
chatChannel = (CustomChannel) Channel.getChatChannel(in.readUTF());
|
||||
uuid = UUID.fromString(in.readUTF());
|
||||
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
||||
} catch (Exception e) { //Idk the exception for reading too far into in.readUTF()
|
||||
e.printStackTrace();
|
||||
} catch (Exception e) {
|
||||
ALogger.error("Failed to read ChatChannel message.", e);
|
||||
}
|
||||
|
||||
if (chatChannel == null) {
|
||||
ALogger.warn("Received ChatChannel message for non existent channel.");
|
||||
return;
|
||||
}
|
||||
if (!chatChannel.getServers().contains(Bukkit.getServer().getName())) {
|
||||
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||
ALogger.warn("Received ChatChannel message for the wrong server.");
|
||||
return;
|
||||
}
|
||||
@@ -211,7 +215,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||
public void run() {
|
||||
Bukkit.getOnlinePlayers().stream()
|
||||
.filter(p -> p.hasPermission(finalChatChannel.getPermission()))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(finalUuid))
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers()
|
||||
.contains(finalUuid))
|
||||
.forEach(p -> p.sendMessage(finalComponent));
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
|
||||
@@ -4,100 +4,21 @@ import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NickUtilities
|
||||
{
|
||||
public class NickUtilities {
|
||||
public static String stringRegen;
|
||||
|
||||
public static String applyColor(String message) {
|
||||
ChatColor hexColor1 = null;
|
||||
ChatColor hexColor2;
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
message = ChatColor.translateAlternateColorCodes('&', message);
|
||||
boolean startsWithColor = false;
|
||||
boolean lastColorMatters = false;
|
||||
|
||||
if (message.matches(".*" + NickUtilities.stringRegen + ".*")) {
|
||||
String[] split = message.split(NickUtilities.stringRegen);
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
int nextIndex = 0;
|
||||
if (message.indexOf("}") <= 11) {
|
||||
startsWithColor = true;
|
||||
list.add(message.substring(0, message.indexOf("}") + 1));
|
||||
}
|
||||
for (String s : split) {
|
||||
nextIndex += s.length();
|
||||
int tmp = message.indexOf("}", nextIndex);
|
||||
if (tmp < message.length() && tmp>=0) {
|
||||
list.add(message.substring(nextIndex, tmp + 1));
|
||||
nextIndex = tmp + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int i;
|
||||
boolean firstLoop = true;
|
||||
if (startsWithColor) {
|
||||
i = -1;
|
||||
} else {
|
||||
i = 0;
|
||||
stringBuilder.append(split[i]);
|
||||
}
|
||||
|
||||
for (String s : list) {
|
||||
boolean lesser = s.contains("<");
|
||||
boolean bigger = s.contains(">");
|
||||
|
||||
if (bigger && lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 3));
|
||||
} else if (bigger || lesser) {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() - 2));
|
||||
} else {
|
||||
hexColor2 = ChatColor.of(s.substring(1, s.length() -1));
|
||||
}
|
||||
|
||||
if (firstLoop) {
|
||||
lastColorMatters = bigger;
|
||||
hexColor1 = hexColor2;
|
||||
firstLoop = false;
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lesser && lastColorMatters) {
|
||||
stringBuilder.append(hexGradient(hexColor1.getColor(), hexColor2.getColor(), split[i]));
|
||||
} else {
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
|
||||
hexColor1 = hexColor2;
|
||||
lastColorMatters = bigger;
|
||||
i++;
|
||||
}
|
||||
if (split.length > i){
|
||||
stringBuilder.append(hexColor1).append(split[i]);
|
||||
}
|
||||
}
|
||||
return stringBuilder.length()==0 ? message : stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static String removeAllColors(String string) {
|
||||
|
||||
for (final String colorCodes : Config.NICK_ALLOWED_COLOR_CODESLIST) {
|
||||
@@ -111,29 +32,6 @@ public class NickUtilities
|
||||
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||
}
|
||||
|
||||
public static String hexGradient(Color color1, Color color2, String text){
|
||||
double r = color1.getRed();
|
||||
double g = color1.getGreen();
|
||||
double b = color1.getBlue();
|
||||
|
||||
double rDifference = (color1.getRed() - color2.getRed()) / ((double) text.length() - 1);
|
||||
double gDifference = (color1.getGreen() - color2.getGreen()) / ((double) text.length() - 1);
|
||||
double bDifference = (color1.getBlue() - color2.getBlue()) / ((double) text.length() - 1);
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
char[] chars = text.toCharArray();
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (i > 0) {
|
||||
r = r - rDifference;
|
||||
g = g - gDifference;
|
||||
b = b - bDifference;
|
||||
}
|
||||
stringBuilder.append(ChatColor.of(new Color((int) r, (int) g, (int) b))).append(chars[i]);
|
||||
}
|
||||
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
public static void updateCache() {
|
||||
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()) {
|
||||
Nicknames.getInstance().nickCacheUpdate.forEach(uuid -> {
|
||||
@@ -213,7 +111,7 @@ public class NickUtilities
|
||||
try {
|
||||
msgout.writeUTF(uniqueId.toString());
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
ALogger.error("Failed to write UUID to byte array", exception);
|
||||
return;
|
||||
}
|
||||
byte[] bytes = msgbytes.toByteArray();
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.alttd.chat.events.NickEvent;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
@@ -21,7 +22,6 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||
return true;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
@@ -60,10 +60,10 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
if (offlinePlayer.isOnline() || offlinePlayer.hasPlayedBefore()) {
|
||||
handleNick(player, offlinePlayer, args[2]);
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.SET_OTHERS)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.SET_OTHERS));
|
||||
}
|
||||
} else if (args.length > 3) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS));
|
||||
}
|
||||
break;
|
||||
case "review":
|
||||
@@ -72,7 +72,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
ChatPlugin.getInstance().getServer().getPluginManager().registerEvents(nicknamesGui, ChatPlugin.getInstance());
|
||||
nicknamesGui.openInventory(player);
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.REVIEW)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.REVIEW));
|
||||
}
|
||||
break;
|
||||
case "request":
|
||||
@@ -84,7 +84,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.REQUEST)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.REQUEST));
|
||||
}
|
||||
break;
|
||||
case "try":
|
||||
@@ -92,16 +92,17 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
LuckPerms api = ChatAPI.get().getLuckPerms();
|
||||
if (api != null) {
|
||||
if (NickUtilities.validNick(player, player, args[1])) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_TRYOUT,
|
||||
sender.sendRichMessage(Config.NICK_TRYOUT,
|
||||
Placeholder.component("prefix", Utility.applyColor(api.getUserManager().getUser(player.getUniqueId())
|
||||
.getCachedData().getMetaData().getPrefix())), // TODO pull this from chatuser?
|
||||
Placeholder.component("nick", Utility.applyColor(args[1]))));
|
||||
Placeholder.component("nick", Utility.applyColor(args[1])),
|
||||
Placeholder.unparsed("nickrequest", args[1]));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_NO_LUCKPERMS));
|
||||
sender.sendRichMessage(Config.NICK_NO_LUCKPERMS);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.TRY)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.TRY));
|
||||
}
|
||||
break;
|
||||
case "current":
|
||||
@@ -115,11 +116,11 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
break;
|
||||
case "help":
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)
|
||||
+ "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>"));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL)
|
||||
+ "For more info on nicknames and how to use rgb colors go to: <aqua>https://alttd.com/nicknames<white>");
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(Utility.parseMiniMessage(helpMessage(sender, HelpType.ALL)));
|
||||
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Console commands are disabled.");
|
||||
@@ -130,7 +131,9 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
|
||||
List<String> completions = new ArrayList<>();
|
||||
if (!sender.hasPermission("chat.command.nick")) return completions;
|
||||
if (!sender.hasPermission("chat.command.nick")) {
|
||||
return completions;
|
||||
}
|
||||
|
||||
if (args.length == 1) {
|
||||
List<String> choices = new ArrayList<>();
|
||||
@@ -190,15 +193,15 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
long waitTime = Config.NICK_WAIT_TIME;
|
||||
if (timeSinceLastChange > waitTime || player.hasPermission("chat.command.nick.bypasswaittime")) {
|
||||
if (nick.hasRequest()) {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_REQUEST_PLACED,
|
||||
player.sendRichMessage(Config.NICK_REQUEST_PLACED,
|
||||
Placeholder.component("oldrequestednick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("newrequestednick", Utility.applyColor(nickName))));
|
||||
Placeholder.component("newrequestednick", Utility.applyColor(nickName)));
|
||||
}
|
||||
nick.setNewNick(nickName);
|
||||
nick.setRequestedDate(new Date().getTime());
|
||||
} else {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_TOO_SOON,
|
||||
Placeholder.unparsed("time", formatTime((timeSinceLastChange-waitTime)*-1))));
|
||||
player.sendRichMessage(Config.NICK_TOO_SOON,
|
||||
Placeholder.unparsed("time", formatTime((timeSinceLastChange - waitTime) * -1)));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -206,8 +209,8 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
Queries.newNicknameRequest(uniqueId, nickName);
|
||||
bungeeMessageRequest(player);
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NICK_REQUESTED,
|
||||
Placeholder.component("nick", Utility.applyColor(nickName))));
|
||||
player.sendRichMessage(Config.NICK_REQUESTED,
|
||||
Placeholder.component("nick", Utility.applyColor(nickName)));
|
||||
}
|
||||
|
||||
private void bungeeMessageRequest(Player player) {
|
||||
@@ -224,7 +227,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
try {
|
||||
msgout.writeUTF(uniqueId.toString());
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
ALogger.error("Failed to write UUID to ByteArrayOutputStream", exception);
|
||||
return;
|
||||
}
|
||||
byte[] bytes = msgbytes.toByteArray();
|
||||
@@ -261,22 +264,22 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
|
||||
try {
|
||||
if (target.isOnline()) {
|
||||
resetNick(target.getPlayer());
|
||||
resetNick(Objects.requireNonNull(target.getPlayer()));
|
||||
}
|
||||
Queries.removePlayerFromDataBase(target.getUniqueId());
|
||||
NickCache.remove(target.getUniqueId());
|
||||
nickCacheUpdate.add(target.getUniqueId());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error("Failed to remove nickname from database", e);
|
||||
}
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_RESET_OTHERS,
|
||||
Placeholder.unparsed("player", target.getName())));
|
||||
sender.sendRichMessage(Config.NICK_RESET_OTHERS,
|
||||
Placeholder.unparsed("player", Objects.requireNonNull(target.getName())));
|
||||
}
|
||||
|
||||
if (target.isOnline() && target.getPlayer() != null) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_RESET));
|
||||
target.getPlayer().sendRichMessage(Config.NICK_RESET);
|
||||
}
|
||||
|
||||
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), null, NickEvent.NickEventType.RESET);
|
||||
@@ -304,17 +307,19 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_CHANGED_OTHERS,
|
||||
Placeholder.unparsed("targetplayer", target.getName()),
|
||||
Placeholder.unparsed("targetplayer", Objects.requireNonNull(target.getName())),
|
||||
Placeholder.unparsed("nickname", nickName)));
|
||||
if (target.isOnline()) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_TARGET_NICK_CHANGE,
|
||||
Objects.requireNonNull(target.getPlayer())
|
||||
.sendRichMessage(Config.NICK_TARGET_NICK_CHANGE,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())),
|
||||
Placeholder.unparsed("sendernick", getNick(sender)),
|
||||
Placeholder.unparsed("player", target.getName())));
|
||||
Placeholder.unparsed("player", target.getName()));
|
||||
}
|
||||
} else if (target.isOnline()) {
|
||||
target.getPlayer().sendMessage(Utility.parseMiniMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer()))));
|
||||
Objects.requireNonNull(target.getPlayer())
|
||||
.sendRichMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", getNick(target.getPlayer())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,8 +357,10 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
break;
|
||||
case REQUEST:
|
||||
if (sender.hasPermission("chat.command.nick.request")) {
|
||||
message.append("<gold>/nick request <nickname><white> - Requests a username to be reviewed by staff.\n" +
|
||||
" <gray>Try using <dark_gray>/nick try <nickname><gray> to see if you like the name, you can only change it once per day!\n");
|
||||
message.append("""
|
||||
<gold>/nick request <nickname><white> - Requests a username to be reviewed by staff.
|
||||
<gray>Try using <dark_gray>/nick try <nickname><gray> to see if you like the name, you can only change it once per day!
|
||||
""");
|
||||
}
|
||||
break;
|
||||
case REVIEW:
|
||||
@@ -380,7 +387,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
public void resetNick(final Player player) {
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setDisplayName(player.getName());
|
||||
player.displayName(user.getDisplayName());
|
||||
player.displayName(user.getDisplayName().asComponent());
|
||||
// updateCMIUser(player, null);
|
||||
}
|
||||
|
||||
@@ -390,42 +397,13 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||
}
|
||||
|
||||
public void setNick(final Player player, final String nickName) {
|
||||
if (player == null)
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
user.setDisplayName(nickName);
|
||||
player.displayName(user.getDisplayName());
|
||||
// updateCMIUser(player, nickName);
|
||||
}
|
||||
|
||||
// public static String format(final String m) {
|
||||
// return NickUtilities.applyColor(m);
|
||||
// }
|
||||
|
||||
// public void updateCMIUser(Player player, String nickName) {
|
||||
// if (!isCMIEnabled())
|
||||
// return;
|
||||
//
|
||||
// CMIUser cmiUser = CMI.getInstance().getPlayerManager().getUser(player);
|
||||
// if (nickName == null){
|
||||
// cmiUser.setNickName(null, true);
|
||||
// } else {
|
||||
// cmiUser.setNickName(NickUtilities.applyColor(nickName), true);
|
||||
// }
|
||||
// cmiUser.updateDisplayName();
|
||||
// }
|
||||
|
||||
private Boolean isCMIEnabled = null;
|
||||
private Boolean isCMIEnabled() {
|
||||
if (!(isCMIEnabled == null))
|
||||
return isCMIEnabled;
|
||||
|
||||
Plugin plugin = Bukkit.getPluginManager().getPlugin("CMI");
|
||||
if (plugin != null && plugin.isEnabled())
|
||||
return isCMIEnabled = true;
|
||||
|
||||
return isCMIEnabled = false;
|
||||
player.displayName(user.getDisplayName().asComponent());
|
||||
}
|
||||
|
||||
public static Nicknames getInstance() {
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.Queries;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.event.HoverEvent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -29,7 +31,6 @@ import java.util.UUID;
|
||||
|
||||
public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||
|
||||
@@ -75,8 +76,8 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
player.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_REQUESTS_ON_LOGIN,
|
||||
Placeholder.unparsed("amount", String.valueOf(i))));
|
||||
player.sendRichMessage(Config.NICK_REQUESTS_ON_LOGIN,
|
||||
Placeholder.unparsed("amount", String.valueOf(i)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,14 +111,14 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
name = offlinePlayer.getName() == null ? playerUUID.toString() : offlinePlayer.getName();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ALogger.error("Failed to read plugin message", e);
|
||||
return;
|
||||
}
|
||||
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
switch (subChannel) {
|
||||
case "NickNameRequest":
|
||||
Component component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
|
||||
ComponentLike component = miniMessage.deserialize(Config.NICK_REQUEST_NEW, Placeholder.parsed("player", name))
|
||||
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.RUN_COMMAND,
|
||||
"/nick review"))
|
||||
.hoverEvent(HoverEvent.hoverEvent(HoverEvent.Action.SHOW_TEXT,
|
||||
@@ -138,7 +139,8 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
}
|
||||
break;
|
||||
case "NickNameAccepted":
|
||||
Component deserialize = miniMessage.deserialize("<green><name>'s nickname was accepted!",
|
||||
|
||||
ComponentLike deserialize = Utility.parseMiniMessage("<green><name>'s nickname was accepted!",
|
||||
Placeholder.unparsed("name", name));
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("chat.command.nick.review")) {
|
||||
@@ -153,8 +155,8 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
Player target = Bukkit.getPlayer(playerUUID);
|
||||
if (target != null && nick != null && nick.getCurrentNick() != null) {
|
||||
Nicknames.getInstance().setNick(target, nick.getCurrentNick());
|
||||
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
||||
target.sendRichMessage(Config.NICK_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -181,9 +183,11 @@ public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||
if (offlinePlayer.isOnline()) {
|
||||
Player target = Bukkit.getPlayer(playerUUID);
|
||||
|
||||
if (target == null) break;
|
||||
target.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick())));
|
||||
if (target == null) {
|
||||
break;
|
||||
}
|
||||
target.sendRichMessage(Config.NICK_NOT_CHANGED,
|
||||
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.alttd.chat.events.NickEvent;
|
||||
import com.alttd.chat.objects.Nick;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
@@ -40,7 +41,7 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
public NicknamesGui() {
|
||||
// Create a new inventory, with no owner (as this isn't a real inventory)
|
||||
inv = Bukkit.createInventory(null, 36, Utility.parseMiniMessage("Nicknames GUI"));
|
||||
inv = Bukkit.createInventory(null, 36, Utility.parseMiniMessage("Nicknames GUI").asComponent());
|
||||
|
||||
// Put the items into the inventory
|
||||
currentPage = 1;
|
||||
@@ -92,10 +93,11 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
meta.setOwningPlayer(offlinePlayer);
|
||||
String name = offlinePlayer.getName();
|
||||
if (name == null)
|
||||
if (name == null) {
|
||||
meta.displayName(miniMessage.deserialize("UNKNOWN PLAYER NAME"));
|
||||
else
|
||||
} else {
|
||||
meta.displayName(miniMessage.deserialize(offlinePlayer.getName()));
|
||||
}
|
||||
|
||||
TagResolver resolver = TagResolver.resolver(
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
@@ -132,30 +134,42 @@ public class NicknamesGui implements Listener {
|
||||
// Check for clicks on items
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
if (e.getInventory() != inv) return;
|
||||
if (e.getInventory() != inv) {
|
||||
return;
|
||||
}
|
||||
|
||||
e.setCancelled(true);
|
||||
|
||||
final ItemStack clickedItem = e.getCurrentItem();
|
||||
|
||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) return;
|
||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player p = (Player) e.getWhoClicked();
|
||||
|
||||
if (clickedItem.getType().equals(Material.PAPER)) {
|
||||
String serialize = PlainTextComponentSerializer.plainText().serialize(clickedItem.getItemMeta().displayName());
|
||||
Component component = clickedItem.getItemMeta().displayName();
|
||||
if (component == null) {
|
||||
throw new IllegalStateException("Nicknames GUI: Item with no display name clicked!");
|
||||
}
|
||||
String serialize = PlainTextComponentSerializer.plainText().serialize(component);
|
||||
if (serialize.equals("Next Page")) {
|
||||
setItems(currentPage + 1);
|
||||
}
|
||||
} else if (clickedItem.getType().equals(Material.PLAYER_HEAD)) {
|
||||
SkullMeta meta = (SkullMeta) clickedItem.getItemMeta();
|
||||
ItemMeta itemMeta = clickedItem.getItemMeta();
|
||||
if (itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
SkullMeta meta = (SkullMeta) itemMeta;
|
||||
if (meta.hasEnchants()) {
|
||||
return;
|
||||
}
|
||||
OfflinePlayer owningPlayer = meta.getOwningPlayer();
|
||||
|
||||
if (owningPlayer == null) {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_USER_NOT_FOUND));
|
||||
p.sendRichMessage(Config.NICK_USER_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -171,10 +185,15 @@ public class NicknamesGui implements Listener {
|
||||
} else {
|
||||
nick = Queries.getNick(uniqueId);
|
||||
}
|
||||
Component itemDisplayName = itemMeta.displayName();
|
||||
if (itemDisplayName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (nick == null || !nick.hasRequest()) {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_ALREADY_HANDLED,
|
||||
Placeholder.component("targetplayer", clickedItem.getItemMeta().displayName())));
|
||||
p.sendRichMessage(Config.NICK_ALREADY_HANDLED,
|
||||
Placeholder.component("targetplayer", itemDisplayName))
|
||||
;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -187,20 +206,18 @@ public class NicknamesGui implements Listener {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), clickedItem.getItemMeta().getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||
nickEvent.callEvent();
|
||||
}
|
||||
}.runTask(ChatPlugin.getInstance());
|
||||
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_ACCEPTED,
|
||||
Placeholder.component("targetplayer", clickedItem.getItemMeta().displayName()),
|
||||
p.sendRichMessage(Config.NICK_ACCEPTED,
|
||||
Placeholder.component("targetplayer", itemDisplayName),
|
||||
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? clickedItem.getItemMeta().getDisplayName() : nick.getCurrentNick()))));
|
||||
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? itemMeta.getDisplayName() : nick.getCurrentNick())));
|
||||
|
||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getNewNick());
|
||||
// owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_CHANGED // This message is also send when the plugin message is received
|
||||
// .replace("%nickname%", nick.getNewNick())));
|
||||
}
|
||||
|
||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Accepted");
|
||||
@@ -214,18 +231,16 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(clickedItem.getItemMeta().displayName());
|
||||
itemMeta.displayName(itemMeta.displayName());
|
||||
itemMeta.lore(clickedItem.lore());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE,
|
||||
Placeholder.component("playerName", clickedItem.getItemMeta().displayName())));
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
||||
}
|
||||
|
||||
} else if (e.isRightClick()) {
|
||||
Component displayName = clickedItem.getItemMeta().displayName();
|
||||
if (owningPlayer.hasPlayedBefore()) {
|
||||
Queries.denyNewNickname(uniqueId);
|
||||
|
||||
@@ -234,7 +249,7 @@ public class NicknamesGui implements Listener {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), clickedItem.getItemMeta().getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
||||
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
||||
nickEvent.callEvent();
|
||||
}
|
||||
}.runTask(ChatPlugin.getInstance());
|
||||
@@ -255,11 +270,11 @@ public class NicknamesGui implements Listener {
|
||||
|
||||
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
||||
owningPlayer.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_NOT_CHANGED));
|
||||
owningPlayer.getPlayer().sendRichMessage(Config.NICK_NOT_CHANGED);
|
||||
}
|
||||
|
||||
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Denied");
|
||||
final Component messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
||||
final ComponentLike messageDenied = MiniMessage.miniMessage().deserialize("<red><name>'s nickname was denied!",
|
||||
Placeholder.unparsed("name", owningPlayer.getName()));
|
||||
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||
if (p.hasPermission("chat.command.nick.review")) {
|
||||
@@ -267,19 +282,19 @@ public class NicknamesGui implements Listener {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
itemMeta.displayName(displayName);
|
||||
itemMeta.displayName(itemDisplayName);
|
||||
itemMeta.lore(clickedItem.lore());
|
||||
itemStack.setItemMeta(itemMeta);
|
||||
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||
p.updateInventory();
|
||||
} else {
|
||||
if (displayName == null)
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.parsed("playerName", "UNKNOWN PLAYER NAME")));
|
||||
else
|
||||
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("playerName", displayName)));
|
||||
if (itemDisplayName == null) {
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.parsed("player", "UNKNOWN PLAYER NAME"));
|
||||
} else {
|
||||
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,9 @@ package com.alttd.chat.util;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.RegexManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -16,40 +13,22 @@ import java.util.List;
|
||||
|
||||
public class GalaxyUtility {
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("prefix", prefix),
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
|
||||
Placeholder.parsed("target", (target.isEmpty() ? "tried to say:" : "-> " + target + ":")),
|
||||
Placeholder.parsed("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
|
||||
public static void sendBlockedNotification(String prefix, Player player, ComponentLike input, String target) {
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("prefix", prefix),
|
||||
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getName())),
|
||||
Placeholder.parsed("target", (target.isEmpty() ? "tried to say:" : "-> " + target + ":")),
|
||||
Placeholder.component("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(a -> {
|
||||
if (a.hasPermission("chat.alert-blocked")) {
|
||||
a.sendMessage(blockedNotification);
|
||||
}
|
||||
});
|
||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
player.sendRichMessage("<red>The language you used in your message is not allowed, " +
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>");
|
||||
}
|
||||
|
||||
public static void addAdditionalChatCompletions(Player player) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.alttd.chat.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class ServerName {
|
||||
|
||||
private static final String serverName = loadServerName();
|
||||
|
||||
private static String loadServerName() {
|
||||
String serverName = "unknown";
|
||||
try {
|
||||
File serverPropertiesFile = new File(Bukkit.getWorldContainer().getParentFile(), "server.properties");
|
||||
if (!serverPropertiesFile.exists()) {
|
||||
ALogger.warn(String.format("server.properties file not found in %s!", serverPropertiesFile.getAbsolutePath()));
|
||||
return serverName;
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
FileInputStream fis = new FileInputStream(serverPropertiesFile);
|
||||
properties.load(fis);
|
||||
fis.close();
|
||||
|
||||
serverName = properties.getProperty("server-name", serverName);
|
||||
|
||||
ALogger.info(String.format("Found server name [%s]", serverName));
|
||||
} catch (IOException e) {
|
||||
ALogger.error("Failed to read server.properties", e);
|
||||
}
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public static String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":api"))
|
||||
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||
|
||||
api("com.fasterxml.jackson.core:jackson-databind:2.17.2")
|
||||
api("com.fasterxml.jackson.core:jackson-core:2.17.2")
|
||||
api("com.fasterxml.jackson.core:jackson-annotations:2.17.2")
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(21)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.alttd.matrix;
|
||||
|
||||
public record MatrixConfig(
|
||||
String homeserver, // e.g. "http://127.0.0.1:8008"
|
||||
String asToken, // from as registration yaml
|
||||
String hsToken, // from as registration yaml
|
||||
String domain, // "matrix.alttd.com"
|
||||
String userPrefix, // "mc_"
|
||||
String bindHost, // "127.0.0.1"
|
||||
int bindPort // 9000
|
||||
) {
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.alttd.matrix;
|
||||
|
||||
import com.alttd.matrix.app_service.MatrixAppServiceHttpServer;
|
||||
import com.alttd.matrix.client.HttpMatrixClient;
|
||||
import com.alttd.matrix.interfaces.MatrixAppServiceServer;
|
||||
import com.alttd.matrix.interfaces.MatrixClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public final class MatrixRuntime {
|
||||
|
||||
private MatrixRuntime() {
|
||||
}
|
||||
|
||||
public static MatrixAppServiceServer startAppService(MatrixConfig cfg) throws IOException {
|
||||
var server = new MatrixAppServiceHttpServer(
|
||||
new InetSocketAddress(cfg.bindHost(), cfg.bindPort()),
|
||||
cfg.hsToken()
|
||||
);
|
||||
server.start();
|
||||
return server;
|
||||
}
|
||||
|
||||
public static MatrixClient createClient(MatrixConfig cfg) {
|
||||
return new HttpMatrixClient(cfg.homeserver(), cfg.asToken());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package com.alttd.matrix.app_service;
|
||||
|
||||
import com.alttd.matrix.interfaces.MatrixAppServiceServer;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.sun.net.httpserver.HttpExchange;
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class MatrixAppServiceHttpServer implements MatrixAppServiceServer {
|
||||
|
||||
private final HttpServer server;
|
||||
private final String hsToken;
|
||||
private final ObjectMapper om = new ObjectMapper();
|
||||
|
||||
private volatile Consumer<TransactionEvent> txListener;
|
||||
|
||||
public MatrixAppServiceHttpServer(InetSocketAddress bind, String hsToken) throws IOException {
|
||||
this.server = HttpServer.create(bind, 0);
|
||||
this.hsToken = hsToken;
|
||||
|
||||
server.createContext("/_matrix/app/v1/transactions", this::handleTransactions);
|
||||
server.createContext("/_matrix/app/v1/users", this::handleUsers);
|
||||
|
||||
server.setExecutor(Executors.newCachedThreadPool(r -> {
|
||||
Thread t = new Thread(r, "matrix-as-http");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
}));
|
||||
}
|
||||
|
||||
public void start() {
|
||||
server.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTransactionListener(Consumer<TransactionEvent> listener) {
|
||||
this.txListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
server.stop(0);
|
||||
}
|
||||
|
||||
private void handleUsers(HttpExchange ex) throws IOException {
|
||||
if (!"GET".equals(ex.getRequestMethod())) {
|
||||
send(ex, 405, "{}");
|
||||
return;
|
||||
}
|
||||
if (!validHsToken(ex)) {
|
||||
send(ex, 401, "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Synapse asks "does this user exist?" -> for AS, answer 200 so Synapse will proceed.
|
||||
// You can optionally restrict to your namespace by inspecting the path.
|
||||
send(ex, 200, "{}");
|
||||
}
|
||||
|
||||
private void handleTransactions(HttpExchange ex) throws IOException {
|
||||
if (!"PUT".equals(ex.getRequestMethod())) {
|
||||
send(ex, 405, "{}");
|
||||
return;
|
||||
}
|
||||
if (!validHsToken(ex)) {
|
||||
send(ex, 401, "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
JsonNode root;
|
||||
try (InputStream in = ex.getRequestBody()) {
|
||||
root = om.readTree(in);
|
||||
} catch (Exception e) {
|
||||
send(ex, 400, "{}");
|
||||
return;
|
||||
}
|
||||
|
||||
Consumer<TransactionEvent> listener = txListener;
|
||||
if (listener != null) {
|
||||
JsonNode events = root.path("events");
|
||||
if (events.isArray()) {
|
||||
for (Iterator<JsonNode> it = events.elements(); it.hasNext(); ) {
|
||||
JsonNode ev = it.next();
|
||||
|
||||
// only handle m.room.message text
|
||||
if (!"m.room.message".equals(ev.path("type").asText())) {
|
||||
continue;
|
||||
}
|
||||
if (!"m.text".equals(ev.path("content").path("msgtype").asText())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String roomId = ev.path("room_id").asText(null);
|
||||
String sender = ev.path("sender").asText(null);
|
||||
String eventId = ev.path("event_id").asText(null);
|
||||
String body = ev.path("content").path("body").asText(null);
|
||||
|
||||
if (roomId != null && body != null) {
|
||||
listener.accept(new TransactionEvent(roomId, sender, body, eventId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
send(ex, 200, "{}");
|
||||
}
|
||||
|
||||
private boolean validHsToken(HttpExchange ex) {
|
||||
String q = ex.getRequestURI().getRawQuery();
|
||||
if (q == null) {
|
||||
return false;
|
||||
}
|
||||
Map<String, String> params = parseQuery(q);
|
||||
String token = params.get("access_token");
|
||||
return token != null && token.equals(hsToken);
|
||||
}
|
||||
|
||||
private static Map<String, String> parseQuery(String raw) {
|
||||
var map = new java.util.HashMap<String, String>();
|
||||
for (String part : raw.split("&")) {
|
||||
int i = part.indexOf('=');
|
||||
if (i <= 0) {
|
||||
continue;
|
||||
}
|
||||
String k = urlDecode(part.substring(0, i));
|
||||
String v = urlDecode(part.substring(i + 1));
|
||||
map.put(k, v);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static String urlDecode(String s) {
|
||||
return URLDecoder.decode(s, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static void send(HttpExchange ex, int code, String body) throws IOException {
|
||||
byte[] b = body.getBytes(StandardCharsets.UTF_8);
|
||||
ex.getResponseHeaders().set("Content-Type", "application/json");
|
||||
ex.sendResponseHeaders(code, b.length);
|
||||
ex.getResponseBody().write(b);
|
||||
ex.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.alttd.matrix.bridge;
|
||||
|
||||
import com.alttd.matrix.MatrixConfig;
|
||||
import com.alttd.matrix.interfaces.MatrixAppServiceServer;
|
||||
import com.alttd.matrix.interfaces.MatrixBridge;
|
||||
import com.alttd.matrix.interfaces.MatrixClient;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public final class DefaultMatrixBridge implements MatrixBridge {
|
||||
|
||||
private final MatrixClient client;
|
||||
private final MatrixConfig cfg;
|
||||
private final Executor io = Executors.newSingleThreadExecutor(r -> {
|
||||
Thread t = new Thread(r, "matrix-io");
|
||||
t.setDaemon(true);
|
||||
return t;
|
||||
});
|
||||
|
||||
private volatile InboundHandler inbound;
|
||||
private volatile RoomResolver rooms;
|
||||
|
||||
public DefaultMatrixBridge(MatrixConfig cfg, MatrixAppServiceServer asServer, MatrixClient client) {
|
||||
this.cfg = cfg;
|
||||
this.client = client;
|
||||
|
||||
asServer.setTransactionListener(evt -> {
|
||||
InboundHandler h = inbound;
|
||||
RoomResolver rr = rooms;
|
||||
if (h == null || rr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// drop our own puppets to prevent loops
|
||||
if (evt.senderMxid() != null && evt.senderMxid().startsWith("@" + cfg.userPrefix())) {
|
||||
return;
|
||||
}
|
||||
|
||||
h.onMatrixChat(evt.roomId(), evt.senderMxid(), evt.body());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInboundHandler(InboundHandler handler) {
|
||||
this.inbound = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRoomResolver(RoomResolver resolver) {
|
||||
this.rooms = resolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChat(UUID playerUuid, String mcUsername, String serverName, String message) {
|
||||
RoomResolver rr = rooms;
|
||||
if (rr == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String roomId = rr.roomIdForServer(serverName);
|
||||
if (roomId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String mxid = "@" + cfg.userPrefix() + playerUuid + ":" + cfg.domain();
|
||||
|
||||
io.execute(() -> {
|
||||
client.ensureUser(mxid);
|
||||
client.setDisplayName(mxid, mcUsername);
|
||||
client.ensureJoined(mxid, roomId);
|
||||
client.sendText(mxid, roomId, message);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.alttd.matrix.client;
|
||||
|
||||
import com.alttd.matrix.interfaces.MatrixClient;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class HttpMatrixClient implements MatrixClient {
|
||||
|
||||
private final HttpClient http = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build();
|
||||
|
||||
private final ObjectMapper om = new ObjectMapper();
|
||||
|
||||
private final String hs; // e.g. http://127.0.0.1:8008
|
||||
private final String asToken; // AS access token
|
||||
|
||||
public HttpMatrixClient(String homeserver, String asToken) {
|
||||
this.hs = homeserver.endsWith("/") ? homeserver.substring(0, homeserver.length() - 1) : homeserver;
|
||||
this.asToken = asToken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureUser(String mxid) {
|
||||
String localpart = localpart(mxid);
|
||||
|
||||
String url = hs + "/_matrix/client/v3/register"
|
||||
+ "?access_token=" + enc(asToken);
|
||||
|
||||
String body = "{\"type\":\"m.login.application_service\",\"username\":\"" + json(localpart) + "\"}";
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
sendIgnoreConflict(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDisplayName(String mxid, String displayName) {
|
||||
String url = hs + "/_matrix/client/v3/profile/" + encPath(mxid) + "/displayname"
|
||||
+ "?access_token=" + enc(asToken)
|
||||
+ "&user_id=" + enc(mxid);
|
||||
|
||||
String body = "{\"displayname\":\"" + json(displayName) + "\"}";
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.header("Content-Type", "application/json")
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
sendOkOrIgnore(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ensureJoined(String mxid, String roomId) {
|
||||
String url = hs + "/_matrix/client/v3/rooms/" + encPath(roomId) + "/join"
|
||||
+ "?access_token=" + enc(asToken)
|
||||
+ "&user_id=" + enc(mxid);
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.header("Content-Type", "application/json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString("{}"))
|
||||
.build();
|
||||
|
||||
sendOkOrIgnore(req);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendText(String mxid, String roomId, String bodyText) {
|
||||
String txnId = UUID.randomUUID().toString();
|
||||
|
||||
String url = hs + "/_matrix/client/v3/rooms/" + encPath(roomId) + "/send/m.room.message/" + encPath(txnId)
|
||||
+ "?access_token=" + enc(asToken)
|
||||
+ "&user_id=" + enc(mxid);
|
||||
|
||||
String body = "{\"msgtype\":\"m.text\",\"body\":\"" + json(bodyText) + "\"}";
|
||||
|
||||
HttpRequest req = HttpRequest.newBuilder(URI.create(url))
|
||||
.timeout(Duration.ofSeconds(10))
|
||||
.header("Content-Type", "application/json")
|
||||
.PUT(HttpRequest.BodyPublishers.ofString(body))
|
||||
.build();
|
||||
|
||||
sendOkOrIgnore(req);
|
||||
}
|
||||
|
||||
private void sendIgnoreConflict(HttpRequest req) {
|
||||
try {
|
||||
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||
int c = res.statusCode();
|
||||
if (c == 200) {
|
||||
return;
|
||||
}
|
||||
if (c == 400 && res.body() != null && res.body().contains("M_USER_IN_USE")) {
|
||||
return;
|
||||
}
|
||||
if (c == 401 || c == 403) {
|
||||
throw new RuntimeException("Matrix auth failed: " + c + " " + res.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendOkOrIgnore(HttpRequest req) {
|
||||
try {
|
||||
HttpResponse<String> res = http.send(req, HttpResponse.BodyHandlers.ofString());
|
||||
int c = res.statusCode();
|
||||
if (c >= 200 && c < 300) {
|
||||
return;
|
||||
}
|
||||
if (c == 401 || c == 403) {
|
||||
throw new RuntimeException("Matrix auth failed: " + c + " " + res.body());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String localpart(String mxid) {
|
||||
// "@localpart:domain"
|
||||
int at = mxid.indexOf('@');
|
||||
int colon = mxid.indexOf(':');
|
||||
if (at != 0 || colon < 0) {
|
||||
throw new IllegalArgumentException("bad mxid: " + mxid);
|
||||
}
|
||||
return mxid.substring(1, colon);
|
||||
}
|
||||
|
||||
private static String enc(String s) {
|
||||
return URLEncoder.encode(s, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String encPath(String s) {
|
||||
// safe enough for matrix path segments
|
||||
return URLEncoder.encode(s, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private static String json(String s) {
|
||||
return s.replace("\\", "\\\\").replace("\"", "\\\"").replace("\n", "\\n").replace("\r", "\\r");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.alttd.matrix.interfaces;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface MatrixAppServiceServer extends Closeable {
|
||||
void setTransactionListener(Consumer<TransactionEvent> listener);
|
||||
|
||||
record TransactionEvent(String roomId, String senderMxid, String body, String eventId) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.alttd.matrix.interfaces;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface MatrixBridge {
|
||||
void setInboundHandler(InboundHandler handler);
|
||||
|
||||
void setRoomResolver(RoomResolver resolver);
|
||||
|
||||
void sendChat(UUID playerUuid, String mcUsername, String serverName, String message);
|
||||
|
||||
interface InboundHandler {
|
||||
void onMatrixChat(String roomId, String senderMxid, String body);
|
||||
}
|
||||
|
||||
interface RoomResolver {
|
||||
String roomIdForServer(String serverName);
|
||||
|
||||
String serverForRoomId(String roomId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.alttd.matrix.interfaces;
|
||||
|
||||
public interface MatrixClient {
|
||||
void ensureUser(String mxid);
|
||||
|
||||
void setDisplayName(String mxid, String displayName);
|
||||
|
||||
void ensureJoined(String mxid, String roomId);
|
||||
|
||||
void sendText(String mxid, String roomId, String body);
|
||||
}
|
||||
+10
-10
@@ -3,22 +3,13 @@ rootProject.name = "Chat"
|
||||
include(":api")
|
||||
include(":galaxy")
|
||||
include(":velocity")
|
||||
include(":matrix")
|
||||
|
||||
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").get()
|
||||
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
// mavenLocal()
|
||||
mavenCentral()
|
||||
// maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
||||
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
||||
maven("https://nexus.velocitypowered.com/repository/") // Velocity
|
||||
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
||||
maven("https://repo.spongepowered.org/maven") // Configurate
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
||||
maven("https://jitpack.io")
|
||||
maven {
|
||||
name = "nexus"
|
||||
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||
@@ -27,6 +18,13 @@ dependencyResolutionManagement {
|
||||
password = nexusPass
|
||||
}
|
||||
}
|
||||
// mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
||||
maven("https://repo.spongepowered.org/maven") // Configurate
|
||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
||||
maven("https://jitpack.io")
|
||||
}
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
}
|
||||
@@ -36,3 +34,5 @@ pluginManagement {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
include("matrix")
|
||||
|
||||
@@ -7,9 +7,9 @@ dependencies {
|
||||
implementation(project(":api")) // API
|
||||
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||
implementation("mysql:mysql-connector-java:8.0.27") // mysql
|
||||
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.10.1")
|
||||
implementation("mysql:mysql-connector-java:8.0.33") // mysql
|
||||
implementation("org.spongepowered", "configurate-yaml", "4.2.0")
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.23.0")
|
||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5")
|
||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
@@ -2,29 +2,38 @@ package com.alttd.velocitychat;
|
||||
|
||||
import com.alttd.chat.ChatAPI;
|
||||
import com.alttd.chat.ChatImplementation;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.matrix.MatrixConfig;
|
||||
import com.alttd.matrix.MatrixRuntime;
|
||||
import com.alttd.matrix.bridge.DefaultMatrixBridge;
|
||||
import com.alttd.matrix.interfaces.MatrixAppServiceServer;
|
||||
import com.alttd.matrix.interfaces.MatrixBridge;
|
||||
import com.alttd.matrix.interfaces.MatrixClient;
|
||||
import com.alttd.velocitychat.commands.*;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.database.DatabaseConnection;
|
||||
import com.alttd.velocitychat.handlers.ChatHandler;
|
||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
||||
import com.alttd.velocitychat.listeners.ChatListener;
|
||||
import com.alttd.velocitychat.listeners.LiteBansListener;
|
||||
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||
import com.alttd.velocitychat.listeners.PluginMessageListener;
|
||||
import com.alttd.chat.util.ALogger;
|
||||
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||
import com.alttd.velocitychat.matrix.MatrixRoomMap;
|
||||
import com.alttd.velocitychat.matrix.VelocityMatrixInbound;
|
||||
import com.alttd.velocitychat.matrix.VelocityMatrixOutbound;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.EventManager;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
@@ -44,7 +53,9 @@ public class VelocityChat {
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataDirectory;
|
||||
private final EventManager eventManager;
|
||||
|
||||
private MatrixAppServiceServer matrixAsServer;
|
||||
private ChatAPI chatAPI;
|
||||
private ChatHandler chatHandler;
|
||||
private ServerHandler serverHandler;
|
||||
@@ -52,11 +63,12 @@ public class VelocityChat {
|
||||
private ChannelIdentifier channelIdentifier;
|
||||
|
||||
@Inject
|
||||
public VelocityChat(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
|
||||
public VelocityChat(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory, EventManager eventManager) {
|
||||
plugin = this;
|
||||
server = proxyServer;
|
||||
logger = proxyLogger;
|
||||
dataDirectory = proxydataDirectory;
|
||||
this.eventManager = eventManager;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -81,11 +93,12 @@ public class VelocityChat {
|
||||
ChatUser console = new ChatUser(Config.CONSOLEUUID, -1, null);
|
||||
console.setDisplayName(Config.CONSOLENAME);
|
||||
ChatUserManager.addUser(console);
|
||||
initMatrix();
|
||||
}
|
||||
|
||||
public void ReloadConfig() {
|
||||
chatAPI.ReloadConfig();
|
||||
chatAPI.ReloadChatFilters();
|
||||
public void reloadConfig() {
|
||||
chatAPI.reloadConfig();
|
||||
chatAPI.reloadChatFilters();
|
||||
serverHandler.cleanup();
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("reloadconfig");
|
||||
@@ -93,6 +106,42 @@ public class VelocityChat {
|
||||
getProxy().getAllServers().stream().forEach(registeredServer -> registeredServer.sendPluginMessage(getChannelIdentifier(), buf.toByteArray()));
|
||||
}
|
||||
|
||||
//TODO call initMatrix
|
||||
private void initMatrix() {
|
||||
MatrixConfig cfg = new MatrixConfig(
|
||||
Config.MATRIX_SERVER,
|
||||
Config.MATRIX_AS_TOKEN,
|
||||
Config.MATRIX_HS_TOKEN,
|
||||
"matrix.alttd.com",
|
||||
"mc_",
|
||||
"127.0.0.1",
|
||||
9000
|
||||
);
|
||||
|
||||
MatrixAppServiceServer asServer;
|
||||
try {
|
||||
asServer = MatrixRuntime.startAppService(cfg);
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to start Matrix AppService server", e);
|
||||
return;
|
||||
}
|
||||
|
||||
MatrixClient client = MatrixRuntime.createClient(cfg);
|
||||
|
||||
initMatrix(cfg, asServer, client);
|
||||
}
|
||||
|
||||
public void initMatrix(MatrixConfig matrixConfig, MatrixAppServiceServer asServer, MatrixClient client) {
|
||||
MatrixRoomMap roomMap = new MatrixRoomMap();
|
||||
roomMap.put("bayou", "!bayou:matrix.alttd.com");
|
||||
|
||||
MatrixBridge matrix = new DefaultMatrixBridge(matrixConfig, asServer, client);
|
||||
matrix.setRoomResolver(roomMap);
|
||||
matrix.setInboundHandler(new VelocityMatrixInbound(server, roomMap));
|
||||
|
||||
eventManager.register(this, new VelocityMatrixOutbound(matrix));
|
||||
}
|
||||
|
||||
public File getDataDirectory() {
|
||||
return dataDirectory.toFile();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -39,12 +39,13 @@ public class PartyCommand implements SimpleCommand {
|
||||
CommandSource source = invocation.source();
|
||||
|
||||
if (args.length < 1) {
|
||||
if (!source.hasPermission("party.use"))
|
||||
if (!source.hasPermission("party.use")) {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
else if (source instanceof Player)
|
||||
} else if (source instanceof Player) {
|
||||
source.sendMessage(getHelpMessage(source));
|
||||
else
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,10 +53,11 @@ public class PartyCommand implements SimpleCommand {
|
||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||
.findFirst()
|
||||
.ifPresentOrElse(subCommand -> {
|
||||
if (source.hasPermission(subCommand.getPermission()))
|
||||
if (source.hasPermission(subCommand.getPermission())) {
|
||||
subCommand.execute(args, source);
|
||||
else
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||
}
|
||||
}, () -> source.sendMessage(getHelpMessage(source)));
|
||||
}
|
||||
|
||||
@@ -64,9 +66,9 @@ public class PartyCommand implements SimpleCommand {
|
||||
String[] args = invocation.arguments();
|
||||
List<String> suggest = new ArrayList<>();
|
||||
|
||||
if (!invocation.source().hasPermission("party.use"))
|
||||
if (!invocation.source().hasPermission("party.use")) {
|
||||
return suggest;
|
||||
else if (args.length == 0) {
|
||||
} else if (args.length == 0) {
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
||||
@@ -83,11 +85,12 @@ public class PartyCommand implements SimpleCommand {
|
||||
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
if (args.length == 0) {
|
||||
return suggest;
|
||||
else
|
||||
} else {
|
||||
return finalizeSuggest(suggest, args[args.length - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> finalizeSuggest(List<String> possibleValues, String remaining) {
|
||||
List<String> finalValues = new ArrayList<>();
|
||||
@@ -101,16 +104,18 @@ public class PartyCommand implements SimpleCommand {
|
||||
return finalValues;
|
||||
}
|
||||
|
||||
public Component getHelpMessage(CommandSource source) {
|
||||
public ComponentLike getHelpMessage(CommandSource source) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
subCommands.stream()
|
||||
.filter(subCommand -> source.hasPermission(subCommand.getPermission()))
|
||||
.forEach(subCommand -> stringBuilder.append(subCommand.getHelpMessage()).append("\n"));
|
||||
if (source.hasPermission("command.chat.p"))
|
||||
if (source.hasPermission("command.chat.p")) {
|
||||
stringBuilder.append(Config.PARTY_HELP_CHAT).append("\n");
|
||||
if (stringBuilder.length() != 0)
|
||||
}
|
||||
if (!stringBuilder.isEmpty()) {
|
||||
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
|
||||
}
|
||||
|
||||
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER,
|
||||
Placeholder.component("commands", Utility.parseMiniMessage(stringBuilder.toString()))
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Reload {
|
||||
.<CommandSource>literal("reloadchat")
|
||||
.requires(ctx -> ctx.hasPermission("command.chat.reloadchat"))
|
||||
.executes(context -> {
|
||||
VelocityChat.getPlugin().ReloadConfig();
|
||||
VelocityChat.getPlugin().reloadConfig();
|
||||
return 1;
|
||||
})
|
||||
.build();
|
||||
|
||||
@@ -16,8 +16,8 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import jdk.jshell.execution.Util;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.time.Duration;
|
||||
@@ -30,7 +30,7 @@ import java.util.stream.IntStream;
|
||||
|
||||
public class VoteToMuteHelper {
|
||||
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
|
||||
public VoteToMuteHelper(ProxyServer proxyServer) {
|
||||
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||
@@ -51,8 +51,9 @@ public class VoteToMuteHelper {
|
||||
.map(Player::getUsername)
|
||||
.toList();
|
||||
|
||||
if (possibleValues.isEmpty())
|
||||
if (possibleValues.isEmpty()) {
|
||||
return Suggestions.empty();
|
||||
}
|
||||
|
||||
String remaining = builder.getRemaining().toLowerCase();
|
||||
possibleValues.stream()
|
||||
@@ -213,7 +214,8 @@ public class VoteToMuteHelper {
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<green>You voted <red>not</red> to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||
}
|
||||
default -> commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
default ->
|
||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
||||
}
|
||||
return 1;
|
||||
@@ -254,7 +256,7 @@ public class VoteToMuteHelper {
|
||||
}
|
||||
|
||||
private void notifyEligiblePlayers(RegisteredServer server, ActiveVoteToMute activeVoteToMute) {
|
||||
Component message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||
Placeholder.component("prefix", prefix),
|
||||
Placeholder.parsed("voted_for", String.valueOf(activeVoteToMute.getVotedFor())),
|
||||
Placeholder.parsed("total_votes", String.valueOf(activeVoteToMute.getTotalEligibleVoters())),
|
||||
|
||||
+3
-2
@@ -46,11 +46,12 @@ public class Disband implements SubCommand {
|
||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.DISBANDED_PARTY,
|
||||
Placeholder.unparsed("owner", player.getUsername()),
|
||||
Placeholder.unparsed("party", party.getPartyName())
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
party.delete();
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,11 @@ public class Info implements SubCommand {
|
||||
List<Component> displayNames = new ArrayList<>();
|
||||
for (PartyUser partyUser : party.getPartyUsers()) {
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(partyUser.getUuid());
|
||||
if (optionalPlayer.isPresent() && optionalPlayer.get().isActive())
|
||||
displayNames.add(Config.ONLINE_PREFIX.append(partyUser.getDisplayName()));
|
||||
else
|
||||
displayNames.add(Config.OFFLINE_PREFIX.append(partyUser.getDisplayName()));
|
||||
if (optionalPlayer.isPresent() && optionalPlayer.get().isActive()) {
|
||||
displayNames.add(Config.ONLINE_PREFIX.asComponent().append(partyUser.getDisplayName()));
|
||||
} else {
|
||||
displayNames.add(Config.OFFLINE_PREFIX.asComponent().append(partyUser.getDisplayName()));
|
||||
}
|
||||
}
|
||||
|
||||
PartyUser owner = party.getPartyUser(party.getOwnerUuid());
|
||||
|
||||
@@ -52,11 +52,12 @@ public class Join implements SubCommand {
|
||||
}
|
||||
party.addUser(chatUser, player.getUsername());
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.parsed("party_name", party.getPartyName())));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
|
||||
Placeholder.component("player_name", chatUser.getDisplayName()),
|
||||
Placeholder.parsed("party_name", party.getPartyName())
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -35,28 +35,31 @@ public class Leave implements SubCommand {
|
||||
return;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
party.removeUser(player.getUniqueId());
|
||||
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||
if (party.getPartyUsers().size() > 0) {
|
||||
if (!party.getPartyUsers().isEmpty()) {
|
||||
UUID uuid = party.setNewOwner();
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", party.getPartyUser(uuid).getPlayerName())
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
} else {
|
||||
party.delete();
|
||||
}
|
||||
} else {
|
||||
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PLAYER_LEFT_PARTY,
|
||||
Placeholder.unparsed("player_name", player.getUsername())
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,11 +52,12 @@ public class Name implements SubCommand {
|
||||
|
||||
String oldName = party.getPartyName();
|
||||
party.setPartyName(args[1]);
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
||||
Placeholder.component("owner", ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName()),
|
||||
Placeholder.unparsed("old_name", oldName),
|
||||
Placeholder.unparsed("new_name", args[1])
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,6 @@ import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Owner implements SubCommand {
|
||||
@Override
|
||||
@@ -49,26 +48,31 @@ public class Owner implements SubCommand {
|
||||
return;
|
||||
}
|
||||
party.setNewOwner(partyUser.getUuid());
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
VelocityChat.getPlugin().getChatHandler()
|
||||
.sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER,
|
||||
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||
Placeholder.unparsed("new_owner", partyUser.getPlayerName())
|
||||
), null);
|
||||
).asComponent(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(String[] args, CommandSource source) {
|
||||
ArrayList<String> suggest = new ArrayList<>();
|
||||
if (!(source instanceof Player player))
|
||||
if (!(source instanceof Player player)) {
|
||||
return suggest;
|
||||
}
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(uuid);
|
||||
if (party == null)
|
||||
if (party == null) {
|
||||
return suggest;
|
||||
if (args.length == 1 || args.length == 2)
|
||||
}
|
||||
if (args.length == 1 || args.length == 2) {
|
||||
suggest.addAll(party.getPartyUsers().stream()
|
||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||
.map(PartyUser::getPlayerName).collect(Collectors.toList()));
|
||||
.map(PartyUser::getPlayerName)
|
||||
.toList());
|
||||
}
|
||||
return suggest;
|
||||
}
|
||||
|
||||
|
||||
+20
-14
@@ -10,6 +10,7 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -25,12 +26,12 @@ import java.util.stream.Collectors;
|
||||
public class ActiveVoteToMute {
|
||||
|
||||
private static final HashMap<String, ActiveVoteToMute> instances = new HashMap<>();
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
|
||||
private final Player votedPlayer;
|
||||
private final Player startedByPlayer;
|
||||
private HashSet<UUID> votedFor = new HashSet<>();
|
||||
private HashSet<UUID> votedAgainst = new HashSet<>();
|
||||
private final HashSet<UUID> votedFor = new HashSet<>();
|
||||
private final HashSet<UUID> votedAgainst = new HashSet<>();
|
||||
private int totalEligibleVoters;
|
||||
private final boolean countLowerRanks;
|
||||
private final RegisteredServer server;
|
||||
@@ -39,14 +40,16 @@ public class ActiveVoteToMute {
|
||||
private boolean endedVote = false;
|
||||
|
||||
public static Optional<ActiveVoteToMute> getInstance(String username) {
|
||||
if (!instances.containsKey(username))
|
||||
if (!instances.containsKey(username)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(instances.get(username));
|
||||
}
|
||||
|
||||
public static void removePotentialVoter(Player player, RegisteredServer previousServer) {
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute"))
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute")) {
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission("chat.vote-to-mute")) {
|
||||
instances.values().stream()
|
||||
.filter(activeVoteToMute -> previousServer == null || activeVoteToMute.getServer().getServerInfo().hashCode() == previousServer.getServerInfo().hashCode())
|
||||
@@ -60,8 +63,9 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
public static void addPotentialVoter(Player player, ServerConnection server) {
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute"))
|
||||
if (!player.hasPermission("chat.backup-vote-to-mute")) {
|
||||
return;
|
||||
}
|
||||
if (player.hasPermission("chat.vote-to-mute")) {
|
||||
instances.values().stream()
|
||||
.filter(activeVoteToMute -> activeVoteToMute.getServer().getServerInfo().hashCode() == server.getServerInfo().hashCode())
|
||||
@@ -94,14 +98,15 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
private void endVote() {
|
||||
if (endedVote)
|
||||
if (endedVote) {
|
||||
return;
|
||||
}
|
||||
instances.remove(votedPlayer.getUsername());
|
||||
if (votePassed()) {
|
||||
mutePlayer();
|
||||
return;
|
||||
}
|
||||
Component message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</red>",
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</red>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
@@ -109,7 +114,7 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Component message = getVoteStartMessage();
|
||||
ComponentLike message = getVoteStartMessage();
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
.forEach(player -> player.sendMessage(message));
|
||||
@@ -147,7 +152,7 @@ public class ActiveVoteToMute {
|
||||
}
|
||||
|
||||
private void mutePlayer() {
|
||||
Component message = Utility.parseMiniMessage("<prefix> <green>The vote to mute <player> has passed, they will be muted.</green>",
|
||||
ComponentLike message = Utility.parseMiniMessage("<prefix> <green>The vote to mute <player> has passed, they will be muted.</green>",
|
||||
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||
server.getPlayersConnected().stream()
|
||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||
@@ -155,7 +160,6 @@ public class ActiveVoteToMute {
|
||||
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(),
|
||||
String.format("tempmute %s 1h Muted by the community - under review. -p", votedPlayer.getUsername()));
|
||||
|
||||
|
||||
String chatLogsString = PlainTextComponentSerializer.plainText().serialize(chatLogs);
|
||||
EmbedBuilder embedBuilder = buildMutedEmbed(chatLogsString);
|
||||
|
||||
@@ -200,19 +204,21 @@ public class ActiveVoteToMute {
|
||||
|
||||
public void addEligibleVoter(Player player) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
if (votedAgainst.contains(uuid) || votedFor.contains(uuid))
|
||||
if (votedAgainst.contains(uuid) || votedFor.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
totalEligibleVoters++;
|
||||
player.sendMessage(getVoteStartMessage());
|
||||
}
|
||||
|
||||
public void removeEligibleVoter(UUID uuid) {
|
||||
if (votedFor.contains(uuid) || votedAgainst.contains(uuid))
|
||||
if (votedFor.contains(uuid) || votedAgainst.contains(uuid)) {
|
||||
return;
|
||||
}
|
||||
totalEligibleVoters--;
|
||||
}
|
||||
|
||||
private Component getVoteStartMessage() {
|
||||
private ComponentLike getVoteStartMessage() {
|
||||
return Utility.parseMiniMessage(
|
||||
String.format("""
|
||||
<prefix> <green>A vote to mute <player> for one hour has been started, please read the logs below before voting.</green>
|
||||
|
||||
+9
-6
@@ -18,7 +18,7 @@ public class VoteToMuteStarter {
|
||||
|
||||
private static final HashMap<UUID, VoteToMuteStarter> instanceMap = new HashMap<>();
|
||||
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||
private final ChatLogHandler chatLogHandler;
|
||||
private final Player votedPlayer;
|
||||
private final Player commandSource;
|
||||
@@ -27,8 +27,9 @@ public class VoteToMuteStarter {
|
||||
private final boolean countLowerRanks;
|
||||
|
||||
public static Optional<VoteToMuteStarter> getInstance(UUID uuid) {
|
||||
if (!instanceMap.containsKey(uuid))
|
||||
if (!instanceMap.containsKey(uuid)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(instanceMap.get(uuid));
|
||||
}
|
||||
|
||||
@@ -67,8 +68,9 @@ public class VoteToMuteStarter {
|
||||
TagResolver.resolver(
|
||||
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||
playerTag, prefixTag
|
||||
))
|
||||
playerTag,
|
||||
prefixTag
|
||||
)).asComponent()
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
@@ -95,10 +97,11 @@ public class VoteToMuteStarter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the chat logs for the given list of IDs. It removes 1 from the IDs before using them
|
||||
* It removes the instance from the hashmap after this function call
|
||||
* Retrieves the chat logs for the given list of IDs. It removes 1 from the IDs before using them It removes the
|
||||
* instance from the hashmap after this function call
|
||||
*
|
||||
* @param ids A list of integers representing the IDs of the chat logs to retrieve.
|
||||
*
|
||||
* @return A Component object containing the selected chat logs joined by newlines.
|
||||
*/
|
||||
public Component getChatLogsAndClose(List<Integer> ids) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.alttd.velocitychat.data;
|
||||
import com.alttd.chat.config.ServerConfig;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -31,8 +31,7 @@ public class ServerWrapper {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public boolean globalChat()
|
||||
{
|
||||
public boolean globalChat() {
|
||||
return globalChat;
|
||||
}
|
||||
|
||||
@@ -40,10 +39,11 @@ public class ServerWrapper {
|
||||
return joinMessages;
|
||||
}
|
||||
|
||||
public void sendJoinLeaveMessage(UUID uuid, Component component) {
|
||||
if(joinMessages())
|
||||
public void sendJoinLeaveMessage(UUID uuid, ComponentLike component) {
|
||||
if (joinMessages()) {
|
||||
getRegisteredServer().getPlayersConnected().stream()
|
||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||
.forEach(p -> p.sendMessage(component));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
@@ -24,7 +25,10 @@ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
@@ -32,11 +36,15 @@ public class ChatHandler {
|
||||
UUID uuid = UUID.fromString(sender);
|
||||
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||
if(optionalPlayer.isEmpty()) return;
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player = optionalPlayer.get();
|
||||
|
||||
Optional<Player> optionalPlayer2 = VelocityChat.getPlugin().getProxy().getPlayer(target);
|
||||
if(optionalPlayer2.isEmpty()) return;
|
||||
if (optionalPlayer2.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player2 = optionalPlayer2.get();
|
||||
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
||||
|
||||
@@ -54,7 +62,7 @@ public class ChatHandler {
|
||||
serverConnection = player.getCurrentServer().get();
|
||||
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders);
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessageout");
|
||||
buf.writeUTF(player.getUniqueId().toString());
|
||||
@@ -67,7 +75,7 @@ public class ChatHandler {
|
||||
serverConnection = player2.getCurrentServer().get();
|
||||
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER
|
||||
.replaceAll("<sendername>", player.getUsername())
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders);
|
||||
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||
buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("privatemessagein");
|
||||
buf.writeUTF(player2.getUniqueId().toString());
|
||||
@@ -86,7 +94,7 @@ public class ChatHandler {
|
||||
Placeholder.unparsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
|
||||
Placeholder.unparsed("input", input)
|
||||
);
|
||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||
|
||||
serverConnection.getServer().getPlayersConnected().forEach(pl -> {
|
||||
if (pl.hasPermission("chat.alert-blocked")) {
|
||||
@@ -97,13 +105,13 @@ public class ChatHandler {
|
||||
"this constitutes as your only warning. Any further attempts at bypassing the filter will result in staff intervention.</red>"));
|
||||
}
|
||||
|
||||
public void sendPartyMessage(Party party, Component message, @Nullable List<UUID> ignoredPlayers)
|
||||
{
|
||||
public void sendPartyMessage(Party party, Component message, @Nullable List<UUID> ignoredPlayers) {
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.filter(pl -> {
|
||||
UUID uuid = pl.getUniqueId();
|
||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid))
|
||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid)) {
|
||||
return false;
|
||||
}
|
||||
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
|
||||
}).forEach(pl -> {
|
||||
pl.sendMessage(message);
|
||||
@@ -114,7 +122,9 @@ public class ChatHandler {
|
||||
|
||||
public void sendPartyMessage(UUID uuid, String message, Component item, ServerConnection serverConnection) {
|
||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||
if (optionalPlayer.isEmpty()) return;
|
||||
if (optionalPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Player player = optionalPlayer.get();
|
||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||
Party party = PartyManager.getParty(user.getPartyId());
|
||||
@@ -122,7 +132,7 @@ public class ChatHandler {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||
return;
|
||||
}
|
||||
Component senderName = user.getDisplayName();
|
||||
ComponentLike senderName = user.getDisplayName();
|
||||
|
||||
TagResolver Placeholders = TagResolver.resolver(
|
||||
Placeholder.component("sender", senderName),
|
||||
@@ -132,7 +142,7 @@ public class ChatHandler {
|
||||
Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName())
|
||||
);
|
||||
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders)
|
||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders).asComponent()
|
||||
.replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(item).build());
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(partyMessage);
|
||||
@@ -145,7 +155,7 @@ public class ChatHandler {
|
||||
|
||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
||||
|
||||
Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
ComponentLike spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||
for (Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||
if (pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||
pl.sendMessage(spyMessage);
|
||||
@@ -157,18 +167,20 @@ public class ChatHandler {
|
||||
public void globalAdminChat(String message) {
|
||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||
target.sendMessage(component);
|
||||
});
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(component));
|
||||
}
|
||||
|
||||
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||
Component senderName = Component.text(Config.CONSOLENAME);
|
||||
ComponentLike senderName = Component.text(Config.CONSOLENAME);
|
||||
String serverName = "Altitude";
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) commandSource;
|
||||
if (commandSource instanceof Player sender) {
|
||||
ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
|
||||
if(user == null) return;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
senderName = user.getDisplayName();
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
}
|
||||
@@ -178,15 +190,16 @@ public class ChatHandler {
|
||||
Placeholder.component("sender", senderName),
|
||||
Placeholder.unparsed("server", serverName));
|
||||
|
||||
Component component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
|
||||
ComponentLike component = Utility.parseMiniMessage(Config.GACFORMAT, Placeholders);
|
||||
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
|
||||
target.sendMessage(component);
|
||||
});
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(component));
|
||||
}
|
||||
|
||||
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
||||
UUID uuid = Config.CONSOLEUUID;;
|
||||
UUID uuid = Config.CONSOLEUUID;
|
||||
String senderName = Config.CONSOLENAME;
|
||||
UUID targetUUID;
|
||||
if (commandSource instanceof Player player) {
|
||||
@@ -205,6 +218,10 @@ public class ChatHandler {
|
||||
}
|
||||
Mail mail = new Mail(targetUUID, uuid, message);
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(targetUUID);
|
||||
if (chatUser.getIgnoredPlayers().contains(uuid)) {
|
||||
commandSource.sendMessage(Utility.parseMiniMessage("<red>You cannot mail this player</red>"));
|
||||
return;
|
||||
}
|
||||
chatUser.addMail(mail);
|
||||
// TODO load from config
|
||||
String finalSenderName = senderName;
|
||||
@@ -244,7 +261,7 @@ public class ChatHandler {
|
||||
}
|
||||
|
||||
private Component parseMails(List<Mail> mails, boolean mark) {
|
||||
Component component = Utility.parseMiniMessage(Config.mailHeader);
|
||||
Component component = Utility.parseMiniMessage(Config.mailHeader).asComponent();
|
||||
for (Mail mail : mails) {
|
||||
if (mail.isUnRead() && mark) {
|
||||
mail.setReadTime(System.currentTimeMillis());
|
||||
@@ -259,27 +276,13 @@ public class ChatHandler {
|
||||
Placeholder.unparsed("date", date.toString()),
|
||||
Placeholder.unparsed("time_ago", getTimeAgo(Duration.between(date.toInstant(), new Date().toInstant())))
|
||||
);
|
||||
Component mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
|
||||
ComponentLike mailMessage = Utility.parseMiniMessage(Config.mailBody, Placeholders);
|
||||
component = component.append(Component.newline()).append(mailMessage);
|
||||
}
|
||||
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));
|
||||
return component;
|
||||
}
|
||||
|
||||
public void partyChat(String partyId, UUID uuid, Component message) {
|
||||
Party party = PartyManager.getParty(Integer.parseInt(partyId));
|
||||
if (party == null) {
|
||||
ALogger.warn("Received a non existent party");
|
||||
return;
|
||||
}
|
||||
List<UUID> ignoredPlayers = ChatUserManager.getChatUser(uuid).getIgnoredPlayers();
|
||||
List<UUID> partyUsersUuid = party.getPartyUsersUuid();
|
||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||
.filter(p -> partyUsersUuid.contains(p.getUniqueId()))
|
||||
.filter(p -> !ignoredPlayers.contains(p.getUniqueId()))
|
||||
.forEach(p -> p.sendMessage(message));
|
||||
}
|
||||
|
||||
public void mutePlayer(String uuid, boolean muted) {
|
||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||
buf.writeUTF("chatpunishments");
|
||||
@@ -289,10 +292,12 @@ public class ChatHandler {
|
||||
|
||||
private String getTimeAgo(Duration duration) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (duration.toDays() != 0)
|
||||
if (duration.toDays() != 0) {
|
||||
stringBuilder.append(duration.toDays()).append("d ");
|
||||
if (duration.toHoursPart() != 0 || !stringBuilder.isEmpty())
|
||||
}
|
||||
if (duration.toHoursPart() != 0 || !stringBuilder.isEmpty()) {
|
||||
stringBuilder.append(duration.toHoursPart()).append("h ");
|
||||
}
|
||||
stringBuilder.append(duration.toMinutesPart()).append("m ago");
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@@ -8,15 +8,12 @@ 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.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
// TODO code CLEANUP
|
||||
public class ChatListener {
|
||||
|
||||
private VelocityChat plugin;
|
||||
private final VelocityChat plugin;
|
||||
|
||||
public ChatListener() {
|
||||
plugin = VelocityChat.getPlugin();
|
||||
@@ -30,18 +27,20 @@ public class ChatListener {
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) event.getSender();
|
||||
senderName = sender.getUsername();
|
||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
serverName = sender.getCurrentServer().isPresent()
|
||||
? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||
}
|
||||
|
||||
Component message = Utility.parseMiniMessage(Config.GACFORMAT,
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.GACFORMAT,
|
||||
Placeholder.parsed("sender", senderName),
|
||||
Placeholder.component("message", Utility.parseMiniMessage(event.getMessage())),
|
||||
Placeholder.parsed("server", serverName)
|
||||
);
|
||||
|
||||
plugin.getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")).forEach(target -> {
|
||||
target.sendMessage(message);
|
||||
});
|
||||
plugin.getProxy().getAllPlayers()
|
||||
.stream()
|
||||
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||
.forEach(target -> target.sendMessage(message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.alttd.velocitychat.listeners;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.managers.ChatUserManager;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.ChatUser;
|
||||
import com.alttd.chat.objects.Mail;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.VelocityChat;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.velocitychat.commands.vote_to_mute.ActiveVoteToMute;
|
||||
import com.alttd.velocitychat.data.ServerWrapper;
|
||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
||||
import com.alttd.chat.managers.PartyManager;
|
||||
import com.alttd.chat.objects.Party;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
@@ -21,10 +21,16 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.title.Title;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class ProxyPlayerListener {
|
||||
|
||||
@@ -33,14 +39,17 @@ public class ProxyPlayerListener {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||
if (party == null) return;
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null)
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null) {
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_ON,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
),
|
||||
).asComponent(),
|
||||
chatUser.getIgnoredPlayers());
|
||||
// TODO setup ChatUser on Proxy
|
||||
//VelocityChat.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||
@@ -55,22 +64,34 @@ public class ProxyPlayerListener {
|
||||
if (previousServer != null) {
|
||||
ActiveVoteToMute.removePotentialVoter(player, previousServer);
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||
return;
|
||||
}
|
||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||
if (currentServer.isEmpty())
|
||||
if (currentServer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||
List<Mail> unReadMail = chatUser.getUnReadMail();
|
||||
if (unReadMail.isEmpty())
|
||||
if (unReadMail.isEmpty()) {
|
||||
return;
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size()))
|
||||
));
|
||||
}
|
||||
VelocityChat plugin = VelocityChat.getPlugin();
|
||||
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
|
||||
if (!player.isActive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.mailUnread,
|
||||
Placeholder.unparsed("amount", String.valueOf(unReadMail.size())));
|
||||
player.sendMessage(message);
|
||||
player.showTitle(Title.title(message.asComponent(), Component.empty()));
|
||||
}).delay(Config.mailDisplayDelay * 50L, TimeUnit.MILLISECONDS).schedule();
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -78,24 +99,25 @@ public class ProxyPlayerListener {
|
||||
ActiveVoteToMute.removePotentialVoter(event.getPlayer(), null);
|
||||
UUID uuid = event.getPlayer().getUniqueId();
|
||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||
if (party == null) return;
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null)
|
||||
if (party == null) {
|
||||
return;
|
||||
}
|
||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||
if (chatUser == null) {
|
||||
return;
|
||||
}
|
||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_OFF,
|
||||
Placeholder.component("player", chatUser.getDisplayName())
|
||||
),
|
||||
).asComponent(),
|
||||
chatUser.getIgnoredPlayers());
|
||||
// TODO setup ChatUser on Proxy
|
||||
//VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
private static final HashSet<UUID> silentJoin = new HashSet<>();
|
||||
|
||||
public static void addSilentJoin(UUID uuid)
|
||||
{
|
||||
public static void addSilentJoin(UUID uuid) {
|
||||
silentJoin.add(uuid);
|
||||
}
|
||||
|
||||
@@ -115,7 +137,7 @@ public class ProxyPlayerListener {
|
||||
);
|
||||
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||
placeholders);
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player1.hasPermission("command.chat.silent-join-notify"))
|
||||
@@ -133,7 +155,7 @@ public class ProxyPlayerListener {
|
||||
}
|
||||
} else {
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED,
|
||||
ComponentLike message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED,
|
||||
Placeholder.unparsed("player", player.getUsername()));
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player1.hasPermission("command.chat.silent-join-notify"))
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.alttd.velocitychat.matrix;
|
||||
|
||||
import com.alttd.matrix.interfaces.MatrixBridge;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public final class MatrixRoomMap implements MatrixBridge.RoomResolver {
|
||||
private final Map<String, String> serverToRoom = new ConcurrentHashMap<>();
|
||||
private final Map<String, String> roomToServer = new ConcurrentHashMap<>();
|
||||
|
||||
public void put(String serverName, String roomId) {
|
||||
serverToRoom.put(serverName, roomId);
|
||||
roomToServer.put(roomId, serverName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String roomIdForServer(String serverName) {
|
||||
return serverToRoom.get(serverName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverForRoomId(String roomId) {
|
||||
return roomToServer.get(roomId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.alttd.velocitychat.matrix;
|
||||
|
||||
import com.alttd.matrix.interfaces.MatrixBridge;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class VelocityMatrixInbound implements MatrixBridge.InboundHandler {
|
||||
private final ProxyServer proxy;
|
||||
private final MatrixRoomMap rooms;
|
||||
|
||||
public VelocityMatrixInbound(ProxyServer proxy, MatrixRoomMap rooms) {
|
||||
this.proxy = proxy;
|
||||
this.rooms = rooms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMatrixChat(String roomId, String senderMxid, String body) {
|
||||
final String serverName = rooms.serverForRoomId(roomId);
|
||||
if (serverName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// route to backend server players connected to that server
|
||||
Optional<RegisteredServer> rs = proxy.getServer(serverName);
|
||||
if (rs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// minimal formatting; adjust to your chat format
|
||||
String sender = senderMxid != null ? senderMxid : "matrix";
|
||||
Component msg = Component.text("[M] " + sender + ": " + body);
|
||||
|
||||
rs.get().getPlayersConnected().forEach(p -> p.sendMessage(msg));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.alttd.velocitychat.matrix;
|
||||
|
||||
import com.alttd.matrix.interfaces.MatrixBridge;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||
|
||||
public final class VelocityMatrixOutbound {
|
||||
private final MatrixBridge matrix;
|
||||
|
||||
public VelocityMatrixOutbound(MatrixBridge matrix) {
|
||||
this.matrix = matrix;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onChat(PlayerChatEvent e) {
|
||||
if (!e.getResult().isAllowed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player p = e.getPlayer();
|
||||
String serverName = p.getCurrentServer().map(s -> s.getServerInfo().getName()).orElse(null);
|
||||
if (serverName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String msg = PlainTextComponentSerializer.plainText().serialize(e.getMessage());
|
||||
if (msg == null || msg.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
matrix.sendChat(p.getUniqueId(), p.getUsername(), serverName, msg);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user