Compare commits
224 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cc7cca129 | ||
|
|
3bfd358e78 | ||
|
|
eb30750134 | ||
|
|
fc7860145f | ||
|
|
1dd19f0543 | ||
|
|
bbd421c423 | ||
|
|
5fe5a305a5 | ||
|
|
bbfc9c407c | ||
|
|
880108d344 | ||
|
|
61e705b088 | ||
|
|
38228ea585 | ||
|
|
b65fcdb1c7 | ||
|
|
e74361a7b7 | ||
|
|
769859a617 | ||
|
|
cb0bda8d5b | ||
|
|
5212954946 | ||
|
|
f1b8af6136 | ||
|
|
9e437079e4 | ||
|
|
bfc9af69d0 | ||
|
|
ea705c879f | ||
|
|
f5c0a0676c | ||
|
|
9bd9e21321 | ||
|
|
1c570fd524 | ||
|
|
131ea6da9d | ||
|
|
45eceaf4a6 | ||
|
|
3275db13d0 | ||
|
|
c5eebb7e88 | ||
|
|
5e34e6e7fa | ||
|
|
c5c60d25b1 | ||
|
|
804e619e8a | ||
|
|
b3e545a0c8 | ||
|
|
773638c222 | ||
|
|
73e67eed6c | ||
|
|
c9e819645a | ||
|
|
33dc113b36 | ||
|
|
ba8ba373fd | ||
|
|
c3e27edb7e | ||
|
|
bd48c3f0ca | ||
|
|
71a8c652dc | ||
|
|
0877d05296 | ||
|
|
e1d6da56d0 | ||
|
|
13e4966a12 | ||
|
|
340975e99e | ||
|
|
3ea078237d | ||
|
|
2c3feac367 | ||
|
|
c97f5a54d7 | ||
|
|
a908e32d0b | ||
|
|
8393d12c6d | ||
|
|
782c7df4ef | ||
|
|
a876a9f77b | ||
|
|
f3147b3256 | ||
|
|
65503a02f3 | ||
|
|
7140a0cd78 | ||
|
|
99f66c3b4b | ||
|
|
187f71d6c3 | ||
|
|
3b2aa84164 | ||
|
|
0fb497c2f1 | ||
|
|
de24ca4437 | ||
|
|
e351e86bea | ||
|
|
192fca3a89 | ||
|
|
d6135f2456 | ||
|
|
c057c69653 | ||
|
|
c25767e473 | ||
|
|
37aa9fdf4c | ||
|
|
ed2ba74772 | ||
|
|
44d6e994cc | ||
|
|
4e92285261 | ||
|
|
a377bdfe48 | ||
|
|
4af85d0e79 | ||
|
|
034de90062 | ||
|
|
bd8fa02f1e | ||
|
|
8a5b407359 | ||
|
|
f63c4c0836 | ||
|
|
eb7c1dd1e1 | ||
|
|
278129e8d8 | ||
|
|
f1deebf49e | ||
|
|
3e29fc7d17 | ||
|
|
ffa90b5c94 | ||
|
|
9d7f944c88 | ||
|
|
4b930e62c3 | ||
|
|
c02e4dd884 | ||
|
|
8a463696ed | ||
|
|
ce5ea19961 | ||
|
|
591ca93981 | ||
|
|
d7cfe97644 | ||
|
|
c86a344d49 | ||
|
|
5583abbbca | ||
|
|
55918670bc | ||
|
|
f3c7a312c0 | ||
|
|
d8f064e7ca | ||
|
|
9b7868bea7 | ||
|
|
6c6b798677 | ||
|
|
0c1b197054 | ||
|
|
57afbbe805 | ||
|
|
5398d97248 | ||
|
|
d90f5ac376 | ||
|
|
0c7ad69e85 | ||
|
|
7ef9b4a64a | ||
|
|
5b06049265 | ||
|
|
ea051fd905 | ||
|
|
87d5c1b264 | ||
|
|
5e62786010 | ||
|
|
4f01c86877 | ||
|
|
6beb398e10 | ||
|
|
e811b0ca9a | ||
|
|
3eff30a4be | ||
|
|
3aa0b09133 | ||
|
|
5db22461cf | ||
|
|
3bdaa798c3 | ||
|
|
7fcfb2321f | ||
|
|
7af91c1c94 | ||
|
|
7de83f536b | ||
|
|
76f713409b | ||
|
|
ef831c48b3 | ||
|
|
8baa254d5e | ||
|
|
3d14cca551 | ||
|
|
d1df551f35 | ||
|
|
db8524134e | ||
|
|
e99626cebb | ||
|
|
d7bd3aa222 | ||
|
|
9407ba8bec | ||
|
|
aab68e5e7f | ||
|
|
5ec1f08fe1 | ||
|
|
a4e4982dc3 | ||
|
|
3d432a5af6 | ||
|
|
ac994d35a1 | ||
|
|
4b947996da | ||
|
|
df4ff7f6b3 | ||
|
|
2764446e41 | ||
|
|
5db3bc5ffe | ||
|
|
271500bae3 | ||
|
|
244b2aeda2 | ||
|
|
d6562826e4 | ||
|
|
6329eacd07 | ||
|
|
99cbc01106 | ||
|
|
58b80e9eaf | ||
|
|
282fdde48b | ||
|
|
a405862fe1 | ||
|
|
11ecf1ad16 | ||
|
|
fb997ae4ed | ||
|
|
b0e453295b | ||
|
|
1ea2c03fcd | ||
|
|
4d01ccb065 | ||
|
|
a15b13e8ac | ||
|
|
00f4e00011 | ||
|
|
3888298827 | ||
|
|
643fb5a633 | ||
|
|
3ca854e507 | ||
|
|
1eb4d619d6 | ||
|
|
9d7f50ad37 | ||
|
|
d644dbef6e | ||
|
|
425c06af33 | ||
|
|
fb3358e2ea | ||
|
|
ee2a2c2225 | ||
|
|
341a330e3d | ||
|
|
0339458c66 | ||
|
|
d3be713c9a | ||
|
|
6e41a81ed1 | ||
|
|
ce1ec164ef | ||
|
|
9832abbb90 | ||
|
|
66a058225d | ||
|
|
35ad214901 | ||
|
|
32e38ef32b | ||
|
|
b1f2370bec | ||
|
|
20c7f0a6d9 | ||
|
|
40a6e6bcc9 | ||
|
|
7ab95e437a | ||
|
|
4068ad8ea6 | ||
|
|
82eecc3142 | ||
|
|
679602c1f7 | ||
|
|
8c3d03383d | ||
|
|
fe64fb3785 | ||
|
|
c836452d19 | ||
|
|
0997c2bab6 | ||
|
|
e39bab34fd | ||
|
|
41897f4b16 | ||
|
|
60e1ad2220 | ||
|
|
c645201ef3 | ||
|
|
fdd9d81400 | ||
|
|
3e313cb00b | ||
|
|
dac0f7936e | ||
|
|
408d38fb78 | ||
|
|
faa0435131 | ||
|
|
1946cd4ab7 | ||
|
|
29dd5d2d55 | ||
|
|
0a6dfe799e | ||
|
|
e6dfd19b84 | ||
|
|
42585c97cf | ||
|
|
342957ef68 | ||
|
|
ab852cf55e | ||
|
|
ef94169f04 | ||
|
|
5042d62247 | ||
|
|
fe022a02fe | ||
|
|
fbbe0d6ef3 | ||
|
|
647ad2b62a | ||
|
|
59781f486d | ||
|
|
fa79491088 | ||
|
|
e6e1073958 | ||
|
|
2b77607072 | ||
|
|
777415f97e | ||
|
|
bc010bea6e | ||
|
|
8628dacd10 | ||
|
|
3d42fb8bbf | ||
|
|
08a695f2ac | ||
|
|
2c0637b1d1 | ||
|
|
e08c5a4a3b | ||
|
|
f00f6e7658 | ||
|
|
a5d5d8d985 | ||
|
|
c18ffb9578 | ||
|
|
79501c619a | ||
|
|
0c8a4a97d3 | ||
|
|
032d0e2bef | ||
|
|
8d0ed326b5 | ||
|
|
d40c3a45ed | ||
|
|
040c8cfa96 | ||
|
|
787927672a | ||
|
|
aed1885a59 | ||
|
|
43a2be1b1b | ||
|
|
fd58617e44 | ||
|
|
6360d74b30 | ||
|
|
a0a60757f6 | ||
|
|
89938338b1 | ||
|
|
f8ede610b2 | ||
|
|
70d26a2255 |
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
|
|
@ -1,18 +0,0 @@
|
||||||
name: Build
|
|
||||||
on: [ push, pull_request ]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: "!contains(github.event.commits[0].message, '[ci-skip]')"
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: gradle/wrapper-validation-action@v1
|
|
||||||
- uses: actions/setup-java@v2
|
|
||||||
with:
|
|
||||||
distribution: temurin
|
|
||||||
java-version: 17
|
|
||||||
- name: Configure Git
|
|
||||||
run: git config --global user.email "no-reply@github.com" && git config --global user.name "Github Actions"
|
|
||||||
- name: Build
|
|
||||||
run: ./gradlew build --stacktrace
|
|
||||||
23
Jenkinsfile
vendored
Normal file
23
Jenkinsfile
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
environment {
|
||||||
|
NEXUS_CREDS = credentials('alttd-snapshot-user')
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Gradle') {
|
||||||
|
steps {
|
||||||
|
sh './gradlew build -PalttdSnapshotUsername=$NEXUS_CREDS_USR -PalttdSnapshotPassword=$NEXUS_CREDS_PSW'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Archive') {
|
||||||
|
steps {
|
||||||
|
archiveArtifacts artifacts: 'build/libs/', followSymlinks: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('discord') {
|
||||||
|
steps {
|
||||||
|
discordSend description: "Build: ${BUILD_NUMBER}", showChangeset: true, result: currentBuild.currentResult, title: currentBuild.fullProjectName, webhookURL: env.discordwebhook
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,16 +3,12 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") {
|
// Cosmos
|
||||||
exclude("net.kyori.adventure.text.minimessag")
|
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
||||||
|
isChanging = true
|
||||||
}
|
}
|
||||||
compileOnly("net.kyori", "adventure-text-minimessage", "4.10.0-20220122.015731-43") { // Minimessage
|
compileOnly("org.spongepowered:configurate-yaml:4.2.0") // Configurate
|
||||||
exclude("net.kyori")
|
compileOnly("net.luckperms:api:5.5") // Luckperms
|
||||||
exclude("net.kyori.examination")
|
|
||||||
}
|
|
||||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
|
||||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
|
||||||
compileOnly(files("../libs/minimessage-4.10.0-SNAPSHOT.jar")) // Workaround for minimessage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
publishing {
|
publishing {
|
||||||
|
|
@ -22,7 +18,7 @@ publishing {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories{
|
repositories {
|
||||||
maven {
|
maven {
|
||||||
name = "maven"
|
name = "maven"
|
||||||
url = uri("https://repo.destro.xyz/snapshots")
|
url = uri("https://repo.destro.xyz/snapshots")
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ public abstract interface ChatAPI {
|
||||||
|
|
||||||
DatabaseConnection getDataBase();
|
DatabaseConnection getDataBase();
|
||||||
|
|
||||||
void ReloadConfig();
|
void reloadConfig();
|
||||||
|
|
||||||
void ReloadChatFilters();
|
void reloadChatFilters();
|
||||||
|
|
||||||
HashMap<String, String> getPrefixes();
|
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.DatabaseConnection;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.util.ALogger;
|
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
import net.luckperms.api.LuckPermsProvider;
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
import net.luckperms.api.model.group.Group;
|
import net.luckperms.api.model.group.Group;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class ChatImplementation implements ChatAPI{
|
public class ChatImplementation implements ChatAPI{
|
||||||
|
|
||||||
|
|
@ -26,7 +23,7 @@ public class ChatImplementation implements ChatAPI{
|
||||||
|
|
||||||
public ChatImplementation() {
|
public ChatImplementation() {
|
||||||
instance = this;
|
instance = this;
|
||||||
ReloadConfig();
|
reloadConfig();
|
||||||
|
|
||||||
luckPerms = getLuckPerms();
|
luckPerms = getLuckPerms();
|
||||||
databaseConnection = getDataBase();
|
databaseConnection = getDataBase();
|
||||||
|
|
@ -57,13 +54,13 @@ public class ChatImplementation implements ChatAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ReloadConfig() {
|
public void reloadConfig() {
|
||||||
Config.init();
|
Config.init();
|
||||||
loadPrefixes();
|
loadPrefixes();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ReloadChatFilters() {
|
public void reloadChatFilters() {
|
||||||
RegexManager.initialize();
|
RegexManager.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,16 @@
|
||||||
package com.alttd.chat.config;
|
package com.alttd.chat.config;
|
||||||
|
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.google.common.base.Throwables;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import io.leangen.geantyref.TypeToken;
|
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.ConfigurationNode;
|
||||||
|
import org.spongepowered.configurate.ConfigurationOptions;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||||
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -16,9 +19,8 @@ import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
|
||||||
import org.spongepowered.configurate.ConfigurationOptions;
|
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public final class Config {
|
public final class Config {
|
||||||
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
private static final Pattern PATH_PATTERN = Pattern.compile("\\.");
|
||||||
private static final String HEADER = "";
|
private static final String HEADER = "";
|
||||||
|
|
@ -31,32 +33,33 @@ public final class Config {
|
||||||
static boolean verbose;
|
static boolean verbose;
|
||||||
|
|
||||||
public static File CONFIGPATH;
|
public static File CONFIGPATH;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
CONFIGPATH = new File(System.getProperty("user.home") + File.separator + "share" + File.separator + "configs" + File.separator + "ChatPlugin");
|
CONFIGPATH = new File(File.separator + "mnt" + File.separator + "configs" + File.separator + "ChatPlugin");
|
||||||
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
CONFIG_FILE = new File(CONFIGPATH, "config.yml");
|
||||||
configLoader = YamlConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.file(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.nodeStyle(NodeStyle.BLOCK)
|
.nodeStyle(NodeStyle.BLOCK)
|
||||||
.build();
|
.build();
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
if (!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!CONFIG_FILE.exists()) {
|
if (!CONFIG_FILE.exists()) {
|
||||||
try {
|
try {
|
||||||
if(!CONFIG_FILE.createNewFile()) {
|
if (!CONFIG_FILE.createNewFile()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (IOException error) {
|
} catch (IOException error) {
|
||||||
error.printStackTrace();
|
ALogger.error(error.getMessage(), error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false));
|
config = configLoader.load(ConfigurationOptions.defaults().header(HEADER).shouldCopyDefaults(false));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
ALogger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose = getBoolean("verbose", true);
|
verbose = getBoolean("verbose", true);
|
||||||
|
|
@ -66,7 +69,7 @@ public final class Config {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
ALogger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +81,7 @@ public final class Config {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ALogger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +89,7 @@ public final class Config {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ALogger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +97,7 @@ public final class Config {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ALogger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -103,19 +106,22 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void set(String path, Object def) {
|
private static void set(String path, Object def) {
|
||||||
if(config.node(splitPath(path)).virtual()) {
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
try {
|
try {
|
||||||
config.node(splitPath(path)).set(def);
|
config.node(splitPath(path)).set(def);
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
|
ALogger.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setString(String path, String def) {
|
private static void setString(String path, String def) {
|
||||||
try {
|
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);
|
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
|
||||||
} catch(SerializationException ex) {
|
}
|
||||||
|
} catch (SerializationException ex) {
|
||||||
|
ALogger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,29 +154,36 @@ public final class Config {
|
||||||
try {
|
try {
|
||||||
set(path, def);
|
set(path, def);
|
||||||
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
|
return config.node(splitPath(path)).getList(TypeToken.get(String.class));
|
||||||
} catch(SerializationException ex) {
|
} catch (SerializationException ex) {
|
||||||
|
ALogger.error(ex.getMessage(), ex);
|
||||||
}
|
}
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ConfigurationNode getNode(String path) {
|
private static ConfigurationNode getNode(String path) {
|
||||||
if(config.node(splitPath(path)).virtual()) {
|
if (config.node(splitPath(path)).virtual()) {
|
||||||
//new RegexConfig("Dummy");
|
//new RegexConfig("Dummy");
|
||||||
}
|
}
|
||||||
config.childrenMap();
|
config.childrenMap();
|
||||||
return config.node(splitPath(path));
|
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> PREFIXGROUPS = new ArrayList<>();
|
||||||
public static List<String> CONFLICTINGPREFIXGROUPS = new ArrayList<>();
|
public static List<String> CONFLICTINGPREFIXGROUPS = new ArrayList<>();
|
||||||
public static List<String> STAFFGROUPS = new ArrayList<>();
|
public static List<String> STAFFGROUPS = new ArrayList<>();
|
||||||
public static String MINIMIUMSTAFFRANK = "trainee";
|
public static String MINIMIUMSTAFFRANK = "trainee";
|
||||||
public static String CONSOLENAME = "Console";
|
public static String CONSOLENAME = "Console";
|
||||||
public static UUID CONSOLEUUID = UUID.randomUUID();
|
public static UUID CONSOLEUUID = UUID.randomUUID();
|
||||||
|
public static int EMOTELIMIT = 3;
|
||||||
|
public static String MENTIONPLAYERTAG = "<aqua>@</aqua>";
|
||||||
|
|
||||||
private static void settings() {
|
private static void settings() {
|
||||||
PREFIXGROUPS = getList("settings.prefix-groups",
|
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",
|
CONFLICTINGPREFIXGROUPS = getList("settings.prefix-conflicts-groups",
|
||||||
Lists.newArrayList("eventteam", "eventleader"));
|
Lists.newArrayList("eventteam", "eventleader"));
|
||||||
STAFFGROUPS = getList("settings.staff-groups",
|
STAFFGROUPS = getList("settings.staff-groups",
|
||||||
|
|
@ -178,14 +191,19 @@ public final class Config {
|
||||||
CONSOLENAME = getString("settings.console-name", CONSOLENAME);
|
CONSOLENAME = getString("settings.console-name", CONSOLENAME);
|
||||||
CONSOLEUUID = UUID.fromString(getString("settings.console-uuid", CONSOLEUUID.toString()));
|
CONSOLEUUID = UUID.fromString(getString("settings.console-uuid", CONSOLEUUID.toString()));
|
||||||
MINIMIUMSTAFFRANK = getString("settings.minimum-staff-rank", MINIMIUMSTAFFRANK);
|
MINIMIUMSTAFFRANK = getString("settings.minimum-staff-rank", MINIMIUMSTAFFRANK);
|
||||||
|
EMOTELIMIT = getInt("settings.emote-limit", EMOTELIMIT);
|
||||||
|
MENTIONPLAYERTAG = getString("settings.mention-player-tag", MENTIONPLAYERTAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
||||||
public static List<String> REPLYCOMMANDALIASES = 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 MESSAGESENDER =
|
||||||
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>";
|
"<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 MESSAGESPY = "<gray>(<gray><sendername></gray> -> <receivername>) <message>";
|
||||||
public static String RECEIVER_DOES_NOT_EXIST = "<red><player> is not a valid player.</red>";
|
public static String RECEIVER_DOES_NOT_EXIST = "<red><player> is not a valid player.</red>";
|
||||||
|
|
||||||
private static void messageCommand() {
|
private static void messageCommand() {
|
||||||
MESSAGECOMMANDALIASES.clear();
|
MESSAGECOMMANDALIASES.clear();
|
||||||
REPLYCOMMANDALIASES.clear();
|
REPLYCOMMANDALIASES.clear();
|
||||||
|
|
@ -197,12 +215,14 @@ public final class Config {
|
||||||
RECEIVER_DOES_NOT_EXIST = getString("commands.message.receiver-does-not-exist", RECEIVER_DOES_NOT_EXIST);
|
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 String GCPERMISSION = "proxy.globalchat";
|
||||||
public static List<String> GCALIAS = new ArrayList<>();
|
public static List<String> GCALIAS = new ArrayList<>();
|
||||||
public static String GCNOTENABLED = "You don't have global chat enabled.";
|
public static String GCNOTENABLED = "You don't have global chat enabled.";
|
||||||
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again.";
|
public static String GCONCOOLDOWN = "You have to wait <cooldown> seconds before using this feature again.";
|
||||||
public static int GCCOOLDOWN = 30;
|
public static int GCCOOLDOWN = 30;
|
||||||
|
|
||||||
private static void globalChat() {
|
private static void globalChat() {
|
||||||
GCFORMAT = getString("commands.globalchat.format", GCFORMAT);
|
GCFORMAT = getString("commands.globalchat.format", GCFORMAT);
|
||||||
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
GCPERMISSION = getString("commands.globalchat.view-chat-permission", GCPERMISSION);
|
||||||
|
|
@ -212,26 +232,32 @@ public final class Config {
|
||||||
GCCOOLDOWN = getInt("commands.globalchat.cooldown", GCCOOLDOWN);
|
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>";
|
public static String URLFORMAT = "<click:OPEN_URL:<clickurl>><url></click>";
|
||||||
|
|
||||||
private static void Chat() {
|
private static void Chat() {
|
||||||
CHATFORMAT = getString("chat.format", CHATFORMAT);
|
CHATFORMAT = getString("chat.format", CHATFORMAT);
|
||||||
URLFORMAT = getString("chat.urlformat", URLFORMAT);
|
URLFORMAT = getString("chat.urlformat", URLFORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> GACECOMMANDALIASES = new ArrayList<>();
|
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() {
|
private static void globalAdminChat() {
|
||||||
GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg"));
|
GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg"));
|
||||||
GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT);
|
GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String MESSAGECHANNEL = "altitude:chatplugin";
|
public static String MESSAGECHANNEL = "altitude:chatplugin";
|
||||||
|
|
||||||
private static void messageChannels() {
|
private static void messageChannels() {
|
||||||
MESSAGECHANNEL = getString("settings.message-channel", MESSAGECHANNEL);
|
MESSAGECHANNEL = getString("settings.message-channel", MESSAGECHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigurationNode REGEXNODE = null;
|
public static ConfigurationNode REGEXNODE = null;
|
||||||
|
|
||||||
private static void RegexNOde() {
|
private static void RegexNOde() {
|
||||||
REGEXNODE = getNode("regex-settings");
|
REGEXNODE = getNode("regex-settings");
|
||||||
}
|
}
|
||||||
|
|
@ -240,6 +266,7 @@ public final class Config {
|
||||||
public static String SERVERSWTICHMESSAGETO = "<gray>* <player> leaves to <to_server>...";
|
public static String SERVERSWTICHMESSAGETO = "<gray>* <player> leaves to <to_server>...";
|
||||||
public static String SERVERJOINMESSAGE = "<green>* <player> appears from thin air...";
|
public static String SERVERJOINMESSAGE = "<green>* <player> appears from thin air...";
|
||||||
public static String SERVERLEAVEMESSAGE = "<red>* <player> vanishes in the mist...";
|
public static String SERVERLEAVEMESSAGE = "<red>* <player> vanishes in the mist...";
|
||||||
|
|
||||||
private static void JoinLeaveMessages() {
|
private static void JoinLeaveMessages() {
|
||||||
SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM);
|
SERVERSWTICHMESSAGEFROM = getString("messages.switch-server-from", SERVERSWTICHMESSAGEFROM);
|
||||||
SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO);
|
SERVERSWTICHMESSAGETO = getString("messages.switch-server-to", SERVERSWTICHMESSAGETO);
|
||||||
|
|
@ -248,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_FORMAT =
|
||||||
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>";
|
"<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_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 NO_CONSOLE = "<red>This command can not be used by console</red>";
|
||||||
public static String CREATED_PARTY = "<green>You created a chat party called: " +
|
public static String CREATED_PARTY = "<green>You created a chat party called: " +
|
||||||
|
|
@ -263,9 +292,11 @@ public final class Config {
|
||||||
public static String INVALID_PASSWORD = "<red>Invalid password.</red>";
|
public static String INVALID_PASSWORD = "<red>Invalid password.</red>";
|
||||||
public static String JOINED_PARTY = "<green>You joined <party_name>!</green>";
|
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 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 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 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 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>";
|
public static String CANT_REMOVE_PARTY_OWNER = "<red>You can't remove yourself, please leave instead.</red>";
|
||||||
|
|
@ -279,17 +310,23 @@ public final class Config {
|
||||||
"<dark_aqua>You received an invite to join <party>, click this message to accept.</dark_aqua></click>";
|
"<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_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 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 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> " +
|
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.";
|
"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 = """
|
public static String PARTY_INFO = """
|
||||||
<gold><bold>Chat party info</bold>:
|
<gold><bold>Chat party info</bold>:
|
||||||
</gold><green>Name: <dark_aqua><party></dark_aqua>
|
</gold><green>Name: <dark_aqua><party></dark_aqua>
|
||||||
Password: <dark_aqua><password></dark_aqua>
|
Password: <dark_aqua><password></dark_aqua>
|
||||||
Owner: <owner>
|
Owner: <owner>
|
||||||
Members: <members>""";
|
Members: <members>""";
|
||||||
|
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() {
|
private static void party() {
|
||||||
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
PARTY_FORMAT = getString("party.format", PARTY_FORMAT);
|
||||||
PARTY_SPY = getString("party.spy", PARTY_SPY);
|
PARTY_SPY = getString("party.spy", PARTY_SPY);
|
||||||
|
|
@ -321,21 +358,34 @@ public final class Config {
|
||||||
DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY);
|
DISBANDED_PARTY = getString("party.messages.disbanded-party", DISBANDED_PARTY);
|
||||||
PARTY_INFO = getString("party.messages.party-info", PARTY_INFO);
|
PARTY_INFO = getString("party.messages.party-info", PARTY_INFO);
|
||||||
ALREADY_IN_THIS_PARTY = getString("party.messages.already-in-this-party", ALREADY_IN_THIS_PARTY);
|
ALREADY_IN_THIS_PARTY = getString("party.messages.already-in-this-party", ALREADY_IN_THIS_PARTY);
|
||||||
|
ONLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.online-prefix", "<green>■</green>"));
|
||||||
|
OFFLINE_PREFIX = Utility.parseMiniMessage(getString("party.messages.offline-prefix", "<red>■</red>"));
|
||||||
|
PARTY_TOGGLED = getString("party.messages.party-toggled", PARTY_TOGGLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String PARTY_HELP_WRAPPER = "<gold>ChatParty help:\n<commands></gold>";
|
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_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_CREATE =
|
||||||
public static String PARTY_HELP_INFO = "<green>Show info about your current party: <gold>/party info</gold></green>";
|
"<green>Create a party: <gold>/party create <party_name> <party_password></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_INFO =
|
||||||
public static String PARTY_HELP_JOIN = "<green>Join a party: <gold>/party join <party_name> <party_password></gold></green>";
|
"<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_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_NAME =
|
||||||
public static String PARTY_HELP_OWNER = "<green>Change the owner of your party: <gold>/party owner <new_owner_name></gold></green>";
|
"<green>Change the name of your party: <gold>/party name <new_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_OWNER =
|
||||||
public static String PARTY_HELP_REMOVE = "<green>Remove a member from your party: <gold>/party remove <member_name></gold></green>";
|
"<green>Change the owner of your party: <gold>/party owner <new_owner_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_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>";
|
public static String PARTY_HELP_CHAT = "<green>Talk in party chat: <gold>/p <message></gold></green>";
|
||||||
|
|
||||||
private static void partyHelp() {
|
private static void partyHelp() {
|
||||||
PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER);
|
PARTY_HELP_WRAPPER = getString("party.help.wrapper", PARTY_HELP_WRAPPER);
|
||||||
PARTY_HELP_HELP = getString("party.help.help", PARTY_HELP_HELP);
|
PARTY_HELP_HELP = getString("party.help.help", PARTY_HELP_HELP);
|
||||||
|
|
@ -352,10 +402,18 @@ public final class Config {
|
||||||
PARTY_HELP_CHAT = getString("party.help.chat", PARTY_HELP_CHAT);
|
PARTY_HELP_CHAT = getString("party.help.chat", PARTY_HELP_CHAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String CUSTOM_CHANNEL_TOGGLED = "<yellow>Toggled <channel> <status>.</yellow>";
|
||||||
|
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() {
|
private static void chatChannels() {
|
||||||
ConfigurationNode node = getNode("chat-channels");
|
ConfigurationNode node = getNode("chat-channels");
|
||||||
if (node.empty()) {
|
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"));
|
getList("chat-channels.ac.servers", List.of("lobby"));
|
||||||
getBoolean("chat-channels.ac.proxy", false);
|
getBoolean("chat-channels.ac.proxy", false);
|
||||||
node = getNode("chat-channels");
|
node = getNode("chat-channels");
|
||||||
|
|
@ -367,15 +425,26 @@ public final class Config {
|
||||||
new CustomChannel(channelName,
|
new CustomChannel(channelName,
|
||||||
getString(key + "format", ""),
|
getString(key + "format", ""),
|
||||||
getList(key + "servers", Collections.EMPTY_LIST),
|
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_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 SERVERMUTEPERMISSION = "chat.command.mute-server";
|
||||||
public static String SPYPERMISSION = "chat.socialspy";
|
public static String SPYPERMISSION = "chat.socialspy";
|
||||||
|
|
||||||
private static void permissions() {
|
private static void permissions() {
|
||||||
SERVERMUTEPERMISSION = getString("permissions.server-mute", SERVERMUTEPERMISSION);
|
SERVERMUTEPERMISSION = getString("permissions.server-mute", SERVERMUTEPERMISSION);
|
||||||
SPYPERMISSION = getString("permissions.server-mute", SPYPERMISSION);
|
SPYPERMISSION = getString("permissions.spy-permission", SPYPERMISSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String IP = "0.0.0.0";
|
public static String IP = "0.0.0.0";
|
||||||
|
|
@ -383,6 +452,7 @@ public final class Config {
|
||||||
public static String DATABASE = "database";
|
public static String DATABASE = "database";
|
||||||
public static String USERNAME = "root";
|
public static String USERNAME = "root";
|
||||||
public static String PASSWORD = "root";
|
public static String PASSWORD = "root";
|
||||||
|
|
||||||
private static void database() {
|
private static void database() {
|
||||||
IP = getString("database.ip", IP);
|
IP = getString("database.ip", IP);
|
||||||
PORT = getString("database.port", PORT);
|
PORT = getString("database.port", PORT);
|
||||||
|
|
@ -392,18 +462,25 @@ public final class Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String NOTIFICATIONFORMAT = "<red>[<prefix>] <displayname> <target> <input>";
|
public static String NOTIFICATIONFORMAT = "<red>[<prefix>] <displayname> <target> <input>";
|
||||||
|
|
||||||
private static void notificationSettings() {
|
private static void notificationSettings() {
|
||||||
NOTIFICATIONFORMAT = getString("settings.blockedmessage-notification", NOTIFICATIONFORMAT);
|
NOTIFICATIONFORMAT = getString("settings.blockedmessage-notification", NOTIFICATIONFORMAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String mailHeader = "===== List Mails ====='";
|
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 mailFooter = "======================";
|
||||||
public static String mailNoUser = "<red>A player with this name hasn't logged in recently.";
|
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 mailReceived =
|
||||||
public static String mailUnread = "<green><click:run_command:/mail list unread>You have <amount> unread mail, click to view it.</click></green>";
|
"<yellow><click:run_command:/mail list unread>New mail from <sender>, click to view</click></yellow>";
|
||||||
public static String mailSent = "<green>Successfully send mail to <player_name></green>: <#2e8b57><message></#2e8b57>";
|
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 List<String> mailCommandAlias = new ArrayList<>();
|
||||||
|
public static int mailDisplayDelay = 5;
|
||||||
|
|
||||||
private static void mailSettings() {
|
private static void mailSettings() {
|
||||||
mailHeader = getString("settings.mail.header", mailHeader);
|
mailHeader = getString("settings.mail.header", mailHeader);
|
||||||
mailBody = getString("settings.mail.message", mailBody);
|
mailBody = getString("settings.mail.message", mailBody);
|
||||||
|
|
@ -412,10 +489,15 @@ public final class Config {
|
||||||
mailReceived = getString("settings.mail.mail-received", mailReceived);
|
mailReceived = getString("settings.mail.mail-received", mailReceived);
|
||||||
mailUnread = getString("settings.mail.mail-unread", mailUnread);
|
mailUnread = getString("settings.mail.mail-unread", mailUnread);
|
||||||
mailSent = getString("settings.mail.mail-sent", mailSent);
|
mailSent = getString("settings.mail.mail-sent", mailSent);
|
||||||
|
mailDisplayDelay = getInt("settings.mail.delay", mailDisplayDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<String, Long> serverChannelId = new HashMap<>();
|
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_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() {
|
private static void loadChannelIds() {
|
||||||
serverChannelId.clear();
|
serverChannelId.clear();
|
||||||
serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1));
|
serverChannelId.put("general", getLong("discord-channel-id.general", (long) -1));
|
||||||
|
|
@ -423,17 +505,140 @@ public final class Config {
|
||||||
Map<Object, ? extends ConfigurationNode> objectMap = node.childrenMap();
|
Map<Object, ? extends ConfigurationNode> objectMap = node.childrenMap();
|
||||||
for (Object o : objectMap.keySet()) {
|
for (Object o : objectMap.keySet()) {
|
||||||
String key = (String) o;
|
String key = (String) o;
|
||||||
if (key.equalsIgnoreCase("general"))
|
if (key.equalsIgnoreCase("general")) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
ConfigurationNode configurationNode = objectMap.get(o);
|
ConfigurationNode configurationNode = objectMap.get(o);
|
||||||
long channelId = configurationNode.getLong();
|
long channelId = configurationNode.getLong();
|
||||||
serverChannelId.put(key.toLowerCase(), channelId);
|
serverChannelId.put(key.toLowerCase(), channelId);
|
||||||
}
|
}
|
||||||
REPORT_SENT = getString("messages.report-sent", REPORT_SENT);
|
REPORT_SENT = getString("messages.report-sent", REPORT_SENT);
|
||||||
|
REPORT_TOO_SHORT = getString("messages.report-too-short", REPORT_TOO_SHORT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> SILENT_JOIN_COMMAND_ALIASES = new ArrayList<>();
|
||||||
|
public static String SILENT_JOIN_NO_SERVER = "<red>Unable to find destination server</red>";
|
||||||
|
public static String SILENT_JOIN_JOINING = "<green>Sending you to <server> silently.</green>";
|
||||||
|
public static String SILENT_JOIN_JOINED_FROM = "<gold>* <player> silent joined from <from_server>...</gold>";
|
||||||
|
public static String SILENT_JOIN_JOINED = "<gold>* <player> silent joined...</gold>";
|
||||||
|
|
||||||
|
private static void silentJoinCommand() {
|
||||||
|
SILENT_JOIN_COMMAND_ALIASES = getList("commands.silent-join.aliases", Lists.newArrayList("sj"));
|
||||||
|
SILENT_JOIN_NO_SERVER = getString("commands.silent-join.no-server", SILENT_JOIN_NO_SERVER);
|
||||||
|
SILENT_JOIN_JOINING = getString("commands.silent-join.joining", SILENT_JOIN_JOINING);
|
||||||
|
SILENT_JOIN_JOINED_FROM = getString("commands.silent-join.joined-from", SILENT_JOIN_JOINED_FROM);
|
||||||
|
SILENT_JOIN_JOINED = getString("commands.silent-join.joined", SILENT_JOIN_JOINED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String HELP_REPORT = "<red>/report <message></red>";
|
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>";
|
||||||
|
|
||||||
private static void loadMessages() {
|
private static void loadMessages() {
|
||||||
HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT);
|
HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT);
|
||||||
|
FIRST_JOIN = getString("settings.first-join.message", FIRST_JOIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
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> >>----";
|
||||||
|
|
||||||
|
private static void emoteListCommand() {
|
||||||
|
EMOTELIST_HEADER = getString("commands.emotelist.header", EMOTELIST_HEADER);
|
||||||
|
EMOTELIST_ITEM = getString("commands.emotelist.item", EMOTELIST_ITEM);
|
||||||
|
EMOTELIST_FOOTER = getString("commands.emotelist.footer", EMOTELIST_FOOTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
// nicknames TODO minimessage for colors and placeholders
|
||||||
|
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_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_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_NEW = "<green>New nickname request by <player><green>!";
|
||||||
|
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_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>)";
|
||||||
|
|
||||||
|
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);
|
||||||
|
NICK_RESET = getString("nicknames.messages.nick-reset", NICK_RESET);
|
||||||
|
NICK_CHANGED_OTHERS = getString("nicknames.messages.nick-changed-others", NICK_CHANGED_OTHERS);
|
||||||
|
NICK_TARGET_NICK_CHANGE = getString("nicknames.messages.nick-target-nick-change", NICK_TARGET_NICK_CHANGE);
|
||||||
|
NICK_RESET_OTHERS = getString("nicknames.messages.nick-reset-others", NICK_RESET_OTHERS);
|
||||||
|
NICK_INVALID_CHARACTERS = getString("nicknames.messages.nick-invalid-characters", NICK_INVALID_CHARACTERS);
|
||||||
|
NICK_INVALID_LENGTH = getString("nicknames.messages.nick-invalid-length", NICK_INVALID_LENGTH);
|
||||||
|
NICK_PLAYER_NOT_ONLINE = getString("nicknames.messages.nick-player-not-online", NICK_PLAYER_NOT_ONLINE);
|
||||||
|
NICK_BLOCKED_COLOR_CODES = getString("nicknames.messages.nick-blocked-color-codes", NICK_BLOCKED_COLOR_CODES);
|
||||||
|
NICK_USER_NOT_FOUND = getString("nicknames.messages.nick-user-not-found", NICK_USER_NOT_FOUND);
|
||||||
|
NICK_ACCEPTED = getString("nicknames.messages.nick-accepted", NICK_ACCEPTED);
|
||||||
|
NICK_DENIED = getString("nicknames.messages.nick-denied", NICK_DENIED);
|
||||||
|
NICK_ALREADY_HANDLED = getString("nicknames.messages.nick-already-handled", NICK_ALREADY_HANDLED);
|
||||||
|
NICK_NO_LUCKPERMS = getString("nicknames.messages.nick-no-luckperms", NICK_NO_LUCKPERMS);
|
||||||
|
NICK_TOO_SOON = getString("nicknames.messages.nick-too-soon", NICK_TOO_SOON);
|
||||||
|
NICK_REQUEST_PLACED = getString("nicknames.messages.nick-request-placed", NICK_REQUEST_PLACED);
|
||||||
|
NICK_REQUEST_NEW = getString("nicknames.messages.nick-request-new", NICK_REQUEST_NEW);
|
||||||
|
NICK_TRYOUT = getString("nicknames.messages.nick-tryout", NICK_TRYOUT);
|
||||||
|
NICK_REQUESTED = getString("nicknames.messages.nick-requested", NICK_REQUESTED);
|
||||||
|
NICK_REVIEW_WAITING = getString("nicknames.messages.nick-review-waiting", NICK_REVIEW_WAITING);
|
||||||
|
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_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_CURRENT = getString("nicknames.messages.nick-current", NICK_CURRENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int DEATH_MESSAGES_MAX_PER_PERIOD = 5;
|
||||||
|
public static int DEATH_MESSAGES_LIMIT_PERIOD_MINUTES = 15;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long CHAT_LOG_DELETE_OLDER_THAN_DAYS = 31;
|
||||||
|
public static long CHAT_LOG_SAVE_DELAY_MINUTES = 5;
|
||||||
|
|
||||||
|
private static void chatLogSettings() {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ public final class PrefixConfig {
|
||||||
CONFIG_FILE = new File(Config.CONFIGPATH, "prefix.yml");
|
CONFIG_FILE = new File(Config.CONFIGPATH, "prefix.yml");
|
||||||
configLoader = YamlConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.file(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.nodeStyle(NodeStyle.FLOW)
|
.nodeStyle(NodeStyle.BLOCK)
|
||||||
.build();
|
.build();
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
if(!CONFIG_FILE.getParentFile().mkdirs()) {
|
||||||
|
|
@ -80,7 +80,7 @@ public final class PrefixConfig {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,7 +88,7 @@ public final class PrefixConfig {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +96,7 @@ public final class PrefixConfig {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +109,7 @@ public final class PrefixConfig {
|
||||||
try {
|
try {
|
||||||
config.node(splitPath(path)).set(def);
|
config.node(splitPath(path)).set(def);
|
||||||
} catch (SerializationException e) {
|
} catch (SerializationException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -118,6 +119,7 @@ public final class PrefixConfig {
|
||||||
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);
|
config.node(splitPath(path)).set(io.leangen.geantyref.TypeToken.get(String.class), def);
|
||||||
} catch(SerializationException ex) {
|
} catch(SerializationException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,12 @@ package com.alttd.chat.config;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatFilter;
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.google.common.base.Throwables;
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
import org.spongepowered.configurate.ConfigurationNode;
|
import org.spongepowered.configurate.ConfigurationNode;
|
||||||
import org.spongepowered.configurate.ConfigurationOptions;
|
import org.spongepowered.configurate.ConfigurationOptions;
|
||||||
import org.spongepowered.configurate.serialize.SerializationException;
|
import org.spongepowered.configurate.serialize.SerializationException;
|
||||||
import org.spongepowered.configurate.yaml.NodeStyle;
|
import org.spongepowered.configurate.yaml.NodeStyle;
|
||||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -38,7 +36,7 @@ public final class RegexConfig {
|
||||||
CONFIG_FILE = new File(Config.CONFIGPATH, "filters.yml");
|
CONFIG_FILE = new File(Config.CONFIGPATH, "filters.yml");
|
||||||
configLoader = YamlConfigurationLoader.builder()
|
configLoader = YamlConfigurationLoader.builder()
|
||||||
.file(CONFIG_FILE)
|
.file(CONFIG_FILE)
|
||||||
.nodeStyle(NodeStyle.FLOW)
|
.nodeStyle(NodeStyle.BLOCK)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
if (!CONFIG_FILE.getParentFile().exists()) {
|
if (!CONFIG_FILE.getParentFile().exists()) {
|
||||||
|
|
@ -78,7 +76,7 @@ public final class RegexConfig {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
method.invoke(instance);
|
method.invoke(instance);
|
||||||
} catch (InvocationTargetException | IllegalAccessException ex) {
|
} catch (InvocationTargetException | IllegalAccessException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +84,7 @@ public final class RegexConfig {
|
||||||
try {
|
try {
|
||||||
configLoader.save(config);
|
configLoader.save(config);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw Throwables.propagate(ex.getCause());
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,13 +178,18 @@ public final class RegexConfig {
|
||||||
String regex = entry.getValue().node("regex").getString();
|
String regex = entry.getValue().node("regex").getString();
|
||||||
String replacement = entry.getValue().node("replacement").getString();
|
String replacement = entry.getValue().node("replacement").getString();
|
||||||
List<String> exclusions = entry.getValue().node("exclusions").getList(io.leangen.geantyref.TypeToken.get(String.class), new ArrayList<>());
|
List<String> exclusions = entry.getValue().node("exclusions").getList(io.leangen.geantyref.TypeToken.get(String.class), new ArrayList<>());
|
||||||
|
boolean disableInPrivate = false;
|
||||||
|
ConfigurationNode node = entry.getValue().node("disable-in-private");
|
||||||
|
if (node != null) {
|
||||||
|
disableInPrivate = node.getBoolean();
|
||||||
|
}
|
||||||
if (type == null || type.isEmpty() || regex == null || regex.isEmpty()) {
|
if (type == null || type.isEmpty() || regex == null || regex.isEmpty()) {
|
||||||
ALogger.warn("Filter: " + name + " was set up incorrectly");
|
ALogger.warn("Filter: " + name + " was set up incorrectly");
|
||||||
} else {
|
} else {
|
||||||
if (replacement == null || replacement.isEmpty()) {
|
if (replacement == null || replacement.isEmpty()) {
|
||||||
replacement = name;
|
replacement = name;
|
||||||
}
|
}
|
||||||
ChatFilter chatFilter = new ChatFilter(name, type, regex, replacement, exclusions);
|
ChatFilter chatFilter = new ChatFilter(name, type, regex, replacement, exclusions, disableInPrivate);
|
||||||
RegexManager.addFilter(chatFilter);
|
RegexManager.addFilter(chatFilter);
|
||||||
}
|
}
|
||||||
} catch(SerializationException ex) {
|
} catch(SerializationException ex) {
|
||||||
|
|
|
||||||
|
|
@ -74,9 +74,11 @@ public final class ServerConfig {
|
||||||
public boolean GLOBALCHAT = false;
|
public boolean GLOBALCHAT = false;
|
||||||
public boolean JOINLEAVEMSSAGES = true;
|
public boolean JOINLEAVEMSSAGES = true;
|
||||||
public boolean MUTED = false;
|
public boolean MUTED = false;
|
||||||
|
public boolean FIRST_JOIN_MESSAGES = false;
|
||||||
private void ServerSettings() {
|
private void ServerSettings() {
|
||||||
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
GLOBALCHAT = getBoolean("global-chat-enabled", GLOBALCHAT);
|
||||||
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
JOINLEAVEMSSAGES = getBoolean("joinleave-messages-enabled", JOINLEAVEMSSAGES);
|
||||||
MUTED = getBoolean("server-muted", MUTED);
|
MUTED = getBoolean("server-muted", MUTED);
|
||||||
|
FIRST_JOIN_MESSAGES = getBoolean("first-join-messages", FIRST_JOIN_MESSAGES);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,98 @@
|
||||||
|
package com.alttd.chat.database;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLog;
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CompletionException;
|
||||||
|
|
||||||
|
public class ChatLogQueries {
|
||||||
|
|
||||||
|
protected static void createChatLogTable() {
|
||||||
|
String nicknamesTableQuery = "CREATE TABLE IF NOT EXISTS chat_log("
|
||||||
|
+ "uuid CHAR(48) NOT NULL,"
|
||||||
|
+ "time_stamp TIMESTAMP(6) NOT NULL, "
|
||||||
|
+ "server VARCHAR(50) NOT NULL, "
|
||||||
|
+ "chat_message VARCHAR(300) NOT NULL, "
|
||||||
|
+ "blocked BIT(1) NOT NULL DEFAULT 0"
|
||||||
|
+ ")";
|
||||||
|
|
||||||
|
try (PreparedStatement preparedStatement = DatabaseConnection.getConnection().prepareStatement(nicknamesTableQuery)) {
|
||||||
|
preparedStatement.executeUpdate();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
ALogger.error("Failed to create chat log table", throwable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull CompletableFuture<Boolean> storeMessages(HashMap<UUID, List<ChatLog>> chatMessages) {
|
||||||
|
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, blocked) VALUES (?, ?, ?, ?, ?)";
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
try (Connection connection = DatabaseConnection.createTransactionConnection()) {
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
||||||
|
for (List<ChatLog> chatLogList : chatMessages.values()) {
|
||||||
|
for (ChatLog chatLog : chatLogList) {
|
||||||
|
chatLog.prepareStatement(preparedStatement);
|
||||||
|
preparedStatement.addBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int[] updatedRowsCount = preparedStatement.executeBatch();
|
||||||
|
boolean isSuccess = Arrays.stream(updatedRowsCount).allMatch(i -> i >= 0);
|
||||||
|
|
||||||
|
if (isSuccess) {
|
||||||
|
connection.commit();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
connection.rollback();
|
||||||
|
ALogger.warn("Failed to store messages");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (SQLException sqlException) {
|
||||||
|
ALogger.error("Failed to store chat messages", sqlException);
|
||||||
|
throw new CompletionException("Failed to store chat messages", sqlException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @NotNull CompletableFuture<List<ChatLog>> retrieveMessages(ChatLogHandler chatLogHandler, UUID uuid, Duration duration, String server) {
|
||||||
|
String query = "SELECT * FROM chat_log WHERE uuid = ? AND time_stamp > ? AND server = ?";
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||||
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
preparedStatement.setTimestamp(2, Timestamp.from(Instant.now().minus(duration)));
|
||||||
|
preparedStatement.setString(3, server);
|
||||||
|
ResultSet resultSet = preparedStatement.executeQuery();
|
||||||
|
List<ChatLog> chatLogs = new ArrayList<>();
|
||||||
|
while (resultSet.next()) {
|
||||||
|
ChatLog chatLog = chatLogHandler.loadFromResultSet(resultSet);
|
||||||
|
chatLogs.add(chatLog);
|
||||||
|
}
|
||||||
|
return chatLogs;
|
||||||
|
} catch (SQLException sqlException) {
|
||||||
|
ALogger.error(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
||||||
|
throw new CompletionException(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Boolean> deleteOldMessages(Duration duration) {
|
||||||
|
String query = "DELETE FROM chat_log WHERE time_stamp < ?";
|
||||||
|
|
||||||
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
||||||
|
preparedStatement.setTimestamp(1, Timestamp.from(Instant.now().minus(duration)));
|
||||||
|
return preparedStatement.execute();
|
||||||
|
} catch (SQLException sqlException) {
|
||||||
|
ALogger.error(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
||||||
|
throw new CompletionException(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,7 +2,6 @@ package com.alttd.chat.database;
|
||||||
|
|
||||||
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.util.ALogger;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
|
@ -66,6 +65,21 @@ public class DatabaseConnection {
|
||||||
return connection;
|
return connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a transactional database connection.
|
||||||
|
*
|
||||||
|
* @return A {@code Connection} object representing the transactional database connection.
|
||||||
|
* @throws SQLException If there is an error creating the database connection.
|
||||||
|
*/
|
||||||
|
public static Connection createTransactionConnection() throws SQLException {
|
||||||
|
connection = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true"+
|
||||||
|
"&useSSL=false",
|
||||||
|
Config.USERNAME, Config.PASSWORD);
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the connection for this instance
|
* Sets the connection for this instance
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,13 @@
|
||||||
package com.alttd.chat.database;
|
package com.alttd.chat.database;
|
||||||
|
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.*;
|
||||||
import com.alttd.chat.objects.Mail;
|
|
||||||
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.Channel;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class Queries {
|
public class Queries {
|
||||||
|
|
||||||
|
|
@ -24,7 +19,9 @@ public class Queries {
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_channel` VARCHAR(36) NULL DEFAULT NULL, PRIMARY KEY (`uuid`))");
|
tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_channel` VARCHAR(36) NULL DEFAULT NULL, PRIMARY KEY (`uuid`))");
|
||||||
tables.add("CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `sender` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`))");
|
tables.add("CREATE TABLE IF NOT EXISTS mails (`id` INT NOT NULL AUTO_INCREMENT, `uuid` VARCHAR(36) NOT NULL, `sender` VARCHAR(36) NOT NULL, `message` VARCHAR(256) NOT NULL, `sendtime` BIGINT default 0, `readtime` BIGINT default 0, PRIMARY KEY (`id`))");
|
||||||
|
createNicknamesTable();
|
||||||
|
createRequestedNicknamesTable();
|
||||||
|
ChatLogQueries.createChatLogTable();
|
||||||
try {
|
try {
|
||||||
Connection connection = DatabaseConnection.getConnection();
|
Connection connection = DatabaseConnection.getConnection();
|
||||||
|
|
||||||
|
|
@ -39,6 +36,51 @@ public class Queries {
|
||||||
//-----------------------------------------
|
//-----------------------------------------
|
||||||
|
|
||||||
//Nicknames
|
//Nicknames
|
||||||
|
private static void createNicknamesTable() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String nicknamesTableQuery = "CREATE TABLE IF NOT EXISTS nicknames("
|
||||||
|
+ "uuid VARCHAR(48) NOT NULL,"
|
||||||
|
+ "PRIMARY KEY (uuid))";
|
||||||
|
DatabaseConnection.getConnection().prepareStatement(nicknamesTableQuery).executeUpdate();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> columns = new ArrayList<>();
|
||||||
|
columns.add("ALTER TABLE nicknames ADD nickname VARCHAR(192)");
|
||||||
|
columns.add("ALTER TABLE nicknames ADD date_changed BIGINT default 0");
|
||||||
|
for (String string : columns) {
|
||||||
|
try {
|
||||||
|
DatabaseConnection.getConnection().prepareStatement(string).executeUpdate();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createRequestedNicknamesTable() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
String requestedNicknamesTableQuery = "CREATE TABLE IF NOT EXISTS requested_nicknames("
|
||||||
|
+ "uuid VARCHAR(48) NOT NULL,"
|
||||||
|
+ "PRIMARY KEY (uuid))";
|
||||||
|
DatabaseConnection.getConnection().prepareStatement(requestedNicknamesTableQuery).executeUpdate();
|
||||||
|
} catch (Throwable throwable) {
|
||||||
|
throwable.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> columns = new ArrayList<>();
|
||||||
|
columns.add("ALTER TABLE requested_nicknames ADD nickname VARCHAR(192)");
|
||||||
|
columns.add("ALTER TABLE requested_nicknames ADD date_requested BIGINT default 0");
|
||||||
|
for (String string : columns) {
|
||||||
|
try {
|
||||||
|
DatabaseConnection.getConnection().prepareStatement(string).executeUpdate();
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static String getNickname(UUID uuid) {
|
public static String getNickname(UUID uuid) {
|
||||||
// View has been created.
|
// View has been created.
|
||||||
|
|
@ -564,4 +606,172 @@ public class Queries {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nicknames
|
||||||
|
public static void setNicknameInDatabase(final UUID uuid, final String nickName) {
|
||||||
|
final String sql = "INSERT INTO nicknames (uuid, nickname, date_changed) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE nickname = ?";
|
||||||
|
try (final PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement(sql)) {
|
||||||
|
statement.setString(1, uuid.toString());
|
||||||
|
statement.setString(2, nickName);
|
||||||
|
statement.setLong(3, new java.util.Date().getTime());
|
||||||
|
statement.setString(4, nickName);
|
||||||
|
statement.execute();
|
||||||
|
}
|
||||||
|
catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlayerFromDataBase(final UUID uuid) throws SQLException {
|
||||||
|
final PreparedStatement insert = DatabaseConnection.getConnection().prepareStatement("DELETE FROM nicknames WHERE uuid = ?");
|
||||||
|
insert.setString(1, uuid.toString());
|
||||||
|
insert.executeUpdate();
|
||||||
|
insert.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<Nick> getNicknamesList() {
|
||||||
|
ArrayList<Nick> nickList = new ArrayList<>();
|
||||||
|
String queryNicknames = "SELECT uuid, nickname, date_changed FROM nicknames ";
|
||||||
|
String queryRequests = "SELECT `requested_nicknames`.`nickname` AS new_nick, `requested_nicknames`.`date_requested`, " +
|
||||||
|
"`nicknames`.`nickname` AS old_nick, `nicknames`.`date_changed`, `requested_nicknames`.`uuid` " +
|
||||||
|
"FROM `requested_nicknames`" +
|
||||||
|
"LEFT JOIN `nicknames` ON `requested_nicknames`.`uuid` = `nicknames`.`uuid` ";
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResultSet resultSetNicknames = getStringResult(queryNicknames);
|
||||||
|
while (resultSetNicknames.next()){
|
||||||
|
nickList.add(new Nick(
|
||||||
|
UUID.fromString(resultSetNicknames.getString("uuid")),
|
||||||
|
resultSetNicknames.getString("nickname"),
|
||||||
|
resultSetNicknames.getLong("date_changed")));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultSet resultSetRequests = getStringResult(queryRequests);
|
||||||
|
while (resultSetRequests.next()){
|
||||||
|
nickList.add(new Nick(
|
||||||
|
UUID.fromString(resultSetRequests.getString("uuid")),
|
||||||
|
resultSetRequests.getString("old_nick"),
|
||||||
|
resultSetRequests.getLong("date_changed"),
|
||||||
|
resultSetRequests.getString("new_nick"),
|
||||||
|
resultSetRequests.getLong("date_requested")));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.warn("Failed to get nicknames list\n" + Arrays.toString(e.getStackTrace())
|
||||||
|
.replace(",", "\n"));
|
||||||
|
}
|
||||||
|
return nickList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Nick getNick(UUID uniqueId) {
|
||||||
|
String getNick = "SELECT nickname, date_changed, uuid FROM nicknames WHERE uuid = ?";
|
||||||
|
String getRequest = "SELECT nickname, date_requested, uuid FROM requested_nicknames WHERE uuid = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
ResultSet resultSetNick = getStringResult(getNick, uniqueId.toString());
|
||||||
|
ResultSet resultSetRequest = getStringResult(getRequest, uniqueId.toString());
|
||||||
|
String uuid = null;
|
||||||
|
String currentNick = null;
|
||||||
|
long dateChanged = 0;
|
||||||
|
String requestedNick = null;
|
||||||
|
long dateRequested = 0;
|
||||||
|
|
||||||
|
if (resultSetNick.next()) {
|
||||||
|
uuid = resultSetNick.getString("uuid");
|
||||||
|
currentNick = resultSetNick.getString("nickname");
|
||||||
|
dateChanged = resultSetNick.getLong("date_changed");
|
||||||
|
}
|
||||||
|
if (resultSetRequest.next()) {
|
||||||
|
uuid = resultSetRequest.getString("uuid");
|
||||||
|
requestedNick = resultSetRequest.getString("nickname");
|
||||||
|
dateRequested = resultSetRequest.getLong("date_requested");
|
||||||
|
}
|
||||||
|
if (uuid != null) {
|
||||||
|
return new Nick(UUID.fromString(uuid), currentNick, dateChanged, requestedNick, dateRequested);
|
||||||
|
}
|
||||||
|
} catch (SQLException e){
|
||||||
|
ALogger.warn("Failed to get nicknames for "
|
||||||
|
+ uniqueId.toString() + "\n" + Arrays.toString(e.getStackTrace())
|
||||||
|
.replace(",", "\n"));
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void denyNewNickname(UUID uniqueId) {
|
||||||
|
String query = "DELETE FROM requested_nicknames WHERE uuid = ?";
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement(query);
|
||||||
|
statement.setString(1, uniqueId.toString());
|
||||||
|
statement.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.warn("Failed to delete requested nickname for "
|
||||||
|
+ uniqueId.toString() + "\n" + Arrays.toString(e.getStackTrace())
|
||||||
|
.replace(",", "\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void acceptNewNickname(UUID uniqueId, String newNick){
|
||||||
|
String delete = "DELETE FROM requested_nicknames WHERE uuid = ?";
|
||||||
|
String update = "INSERT INTO nicknames (uuid, nickname, date_changed) VALUES (?, ?, ?) " +
|
||||||
|
"ON DUPLICATE KEY UPDATE nickname = ?, date_changed = ?";
|
||||||
|
long time = new java.util.Date().getTime();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement deleteStatement = DatabaseConnection.getConnection().prepareStatement(delete);
|
||||||
|
deleteStatement.setString(1, uniqueId.toString());
|
||||||
|
|
||||||
|
deleteStatement.execute();
|
||||||
|
|
||||||
|
PreparedStatement updateStatement = DatabaseConnection.getConnection().prepareStatement(update);
|
||||||
|
updateStatement.setString(1, uniqueId.toString());
|
||||||
|
updateStatement.setString(2, newNick);
|
||||||
|
updateStatement.setLong(3, time);
|
||||||
|
updateStatement.setString(4, newNick);
|
||||||
|
updateStatement.setLong(5, time);
|
||||||
|
|
||||||
|
updateStatement.execute();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.warn("Failed to accept requested nickname for "
|
||||||
|
+ uniqueId.toString() + "\n" + Arrays.toString(e.getStackTrace())
|
||||||
|
.replace(",", "\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void newNicknameRequest(UUID uniqueId, String nickName) {
|
||||||
|
String requestQuery = "INSERT INTO requested_nicknames (uuid, nickname, date_requested) VALUES (?, ?, ?) " +
|
||||||
|
"ON DUPLICATE KEY UPDATE nickname = ?, date_requested = ?";
|
||||||
|
String nickQuery = "INSERT INTO nicknames (uuid, nickname, date_changed) VALUES (?, ?, 0) " +
|
||||||
|
"ON DUPLICATE KEY UPDATE uuid = uuid";
|
||||||
|
long time = new Date().getTime();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement requestPreparedStatement = DatabaseConnection.getConnection().prepareStatement(requestQuery);
|
||||||
|
requestPreparedStatement.setString(1, uniqueId.toString());
|
||||||
|
requestPreparedStatement.setString(2, nickName);
|
||||||
|
requestPreparedStatement.setLong(3, time);
|
||||||
|
requestPreparedStatement.setString(4, nickName);
|
||||||
|
requestPreparedStatement.setLong(5, time);
|
||||||
|
|
||||||
|
requestPreparedStatement.execute();
|
||||||
|
|
||||||
|
PreparedStatement nickPreparedStatement = DatabaseConnection.getConnection().prepareStatement(nickQuery);
|
||||||
|
nickPreparedStatement.setString(1, uniqueId.toString());
|
||||||
|
nickPreparedStatement.setString(2, null);
|
||||||
|
|
||||||
|
nickPreparedStatement.execute();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.warn("Failed to store requested nickname for "
|
||||||
|
+ uniqueId.toString() + "\n" + Arrays.toString(e.getStackTrace())
|
||||||
|
.replace(",", "\n"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ResultSet getStringResult(final String query, final String... parameters) throws SQLException {
|
||||||
|
final PreparedStatement statement = DatabaseConnection.getConnection().prepareStatement(query);
|
||||||
|
for (int i = 1; i < parameters.length + 1; ++i) {
|
||||||
|
statement.setString(i, parameters[i - 1]);
|
||||||
|
}
|
||||||
|
return statement.executeQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
56
api/src/main/java/com/alttd/chat/events/NickEvent.java
Normal file
56
api/src/main/java/com/alttd/chat/events/NickEvent.java
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.alttd.chat.events;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class NickEvent extends Event{
|
||||||
|
|
||||||
|
String senderName;
|
||||||
|
String targetName;
|
||||||
|
String nickName;
|
||||||
|
NickEventType nickEventType;
|
||||||
|
|
||||||
|
public NickEvent(String senderName, String targetName, String nickName, NickEventType nickEventType) {
|
||||||
|
this.senderName = senderName;
|
||||||
|
this.targetName = targetName;
|
||||||
|
this.nickName = nickName;
|
||||||
|
this.nickEventType = nickEventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSenderName() {
|
||||||
|
return this.senderName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetName() {
|
||||||
|
return this.targetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNickName() {
|
||||||
|
return this.nickName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NickEventType getNickEventType() {
|
||||||
|
return this.nickEventType;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final HandlerList HANDLERS = new HandlerList();
|
||||||
|
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return HANDLERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum NickEventType {
|
||||||
|
ACCEPTED,
|
||||||
|
DENIED,
|
||||||
|
SET,
|
||||||
|
RESET
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,10 +2,10 @@ package com.alttd.chat.managers;
|
||||||
|
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Mail;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.TreeMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class ChatUserManager {
|
public final class ChatUserManager {
|
||||||
|
|
||||||
|
|
@ -15,15 +15,15 @@ public final class ChatUserManager {
|
||||||
chatUsers = new TreeMap<>();
|
chatUsers = new TreeMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addUser(ChatUser user) {
|
public static synchronized void addUser(ChatUser user) {
|
||||||
chatUsers.put(user.getUuid(), user);
|
chatUsers.put(user.getUuid(), user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeUser(ChatUser user) {
|
public static synchronized void removeUser(ChatUser user) {
|
||||||
chatUsers.remove(user.getUuid());
|
chatUsers.remove(user.getUuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatUser getChatUser(UUID uuid) {
|
public static synchronized ChatUser getChatUser(UUID uuid) {
|
||||||
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
|
return chatUsers.computeIfAbsent(uuid, k -> Queries.loadChatUser(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,25 +3,42 @@ package com.alttd.chat.managers;
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.config.RegexConfig;
|
import com.alttd.chat.config.RegexConfig;
|
||||||
import com.alttd.chat.objects.ChatFilter;
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
|
import com.alttd.chat.objects.FilterType;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import net.luckperms.api.cacheddata.CachedPermissionData;
|
import net.luckperms.api.cacheddata.CachedPermissionData;
|
||||||
import net.luckperms.api.model.user.User;
|
import net.luckperms.api.model.user.User;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class RegexManager {
|
public class RegexManager {
|
||||||
|
|
||||||
private static List<ChatFilter> chatFilters;
|
private static List<ChatFilter> chatFilters;
|
||||||
private static final Pattern pattern = Pattern.compile("(.)\\1{4,}");
|
private static final Pattern pattern = Pattern.compile("(.)\\1{4,}");
|
||||||
|
private static final List<ChatFilter> emotes = new ArrayList<>();
|
||||||
|
public static final List<String> emotesList = new ArrayList<>();
|
||||||
|
|
||||||
public static void initialize() {
|
public static void initialize() {
|
||||||
chatFilters = new ArrayList<>();
|
chatFilters = new ArrayList<>();
|
||||||
|
|
||||||
RegexConfig.init();
|
RegexConfig.init();
|
||||||
|
loadEmotes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void loadEmotes() {
|
||||||
|
emotes.clear();
|
||||||
|
for(ChatFilter chatFilter : chatFilters) {
|
||||||
|
if (chatFilter.getType() != FilterType.EMOTE) continue;
|
||||||
|
|
||||||
|
emotes.add(chatFilter);
|
||||||
|
emotesList.add(chatFilter.getRegex());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addFilter(ChatFilter filter) {
|
public static void addFilter(ChatFilter filter) {
|
||||||
|
|
@ -29,17 +46,24 @@ public class RegexManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, String channel) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, String channel) { // TODO loop all objects in the list and check if they violate based on the MATCHER
|
||||||
return filterText(playerName, uuid, modifiableString, true, channel);
|
return filterText(playerName, uuid, modifiableString, true, channel, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) {
|
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel) {
|
||||||
|
return filterText(playerName, uuid, modifiableString, matcher, channel, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean filterText(String playerName, UUID uuid, ModifiableString modifiableString, boolean matcher, String channel, Consumer<FilterType> filterAction) {
|
||||||
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
User user = ChatAPI.get().getLuckPerms().getUserManager().getUser(uuid);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
ALogger.warn("Tried to check chat filters for a user who doesn't exist in LuckPerms");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
CachedPermissionData permissionData = user.getCachedData().getPermissionData();
|
CachedPermissionData permissionData = user.getCachedData().getPermissionData();
|
||||||
|
boolean isPrivate = channel.equals("party");
|
||||||
for(ChatFilter chatFilter : chatFilters) {
|
for(ChatFilter chatFilter : chatFilters) {
|
||||||
|
if (isPrivate && chatFilter.isDisabledInPrivate())
|
||||||
|
continue;
|
||||||
switch (chatFilter.getType()) {
|
switch (chatFilter.getType()) {
|
||||||
case CHAT:
|
case CHAT:
|
||||||
break;
|
break;
|
||||||
|
|
@ -50,7 +74,8 @@ public class RegexManager {
|
||||||
if(!permissionData.checkPermission("chat.bypass-filter-channel." + channel).asBoolean() &&
|
if(!permissionData.checkPermission("chat.bypass-filter-channel." + channel).asBoolean() &&
|
||||||
!permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean() &&
|
!permissionData.checkPermission("chat.bypass-filter." + chatFilter.getName()).asBoolean() &&
|
||||||
chatFilter.matches(modifiableString)) { // todo find a better way to do this?
|
chatFilter.matches(modifiableString)) { // todo find a better way to do this?
|
||||||
ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName() + ".");
|
ALogger.info(playerName + " triggered the chat filter for " + chatFilter.getName()
|
||||||
|
+ " with: " + modifiableString.string() + ".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -59,9 +84,35 @@ public class RegexManager {
|
||||||
chatFilter.replaceMatcher(modifiableString);
|
chatFilter.replaceMatcher(modifiableString);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case PUNISH:
|
||||||
|
if (permissionData.checkPermission("chat.bypass-punish").asBoolean())
|
||||||
|
break;
|
||||||
|
if (chatFilter.matches(modifiableString)) {
|
||||||
|
ALogger.info(playerName + " triggered the punish filter for " + chatFilter.getName()
|
||||||
|
+ " with: " + modifiableString.string() + ".");
|
||||||
|
|
||||||
|
if (filterAction == null){
|
||||||
|
ALogger.info("No filterAction was provided, not doing anything");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) {
|
||||||
|
ALogger.warn("Tried to punish a player who triggered the filter, but the player is offline.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
filterAction.accept(FilterType.PUNISH);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<ChatFilter> getChatFilters() {
|
||||||
|
return chatFilters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ChatFilter> getEmoteFilters() {
|
||||||
|
return emotes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public interface BatchInsertable {
|
||||||
|
|
||||||
|
void prepareStatement(PreparedStatement preparedStatement) throws SQLException;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
@ -12,14 +17,16 @@ public class ChatFilter {
|
||||||
private final Pattern pattern;
|
private final Pattern pattern;
|
||||||
private final String replacement;
|
private final String replacement;
|
||||||
private final List<String> exclusions;
|
private final List<String> exclusions;
|
||||||
|
private final boolean disableInPrivate;
|
||||||
|
|
||||||
public ChatFilter(String name, String type, String regex, String replacement, List<String> exclusions) {
|
public ChatFilter(String name, String type, String regex, String replacement, List<String> exclusions, boolean disableInPrivate) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.filterType = FilterType.getType(type);
|
this.filterType = FilterType.getType(type);
|
||||||
this.regex = regex;
|
this.regex = regex;
|
||||||
this.pattern = Pattern.compile(getRegex(), Pattern.CASE_INSENSITIVE);
|
this.pattern = Pattern.compile(getRegex(), Pattern.CASE_INSENSITIVE);
|
||||||
this.replacement = replacement;
|
this.replacement = replacement;
|
||||||
this.exclusions = exclusions;
|
this.exclusions = exclusions;
|
||||||
|
this.disableInPrivate = disableInPrivate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
@ -42,12 +49,22 @@ public class ChatFilter {
|
||||||
return this.exclusions;
|
return this.exclusions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDisabledInPrivate() {
|
||||||
|
return disableInPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean matches(ModifiableString filterableString) {
|
public boolean matches(ModifiableString filterableString) {
|
||||||
String input = filterableString.string();
|
String input = filterableString.string();
|
||||||
Matcher matcher = pattern.matcher(input);
|
Matcher matcher = pattern.matcher(input);
|
||||||
while (matcher.find())
|
while (matcher.find())
|
||||||
if (!isException(input, matcher.start())) {
|
if (!isException(input, matcher.start())) {
|
||||||
filterableString.string(filterableString.string().replaceFirst(matcher.group(), "<gold>" + matcher.group() + "</gold>"));
|
// filterableString.string(filterableString.string().replaceFirst(matcher.group(), "<gold>" + matcher.group() + "</gold>"));
|
||||||
|
filterableString.string(filterableString.component()
|
||||||
|
.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.match(matcher.pattern())
|
||||||
|
.replacement(Component.text(matcher.group()).style(Style.style(NamedTextColor.GOLD)))
|
||||||
|
.build()));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return matcher.matches();
|
return matcher.matches();
|
||||||
|
|
@ -76,7 +93,12 @@ public class ChatFilter {
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group(); // todo debug
|
String group = matcher.group(); // todo debug
|
||||||
if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/
|
if (getExclusions().stream().noneMatch(s -> s.equalsIgnoreCase(group))) { // idk how heavy this is:/
|
||||||
modifiableString.string(input.replace(group, getReplacement()));
|
modifiableString.replace(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.matchLiteral(group)
|
||||||
|
.replacement(getReplacement())
|
||||||
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +114,10 @@ public class ChatFilter {
|
||||||
Matcher matcher = pattern.matcher(input);
|
Matcher matcher = pattern.matcher(input);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group();
|
String group = matcher.group();
|
||||||
modifiableString.string(input.replace(group, group.substring(0, length)));
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
.matchLiteral(group)
|
||||||
|
.replacement(Component.text(group.substring(0, length), modifiableString.component().color()))
|
||||||
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package com.alttd.chat.objects;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.util.Utility;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -13,19 +13,20 @@ import java.util.stream.Collectors;
|
||||||
public class ChatUser {
|
public class ChatUser {
|
||||||
private final UUID uuid; // player uuid
|
private final UUID uuid; // player uuid
|
||||||
private int partyId; // the party they are in
|
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 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 prefix; // doesn't need saving, we get this from luckperms
|
||||||
// private Component staffPrefix; // 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
|
// private Component prefixAll; // doesn't need saving, we get this from luckperms
|
||||||
//private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
|
//private boolean toggleGc; // should be saved, this toggles if the player can see and use global chat
|
||||||
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
|
private String replyTarget; // reply target for use in /msg i don't mind setting this to null on login, feedback?
|
||||||
|
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 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 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 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 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> 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<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;
|
private boolean isMuted;
|
||||||
|
|
||||||
public ChatUser(UUID uuid, int partyId, Channel toggledChannel) {
|
public ChatUser(UUID uuid, int partyId, Channel toggledChannel) {
|
||||||
|
|
@ -39,12 +40,13 @@ public class ChatUser {
|
||||||
}
|
}
|
||||||
setDisplayName(name);
|
setDisplayName(name);
|
||||||
|
|
||||||
// prefix = Utility.getPrefix(uuid, true); // TODO we need to update this, so cache and update when needed or always request it?
|
// prefix = Utility.getPrefix(uuid, true); // TODO we need to update this, so cache and update when needed or always request it?
|
||||||
// staffPrefix = Utility.getStaffPrefix(uuid);
|
// staffPrefix = Utility.getStaffPrefix(uuid);
|
||||||
//
|
//
|
||||||
// prefixAll = Utility.getPrefix(uuid, false);
|
// prefixAll = Utility.getPrefix(uuid, false);
|
||||||
|
|
||||||
replyTarget = null;
|
replyTarget = "";
|
||||||
|
replyContinueTarget = "";
|
||||||
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
|
gcCooldown = System.currentTimeMillis(); // players can't use gc for 30 seconds after logging in if we use this?
|
||||||
mails = Queries.getMails(uuid);
|
mails = Queries.getMails(uuid);
|
||||||
ignoredPlayers = Queries.getIgnoredUsers(uuid);
|
ignoredPlayers = Queries.getIgnoredUsers(uuid);
|
||||||
|
|
@ -69,12 +71,7 @@ public class ChatUser {
|
||||||
return toggledChannel;
|
return toggledChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setToggledChannel(Channel channel) {
|
public ComponentLike getDisplayName() {
|
||||||
toggledChannel = channel;
|
|
||||||
Queries.setToggledChannel(toggledChannel, uuid); //TODO: Async pls - no CompleteableFuture<>!
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getDisplayName() {
|
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,17 +79,17 @@ public class ChatUser {
|
||||||
this.displayName = Utility.applyColor(displayName);
|
this.displayName = Utility.applyColor(displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getPrefix() {
|
public ComponentLike getPrefix() {
|
||||||
//return prefix;
|
//return prefix;
|
||||||
return Utility.getPrefix(uuid, true); // No longer cache this data
|
return Utility.getPrefix(uuid, true); // No longer cache this data
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getStaffPrefix() {
|
public ComponentLike getStaffPrefix() {
|
||||||
//return staffPrefix;
|
//return staffPrefix;
|
||||||
return Utility.getStaffPrefix(uuid);
|
return Utility.getStaffPrefix(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getPrefixAll() {
|
public ComponentLike getPrefixAll() {
|
||||||
//return prefixAll;
|
//return prefixAll;
|
||||||
return Utility.getPrefix(uuid, false);
|
return Utility.getPrefix(uuid, false);
|
||||||
}
|
}
|
||||||
|
|
@ -101,10 +98,18 @@ public class ChatUser {
|
||||||
return replyTarget;
|
return replyTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getReplyContinueTarget() {
|
||||||
|
return replyContinueTarget;
|
||||||
|
}
|
||||||
|
|
||||||
public void setReplyTarget(String replyTarget) {
|
public void setReplyTarget(String replyTarget) {
|
||||||
this.replyTarget = replyTarget;
|
this.replyTarget = replyTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setReplyContinueTarget(String replyTarget) {
|
||||||
|
this.replyContinueTarget = replyTarget;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Mail> getMails() {
|
public List<Mail> getMails() {
|
||||||
return mails;
|
return mails;
|
||||||
}
|
}
|
||||||
|
|
@ -135,10 +140,6 @@ public class ChatUser {
|
||||||
return ignoredBy;
|
return ignoredBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addIgnoredBy(UUID uuid) {
|
|
||||||
ignoredBy.add(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getGcCooldown() {
|
public long getGcCooldown() {
|
||||||
return gcCooldown;
|
return gcCooldown;
|
||||||
}
|
}
|
||||||
|
|
@ -170,4 +171,8 @@ public class ChatUser {
|
||||||
}
|
}
|
||||||
setDisplayName(name);
|
setDisplayName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNickNameString() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
64
api/src/main/java/com/alttd/chat/objects/EmoteList.java
Normal file
64
api/src/main/java/com/alttd/chat/objects/EmoteList.java
Normal file
|
|
@ -0,0 +1,64 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
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 java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class EmoteList {
|
||||||
|
|
||||||
|
public static final Map<UUID, EmoteList> emoteLists = new HashMap<>();
|
||||||
|
public static final int pageSize = 7;
|
||||||
|
// public static int pages = RegexManager.getEmoteFilters().size() / pageSize;// TODO reload this when config is reloaded.
|
||||||
|
|
||||||
|
public static EmoteList getEmoteList(UUID uuid) {
|
||||||
|
synchronized (emoteLists) {
|
||||||
|
return emoteLists.computeIfAbsent(uuid, k -> new EmoteList());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int page;
|
||||||
|
|
||||||
|
public ComponentLike showEmotePage() {
|
||||||
|
int startIndex = page * pageSize;
|
||||||
|
int pages = RegexManager.getEmoteFilters().size() / pageSize;
|
||||||
|
int endIndex = Math.min(startIndex + pageSize, RegexManager.getEmoteFilters().size());
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("page", String.valueOf(page)),
|
||||||
|
Placeholder.unparsed("pages", String.valueOf(pages))
|
||||||
|
);
|
||||||
|
Component list = Utility.parseMiniMessage(Config.EMOTELIST_HEADER, placeholders).asComponent();
|
||||||
|
|
||||||
|
for (int i = startIndex; i < endIndex; i++) {
|
||||||
|
ChatFilter emote = RegexManager.getEmoteFilters().get(i);
|
||||||
|
TagResolver emotes = TagResolver.resolver(
|
||||||
|
Placeholder.parsed("regex", emote.getRegex()),
|
||||||
|
Placeholder.parsed("emote", emote.getReplacement())
|
||||||
|
);
|
||||||
|
list = list.append(Utility.parseMiniMessage(Config.EMOTELIST_ITEM, emotes));
|
||||||
|
}
|
||||||
|
list = list.append(Utility.parseMiniMessage(Config.EMOTELIST_FOOTER, placeholders));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPage(int page) {
|
||||||
|
this.page = Math.min(page, RegexManager.getEmoteFilters().size() / pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextPage() {
|
||||||
|
this.page = Math.min(page + 1, RegexManager.getEmoteFilters().size() / pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prevPage() {
|
||||||
|
this.page -= 1;
|
||||||
|
this.page = Math.max(page - 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,11 @@ package com.alttd.chat.objects;
|
||||||
|
|
||||||
public enum FilterType {
|
public enum FilterType {
|
||||||
REPLACE("replace"),
|
REPLACE("replace"),
|
||||||
|
EMOTE("emote"),
|
||||||
CHAT("chat"),
|
CHAT("chat"),
|
||||||
REPLACEMATCHER("replacematcher"),
|
REPLACEMATCHER("replacematcher"),
|
||||||
BLOCK("block");
|
BLOCK("block"),
|
||||||
|
PUNISH("punish");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,29 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
public class ModifiableString {
|
import net.kyori.adventure.text.Component;
|
||||||
private String string;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
|
||||||
public ModifiableString(String string) {
|
public class ModifiableString {
|
||||||
this.string = string;
|
private Component text;
|
||||||
|
|
||||||
|
public ModifiableString(Component text) {
|
||||||
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void string(String string) {
|
public void string(Component text) {
|
||||||
this.string = string;
|
this.text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replace(TextReplacementConfig textReplacementConfig) {
|
||||||
|
text = text.replaceText(textReplacementConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String string() {
|
public String string() {
|
||||||
return string;
|
return PlainTextComponentSerializer.plainText().serialize(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component component() {
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
99
api/src/main/java/com/alttd/chat/objects/Nick.java
Normal file
99
api/src/main/java/com/alttd/chat/objects/Nick.java
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class Nick {
|
||||||
|
private final UUID uuid;
|
||||||
|
private String currentNick;
|
||||||
|
private String currentNickNoColor;
|
||||||
|
private long lastChangedDate;
|
||||||
|
private String newNick;
|
||||||
|
private String newNickNoColor;
|
||||||
|
private long requestedDate;
|
||||||
|
private boolean hasRequest;
|
||||||
|
|
||||||
|
public Nick(UUID uuid, String currentNick, long lastChangedDate) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.currentNick = currentNick;
|
||||||
|
currentNickNoColor = currentNick == null ? null : Utility.removeAllColors(currentNick);
|
||||||
|
this.lastChangedDate = lastChangedDate;
|
||||||
|
newNick = null;
|
||||||
|
newNickNoColor = null;
|
||||||
|
requestedDate = 0;
|
||||||
|
hasRequest = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Nick(UUID uuid, String currentNick, long lastChangedDate, String newNick, long requestedDate) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.currentNick = currentNick;
|
||||||
|
currentNickNoColor = currentNick == null ? null : Utility.removeAllColors(currentNick);
|
||||||
|
this.lastChangedDate = lastChangedDate;
|
||||||
|
this.newNick = newNick;
|
||||||
|
newNickNoColor = newNick == null ? null : Utility.removeAllColors(newNick);
|
||||||
|
this.requestedDate = requestedDate;
|
||||||
|
hasRequest = newNick != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentNickNoColor() {
|
||||||
|
return currentNickNoColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrentNick() {
|
||||||
|
return currentNick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentNick(String currentNick) {
|
||||||
|
this.currentNick = currentNick;
|
||||||
|
currentNickNoColor = currentNick == null ? null : Utility.removeAllColors(currentNick);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastChangedDate(){
|
||||||
|
return lastChangedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastChangedDateFormatted() {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd").format(new Date(lastChangedDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastChangedDate(long lastChangedDate) {
|
||||||
|
this.lastChangedDate = lastChangedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewNickNoColor() {
|
||||||
|
return newNickNoColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewNick() {
|
||||||
|
return newNick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewNick(String newNick) {
|
||||||
|
this.newNick = newNick;
|
||||||
|
newNickNoColor = newNick == null ? null : Utility.removeAllColors(newNick);
|
||||||
|
hasRequest = newNick != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getRequestedDate(){
|
||||||
|
return requestedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRequestedDateFormatted() {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd").format(new Date(requestedDate));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestedDate(long requestedDate) {
|
||||||
|
this.requestedDate = requestedDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasRequest() {
|
||||||
|
return hasRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -48,6 +48,7 @@ public class Party {
|
||||||
.findFirst();
|
.findFirst();
|
||||||
if (first.isEmpty()) return;
|
if (first.isEmpty()) return;
|
||||||
partyUsers.remove(first.get());
|
partyUsers.remove(first.get());
|
||||||
|
chatUser.setPartyId(-1);
|
||||||
Queries.removePartyUser(uuid);
|
Queries.removePartyUser(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,21 @@
|
||||||
package com.alttd.chat.objects;
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PartyUser {
|
public class PartyUser {
|
||||||
|
|
||||||
protected UUID uuid;
|
protected UUID uuid;
|
||||||
protected Component displayName;
|
protected ComponentLike displayName;
|
||||||
protected String playerName;
|
protected String playerName;
|
||||||
|
|
||||||
public PartyUser(UUID uuid, String displayName, String playerName) {
|
public PartyUser(UUID uuid, String displayName, String playerName) {
|
||||||
this(uuid, Utility.applyColor(displayName), 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.uuid = uuid;
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.playerName = playerName;
|
this.playerName = playerName;
|
||||||
|
|
@ -25,7 +25,7 @@ public class PartyUser {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getDisplayName() {
|
public ComponentLike getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
62
api/src/main/java/com/alttd/chat/objects/Toggleable.java
Normal file
62
api/src/main/java/com/alttd/chat/objects/Toggleable.java
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.alttd.chat.objects;
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public abstract class Toggleable {
|
||||||
|
|
||||||
|
private static final List<Toggleable> togglableClasses = new ArrayList<>();
|
||||||
|
|
||||||
|
public Toggleable() {
|
||||||
|
togglableClasses.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Toggleable getToggleable(UUID uuid) {
|
||||||
|
for (Toggleable toggleableClass : togglableClasses) {
|
||||||
|
if (toggleableClass.isToggled(uuid))
|
||||||
|
return toggleableClass;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean isToggled(UUID uuid);
|
||||||
|
|
||||||
|
public abstract void setOff(UUID uuid);
|
||||||
|
|
||||||
|
public boolean toggle(UUID uuid) {
|
||||||
|
if (isToggled(uuid)) {
|
||||||
|
setOff(uuid);
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
for (Toggleable toggleable : togglableClasses) {
|
||||||
|
if (toggleable.isToggled(uuid)) {
|
||||||
|
setOff(uuid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setOn(uuid);
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void setOn(UUID uuid);
|
||||||
|
|
||||||
|
public static void disableToggles(UUID uuid) {
|
||||||
|
for (Toggleable toggleable : togglableClasses) {
|
||||||
|
if (toggleable.isToggled(uuid)) {
|
||||||
|
toggleable.setOff(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(Player player, Component message) {
|
||||||
|
sendMessage(player, PlainTextComponentSerializer.plainText().serialize(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void sendMessage(Player player, String message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -3,19 +3,21 @@ package com.alttd.chat.objects.channels;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public abstract class Channel {
|
public class Channel {
|
||||||
|
|
||||||
public static HashMap<String, Channel> channels = new HashMap<>();
|
public static HashMap<String, Channel> channels = new HashMap<>();
|
||||||
protected String permission;
|
protected String permission;
|
||||||
protected String channelName;
|
protected String channelName;
|
||||||
protected String format;
|
protected String format;
|
||||||
protected boolean proxy;
|
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.permission = "chat.channel." + channelName.toLowerCase();
|
||||||
this.channelName = channelName;
|
this.channelName = channelName;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
|
this.local = local;
|
||||||
channels.put(channelName.toLowerCase(), this);
|
channels.put(channelName.toLowerCase(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -39,6 +41,10 @@ public abstract class Channel {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLocal() {
|
||||||
|
return local;
|
||||||
|
}
|
||||||
|
|
||||||
public static Channel getChatChannel(String channelName) {
|
public static Channel getChatChannel(String channelName) {
|
||||||
return channels.get(channelName.toLowerCase());
|
return channels.get(channelName.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,27 @@
|
||||||
package com.alttd.chat.objects.channels;
|
package com.alttd.chat.objects.channels;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.List;
|
||||||
|
|
||||||
public class CustomChannel extends Channel {
|
public class CustomChannel extends Channel {
|
||||||
private final List<String> servers;
|
private final List<String> servers;
|
||||||
|
private final List<String> aliases;
|
||||||
|
|
||||||
public CustomChannel(String channelName, String format, List<String> servers, boolean proxy) {
|
public CustomChannel(String channelName, String format, List<String> servers, List<String> aliases, boolean proxy,
|
||||||
super(channelName, format, proxy);
|
boolean local) {
|
||||||
|
super(channelName, format, proxy, local);
|
||||||
this.permission = "chat.channel." + channelName.toLowerCase();
|
this.permission = "chat.channel." + channelName.toLowerCase();
|
||||||
this.channelName = channelName;
|
this.channelName = channelName;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.servers = servers;
|
this.servers = servers;
|
||||||
this.proxy = proxy;
|
this.proxy = proxy;
|
||||||
channels.put(channelName.toLowerCase(), this);
|
this.aliases = aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getServers() {
|
public List<String> getServers() {
|
||||||
return servers;
|
return servers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<String> getAliases() {
|
||||||
|
return aliases;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
package com.alttd.chat.objects.channels;
|
package com.alttd.chat.objects.channels;
|
||||||
|
|
||||||
public class DefaultChannel extends Channel{
|
public abstract class DefaultChannel extends Channel{
|
||||||
public DefaultChannel(String channelName, String format, boolean proxy) {
|
public DefaultChannel(String channelName, String format, boolean proxy) {
|
||||||
super(channelName, format, proxy);
|
super(channelName, format, proxy, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.BatchInsertable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ChatLog implements BatchInsertable {
|
||||||
|
|
||||||
|
private final UUID uuid;
|
||||||
|
private final Instant timestamp;
|
||||||
|
private final String server;
|
||||||
|
private final String message;
|
||||||
|
private final boolean blocked;
|
||||||
|
|
||||||
|
protected ChatLog(UUID uuid, Instant timestamp, String server, String message, boolean blocked) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
this.server = server;
|
||||||
|
this.message = message;
|
||||||
|
this.blocked = blocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void prepareStatement(@NotNull PreparedStatement preparedStatement) throws SQLException {
|
||||||
|
preparedStatement.setString(1, uuid.toString());
|
||||||
|
preparedStatement.setTimestamp(2, Timestamp.from(timestamp));
|
||||||
|
preparedStatement.setString(3, server);
|
||||||
|
preparedStatement.setString(4, message);
|
||||||
|
preparedStatement.setInt(5, blocked ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBlocked() {
|
||||||
|
return blocked;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
package com.alttd.chat.objects.chat_log;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.database.ChatLogQueries;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
public class ChatLogHandler {
|
||||||
|
|
||||||
|
private static ChatLogHandler instance = null;
|
||||||
|
private ScheduledExecutorService executorService = null;
|
||||||
|
|
||||||
|
public static ChatLogHandler getInstance(boolean enableLogging) {
|
||||||
|
if (instance == null)
|
||||||
|
instance = new ChatLogHandler(enableLogging);
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSaving;
|
||||||
|
private final Queue<ChatLog> chatLogQueue = new ConcurrentLinkedQueue<>();
|
||||||
|
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
|
||||||
|
|
||||||
|
public ChatLogHandler(boolean enableLogging) {
|
||||||
|
if (!enableLogging) {
|
||||||
|
ALogger.info("Logging is not enabled on this server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
||||||
|
ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> {
|
||||||
|
if (success) {
|
||||||
|
ALogger.info(String.format("Deleted all messages older than %s days from chat log database.", deleteThreshold.toDays()));
|
||||||
|
} else {
|
||||||
|
ALogger.warn(String.format("Failed to delete all messages older than %s days from chat log database.", deleteThreshold.toDays()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
executorService.scheduleAtFixedRate(() -> {
|
||||||
|
saveToDatabase(false);
|
||||||
|
ALogger.info(String.format("Running scheduler to save messages with a %d delay", Config.CHAT_LOG_SAVE_DELAY_MINUTES));
|
||||||
|
},
|
||||||
|
Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES);
|
||||||
|
ALogger.info("Logging has started!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuts down the executor service and saves the chat logs to the database.
|
||||||
|
* Will throw an error if called on a ChatLogHandler that was started without logging
|
||||||
|
*/
|
||||||
|
public void shutDown() {
|
||||||
|
executorService.shutdown();
|
||||||
|
saveToDatabase(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void savingToDatabase(boolean saving) {
|
||||||
|
isSaving = saving;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized boolean isBlocked() {
|
||||||
|
return isSaving;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void addLog(ChatLog chatLog) {
|
||||||
|
if (isBlocked()) {
|
||||||
|
chatLogQueue.add(chatLog);
|
||||||
|
} else {
|
||||||
|
chatLogs.computeIfAbsent(chatLog.getUuid(), k -> new ArrayList<>()).add(chatLog);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void saveToDatabase(boolean onMainThread) {
|
||||||
|
savingToDatabase(true);
|
||||||
|
ALogger.info(String.format("Saving %d messages to database", chatLogs.size()));
|
||||||
|
CompletableFuture<Boolean> booleanCompletableFuture = ChatLogQueries.storeMessages(chatLogs);
|
||||||
|
if (onMainThread) {
|
||||||
|
booleanCompletableFuture.join();
|
||||||
|
ALogger.info("Finished saving messages on main thread");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
booleanCompletableFuture.whenComplete((result, throwable) -> {
|
||||||
|
if (throwable == null && result) {
|
||||||
|
chatLogs.clear();
|
||||||
|
} else {
|
||||||
|
ALogger.error("Failed to save chat messages.");
|
||||||
|
}
|
||||||
|
savingToDatabase(false);
|
||||||
|
if (!chatLogQueue.isEmpty()) {
|
||||||
|
ALogger.info("Adding back messages from queue to chatLogs map");
|
||||||
|
}
|
||||||
|
while (!chatLogQueue.isEmpty()) {
|
||||||
|
addLog(chatLogQueue.remove());
|
||||||
|
}
|
||||||
|
ALogger.info("Finished saving messages");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChatLog loadFromResultSet(@NotNull ResultSet resultSet) throws SQLException {
|
||||||
|
UUID chatLogUUID = UUID.fromString(resultSet.getString("uuid"));
|
||||||
|
Instant chatTimestamp = resultSet.getTimestamp("time_stamp").toInstant();
|
||||||
|
String server = resultSet.getString("server");
|
||||||
|
String chatMessage = resultSet.getString("chat_message");
|
||||||
|
boolean chatMessageBlocked = resultSet.getInt("blocked") == 1;
|
||||||
|
return new ChatLog(chatLogUUID, chatTimestamp, server, chatMessage, chatMessageBlocked);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChatLog(UUID uuid, String server, String message, boolean blocked) {
|
||||||
|
addLog(new ChatLog(uuid, Instant.now(), server, message, blocked));
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompletableFuture<List<ChatLog>> retrieveChatLogs(UUID uuid, Duration duration, String server) {
|
||||||
|
List<ChatLog> chatLogList = chatLogs.getOrDefault(uuid, new ArrayList<>());
|
||||||
|
return ChatLogQueries.retrieveMessages(this, uuid, duration, server)
|
||||||
|
.thenCompose(chatLogs -> CompletableFuture.supplyAsync(() -> {
|
||||||
|
chatLogList.addAll(chatLogs);
|
||||||
|
return chatLogList;
|
||||||
|
}))
|
||||||
|
.exceptionally(ex -> {
|
||||||
|
throw new CompletionException(ex);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,10 @@ public class ALogger {
|
||||||
logger.warn(message);
|
logger.warn(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void warn(String message, Throwable throwable) {
|
||||||
|
logger.warn(message, throwable);
|
||||||
|
}
|
||||||
|
|
||||||
public static void info(String message) {
|
public static void info(String message) {
|
||||||
logger.info(message);
|
logger.info(message);
|
||||||
}
|
}
|
||||||
|
|
@ -23,4 +27,8 @@ public class ALogger {
|
||||||
public static void error(String message) {
|
public static void error(String message) {
|
||||||
logger.error(message);
|
logger.error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void error(String message, Throwable throwable) {
|
||||||
|
logger.error(message, throwable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
api/src/main/java/com/alttd/chat/util/Pair.java
Normal file
20
api/src/main/java/com/alttd/chat/util/Pair.java
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.alttd.chat.util;
|
||||||
|
|
||||||
|
public class Pair<X, Y> {
|
||||||
|
|
||||||
|
private final X x;
|
||||||
|
private final Y y;
|
||||||
|
|
||||||
|
public Pair(X x, Y y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public X getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Y getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,11 +3,11 @@ package com.alttd.chat.util;
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import net.kyori.adventure.text.Component;
|
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.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.PlaceholderResolver;
|
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
import net.luckperms.api.model.group.Group;
|
import net.luckperms.api.model.group.Group;
|
||||||
import net.luckperms.api.model.user.User;
|
import net.luckperms.api.model.user.User;
|
||||||
|
|
@ -16,17 +16,17 @@ import net.luckperms.api.node.Node;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Utility {
|
public class Utility {
|
||||||
|
|
||||||
static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?");
|
private static final List<String> EMPTY_LIST = new ArrayList<>();
|
||||||
|
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;
|
private static MiniMessage miniMessage = null;
|
||||||
|
|
||||||
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
public static String stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||||
public static HashMap<String, String> colors;
|
public static HashMap<String, String> colors;
|
||||||
private static LegacyComponentSerializer legacySerializer;
|
|
||||||
static { // this might be in minimessage already?
|
static { // this might be in minimessage already?
|
||||||
colors = new HashMap<>();
|
colors = new HashMap<>();
|
||||||
colors.put("&0", "<black>");
|
colors.put("&0", "<black>");
|
||||||
|
|
@ -47,8 +47,43 @@ public class Utility {
|
||||||
colors.put("&f", "<white>");
|
colors.put("&f", "<white>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()));
|
||||||
|
formattingPerms.put("chat.format.bold",
|
||||||
|
new Pair<>(StandardTags.decorations(TextDecoration.BOLD), List.of("<bold>", "<b>")));
|
||||||
|
formattingPerms.put("chat.format.italic",
|
||||||
|
new Pair<>(StandardTags.decorations(TextDecoration.ITALIC), List.of("<italic>", "<i>")));
|
||||||
|
formattingPerms.put("chat.format.underlined",
|
||||||
|
new Pair<>(StandardTags.decorations(TextDecoration.UNDERLINED), List.of("<underlined>", "<u>")));
|
||||||
|
formattingPerms.put("chat.format.strikethrough",
|
||||||
|
new Pair<>(StandardTags.decorations(TextDecoration.STRIKETHROUGH), List.of("<strikethrough>", "<st>")));
|
||||||
|
formattingPerms.put("chat.format.obfuscated",
|
||||||
|
new Pair<>(StandardTags.decorations(TextDecoration.OBFUSCATED), List.of("<obfuscated>", "<obf>")));
|
||||||
|
formattingPerms.put("chat.format.gradient",
|
||||||
|
new Pair<>(StandardTags.gradient(), EMPTY_LIST));
|
||||||
|
formattingPerms.put("chat.format.font",
|
||||||
|
new Pair<>(StandardTags.font(), EMPTY_LIST));
|
||||||
|
formattingPerms.put("chat.format.rainbow",
|
||||||
|
new Pair<>(StandardTags.rainbow(), List.of("<rainbow>")));
|
||||||
|
formattingPerms.put("chat.format.hover",
|
||||||
|
new Pair<>(StandardTags.hoverEvent(), EMPTY_LIST));
|
||||||
|
formattingPerms.put("chat.format.click",
|
||||||
|
new Pair<>(StandardTags.clickEvent(), EMPTY_LIST));
|
||||||
|
formattingPerms.put("chat.format.transition",
|
||||||
|
new Pair<>(StandardTags.transition(), EMPTY_LIST));
|
||||||
|
formattingPerms.put("chat.format.reset",
|
||||||
|
new Pair<>(StandardTags.reset(), List.of("<reset>", "<r>")));
|
||||||
|
formattingPerms.put("chat.format.newline",
|
||||||
|
new Pair<>(StandardTags.newline(), List.of("<newline>")));
|
||||||
|
}
|
||||||
|
|
||||||
public static String parseColors(String message) {
|
public static String parseColors(String message) {
|
||||||
if (message == null) return "";
|
if (message == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
// split string in sections and check those vs looping hashmap?:/
|
// split string in sections and check those vs looping hashmap?:/
|
||||||
// think this is better, but will check numbers on this
|
// think this is better, but will check numbers on this
|
||||||
for (String key : colors.keySet()) {
|
for (String key : colors.keySet()) {
|
||||||
|
|
@ -59,15 +94,17 @@ public class Utility {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component getPrefix(UUID uuid, boolean single) {
|
public static ComponentLike getPrefix(UUID uuid, boolean single) {
|
||||||
StringBuilder prefix = new StringBuilder();
|
StringBuilder prefix = new StringBuilder();
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
List<String> prefixGroups = Config.PREFIXGROUPS;
|
List<String> prefixGroups = Config.PREFIXGROUPS;
|
||||||
if(user == null) return Component.empty();
|
if (user == null) {
|
||||||
if(!single) {
|
return Component.empty();
|
||||||
|
}
|
||||||
|
if (!single) {
|
||||||
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
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
|
prefixGroups.remove("eventteam"); // hardcoded for now, new prefix system would load this from config
|
||||||
}
|
}
|
||||||
inheritedGroups.stream()
|
inheritedGroups.stream()
|
||||||
|
|
@ -79,21 +116,23 @@ public class Utility {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
prefix.append(getUserPrefix(user));
|
prefix.append(getUserPrefix(user));
|
||||||
// prefix.append(user.getCachedData().getMetaData().getPrefix());
|
|
||||||
|
|
||||||
return applyColor(prefix.toString());
|
return applyColor(prefix.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component getStaffPrefix(UUID uuid) {
|
public static ComponentLike getStaffPrefix(UUID uuid) {
|
||||||
StringBuilder prefix = new StringBuilder();
|
StringBuilder prefix = new StringBuilder();
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return Component.empty();
|
if (user == null) {
|
||||||
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
return Component.empty();
|
||||||
|
}
|
||||||
|
if (user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
||||||
Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
|
Group group = luckPerms.getGroupManager().getGroup(user.getPrimaryGroup());
|
||||||
if(group != null)
|
if (group != null) {
|
||||||
prefix.append(getGroupPrefix(group));
|
prefix.append(getGroupPrefix(group));
|
||||||
// prefix.append(group.getCachedData().getMetaData().getPrefix());
|
}
|
||||||
|
// prefix.append(group.getCachedData().getMetaData().getPrefix());
|
||||||
}
|
}
|
||||||
return applyColor(prefix.toString());
|
return applyColor(prefix.toString());
|
||||||
}
|
}
|
||||||
|
|
@ -104,26 +143,32 @@ public class Utility {
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", user.getCachedData().getMetaData().getPrefix());
|
String prefix = user.getCachedData().getMetaData().getPrefix();
|
||||||
}
|
if (prefix == null) {
|
||||||
|
ALogger.warn("User " + user.getUsername() + " has no prefix set!");
|
||||||
public static String getGroupPrefix(String groupName) {
|
|
||||||
Group group = ChatAPI.get().getLuckPerms().getGroupManager().getGroup(groupName);
|
|
||||||
if (group == null) {
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return getGroupPrefix(group);
|
return ChatAPI.get().getPrefixes().get(group.getName()).replace("<prefix>", prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getGroupPrefix(Group group) {
|
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) {
|
public static String getDisplayName(UUID uuid, String playerName) {
|
||||||
if (!playerName.isBlank()) return playerName;
|
if (!playerName.isBlank()) {
|
||||||
|
return playerName;
|
||||||
|
}
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return "";
|
if (user == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
return user.getUsername();
|
return user.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,20 +176,22 @@ public class Utility {
|
||||||
ChatAPI.get().getLuckPerms().getUserManager().modifyUser(uuid, user -> {
|
ChatAPI.get().getLuckPerms().getUserManager().modifyUser(uuid, user -> {
|
||||||
// Add the permission
|
// Add the permission
|
||||||
user.data().add(Node.builder(permission)
|
user.data().add(Node.builder(permission)
|
||||||
.value(!user.getCachedData().getPermissionData().checkPermission(permission).asBoolean()).build());
|
.value(!user.getCachedData().getPermissionData().checkPermission(permission).asBoolean()).build());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean hasPermission(UUID uuid, String permission) {
|
public static boolean hasPermission(UUID uuid, String permission) {
|
||||||
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
||||||
User user = luckPerms.getUserManager().getUser(uuid);
|
User user = luckPerms.getUserManager().getUser(uuid);
|
||||||
if(user == null) return false;
|
if (user == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
return user.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component applyColor(String message) {
|
public static ComponentLike applyColor(String message) {
|
||||||
String hexColor1 = "";
|
String hexColor1 = "";
|
||||||
String hexColor2 = "";
|
String hexColor2;
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
message = parseColors(message);
|
message = parseColors(message);
|
||||||
boolean startsWithColor = false;
|
boolean startsWithColor = false;
|
||||||
|
|
@ -162,7 +209,7 @@ public class Utility {
|
||||||
for (String s : split) {
|
for (String s : split) {
|
||||||
nextIndex += s.length();
|
nextIndex += s.length();
|
||||||
int tmp = message.indexOf("}", nextIndex);
|
int tmp = message.indexOf("}", nextIndex);
|
||||||
if (tmp < message.length() && tmp>=0) {
|
if (tmp < message.length() && tmp >= 0) {
|
||||||
list.add(message.substring(nextIndex, tmp + 1));
|
list.add(message.substring(nextIndex, tmp + 1));
|
||||||
nextIndex = tmp + 1;
|
nextIndex = tmp + 1;
|
||||||
}
|
}
|
||||||
|
|
@ -186,7 +233,7 @@ public class Utility {
|
||||||
} else if (bigger || lesser) {
|
} else if (bigger || lesser) {
|
||||||
hexColor2 = s.substring(1, s.length() - 2);
|
hexColor2 = s.substring(1, s.length() - 2);
|
||||||
} else {
|
} else {
|
||||||
hexColor2 = s.substring(1, s.length() -1);
|
hexColor2 = s.substring(1, s.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstLoop) {
|
if (firstLoop) {
|
||||||
|
|
@ -207,63 +254,112 @@ public class Utility {
|
||||||
lastColorMatters = bigger;
|
lastColorMatters = bigger;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (split.length > i){
|
if (split.length > i) {
|
||||||
stringBuilder.append("<").append(hexColor1).append(">").append(split[i]);
|
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());
|
: Utility.parseMiniMessage(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkNickBrightEnough(String nickname) {
|
||||||
|
if (!nickname.matches(".*" + stringRegen + ".*")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile(stringRegen);
|
||||||
|
Matcher matcher = pattern.matcher(nickname);
|
||||||
|
|
||||||
|
while (matcher.find()) {
|
||||||
|
String hexColor = matcher.group();
|
||||||
|
if (!checkHexHighEnough(hexColor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean checkHexHighEnough(String hexColor) {
|
||||||
|
// Remove the leading "#" if present
|
||||||
|
if (hexColor.startsWith("{")) {
|
||||||
|
hexColor = hexColor.substring(1);
|
||||||
|
}
|
||||||
|
if (hexColor.startsWith("#")) {
|
||||||
|
hexColor = hexColor.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract the color parts
|
||||||
|
String redPart = hexColor.substring(0, 2);
|
||||||
|
String greenPart = hexColor.substring(2, 4);
|
||||||
|
String bluePart = hexColor.substring(4, 6);
|
||||||
|
|
||||||
|
// Convert the color parts to integers
|
||||||
|
int red = Integer.parseInt(redPart, 16);
|
||||||
|
int green = Integer.parseInt(greenPart, 16);
|
||||||
|
int blue = Integer.parseInt(bluePart, 16);
|
||||||
|
|
||||||
|
// Check if any part is over 30 in hexadecimal
|
||||||
|
return red > 0x30 || green > 0x30 || blue > 0x30;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String formatText(String message) {
|
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);
|
Matcher matcher = DEFAULT_URL_PATTERN.matcher(message);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String url = matcher.group();
|
String url = matcher.group();
|
||||||
String clickUrl = url;
|
|
||||||
String urlFormat = Config.URLFORMAT;
|
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;
|
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);
|
return getMiniMessage().deserialize(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component parseMiniMessage(String message, Map<String, Replacement<?>> placeholders) {
|
public static ComponentLike parseMiniMessage(String message, TagResolver placeholders) {
|
||||||
if (placeholders == null) {
|
if (placeholders == null) {
|
||||||
return getMiniMessage().deserialize(message);
|
return getMiniMessage().deserialize(message);
|
||||||
} else {
|
} else {
|
||||||
return getMiniMessage().deserialize(message, PlaceholderResolver.map(placeholders));
|
return getMiniMessage().deserialize(message, placeholders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Component parseMiniMessage(String message, Placeholder<?> ... placeholders) {
|
public static ComponentLike parseMiniMessage(String message, TagResolver... placeholders) {
|
||||||
if (placeholders == null) {
|
if (placeholders == null) {
|
||||||
return getMiniMessage().deserialize(message);
|
return getMiniMessage().deserialize(message);
|
||||||
} else {
|
} else {
|
||||||
return getMiniMessage().deserialize(message, PlaceholderResolver.placeholders(placeholders));
|
return getMiniMessage().deserialize(message, TagResolver.resolver(placeholders));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stripTokens(String input) {
|
public static String stripTokens(String input) {
|
||||||
return getMiniMessage().stripTokens(input);
|
return getMiniMessage().stripTags(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MiniMessage getMiniMessage() {
|
public static MiniMessage getMiniMessage() {
|
||||||
if (miniMessage == null) miniMessage = MiniMessage.miniMessage();
|
if (miniMessage == null) {
|
||||||
|
miniMessage = MiniMessage.miniMessage();
|
||||||
|
}
|
||||||
return miniMessage;
|
return miniMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String removeAllColors(String string) {
|
||||||
|
|
||||||
|
for (String colorCodes : colors.keySet()) {
|
||||||
|
string = string.replace(colorCodes, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.replaceAll("\\{#[A-Fa-f0-9]{6}(<)?(>)?}", "");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
plugins {
|
plugins {
|
||||||
`java-library`
|
`java-library`
|
||||||
id("com.github.johnrengelman.shadow") version "7.1.0"
|
id("io.github.goooler.shadow") version "8.1.8"
|
||||||
|
id("com.github.ben-manes.versions") version "0.52.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "com.alttd.chat"
|
group = "com.alttd.chat"
|
||||||
version = "1.0.0-SNAPSHOT"
|
version = "2.0.0-SNAPSHOT"
|
||||||
description = "All in one minecraft chat plugin"
|
description = "All in one minecraft chat plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -14,7 +15,7 @@ subprojects {
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion.set(JavaLanguageVersion.of(17))
|
languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,13 +49,13 @@ dependencies {
|
||||||
tasks {
|
tasks {
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
archiveFileName.set("${project.name}.jar")
|
||||||
minimize() {
|
minimize() {
|
||||||
exclude { it.moduleName == "galaxy" }
|
exclude { it.moduleName == "galaxy" }
|
||||||
exclude { it.moduleName == "velocity" }
|
exclude { it.moduleName == "velocity" }
|
||||||
}
|
}
|
||||||
listOf(
|
listOf(
|
||||||
"net.kyori.adventure.text.minimessage",
|
// "net.kyori.adventure.text.minimessage",
|
||||||
"org.spongepowered.configurate"
|
"org.spongepowered.configurate"
|
||||||
// ).forEach { relocate(it, "${rootProject.group}.lib.$it") }
|
// ).forEach { relocate(it, "${rootProject.group}.lib.$it") }
|
||||||
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
|
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
|
||||||
|
|
@ -64,4 +65,7 @@ tasks {
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jar {
|
||||||
|
enabled = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,25 +1,22 @@
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("com.github.johnrengelman.shadow")
|
id("io.github.goooler.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api")) // API
|
implementation(project(":api")) // API
|
||||||
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT") {
|
compileOnly("com.alttd.cosmos:cosmos-api:1.21.8-R0.1-SNAPSHOT") {
|
||||||
exclude("net.kyori.adventure.text.minimessag")
|
isChanging = true
|
||||||
} // Galaxy
|
|
||||||
compileOnly("net.kyori", "adventure-text-minimessage", "4.10.0-20220122.015731-43") { // Minimessage
|
|
||||||
exclude("net.kyori")
|
|
||||||
exclude("net.kyori.examination")
|
|
||||||
}
|
}
|
||||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
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 {
|
tasks {
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
archiveFileName.set("${rootProject.name}-${project.name}-${project.version}.jar")
|
||||||
// minimize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build {
|
build {
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,21 @@ import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.config.ServerConfig;
|
import com.alttd.chat.config.ServerConfig;
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
import com.alttd.chat.database.DatabaseConnection;
|
||||||
import com.alttd.chat.handler.ChatHandler;
|
import com.alttd.chat.handler.ChatHandler;
|
||||||
import com.alttd.chat.listeners.ChatListener;
|
import com.alttd.chat.listeners.*;
|
||||||
import com.alttd.chat.listeners.PlayerListener;
|
import com.alttd.chat.nicknames.Nicknames;
|
||||||
import com.alttd.chat.listeners.PluginMessage;
|
import com.alttd.chat.nicknames.NicknamesEvents;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
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.ALogger;
|
||||||
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Objects;
|
||||||
|
|
||||||
public class ChatPlugin extends JavaPlugin {
|
public class ChatPlugin extends JavaPlugin {
|
||||||
|
|
||||||
|
|
@ -27,7 +28,6 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
private ChatAPI chatAPI;
|
private ChatAPI chatAPI;
|
||||||
private ChatHandler chatHandler;
|
private ChatHandler chatHandler;
|
||||||
|
|
||||||
private String messageChannel;
|
|
||||||
private ServerConfig serverConfig;
|
private ServerConfig serverConfig;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -37,29 +37,38 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
chatAPI = new ChatImplementation();
|
chatAPI = new ChatImplementation();
|
||||||
chatHandler = new ChatHandler();
|
chatHandler = new ChatHandler();
|
||||||
DatabaseConnection.initialize();
|
DatabaseConnection.initialize();
|
||||||
serverConfig = new ServerConfig(Bukkit.getServerName());
|
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||||
registerListener(new PlayerListener(), new ChatListener());
|
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||||
if(serverConfig.GLOBALCHAT) {
|
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
||||||
|
if (serverConfig.GLOBALCHAT) {
|
||||||
registerCommand("globalchat", new GlobalChat());
|
registerCommand("globalchat", new GlobalChat());
|
||||||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||||
}
|
}
|
||||||
registerCommand("message", new Message());
|
registerCommand("message", new Message());
|
||||||
registerCommand("reply", new Reply());
|
registerCommand("reply", new Reply());
|
||||||
|
registerCommand("continue", new Continue());
|
||||||
registerCommand("ignore", new Ignore());
|
registerCommand("ignore", new Ignore());
|
||||||
registerCommand("unignore", new Unignore());
|
registerCommand("unignore", new Unignore());
|
||||||
registerCommand("muteserver", new MuteServer());
|
registerCommand("muteserver", new MuteServer());
|
||||||
registerCommand("spy", new Spy());
|
registerCommand("spy", new Spy());
|
||||||
registerCommand("chatclear", new ChatClear());
|
registerCommand("chatclear", new ChatClear());
|
||||||
// registerCommand("chatparty", new ChatParty());
|
|
||||||
registerCommand("p", new PartyChat());
|
registerCommand("p", new PartyChat());
|
||||||
|
registerCommand("emotes", new Emotes());
|
||||||
for (Channel channel : Channel.getChannels()) {
|
for (Channel channel : Channel.getChannels()) {
|
||||||
if (!(channel instanceof CustomChannel customChannel)) continue;
|
if (!(channel instanceof CustomChannel customChannel)) {
|
||||||
this.getServer().getCommandMap().register(channel.getChannelName().toLowerCase(), new ChatChannel(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().registerOutgoingPluginChannel(this, messageChannel);
|
||||||
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, new PluginMessage());
|
||||||
|
|
||||||
|
NicknamesEvents nicknamesEvents = new NicknamesEvents();
|
||||||
|
getServer().getMessenger().registerIncomingPluginChannel(this, messageChannel, nicknamesEvents);
|
||||||
|
getServer().getPluginManager().registerEvents(nicknamesEvents, this);
|
||||||
|
registerCommand("nick", new Nicknames());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -74,23 +83,13 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerCommand(String commandName, CommandExecutor commandExecutor) {
|
public void registerCommand(String commandName, CommandExecutor commandExecutor) {
|
||||||
getCommand(commandName).setExecutor(commandExecutor);
|
Objects.requireNonNull(getCommand(commandName)).setExecutor(commandExecutor);
|
||||||
}
|
|
||||||
|
|
||||||
public void registerCommand(String commandName, CommandExecutor commandExecutor, List<String> aliases) {
|
|
||||||
PluginCommand command = getCommand(commandName);
|
|
||||||
command.setAliases(aliases);
|
|
||||||
command.setExecutor(commandExecutor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ChatPlugin getInstance() {
|
public static ChatPlugin getInstance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatAPI getChatAPI() {
|
|
||||||
return chatAPI;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChatHandler getChatHandler() {
|
public ChatHandler getChatHandler() {
|
||||||
return chatHandler;
|
return chatHandler;
|
||||||
}
|
}
|
||||||
|
|
@ -107,11 +106,11 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
serverConfig.MUTED = !serverConfig.MUTED;
|
serverConfig.MUTED = !serverConfig.MUTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadConfig() {
|
public void reloadConfig() {
|
||||||
chatAPI.ReloadConfig();
|
chatAPI.reloadConfig();
|
||||||
chatAPI.ReloadChatFilters();
|
chatAPI.reloadChatFilters();
|
||||||
serverConfig = new ServerConfig(Bukkit.getServerName());
|
serverConfig = new ServerConfig(ServerName.getServerName());
|
||||||
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config."), "command.chat.reloadchat");
|
Bukkit.broadcast(Utility.parseMiniMessage("Reloaded ChatPlugin Config.").asComponent(), "command.chat.reloadchat");
|
||||||
ALogger.info("Reloaded ChatPlugin config.");
|
ALogger.info("Reloaded ChatPlugin config.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,25 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import com.alttd.chat.util.ToggleableForCustomChannel;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.defaults.BukkitCommand;
|
import org.bukkit.command.defaults.BukkitCommand;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ChatChannel extends BukkitCommand {
|
public class ChatChannel extends BukkitCommand {
|
||||||
|
|
||||||
CustomChannel channel;
|
CustomChannel channel;
|
||||||
String command;
|
String command;
|
||||||
|
ToggleableForCustomChannel toggleableForCustomChannel;
|
||||||
|
private static final List<ChatChannel> activeCommands = new ArrayList<>();
|
||||||
|
|
||||||
public ChatChannel(CustomChannel channel) {
|
public ChatChannel(CustomChannel channel) {
|
||||||
super(channel.getChannelName().toLowerCase());
|
super(channel.getChannelName().toLowerCase());
|
||||||
|
|
@ -22,24 +27,28 @@ public class ChatChannel extends BukkitCommand {
|
||||||
this.command = channel.getChannelName().toLowerCase();
|
this.command = channel.getChannelName().toLowerCase();
|
||||||
this.description = "Chat channel named " + channel.getChannelName() + ".";
|
this.description = "Chat channel named " + channel.getChannelName() + ".";
|
||||||
this.usageMessage = "/" + command + " <message>";
|
this.usageMessage = "/" + command + " <message>";
|
||||||
this.setAliases(Collections.emptyList());
|
this.setAliases(channel.getAliases());
|
||||||
|
activeCommands.add(this);
|
||||||
|
this.toggleableForCustomChannel = new ToggleableForCustomChannel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean execute(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
public boolean execute(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
|
||||||
if(!(sender instanceof Player player)) { // must be a player
|
if (!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args.length == 0) return false;
|
|
||||||
|
if (args.length == 0 && player.hasPermission(channel.getPermission())) {
|
||||||
|
player.sendRichMessage(Config.CUSTOM_CHANNEL_TOGGLED, TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("channel", channel.getChannelName()),
|
||||||
|
Placeholder.component("status", toggleableForCustomChannel.toggle(player.getUniqueId())
|
||||||
|
? Config.TOGGLED_ON : Config.TOGGLED_OFF)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String message = StringUtils.join(args, " ", 0, args.length);
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
|
|
||||||
new BukkitRunnable() {
|
toggleableForCustomChannel.sendMessage(player, message);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ChatPlugin.getInstance().getChatHandler().chatChannel(player, channel, message);
|
|
||||||
}
|
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,36 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.util.Utility;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.PlaceholderResolver;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ChatClear implements CommandExecutor {
|
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();
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
@Override
|
@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")) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
for (Player player : Bukkit.getOnlinePlayers())
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
if (!player.hasPermission("chat.clear-bypass"))
|
if (!player.hasPermission("chat.clear-bypass")) {
|
||||||
player.sendMessage(component);
|
player.sendMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Bukkit.getServer().sendMessage(miniMessage.deserialize(
|
Bukkit.getServer().sendMessage(miniMessage.deserialize(
|
||||||
"<gold><player> cleared chat.</gold>", PlaceholderResolver.placeholders(
|
"<gold><player> cleared chat.</gold>",
|
||||||
Placeholder.component("player", miniMessage.deserialize(sender.getName()))
|
Placeholder.component("player", sender.name()))
|
||||||
)));
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
galaxy/src/main/java/com/alttd/chat/commands/Continue.java
Normal file
32
galaxy/src/main/java/com/alttd/chat/commands/Continue.java
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
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.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class Continue implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
|
ChatPlugin.getInstance().getChatHandler().continuePrivateMessage(player, user.getReplyContinueTarget(), message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
33
galaxy/src/main/java/com/alttd/chat/commands/Emotes.java
Normal file
33
galaxy/src/main/java/com/alttd/chat/commands/Emotes.java
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.EmoteList;
|
||||||
|
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 Emotes implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
EmoteList emoteList = EmoteList.getEmoteList(player.getUniqueId());
|
||||||
|
if(args.length > 0) {
|
||||||
|
try {
|
||||||
|
int page = Integer.parseInt(args[0]);
|
||||||
|
emoteList.setPage(page);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "next" -> emoteList.nextPage();
|
||||||
|
case "prev", "previous" -> emoteList.prevPage();
|
||||||
|
default -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player.sendMessage(emoteList.showEmotePage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class GlobalChat implements CommandExecutor {
|
public class GlobalChat implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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
|
if (!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(args.length == 0) return false;
|
if (args.length == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
String message = StringUtils.join(args, " ", 0, args.length);
|
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.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.util.Utility;
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Ignore implements CommandExecutor {
|
public class Ignore implements CommandExecutor {
|
||||||
|
|
@ -29,11 +27,13 @@ public class Ignore implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
if (!(sender instanceof Player player)) {
|
||||||
return true;
|
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];
|
String targetName = args[0];
|
||||||
if (targetName.equals("?")) {
|
if (targetName.equals("?")) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
@ -44,7 +44,7 @@ public class Ignore implements CommandExecutor {
|
||||||
StringBuilder ignoredMessage = new StringBuilder();
|
StringBuilder ignoredMessage = new StringBuilder();
|
||||||
|
|
||||||
if (userNames.isEmpty()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,21 +52,21 @@ public class Ignore implements CommandExecutor {
|
||||||
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
|
userNames.forEach(username -> ignoredMessage.append(username).append("\n"));
|
||||||
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
|
ignoredMessage.delete(ignoredMessage.length() - 1, ignoredMessage.length());
|
||||||
|
|
||||||
player.sendMessage(Utility.parseMiniMessage(ignoredMessage.toString()));
|
player.sendRichMessage(ignoredMessage.toString());
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(plugin);
|
}.runTaskAsynchronously(plugin);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player targetPlayer = Bukkit.getPlayer(targetName);
|
Player targetPlayer = Bukkit.getPlayer(targetName);
|
||||||
if(targetPlayer == null) { // can't ignore offline players
|
if (targetPlayer == null) { // can't ignore offline players
|
||||||
sender.sendMessage("You can't ignore offline players");
|
sender.sendMessage("You can't ignore offline players");
|
||||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UUID target = targetPlayer.getUniqueId();
|
UUID target = targetPlayer.getUniqueId();
|
||||||
if(targetPlayer.hasPermission("chat.ignorebypass") || target.equals(player.getUniqueId())) {
|
if (targetPlayer.hasPermission("chat.ignorebypass") || target.equals(player.getUniqueId())) {
|
||||||
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
sender.sendMessage("You can't ignore this player"); // TODO load from config and minimessage
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -74,9 +74,9 @@ public class Ignore implements CommandExecutor {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(!chatUser.getIgnoredPlayers().contains(target)) {
|
if (!chatUser.getIgnoredPlayers().contains(target)) {
|
||||||
chatUser.addIgnoredPlayers(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
|
sender.sendMessage("You have ignored " + targetName + "."); // TODO load from config and minimessage
|
||||||
sendPluginMessage("ignore", player, target);
|
sendPluginMessage("ignore", player, target);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
package com.alttd.chat.commands;
|
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class Mail implements CommandExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if(!(sender instanceof Player)) { // must be a player, @teri should console be able to /msg?
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Player player = (Player) sender;
|
|
||||||
if(args.length > 2) return false; // todo error message or command info
|
|
||||||
|
|
||||||
String message = StringUtils.join(args, " ", 1, args.length);
|
|
||||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,22 +1,28 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Message implements CommandExecutor {
|
public class Message implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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)) {
|
if (!(sender instanceof Player player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
if (args.length < 2) {
|
||||||
if(args.length < 2) return false; // todo error message or command info
|
return false; // todo error message or command info
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
user.setReplyContinueTarget(args[0]);
|
||||||
String message = StringUtils.join(args, " ", 1, args.length);
|
String message = StringUtils.join(args, " ", 1, args.length);
|
||||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
|
ChatPlugin.getInstance().getChatHandler().privateMessage(player, args[0], message);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,22 @@ package com.alttd.chat.commands;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.util.Utility;
|
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 org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class MuteServer implements CommandExecutor {
|
public class MuteServer implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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
|
if (!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
|
|
@ -26,13 +26,13 @@ public class MuteServer implements CommandExecutor {
|
||||||
public void run() {
|
public void run() {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
if (!Utility.hasPermission(uuid, Config.SERVERMUTEPERMISSION)) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatPlugin.getInstance().toggleServerMuted();
|
ChatPlugin.getInstance().toggleServerMuted();
|
||||||
|
|
||||||
Component component;
|
ComponentLike component;
|
||||||
if (ChatPlugin.getInstance().serverMuted()) {
|
if (ChatPlugin.getInstance().serverMuted()) {
|
||||||
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
component = Utility.parseMiniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName()) + " <red>muted</red><white> chat.");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Toggleable;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.ALogger;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
@ -13,7 +13,12 @@ import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class PartyChat implements CommandExecutor {
|
import java.util.HashSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PartyChat extends Toggleable implements CommandExecutor {
|
||||||
|
|
||||||
|
private final HashSet<UUID> toggledUsers = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
|
|
@ -22,7 +27,8 @@ public class PartyChat implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args.length == 0) {
|
if(args.length == 0) {
|
||||||
// TODO: 08/08/2021 lock into party chat
|
player.sendRichMessage(Config.PARTY_TOGGLED, Placeholder.component("status",
|
||||||
|
toggle(player.getUniqueId()) ? Config.TOGGLED_ON : Config.TOGGLED_OFF));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,4 +43,31 @@ public class PartyChat implements CommandExecutor {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isToggled(UUID uuid) {
|
||||||
|
return toggledUsers.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOff(UUID uuid) {
|
||||||
|
toggledUsers.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOn(UUID uuid) {
|
||||||
|
disableToggles(uuid);
|
||||||
|
toggledUsers.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Player player, String message) {
|
||||||
|
ALogger.info(player.getName() + " sent party message: " + message);
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ChatPlugin.getInstance().getChatHandler().partyMessage(player, message);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,27 @@ package com.alttd.chat.commands;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class Reply implements CommandExecutor {
|
public class Reply implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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)) {
|
if (!(sender instanceof Player player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if (user.getReplyTarget() == null) return false;
|
if (user.getReplyTarget() == null) {
|
||||||
if(args.length == 0) return false; // todo error message or command info
|
return false;
|
||||||
|
}
|
||||||
|
if (args.length == 0) {
|
||||||
|
return false; // todo error message or command info
|
||||||
|
}
|
||||||
|
|
||||||
String message = StringUtils.join(args, " ", 0, args.length);
|
String message = StringUtils.join(args, " ", 0, args.length);
|
||||||
ChatPlugin.getInstance().getChatHandler().privateMessage(player, user.getReplyTarget(), message);
|
ChatPlugin.getInstance().getChatHandler().privateMessage(player, user.getReplyTarget(), message);
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,29 @@
|
||||||
package com.alttd.chat.commands;
|
package com.alttd.chat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Spy implements CommandExecutor {
|
public class Spy implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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)) { // must be a player
|
if (!(sender instanceof Player player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UUID uuid = ((Player) sender).getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
user.toggleSpy();
|
user.toggleSpy();
|
||||||
sender.sendMessage(Utility.parseMiniMessage("You have turned spy " + (user.isSpy() ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
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.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import jdk.jshell.execution.Util;
|
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ToggleGlobalChat implements CommandExecutor {
|
public class ToggleGlobalChat implements CommandExecutor {
|
||||||
|
|
||||||
@Override
|
@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)) { // must be a player
|
if (!(sender instanceof Player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UUID uuid = ((Player) sender).getUniqueId();
|
UUID uuid = ((Player) sender).getUniqueId();
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
ChatUserManager.getChatUser(uuid);
|
||||||
//chatUser.toggleGc();
|
|
||||||
Utility.flipPermission(uuid, Config.GCPERMISSION);
|
Utility.flipPermission(uuid, Config.GCPERMISSION);
|
||||||
//Queries.setGlobalChatState(chatUser.isGcOn(), chatUser.getUuid());
|
sender.sendRichMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off.")); // TODO load from config and minimessage
|
||||||
sender.sendMessage(Utility.parseMiniMessage("You have turned globalchat " + (!Utility.hasPermission(uuid, Config.GCPERMISSION) ? "<green>on." : "<red>off."))); // TODO load from config and minimessage
|
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,17 @@ package com.alttd.chat.commands;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.listeners.PluginMessage;
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
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.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginCommand;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -30,22 +26,20 @@ public class Unignore implements CommandExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
if (!(sender instanceof Player player)) { // must be a player
|
||||||
return true;
|
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];
|
String targetName = args[0];
|
||||||
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
UUID target = Bukkit.getOfflinePlayer(targetName).getUniqueId();
|
||||||
if(target == null) {
|
|
||||||
//sender.sendMessage("Target not found..."); // TODO load from config and minimessage
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(chatUser.getIgnoredPlayers().contains(target)) {
|
if (chatUser.getIgnoredPlayers().contains(target)) {
|
||||||
chatUser.removeIgnoredPlayers(target);
|
chatUser.removeIgnoredPlayers(target);
|
||||||
Queries.unIgnoreUser(player.getUniqueId(), target);
|
Queries.unIgnoreUser(player.getUniqueId(), target);
|
||||||
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
sender.sendMessage("You no longer ignore " + targetName + "."); // TODO load from config and minimessage
|
||||||
|
|
|
||||||
|
|
@ -4,73 +4,111 @@ import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.kyori.adventure.text.Component;
|
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.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
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;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ChatHandler {
|
public class ChatHandler {
|
||||||
|
|
||||||
private final ChatPlugin plugin;
|
private final ChatPlugin plugin;
|
||||||
|
|
||||||
private final Component GCNOTENABLED;
|
private final ComponentLike GCNOTENABLED;
|
||||||
|
|
||||||
public ChatHandler() {
|
public ChatHandler() {
|
||||||
plugin = ChatPlugin.getInstance();
|
plugin = ChatPlugin.getInstance();
|
||||||
GCNOTENABLED = Utility.parseMiniMessage(Config.GCNOTENABLED);
|
GCNOTENABLED = Utility.parseMiniMessage(Config.GCNOTENABLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void privateMessage(Player player, String target, String message) {
|
public void continuePrivateMessage(Player player, String target, String message) {
|
||||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
// user.setReplyTarget(target);
|
// user.setReplyTarget(target);
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.component("message", parseMessageContent(player, message)),
|
||||||
|
Placeholder.component("sendername", player.name()),
|
||||||
|
Placeholder.parsed("receivername", target)
|
||||||
|
);
|
||||||
|
|
||||||
|
ComponentLike component = Utility.parseMiniMessage("<message>", placeholders);
|
||||||
|
|
||||||
|
ModifiableString modifiableString = new ModifiableString(component.asComponent());
|
||||||
// todo a better way for this
|
// todo a better way for this
|
||||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||||
GalaxyUtility.sendBlockedNotification("DM Language",
|
GalaxyUtility.sendBlockedNotification("DM Language",
|
||||||
player,
|
player,
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
target);
|
target);
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
String updatedMessage = modifiableString.string();
|
|
||||||
|
|
||||||
if(!player.hasPermission("chat.format")) {
|
component = modifiableString.component();
|
||||||
updatedMessage = Utility.stripTokens(updatedMessage);
|
|
||||||
} else {
|
sendPrivateMessage(player, target, "privatemessage", component.asComponent());
|
||||||
updatedMessage = Utility.parseColors(updatedMessage);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void privateMessage(Player player, String target, String message) {
|
||||||
|
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
// user.setReplyTarget(target);
|
||||||
|
|
||||||
|
Component messageComponent = parseMessageContent(player, message);
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.component("message", messageComponent),
|
||||||
|
Placeholder.component("sendername", player.name()),
|
||||||
|
Placeholder.parsed("receivername", target)
|
||||||
|
);
|
||||||
|
|
||||||
|
ModifiableString modifiableString = new ModifiableString(messageComponent);
|
||||||
|
// todo a better way for this
|
||||||
|
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "privatemessage")) {
|
||||||
|
GalaxyUtility.sendBlockedNotification("DM Language",
|
||||||
|
player,
|
||||||
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
|
target);
|
||||||
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
|
||||||
if(updatedMessage.contains("[i]"))
|
messageComponent = modifiableString.component();
|
||||||
updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
|
||||||
|
|
||||||
updatedMessage = Utility.formatText(updatedMessage);
|
// Component component = Utility.parseMiniMessage("<message>", placeholders)
|
||||||
|
// .replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand())).build());
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
sendPrivateMessage(player, target, "privatemessage", messageComponent);
|
||||||
placeholders.put("message", Replacement.miniMessage(updatedMessage));
|
ComponentLike spymessage = Utility.parseMiniMessage(Config.MESSAGESPY, placeholders);
|
||||||
placeholders.put("sendername", Replacement.miniMessage(player.getName()));
|
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||||
placeholders.put("receivername", Replacement.miniMessage(target));
|
if (pl.hasPermission(Config.SPYPERMISSION) && ChatUserManager.getChatUser(pl.getUniqueId()).isSpy() && !pl.equals(player) && !pl.getName().equalsIgnoreCase(target)) {
|
||||||
placeholders.put("[i]", Replacement.component(itemComponent(player.getInventory().getItemInMainHand())));
|
|
||||||
|
|
||||||
Component component = Utility.parseMiniMessage("<message>", placeholders);
|
|
||||||
|
|
||||||
sendPrivateMessage(player, target, "privatemessage", component);
|
|
||||||
Component 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);
|
pl.sendMessage(spymessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +116,7 @@ public class ChatHandler {
|
||||||
|
|
||||||
public void globalChat(Player player, String message) {
|
public void globalChat(Player player, String message) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
if(!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
|
if (!Utility.hasPermission(player.getUniqueId(), Config.GCPERMISSION)) {
|
||||||
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
player.sendMessage(GCNOTENABLED);// GC IS OFF INFORM THEM ABOUT THIS and cancel
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -88,92 +126,75 @@ public class ChatHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
long timeLeft = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - user.getGcCooldown());
|
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
|
if (timeLeft <= Config.GCCOOLDOWN && !player.hasPermission("chat.globalchat.cooldownbypass")) { // player is on cooldown and should wait x seconds
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
player.sendRichMessage(Config.GCONCOOLDOWN, Placeholder.parsed("cooldown", Config.GCCOOLDOWN - timeLeft + ""));
|
||||||
placeholders.put("cooldown", Replacement.miniMessage(Config.GCCOOLDOWN-timeLeft+""));
|
|
||||||
player.sendMessage(Utility.parseMiniMessage(Config.GCONCOOLDOWN, placeholders));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component senderName = user.getDisplayName();
|
ComponentLike senderName = user.getDisplayName();
|
||||||
Component prefix = user.getPrefix();
|
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", ServerName.getServerName())
|
||||||
|
);
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders).asComponent();
|
||||||
|
|
||||||
|
ModifiableString modifiableString = new ModifiableString(component);
|
||||||
// todo a better way for this
|
// todo a better way for this
|
||||||
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "globalchat")) {
|
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "globalchat")) {
|
||||||
GalaxyUtility.sendBlockedNotification("GC Language",
|
GalaxyUtility.sendBlockedNotification("GC Language",
|
||||||
player,
|
player,
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
"");
|
"");
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
component = modifiableString.component();
|
||||||
|
|
||||||
String updatedMessage = modifiableString.string();
|
|
||||||
if(!player.hasPermission("chat.format")) {
|
|
||||||
updatedMessage = Utility.stripTokens(updatedMessage);
|
|
||||||
} else {
|
|
||||||
updatedMessage = Utility.parseColors(updatedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(updatedMessage.contains("[i]"))
|
|
||||||
updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
|
||||||
|
|
||||||
updatedMessage = Utility.formatText(updatedMessage);
|
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
|
||||||
placeholders.put("sender", Replacement.component(senderName));
|
|
||||||
placeholders.put("prefix", Replacement.component(prefix));
|
|
||||||
placeholders.put("message", Replacement.miniMessage(updatedMessage));
|
|
||||||
placeholders.put("server", Replacement.miniMessage(Bukkit.getServerName()));
|
|
||||||
placeholders.put("[i]", Replacement.component(itemComponent(player.getInventory().getItemInMainHand())));
|
|
||||||
|
|
||||||
Component component = Utility.parseMiniMessage(Config.GCFORMAT, placeholders);
|
|
||||||
user.setGcCooldown(System.currentTimeMillis());
|
user.setGcCooldown(System.currentTimeMillis());
|
||||||
sendPluginMessage(player, "globalchat", component);
|
sendPluginMessage(player, "globalchat", component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void chatChannel(Player player, CustomChannel channel, String message) {
|
public void chatChannel(Player player, CustomChannel channel, String message) {
|
||||||
if (!player.hasPermission(channel.getPermission())) {
|
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;
|
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());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
Component senderName = user.getDisplayName();
|
ComponentLike senderName = user.getDisplayName();
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
|
Placeholder.component("sender", senderName),
|
||||||
|
Placeholder.component("message", parseMessageContent(player, message)),
|
||||||
|
Placeholder.parsed("server", ServerName.getServerName()),
|
||||||
|
Placeholder.parsed("channel", channel.getChannelName())
|
||||||
|
);
|
||||||
|
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders).asComponent();
|
||||||
|
|
||||||
|
ModifiableString modifiableString = new ModifiableString(component);
|
||||||
|
if (!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, channel.getChannelName())) {
|
||||||
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language",
|
GalaxyUtility.sendBlockedNotification(channel.getChannelName() + " Language",
|
||||||
player,
|
player,
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
"");
|
"");
|
||||||
return; // the message was blocked
|
ALogger.info("Refusing to send blocked chat message");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String updatedMessage = modifiableString.string();
|
component = modifiableString.component();
|
||||||
if(!player.hasPermission("chat.format")) {
|
|
||||||
updatedMessage = Utility.stripTokens(updatedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
|
||||||
|
|
||||||
updatedMessage = Utility.formatText(updatedMessage);
|
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
|
||||||
placeholders.put("sender", Replacement.component(senderName));
|
|
||||||
placeholders.put("message", Replacement.miniMessage(updatedMessage));
|
|
||||||
placeholders.put("server", Replacement.miniMessage(Bukkit.getServerName()));
|
|
||||||
placeholders.put("channel", Replacement.miniMessage(channel.getChannelName()));
|
|
||||||
placeholders.put("[i]", Replacement.component(itemComponent(player.getInventory().getItemInMainHand())));
|
|
||||||
|
|
||||||
Component component = Utility.parseMiniMessage(channel.getFormat(), placeholders);
|
|
||||||
|
|
||||||
if (channel.isProxy()) {
|
if (channel.isProxy()) {
|
||||||
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component);
|
sendChatChannelMessage(player, channel.getChannelName(), "chatchannel", component, message);
|
||||||
} else {
|
} else {
|
||||||
sendChatChannelMessage(channel, player.getUniqueId(), component);
|
sendChatChannelMessage(channel, player.getUniqueId(), component, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,55 +205,92 @@ public class ChatHandler {
|
||||||
out.writeUTF(message);
|
out.writeUTF(message);
|
||||||
out.writeUTF(GsonComponentSerializer.gson().serialize(
|
out.writeUTF(GsonComponentSerializer.gson().serialize(
|
||||||
itemComponent(player.getInventory().getItemInMainHand())
|
itemComponent(player.getInventory().getItemInMainHand())
|
||||||
));
|
));
|
||||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
|
||||||
|
// if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
||||||
// if (isMuted(player, message, "[" + party.getPartyName() + " Muted] ")) return;
|
//
|
||||||
//
|
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
// Component senderName = user.getDisplayName();
|
||||||
// Component senderName = user.getDisplayName();
|
//
|
||||||
//
|
// String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
||||||
// String updatedMessage = RegexManager.replaceText(player.getName(), player.getUniqueId(), message);
|
// if(updatedMessage == null) {
|
||||||
// if(updatedMessage == null) {
|
// GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
||||||
// GalaxyUtility.sendBlockedNotification("Party Language", player, message, "");
|
// return; // the message was blocked
|
||||||
// return; // the message was blocked
|
// }
|
||||||
// }
|
//
|
||||||
//
|
// if(!player.hasPermission("chat.format")) {
|
||||||
// if(!player.hasPermission("chat.format")) {
|
// updatedMessage = Utility.stripTokens(updatedMessage);
|
||||||
// updatedMessage = Utility.stripTokens(updatedMessage);
|
// }
|
||||||
// }
|
//
|
||||||
//
|
// if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replaceFirst("[i]", "<item>");
|
||||||
// if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
//
|
||||||
//
|
// updatedMessage = Utility.formatText(updatedMessage);
|
||||||
// updatedMessage = Utility.formatText(updatedMessage);
|
//
|
||||||
//
|
// List<Placeholder> Placeholders = new ArrayList<>(List.of(
|
||||||
// List<Template> templates = new ArrayList<>(List.of(
|
// Placeholder.miniMessage("sender", senderName),
|
||||||
// Placeholder.miniMessage("sender", senderName),
|
// Placeholder.miniMessage("sendername", senderName),
|
||||||
// Placeholder.miniMessage("sendername", senderName),
|
// Placeholder.miniMessage("partyname", party.getPartyName()),
|
||||||
// Placeholder.miniMessage("partyname", party.getPartyName()),
|
// Placeholder.miniMessage("message", updatedMessage),
|
||||||
// Placeholder.miniMessage("message", updatedMessage),
|
// Placeholder.miniMessage("server", Bukkit.getServerName()),
|
||||||
// Placeholder.miniMessage("server", Bukkit.getServerName()),
|
// Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
||||||
// Placeholder.miniMessage("[i]", itemComponent(player.getInventory().getItemInMainHand()))));
|
//
|
||||||
//
|
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders);
|
||||||
// Component component = Utility.parseMiniMessage(Config.PARTY_FORMAT, templates);
|
//// sendPartyMessage(player, party.getPartyId(), component);
|
||||||
//// sendPartyMessage(player, party.getPartyId(), component);
|
//
|
||||||
//
|
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, Placeholders);
|
||||||
// Component spyMessage = Utility.parseMiniMessage(Config.PARTY_SPY, templates);
|
// for(Player pl : Bukkit.getOnlinePlayers()) {
|
||||||
// for(Player pl : Bukkit.getOnlinePlayers()) {
|
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||||
// if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
// pl.sendMessage(spyMessage);
|
||||||
// pl.sendMessage(spyMessage);
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, Component component) {
|
private void sendChatChannelMessage(CustomChannel chatChannel, UUID uuid, ComponentLike component, String message) {
|
||||||
if (!chatChannel.getServers().contains(Bukkit.getServerName())) return;
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) {
|
||||||
|
ALogger.warn("Failed to send chat message from non existent player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||||
|
|| receiver.hasPermission("chat.ignorebypass"));
|
||||||
|
}
|
||||||
|
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()
|
Bukkit.getServer().getOnlinePlayers().stream()
|
||||||
.filter(p -> p.hasPermission(chatChannel.getPermission()))
|
.filter(onlinePlayer -> onlinePlayer.hasPermission(Config.SPYPERMISSION))
|
||||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
.filter(onlinePlayer -> !recipientUUIDs.contains(onlinePlayer.getUniqueId()))
|
||||||
.forEach(p -> p.sendMessage(component));
|
.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) {
|
private void sendPluginMessage(Player player, String channel, Component component) {
|
||||||
|
|
@ -252,7 +310,7 @@ public class ChatHandler {
|
||||||
player.sendPluginMessage(plugin, Config.MESSAGECHANNEL, out.toByteArray());
|
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();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF(channel);
|
out.writeUTF(channel);
|
||||||
out.writeUTF(chatChannelName);
|
out.writeUTF(chatChannelName);
|
||||||
|
|
@ -265,9 +323,11 @@ public class ChatHandler {
|
||||||
|
|
||||||
private boolean isMuted(Player player, String message, String prefix) {
|
private boolean isMuted(Player player, String message, String prefix) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
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 (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"))) {
|
// 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)), "");
|
GalaxyUtility.sendBlockedNotification(prefix, player, Utility.parseMiniMessage(Utility.stripTokens(message)), "");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -276,11 +336,12 @@ public class ChatHandler {
|
||||||
|
|
||||||
public static Component itemComponent(ItemStack item) {
|
public static Component itemComponent(ItemStack item) {
|
||||||
Component component = Component.text("[i]", NamedTextColor.AQUA);
|
Component component = Component.text("[i]", NamedTextColor.AQUA);
|
||||||
if(item.getType().equals(Material.AIR))
|
if (item.getType().equals(Material.AIR)) {
|
||||||
return component.color(NamedTextColor.WHITE);
|
return component.color(NamedTextColor.WHITE);
|
||||||
|
}
|
||||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||||
if(dname) {
|
if (dname) {
|
||||||
component = component.append(item.getItemMeta().displayName());
|
component = component.append(Objects.requireNonNull(item.getItemMeta().displayName()));
|
||||||
} else {
|
} else {
|
||||||
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
|
component = component.append(Component.text(materialToName(item.getType()), NamedTextColor.WHITE));
|
||||||
}
|
}
|
||||||
|
|
@ -302,10 +363,12 @@ public class ChatHandler {
|
||||||
int loc = sb.lastIndexOf(split);
|
int loc = sb.lastIndexOf(split);
|
||||||
char charLoc = sb.charAt(loc);
|
char charLoc = sb.charAt(loc);
|
||||||
if (!(split.equalsIgnoreCase("of") || split.equalsIgnoreCase("and") ||
|
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));
|
sb.setCharAt(loc, Character.toUpperCase(charLoc));
|
||||||
if (pos != splits.length - 1)
|
}
|
||||||
|
if (pos != splits.length - 1) {
|
||||||
sb.append(' ');
|
sb.append(' ');
|
||||||
|
}
|
||||||
++pos;
|
++pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -313,4 +376,34 @@ public class ChatHandler {
|
||||||
}
|
}
|
||||||
// end - move these to util
|
// end - move these to util
|
||||||
|
|
||||||
|
private Component parseMessageContent(Player player, String rawMessage) {
|
||||||
|
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||||
|
|
||||||
|
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
tagResolver.resolver(pair.getX());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||||
|
Component component = miniMessage.deserialize(rawMessage);
|
||||||
|
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||||
|
component = component.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.times(Config.EMOTELIMIT)
|
||||||
|
.match(chatFilter.getRegex())
|
||||||
|
.replacement(chatFilter.getReplacement()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
component = component
|
||||||
|
.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.once()
|
||||||
|
.matchLiteral("[i]")
|
||||||
|
.replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
return component;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
61
galaxy/src/main/java/com/alttd/chat/listeners/BookListener.java
Executable file
61
galaxy/src/main/java/com/alttd/chat/listeners/BookListener.java
Executable file
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.managers.RegexManager;
|
||||||
|
import com.alttd.chat.objects.ChatFilter;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||||
|
import org.bukkit.inventory.meta.BookMeta;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BookListener implements Listener {
|
||||||
|
|
||||||
|
private final PlainTextComponentSerializer plainTextComponentSerializer = PlainTextComponentSerializer.plainText();
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onPlayerEditBookEvent(PlayerEditBookEvent event) {
|
||||||
|
BookMeta bookMeta = event.getNewBookMeta();
|
||||||
|
List<Component> pages = new ArrayList<>();
|
||||||
|
for (Component component : bookMeta.pages()) {
|
||||||
|
Component formatComponent = Component.text("%message%");
|
||||||
|
Component message = parseMessageContent(event.getPlayer(), plainTextComponentSerializer.serialize(component));
|
||||||
|
pages.add(formatComponent.replaceText(TextReplacementConfig.builder().match("%message%").replacement(message).build()));
|
||||||
|
}
|
||||||
|
bookMeta.pages(pages);
|
||||||
|
event.setNewBookMeta(bookMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component parseMessageContent(Player player, String rawMessage) {
|
||||||
|
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||||
|
|
||||||
|
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
tagResolver.resolver(pair.getX());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||||
|
Component component = miniMessage.deserialize(rawMessage);
|
||||||
|
for(ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||||
|
component = component.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.times(Config.EMOTELIMIT)
|
||||||
|
.match(chatFilter.getRegex())
|
||||||
|
.replacement(chatFilter.getReplacement()).build());
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -5,89 +5,227 @@ import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.handler.ChatHandler;
|
import com.alttd.chat.handler.ChatHandler;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.*;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
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.GalaxyUtility;
|
||||||
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import io.papermc.paper.chat.ChatRenderer;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||||
|
import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||||
import net.kyori.adventure.audience.Audience;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
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;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ChatListener implements Listener, ChatRenderer {
|
public class ChatListener implements Listener {
|
||||||
|
|
||||||
|
private final PlainTextComponentSerializer plainTextComponentSerializer = PlainTextComponentSerializer.plainText();
|
||||||
|
private final ChatLogHandler chatLogHandler;
|
||||||
|
|
||||||
|
public ChatListener(ChatLogHandler chatLogHandler) {
|
||||||
|
this.chatLogHandler = chatLogHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
|
public void onChatCommandDecorate(AsyncChatCommandDecorateEvent event) {
|
||||||
|
if (event.player() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Component formatComponent = Component.text("%message%");
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Component formatComponent = Component.text("%message%");
|
||||||
|
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)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerChat(AsyncChatEvent event) {
|
public void onPlayerChat(AsyncChatEvent event) {
|
||||||
|
event.setCancelled(true); //Always cancel the event because we do not want to deal with Microsoft's stupid bans
|
||||||
|
Toggleable toggleable = Toggleable.getToggleable(event.getPlayer().getUniqueId());
|
||||||
|
if (toggleable != null) {
|
||||||
|
toggleable.sendMessage(event.getPlayer(), event.message());
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ChatPlugin.getInstance().serverMuted() && !event.getPlayer().hasPermission("chat.bypass-server-muted")) {
|
if (ChatPlugin.getInstance().serverMuted() && !event.getPlayer().hasPermission("chat.bypass-server-muted")) {
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
GalaxyUtility.sendBlockedNotification("Chat Muted", player, event.message(), "");
|
GalaxyUtility.sendBlockedNotification("Chat Muted", player, event.message(), "");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
// ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
UUID uuid = player.getUniqueId();
|
||||||
|
|
||||||
event.viewers().removeIf(audience -> audience instanceof Player receiver
|
ComponentLike input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||||
&& ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()));
|
|
||||||
|
|
||||||
Component input = event.message();
|
ModifiableString modifiableString = new ModifiableString(input.asComponent());
|
||||||
String message = PlainTextComponentSerializer.plainText().serialize(input);
|
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
// todo a better way for this
|
||||||
// todo a better way for this
|
if (!RegexManager.filterText(player.getName(), uuid, modifiableString, true, "chat", filterType -> {
|
||||||
if(!RegexManager.filterText(player.getName(), player.getUniqueId(), modifiableString, "chat")) {
|
if (!filterType.equals(FilterType.PUNISH)) {
|
||||||
|
ALogger.warn("Received another FilterType than punish when filtering chat and executing a filter action");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
out.writeUTF("punish");
|
||||||
|
out.writeUTF(player.getName());
|
||||||
|
out.writeUTF(uuid.toString());
|
||||||
|
out.writeUTF(modifiableString.string());
|
||||||
|
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
})) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
GalaxyUtility.sendBlockedNotification("Language", player,
|
GalaxyUtility.sendBlockedNotification("Language", player,
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
modifiableString.component(),
|
||||||
"");
|
"");
|
||||||
|
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), PlainTextComponentSerializer.plainText().serialize(input.asComponent()), true);
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
message = modifiableString.string();
|
|
||||||
if(!player.hasPermission("chat.format")) {
|
Stream<Player> stream = event.viewers().stream().filter(audience -> audience instanceof Player)
|
||||||
message = Utility.stripTokens(message);
|
.map(audience -> (Player) audience);
|
||||||
} else {
|
|
||||||
message = Utility.parseColors(message);
|
if (!player.hasPermission("chat.ignorebypass")) {
|
||||||
|
stream = stream.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(uuid)
|
||||||
|
|| receiver.hasPermission("chat.ignorebypass"));
|
||||||
}
|
}
|
||||||
|
Set<Player> receivers = stream.collect(Collectors.toSet());
|
||||||
|
|
||||||
if(message.contains("[i]"))
|
Set<Player> playersToPing = new HashSet<>();
|
||||||
message = message.replace("[i]", "<[i]>"); // end of todo
|
pingPlayers(playersToPing, modifiableString, player);
|
||||||
|
|
||||||
message = Utility.formatText(message);
|
input = render(player, modifiableString.component());
|
||||||
|
for (Player receiver : receivers) {
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
receiver.sendMessage(input);
|
||||||
placeholders.put("message", Replacement.miniMessage(message));
|
}
|
||||||
placeholders.put("[i]", Replacement.component(ChatHandler.itemComponent(player.getInventory().getItemInMainHand())));
|
for (Player pingPlayer : playersToPing) {
|
||||||
|
pingPlayer.playSound(pingPlayer.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1);
|
||||||
Component component = Utility.parseMiniMessage("<message>", placeholders);
|
}
|
||||||
|
chatLogHandler.addChatLog(uuid, ServerName.getServerName(), modifiableString.string(), false);
|
||||||
event.message(component);
|
ALogger.info(PlainTextComponentSerializer.plainText().serialize(input.asComponent()));
|
||||||
event.renderer(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void pingPlayers(Set<Player> playersToPing, ModifiableString modifiableString, Player player) {
|
||||||
public @NotNull Component render(@NotNull Player player, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer) {
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
String name = onlinePlayer.getName();
|
||||||
|
String nickName = PlainTextComponentSerializer.plainText().serialize(onlinePlayer.displayName());
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
Pattern namePattern = Pattern.compile("\\b(?<!\\\\)" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
placeholders.put("sender", Replacement.component(player.displayName()));
|
// Pattern escapedNamePattern = Pattern.compile("\\b\\\\" + name + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
placeholders.put("sendername", Replacement.component(player.name()));
|
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
placeholders.put("prefix", Replacement.component(user.getPrefix()));
|
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
placeholders.put("prefixall", Replacement.component(user.getPrefixAll()));
|
|
||||||
placeholders.put("staffprefix", Replacement.component(user.getStaffPrefix()));
|
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
|
||||||
placeholders.put("message", Replacement.component(message));
|
if (namePattern.matcher(modifiableString.string()).find()) {
|
||||||
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
.once()
|
||||||
|
.match(namePattern)
|
||||||
|
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||||
|
.build());
|
||||||
|
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
||||||
|
// modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
// .once()
|
||||||
|
// .match(escapedNamePattern)
|
||||||
|
// .replacement((a, b) -> {
|
||||||
|
// String substring = a.group().substring(1);
|
||||||
|
// return ;
|
||||||
|
// });
|
||||||
|
|
||||||
|
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||||
|
|| player.hasPermission("chat.ignorebypass")) {
|
||||||
|
playersToPing.add(onlinePlayer);
|
||||||
|
}
|
||||||
|
} else if (nickPattern.matcher(modifiableString.string()).find()) {
|
||||||
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
.once()
|
||||||
|
.match(nickPattern)
|
||||||
|
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||||
|
.build());
|
||||||
|
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId())
|
||||||
|
|| player.hasPermission("chat.ignorebypass")) {
|
||||||
|
playersToPing.add(onlinePlayer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()),
|
||||||
|
Placeholder.parsed("sendername", player.getName()),
|
||||||
|
Placeholder.component("prefix", user.getPrefix()),
|
||||||
|
Placeholder.component("prefixall", user.getPrefixAll()),
|
||||||
|
Placeholder.component("staffprefix", user.getStaffPrefix()),
|
||||||
|
Placeholder.component("message", message)
|
||||||
|
);
|
||||||
|
|
||||||
return Utility.parseMiniMessage(Config.CHATFORMAT, placeholders);
|
return Utility.parseMiniMessage(Config.CHATFORMAT, placeholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ComponentLike parseMessageContent(Player player, String rawMessage) {
|
||||||
|
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||||
|
|
||||||
|
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
tagResolver.resolver(pair.getX());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||||
|
Component component = miniMessage.deserialize(Utility.formatText(rawMessage));
|
||||||
|
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||||
|
component = component.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.times(Config.EMOTELIMIT)
|
||||||
|
.match(chatFilter.getRegex())
|
||||||
|
.replacement(chatFilter.getReplacement()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
component = component
|
||||||
|
.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.once()
|
||||||
|
.matchLiteral("[i]")
|
||||||
|
.replacement(ChatHandler.itemComponent(player.getInventory().getItemInMainHand()))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
return component;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -1,31 +1,63 @@
|
||||||
package com.alttd.chat.listeners;
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.config.ServerConfig;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
import com.alttd.chat.objects.ModifiableString;
|
||||||
|
import com.alttd.chat.objects.Toggleable;
|
||||||
import com.alttd.chat.util.GalaxyUtility;
|
import com.alttd.chat.util.GalaxyUtility;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.TextReplacementConfig;
|
||||||
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class PlayerListener implements Listener {
|
public class PlayerListener implements Listener {
|
||||||
|
|
||||||
|
private final ServerConfig serverConfig;
|
||||||
|
|
||||||
|
public PlayerListener(ServerConfig serverConfig) {
|
||||||
|
this.serverConfig = serverConfig;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
private void onPlayerLogin(PlayerJoinEvent event) {
|
private void onPlayerLogin(PlayerJoinEvent event) {
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
Player player = event.getPlayer();
|
||||||
|
GalaxyUtility.addAdditionalChatCompletions(player);
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
Toggleable.disableToggles(uuid);
|
||||||
|
|
||||||
|
if (serverConfig.FIRST_JOIN_MESSAGES && (!player.hasPlayedBefore() || System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(10))) {
|
||||||
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
if(user != null) return;
|
if(user != null) return;
|
||||||
|
|
||||||
|
|
||||||
// user failed to load - create a new one
|
// user failed to load - create a new one
|
||||||
ChatUser chatUser = new ChatUser(uuid, -1, null);
|
ChatUser chatUser = new ChatUser(uuid, -1, null);
|
||||||
ChatUserManager.addUser(chatUser);
|
ChatUserManager.addUser(chatUser);
|
||||||
|
|
@ -47,8 +79,8 @@ public class PlayerListener implements Listener {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
Component component = event.line(i);
|
Component component = event.line(i);
|
||||||
if (component != null) {
|
if (component != null) {
|
||||||
String message = PlainTextComponentSerializer.plainText().serialize(component);
|
ModifiableString modifiableString = new ModifiableString(component);
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
// todo a better way for this
|
// todo a better way for this
|
||||||
|
|
@ -58,13 +90,51 @@ public class PlayerListener implements Listener {
|
||||||
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
Utility.parseMiniMessage(Utility.parseColors(modifiableString.string())),
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
message = modifiableString.string();
|
|
||||||
|
|
||||||
component = message == null ? Component.empty() : Component.text(message);
|
component = modifiableString.component() == null ? Component.empty() : modifiableString.component();
|
||||||
|
|
||||||
event.line(i, component);
|
event.line(i, component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private final HashMap<UUID, Stack<Instant>> sendPlayerDeaths = new HashMap<>();
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerDeath(@NotNull PlayerDeathEvent event) {
|
||||||
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
|
Stack<Instant> playerDeathsStack = sendPlayerDeaths.computeIfAbsent(uuid, key -> new Stack<>());
|
||||||
|
Instant cutOff = Instant.now().minus(Config.DEATH_MESSAGES_LIMIT_PERIOD_MINUTES, ChronoUnit.MINUTES);
|
||||||
|
|
||||||
|
while (!playerDeathsStack.isEmpty() && playerDeathsStack.peek().isBefore(cutOff)) {
|
||||||
|
playerDeathsStack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerDeathsStack.size() > Config.DEATH_MESSAGES_MAX_PER_PERIOD || serverConfig.MUTED) {
|
||||||
|
event.deathMessage(Component.empty());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Component component = event.deathMessage();
|
||||||
|
|
||||||
|
playerDeathsStack.push(Instant.now());
|
||||||
|
if (component == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TextReplacementConfig playerReplacement = TextReplacementConfig.builder()
|
||||||
|
.match(event.getPlayer().getName())
|
||||||
|
.replacement(event.getPlayer().displayName())
|
||||||
|
.build();
|
||||||
|
component = component.replaceText(playerReplacement);
|
||||||
|
Player killer = event.getPlayer().getKiller();
|
||||||
|
if (killer != null) {
|
||||||
|
TextReplacementConfig killerReplacement = TextReplacementConfig.builder()
|
||||||
|
.match(killer.getName())
|
||||||
|
.replacement(killer.displayName())
|
||||||
|
.build();
|
||||||
|
component = component.replaceText(killerReplacement);
|
||||||
|
}
|
||||||
|
component = MiniMessage.miniMessage().deserialize("<dark_red>[</dark_red><red>☠</red><dark_red>]</dark_red> ").append(component);
|
||||||
|
component = component.style(Style.style(TextColor.color(255, 155, 48), TextDecoration.ITALIC));
|
||||||
|
event.deathMessage(component);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,104 +5,110 @@ import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.Queries;
|
import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
import com.alttd.chat.objects.PartyUser;
|
import com.alttd.chat.objects.PartyUser;
|
||||||
import com.alttd.chat.objects.channels.Channel;
|
import com.alttd.chat.objects.channels.Channel;
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import com.alttd.chat.util.ServerName;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PluginMessage implements PluginMessageListener {
|
public class PluginMessage implements PluginMessageListener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] bytes) {
|
public void onPluginMessageReceived(String channel, @NotNull Player ignored, byte[] bytes) {
|
||||||
if (!channel.equals(Config.MESSAGECHANNEL)) {
|
if (!channel.equals(Config.MESSAGECHANNEL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||||
String subChannel = in.readUTF();
|
String subChannel = in.readUTF();
|
||||||
switch (subChannel) {
|
switch (subChannel) {
|
||||||
case "privatemessagein": {
|
case "privatemessagein" -> {
|
||||||
UUID uuid = UUID.fromString(in.readUTF());
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
String target = in.readUTF();
|
String target = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
String message = in.readUTF();
|
String message = in.readUTF();
|
||||||
UUID targetuuid = UUID.fromString(in.readUTF());
|
UUID targetuuid = UUID.fromString(in.readUTF());
|
||||||
if (p != null) {
|
if (player == null) {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
break;
|
||||||
if (!chatUser.getIgnoredPlayers().contains(targetuuid)) {
|
}
|
||||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||||
p.playSound(p.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS, 1, 1); // todo load this from config
|
if (isTargetNotIgnored(chatUser, targetuuid)) {
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||||
|
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)) {
|
||||||
user.setReplyTarget(target);
|
user.setReplyTarget(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "privatemessageout": {
|
case "privatemessageout" -> {
|
||||||
UUID uuid = UUID.fromString(in.readUTF());
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
String target = in.readUTF();
|
String target = in.readUTF();
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
String message = in.readUTF();
|
String message = in.readUTF();
|
||||||
UUID targetuuid = UUID.fromString(in.readUTF());
|
UUID targetuuid = UUID.fromString(in.readUTF());
|
||||||
if (p != null) {
|
if (player == null) {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
break;
|
||||||
if (!chatUser.getIgnoredPlayers().contains(targetuuid)) {
|
}
|
||||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
if (isTargetNotIgnored(chatUser, targetuuid)) {
|
||||||
user.setReplyTarget(target);
|
chatUser.setReplyTarget(target);
|
||||||
}
|
player.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||||
|
// ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
|
// user.setReplyTarget(target);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "globalchat": {
|
case "globalchat" -> {
|
||||||
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) break;
|
if (!ChatPlugin.getInstance().serverGlobalChatEnabled() || ChatPlugin.getInstance().serverMuted()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
UUID uuid = UUID.fromString(in.readUTF());
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
String message = in.readUTF();
|
String message = in.readUTF();
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission(Config.GCPERMISSION)).forEach(p -> {
|
Bukkit.getOnlinePlayers().stream().filter(p -> p.hasPermission(Config.GCPERMISSION)).forEach(p -> {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(p.getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(p.getUniqueId());
|
||||||
if (!chatUser.getIgnoredPlayers().contains(uuid)) {
|
if (isTargetNotIgnored(chatUser, uuid)) {
|
||||||
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
p.sendMessage(GsonComponentSerializer.gson().deserialize(message));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "ignore": {
|
case "ignore" -> {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
||||||
UUID targetUUID = UUID.fromString(in.readUTF());
|
UUID targetUUID = UUID.fromString(in.readUTF());
|
||||||
|
|
||||||
if(!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
if (!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
||||||
chatUser.addIgnoredPlayers(targetUUID);
|
chatUser.addIgnoredPlayers(targetUUID);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "unignore": {
|
case "unignore" -> {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
ChatUser chatUser = ChatUserManager.getChatUser(UUID.fromString(in.readUTF()));
|
||||||
chatUser.removeIgnoredPlayers(UUID.fromString(in.readUTF()));
|
chatUser.removeIgnoredPlayers(UUID.fromString(in.readUTF()));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "chatchannel": {
|
case "chatchannel" -> {
|
||||||
if (ChatPlugin.getInstance().serverMuted()) break;
|
if (ChatPlugin.getInstance().serverMuted()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
chatChannel(in);
|
chatChannel(in);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "tmppartyupdate" : {
|
case "tmppartyupdate" -> {
|
||||||
int id = Integer.parseInt(in.readUTF());
|
int id = Integer.parseInt(in.readUTF());
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -110,9 +116,8 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
Queries.loadPartyUsers(id);
|
Queries.loadPartyUsers(id);
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "partylogin": {
|
case "partylogin" -> {
|
||||||
int id = Integer.parseInt(in.readUTF());
|
int id = Integer.parseInt(in.readUTF());
|
||||||
Party party = PartyManager.getParty(id);
|
Party party = PartyManager.getParty(id);
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
|
|
@ -124,19 +129,20 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PartyUser user = party.getPartyUser(uuid);
|
PartyUser user = party.getPartyUser(uuid);
|
||||||
if(user != null) {
|
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()
|
Bukkit.getOnlinePlayers().stream()
|
||||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
.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));
|
.forEach(p -> p.sendMessage(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "partylogout": {
|
case "partylogout" -> {
|
||||||
int id = Integer.parseInt(in.readUTF());
|
int id = Integer.parseInt(in.readUTF());
|
||||||
Party party = PartyManager.getParty(id);
|
Party party = PartyManager.getParty(id);
|
||||||
if (party == null) {
|
if (party == null) {
|
||||||
|
|
@ -148,30 +154,31 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PartyUser user = party.getPartyUser(uuid);
|
PartyUser user = party.getPartyUser(uuid);
|
||||||
if(user != null) {
|
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()
|
Bukkit.getOnlinePlayers().stream()
|
||||||
.filter(p -> party.getPartyUsersUuid().contains(p.getUniqueId()))
|
.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));
|
.forEach(p -> p.sendMessage(component));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "reloadconfig":
|
case "reloadconfig" -> ChatPlugin.getInstance().reloadConfig();
|
||||||
ChatPlugin.getInstance().ReloadConfig();
|
case "chatpunishments" -> {
|
||||||
break;
|
|
||||||
case "chatpunishments":
|
|
||||||
UUID uuid = UUID.fromString(in.readUTF());
|
UUID uuid = UUID.fromString(in.readUTF());
|
||||||
boolean mute = in.readBoolean();
|
boolean mute = in.readBoolean();
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
if (user == null) return;
|
if (user == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
user.setMuted(mute);
|
user.setMuted(mute);
|
||||||
break;
|
}
|
||||||
default:
|
default -> {
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,15 +190,15 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
chatChannel = (CustomChannel) Channel.getChatChannel(in.readUTF());
|
chatChannel = (CustomChannel) Channel.getChatChannel(in.readUTF());
|
||||||
uuid = UUID.fromString(in.readUTF());
|
uuid = UUID.fromString(in.readUTF());
|
||||||
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
component = GsonComponentSerializer.gson().deserialize(in.readUTF());
|
||||||
} catch (Exception e) { //Idk the exception for reading too far into in.readUTF()
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
ALogger.error("Failed to read ChatChannel message.", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
ALogger.warn("Received ChatChannel message for non existent channel.");
|
ALogger.warn("Received ChatChannel message for non existent channel.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!chatChannel.getServers().contains(Bukkit.getServerName())) {
|
if (!chatChannel.getServers().contains(ServerName.getServerName())) {
|
||||||
ALogger.warn("Received ChatChannel message for the wrong server.");
|
ALogger.warn("Received ChatChannel message for the wrong server.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -208,10 +215,22 @@ public class PluginMessage implements PluginMessageListener {
|
||||||
public void run() {
|
public void run() {
|
||||||
Bukkit.getOnlinePlayers().stream()
|
Bukkit.getOnlinePlayers().stream()
|
||||||
.filter(p -> p.hasPermission(finalChatChannel.getPermission()))
|
.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));
|
.forEach(p -> p.sendMessage(finalComponent));
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isTargetNotIgnored(ChatUser chatUser, UUID targetUUID) {
|
||||||
|
if (!chatUser.getIgnoredPlayers().contains(targetUUID)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Player target = Bukkit.getPlayer(targetUUID);
|
||||||
|
if (target == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return target.hasPermission("chat.ignorebypass");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package com.alttd.chat.listeners;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
public class ShutdownListener implements Listener {
|
||||||
|
|
||||||
|
private final ChatLogHandler chatLogHandler;
|
||||||
|
private final Plugin thisPlugin;
|
||||||
|
|
||||||
|
public ShutdownListener(ChatLogHandler chatLogHandler, Plugin thisPlugin) {
|
||||||
|
this.chatLogHandler = chatLogHandler;
|
||||||
|
this.thisPlugin = thisPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onShutdown(PluginDisableEvent event) {
|
||||||
|
if (!event.getPlugin().getName().equals(thisPlugin.getName())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
chatLogHandler.shutDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
123
galaxy/src/main/java/com/alttd/chat/nicknames/NickUtilities.java
Normal file
123
galaxy/src/main/java/com/alttd/chat/nicknames/NickUtilities.java
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
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 org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class NickUtilities {
|
||||||
|
public static String stringRegen;
|
||||||
|
|
||||||
|
public static String removeAllColors(String string) {
|
||||||
|
|
||||||
|
for (final String colorCodes : Config.NICK_ALLOWED_COLOR_CODESLIST) {
|
||||||
|
string = string.replace(colorCodes, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.replaceAll("\\{#[A-Fa-f0-9]{6}(<)?(>)?}", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
NickUtilities.stringRegen = "\\{#[A-Fa-f0-9]{6}(<)?(>)?}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updateCache() {
|
||||||
|
if (!Nicknames.getInstance().nickCacheUpdate.isEmpty()) {
|
||||||
|
Nicknames.getInstance().nickCacheUpdate.forEach(uuid -> {
|
||||||
|
Nick nick = Queries.getNick(uuid);
|
||||||
|
if (nick == null) {
|
||||||
|
Nicknames.getInstance().NickCache.remove(uuid);
|
||||||
|
} else {
|
||||||
|
Nicknames.getInstance().NickCache.put(uuid, nick);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean validNick(Player sender, OfflinePlayer target, String nickName) {
|
||||||
|
if (!noBlockedCodes(nickName)) {
|
||||||
|
sender.sendRichMessage(Config.NICK_BLOCKED_COLOR_CODES);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Utility.checkNickBrightEnough(nickName)) {
|
||||||
|
sender.sendRichMessage("<red>At least one color must be brighter than 30 for each color</red>");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String cleanNick = NickUtilities.removeAllColors(nickName);
|
||||||
|
|
||||||
|
if (cleanNick.length() < 3 || cleanNick.length() > 16) {
|
||||||
|
sender.sendRichMessage(Config.NICK_INVALID_LENGTH);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!cleanNick.matches("[a-zA-Z0-9_]*") || nickName.length() > 192) { //192 is if someone puts {#xxxxxx<>} in front of every letter
|
||||||
|
sender.sendRichMessage(Config.NICK_INVALID_CHARACTERS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cleanNick.equalsIgnoreCase(target.getName())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Nick nick : Nicknames.getInstance().NickCache.values()) {
|
||||||
|
if (!nick.getUuid().equals(target.getUniqueId())
|
||||||
|
&& ((nick.getCurrentNickNoColor() != null && nick.getCurrentNickNoColor().equalsIgnoreCase(cleanNick))
|
||||||
|
|| (nick.getNewNickNoColor() != null && nick.getNewNickNoColor().equalsIgnoreCase(cleanNick)))) {
|
||||||
|
UUID uuid = nick.getUuid();
|
||||||
|
UUID uniqueId = target.getUniqueId();
|
||||||
|
if (uniqueId.equals(uuid)) {
|
||||||
|
ChatPlugin.getInstance().getLogger().info(uuid + " " + uniqueId);
|
||||||
|
}
|
||||||
|
sender.sendRichMessage(Config.NICK_TAKEN);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean noBlockedCodes(final String getNick) {
|
||||||
|
for (final String blockedCodes : Config.NICK_BLOCKED_COLOR_CODESLIST) {
|
||||||
|
if (getNick.contains(blockedCodes)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void bungeeMessageHandled(UUID uniqueId, Player player, String channel) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||||
|
// out.writeUTF("ALL");
|
||||||
|
out.writeUTF("NickName" + channel); // The channel name to check if this your data
|
||||||
|
|
||||||
|
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream msgout = new DataOutputStream(msgbytes);
|
||||||
|
try {
|
||||||
|
msgout.writeUTF(uniqueId.toString());
|
||||||
|
} catch (IOException exception) {
|
||||||
|
ALogger.error("Failed to write UUID to byte array", exception);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] bytes = msgbytes.toByteArray();
|
||||||
|
out.writeShort(bytes.length);
|
||||||
|
out.write(bytes);
|
||||||
|
|
||||||
|
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
421
galaxy/src/main/java/com/alttd/chat/nicknames/Nicknames.java
Normal file
421
galaxy/src/main/java/com/alttd/chat/nicknames/Nicknames.java
Normal file
|
|
@ -0,0 +1,421 @@
|
||||||
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatAPI;
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.database.Queries;
|
||||||
|
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;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
import net.luckperms.api.LuckPerms;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
static Nicknames instance;
|
||||||
|
HashMap<UUID, Nick> NickCache;
|
||||||
|
ArrayList<UUID> nickCacheUpdate;
|
||||||
|
|
||||||
|
public Nicknames() {
|
||||||
|
instance = this;
|
||||||
|
NickCache = new HashMap<>();
|
||||||
|
nickCacheUpdate = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||||
|
if (sender instanceof Player player) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (args[0].toLowerCase()) {
|
||||||
|
case "set":
|
||||||
|
if (args.length == 2 && hasPermission(sender, "chat.command.nick.set")) {
|
||||||
|
handleNick(player, player, args[1]);
|
||||||
|
} else if (args.length == 3 && hasPermission(sender, "chat.command.nick.set.others")) {
|
||||||
|
OfflinePlayer offlinePlayer = sender.getServer().getOfflinePlayer(args[1]);
|
||||||
|
|
||||||
|
if (offlinePlayer.isOnline() || offlinePlayer.hasPlayedBefore()) {
|
||||||
|
handleNick(player, offlinePlayer, args[2]);
|
||||||
|
} else {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.SET_OTHERS));
|
||||||
|
}
|
||||||
|
} else if (args.length > 3) {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.SET_SELF, HelpType.SET_OTHERS));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "review":
|
||||||
|
if (args.length == 1 && hasPermission(sender, "chat.command.nick.review")) {
|
||||||
|
NicknamesGui nicknamesGui = new NicknamesGui();
|
||||||
|
ChatPlugin.getInstance().getServer().getPluginManager().registerEvents(nicknamesGui, ChatPlugin.getInstance());
|
||||||
|
nicknamesGui.openInventory(player);
|
||||||
|
} else {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.REVIEW));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "request":
|
||||||
|
if (args.length == 2 && hasPermission(sender, "chat.command.nick.request")) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
handleNickRequest(player, args[1]);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
} else {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.REQUEST));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "try":
|
||||||
|
if (args.length == 2 && hasPermission(sender, "chat.command.nick.try")) {
|
||||||
|
LuckPerms api = ChatAPI.get().getLuckPerms();
|
||||||
|
if (api != null) {
|
||||||
|
if (NickUtilities.validNick(player, player, args[1])) {
|
||||||
|
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.unparsed("nickrequest", args[1]));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendRichMessage(Config.NICK_NO_LUCKPERMS);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendRichMessage(helpMessage(sender, HelpType.TRY));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "current":
|
||||||
|
if (hasPermission(sender, "chat.command.nick.current")) {
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.component("nickname", chatUser.getDisplayName()),
|
||||||
|
Placeholder.parsed("currentnickname", chatUser.getNickNameString())
|
||||||
|
);
|
||||||
|
player.sendRichMessage(Config.NICK_CURRENT, placeholders);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "help":
|
||||||
|
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.sendRichMessage(helpMessage(sender, HelpType.ALL));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Console commands are disabled.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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 (args.length == 1) {
|
||||||
|
List<String> choices = new ArrayList<>();
|
||||||
|
if (sender.hasPermission("chat.command.nick.set")) {
|
||||||
|
choices.add("set");
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("chat.command.nick.review")) {
|
||||||
|
choices.add("review");
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("chat.command.nick.request")) {
|
||||||
|
choices.add("request");
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("chat.command.nick.try")) {
|
||||||
|
choices.add("try");
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("chat.command.nick.current")) {
|
||||||
|
choices.add("current");
|
||||||
|
}
|
||||||
|
choices.add("help");
|
||||||
|
|
||||||
|
for (String s : choices) {
|
||||||
|
if (s.startsWith(args[0])) {
|
||||||
|
completions.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (args.length == 2) {
|
||||||
|
if (args[0].equalsIgnoreCase("set")) {
|
||||||
|
List<String> choices = new ArrayList<>();
|
||||||
|
List<String> onlinePlayers = new ArrayList<>();
|
||||||
|
Bukkit.getOnlinePlayers().forEach(a -> onlinePlayers.add(a.getName()));
|
||||||
|
|
||||||
|
if (sender.hasPermission("chat.command.nick.set.others")) {
|
||||||
|
choices.addAll(onlinePlayers);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : choices) {
|
||||||
|
if (s.startsWith(args[1])) {
|
||||||
|
completions.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNickRequest(Player player, String nickName) {
|
||||||
|
if (!NickUtilities.validNick(player, player, nickName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NickUtilities.updateCache();
|
||||||
|
UUID uniqueId = player.getUniqueId();
|
||||||
|
|
||||||
|
if (NickCache.containsKey(uniqueId)) {
|
||||||
|
Nick nick = NickCache.get(uniqueId);
|
||||||
|
long timeSinceLastChange = new Date().getTime() - nick.getLastChangedDate();
|
||||||
|
long waitTime = Config.NICK_WAIT_TIME;
|
||||||
|
if (timeSinceLastChange > waitTime || player.hasPermission("chat.command.nick.bypasswaittime")) {
|
||||||
|
if (nick.hasRequest()) {
|
||||||
|
player.sendRichMessage(Config.NICK_REQUEST_PLACED,
|
||||||
|
Placeholder.component("oldrequestednick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
Placeholder.component("newrequestednick", Utility.applyColor(nickName)));
|
||||||
|
}
|
||||||
|
nick.setNewNick(nickName);
|
||||||
|
nick.setRequestedDate(new Date().getTime());
|
||||||
|
} else {
|
||||||
|
player.sendRichMessage(Config.NICK_TOO_SOON,
|
||||||
|
Placeholder.unparsed("time", formatTime((timeSinceLastChange - waitTime) * -1)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NickCache.put(uniqueId, new Nick(uniqueId, null, 0, nickName, new Date().getTime()));
|
||||||
|
}
|
||||||
|
Queries.newNicknameRequest(uniqueId, nickName);
|
||||||
|
bungeeMessageRequest(player);
|
||||||
|
player.sendRichMessage(Config.NICK_REQUESTED,
|
||||||
|
Placeholder.component("nick", Utility.applyColor(nickName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void bungeeMessageRequest(Player player) {
|
||||||
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
|
UUID uniqueId = player.getUniqueId();
|
||||||
|
|
||||||
|
// out.writeUTF("Forward"); // So BungeeCord knows to forward it
|
||||||
|
// out.writeUTF("ALL");
|
||||||
|
out.writeUTF("NickNameRequest"); // The channel name to check if this your data
|
||||||
|
|
||||||
|
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
|
||||||
|
DataOutputStream msgout = new DataOutputStream(msgbytes);
|
||||||
|
try {
|
||||||
|
msgout.writeUTF(uniqueId.toString());
|
||||||
|
} catch (IOException exception) {
|
||||||
|
ALogger.error("Failed to write UUID to ByteArrayOutputStream", exception);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
byte[] bytes = msgbytes.toByteArray();
|
||||||
|
out.writeShort(bytes.length);
|
||||||
|
out.write(bytes);
|
||||||
|
|
||||||
|
player.sendPluginMessage(ChatPlugin.getInstance(), Config.MESSAGECHANNEL, out.toByteArray());
|
||||||
|
|
||||||
|
Nicknames.getInstance().nickCacheUpdate.add(uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String formatTime(long timeInMillis) {
|
||||||
|
long second = (timeInMillis / 1000) % 60;
|
||||||
|
long minute = (timeInMillis / (1000 * 60)) % 60;
|
||||||
|
long hour = (timeInMillis / (1000 * 60 * 60)) % 24;
|
||||||
|
long days = (timeInMillis / (1000 * 60 * 60 * 24));
|
||||||
|
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (days != 0) {
|
||||||
|
stringBuilder.append(days).append(" days ");
|
||||||
|
}
|
||||||
|
if (days != 0 || hour != 0) {
|
||||||
|
stringBuilder.append(hour).append(" hours ");
|
||||||
|
}
|
||||||
|
if (days != 0 || hour != 0 || minute != 0) {
|
||||||
|
stringBuilder.append(minute).append(" minutes and ");
|
||||||
|
}
|
||||||
|
stringBuilder.append(second).append(" seconds");
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNick(Player sender, OfflinePlayer target, final String nickName) {
|
||||||
|
if (nickName.equalsIgnoreCase("off")) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (target.isOnline()) {
|
||||||
|
resetNick(Objects.requireNonNull(target.getPlayer()));
|
||||||
|
}
|
||||||
|
Queries.removePlayerFromDataBase(target.getUniqueId());
|
||||||
|
NickCache.remove(target.getUniqueId());
|
||||||
|
nickCacheUpdate.add(target.getUniqueId());
|
||||||
|
} catch (SQLException e) {
|
||||||
|
ALogger.error("Failed to remove nickname from database", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.equals(target)) {
|
||||||
|
sender.sendRichMessage(Config.NICK_RESET_OTHERS,
|
||||||
|
Placeholder.unparsed("player", Objects.requireNonNull(target.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (target.isOnline() && target.getPlayer() != null) {
|
||||||
|
target.getPlayer().sendRichMessage(Config.NICK_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), null, NickEvent.NickEventType.RESET);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
|
||||||
|
} else if (NickUtilities.validNick(sender, target, nickName)) {
|
||||||
|
if (target.isOnline()) {
|
||||||
|
setNick(target.getPlayer(), nickName);
|
||||||
|
} else {
|
||||||
|
NickUtilities.bungeeMessageHandled(target.getUniqueId(), sender, "Set");
|
||||||
|
}
|
||||||
|
|
||||||
|
Queries.setNicknameInDatabase(target.getUniqueId(), nickName);
|
||||||
|
NickEvent nickEvent = new NickEvent(sender.getName(), target.getName(), nickName, NickEvent.NickEventType.SET);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
|
||||||
|
if (NickCache.containsKey(target.getUniqueId())) {
|
||||||
|
Nick nick = NickCache.get(target.getUniqueId());
|
||||||
|
nick.setCurrentNick(nickName);
|
||||||
|
nick.setLastChangedDate(new Date().getTime());
|
||||||
|
setNick(target.getPlayer(), nickName);
|
||||||
|
} else {
|
||||||
|
NickCache.put(target.getUniqueId(), new Nick(target.getUniqueId(), nickName, new Date().getTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sender.equals(target)) {
|
||||||
|
sender.sendMessage(Utility.parseMiniMessage(Config.NICK_CHANGED_OTHERS,
|
||||||
|
Placeholder.unparsed("targetplayer", Objects.requireNonNull(target.getName())),
|
||||||
|
Placeholder.unparsed("nickname", nickName)));
|
||||||
|
if (target.isOnline()) {
|
||||||
|
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()));
|
||||||
|
}
|
||||||
|
} else if (target.isOnline()) {
|
||||||
|
Objects.requireNonNull(target.getPlayer())
|
||||||
|
.sendRichMessage(Config.NICK_CHANGED,
|
||||||
|
Placeholder.unparsed("nickname", getNick(target.getPlayer())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String helpMessage(final CommandSender sender, final HelpType... helpTypes) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
for (HelpType helpType : helpTypes) {
|
||||||
|
if (helpType.equals(HelpType.ALL)) {
|
||||||
|
return helpMessage(sender, helpType);
|
||||||
|
}
|
||||||
|
message.append(helpMessage(sender, helpType));
|
||||||
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String helpMessage(CommandSender sender, HelpType type) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
switch (type) {
|
||||||
|
case ALL:
|
||||||
|
message.append(helpMessage(sender, HelpType.SET_SELF));
|
||||||
|
message.append(helpMessage(sender, HelpType.SET_OTHERS));
|
||||||
|
message.append(helpMessage(sender, HelpType.REQUEST));
|
||||||
|
message.append(helpMessage(sender, HelpType.REVIEW));
|
||||||
|
message.append(helpMessage(sender, HelpType.TRY));
|
||||||
|
break;
|
||||||
|
case SET_SELF:
|
||||||
|
if (sender.hasPermission("chat.command.nick.set")) {
|
||||||
|
message.append("<gold>/nick set <nickname><white> - Sets your nickname to the specified name.\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SET_OTHERS:
|
||||||
|
if (sender.hasPermission("chat.command.nick.set.others")) {
|
||||||
|
message.append("<gold>/nick set <username> <nickname><white> - Sets the specified user's nickname to the specified name.\n");
|
||||||
|
}
|
||||||
|
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.
|
||||||
|
<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:
|
||||||
|
if (sender.hasPermission("chat.command.nick.review")) {
|
||||||
|
message.append("<gold>/nick review<white> - Opens the nickname review GUI (left click to accept a nick, right click to deny it)\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case TRY:
|
||||||
|
if (sender.hasPermission("chat.command.nick.try")) {
|
||||||
|
message.append("<gold>/nick try <nickname><white> - Shows you what your nickname will look like in chat.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasPermission(CommandSender sender, String permission) {
|
||||||
|
if (!sender.hasPermission(permission)) {
|
||||||
|
sender.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resetNick(final Player player) {
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
user.setDisplayName(player.getName());
|
||||||
|
player.displayName(user.getDisplayName().asComponent());
|
||||||
|
// updateCMIUser(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNick(final Player player) {
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
return user.getNickNameString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNick(final Player player, final String nickName) {
|
||||||
|
if (player == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
user.setDisplayName(nickName);
|
||||||
|
player.displayName(user.getDisplayName().asComponent());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Nicknames getInstance() {
|
||||||
|
return Nicknames.instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum HelpType {
|
||||||
|
ALL,
|
||||||
|
SET_SELF,
|
||||||
|
SET_OTHERS,
|
||||||
|
REVIEW,
|
||||||
|
REQUEST,
|
||||||
|
TRY
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,195 @@
|
||||||
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
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.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;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class NicknamesEvents implements Listener, PluginMessageListener {
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (Nicknames.instance.NickCache.isEmpty()) {
|
||||||
|
Queries.getNicknamesList().forEach(nick -> Nicknames.instance.NickCache.put(nick.getUuid(), nick));
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player player = e.getPlayer();
|
||||||
|
final Nick nick = Queries.getNick(player.getUniqueId());
|
||||||
|
|
||||||
|
if (nick == null) {
|
||||||
|
Nicknames.getInstance().resetNick(player);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String nickName = nick.getCurrentNick();
|
||||||
|
String strippedNick = Nicknames.getInstance().getNick(player);
|
||||||
|
try {
|
||||||
|
strippedNick = MiniMessage.miniMessage().stripTags(Nicknames.getInstance().getNick(player));
|
||||||
|
} catch (NullPointerException ignored) {
|
||||||
|
}
|
||||||
|
// final String strippedNick = CMIChatColor.stripColor(Nicknames.getInstance().getNick(player));
|
||||||
|
|
||||||
|
// final String cmiNick = Util.CMIChatColor.deColorize(Nicknames.getInstance().getNick(player));
|
||||||
|
|
||||||
|
if (nickName == null) {
|
||||||
|
Nicknames.getInstance().resetNick(player);
|
||||||
|
} else if (!nickName.equals(strippedNick)) {
|
||||||
|
Nicknames.getInstance().setNick(player, nickName);
|
||||||
|
}
|
||||||
|
|
||||||
|
Nicknames.getInstance().NickCache.put(e.getPlayer().getUniqueId(), nick);
|
||||||
|
|
||||||
|
if (player.hasPermission("chat.command.nick.review")) {
|
||||||
|
int i = 0;
|
||||||
|
for (Nick iNick : Nicknames.getInstance().NickCache.values()) {
|
||||||
|
if (iNick.hasRequest()) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i > 0) {
|
||||||
|
player.sendRichMessage(Config.NICK_REQUESTS_ON_LOGIN,
|
||||||
|
Placeholder.unparsed("amount", String.valueOf(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPluginMessageReceived(String channel, @NotNull Player player, byte[] message) {
|
||||||
|
if (!channel.equals(Config.MESSAGECHANNEL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayDataInput in = ByteStreams.newDataInput(message);
|
||||||
|
String subChannel = in.readUTF();
|
||||||
|
ALogger.info(channel + ": " + subChannel);
|
||||||
|
if (!subChannel.equals("NickNameRequest") && !subChannel.equals("NickNameAccepted")
|
||||||
|
&& !subChannel.equals("NickNameDenied") && !subChannel.equals("NickNameSet")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
UUID playerUUID;
|
||||||
|
OfflinePlayer offlinePlayer;
|
||||||
|
String name;
|
||||||
|
try {
|
||||||
|
short len = in.readShort();
|
||||||
|
byte[] msgbytes = new byte[len];
|
||||||
|
in.readFully(msgbytes);
|
||||||
|
|
||||||
|
DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
|
||||||
|
playerUUID = UUID.fromString(msgin.readUTF());
|
||||||
|
offlinePlayer = ChatPlugin.getInstance().getServer().getOfflinePlayer(playerUUID);
|
||||||
|
name = offlinePlayer.getName() == null ? playerUUID.toString() : offlinePlayer.getName();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
ALogger.error("Failed to read plugin message", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
switch (subChannel) {
|
||||||
|
case "NickNameRequest":
|
||||||
|
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,
|
||||||
|
miniMessage.deserialize("<gold>Click this text to review the request!")));
|
||||||
|
|
||||||
|
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||||
|
if (p.hasPermission("chat.command.nick.review")) {
|
||||||
|
p.sendMessage(component);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Nicknames.getInstance().nickCacheUpdate.add(playerUUID);
|
||||||
|
|
||||||
|
if (offlinePlayer.isOnline()) {
|
||||||
|
Nick nick = Queries.getNick(playerUUID);
|
||||||
|
if (nick != null && nick.getCurrentNick() != null) {
|
||||||
|
Nicknames.getInstance().setNick(offlinePlayer.getPlayer(), nick.getCurrentNick());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "NickNameAccepted":
|
||||||
|
|
||||||
|
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")) {
|
||||||
|
p.sendMessage(deserialize);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//No break on purpose
|
||||||
|
case "NickNameSet":
|
||||||
|
Nicknames.getInstance().nickCacheUpdate.add(playerUUID);
|
||||||
|
if (offlinePlayer.isOnline()) {
|
||||||
|
Nick nick = Queries.getNick(playerUUID);
|
||||||
|
Player target = Bukkit.getPlayer(playerUUID);
|
||||||
|
if (target != null && nick != null && nick.getCurrentNick() != null) {
|
||||||
|
Nicknames.getInstance().setNick(target, nick.getCurrentNick());
|
||||||
|
target.sendRichMessage(Config.NICK_CHANGED,
|
||||||
|
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "NickNameDenied":
|
||||||
|
final Component messageDenied = miniMessage.deserialize("<red><name>'s nickname was denied",
|
||||||
|
Placeholder.unparsed("name", name));
|
||||||
|
Nick nick = Nicknames.getInstance().NickCache.get(playerUUID);
|
||||||
|
|
||||||
|
ChatPlugin.getInstance().getServer().getOnlinePlayers().forEach(p -> {
|
||||||
|
if (p.hasPermission("chat.command.nick.review")) {
|
||||||
|
p.sendMessage(messageDenied);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (nick.getCurrentNick() == null) {
|
||||||
|
Nicknames.getInstance().NickCache.remove(playerUUID);
|
||||||
|
} else {
|
||||||
|
nick.setNewNick(null);
|
||||||
|
nick.setRequestedDate(0);
|
||||||
|
|
||||||
|
Nicknames.getInstance().NickCache.put(playerUUID, nick);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (offlinePlayer.isOnline()) {
|
||||||
|
Player target = Bukkit.getPlayer(playerUUID);
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
target.sendRichMessage(Config.NICK_NOT_CHANGED,
|
||||||
|
Placeholder.unparsed("nickname", nick.getCurrentNick()));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
312
galaxy/src/main/java/com/alttd/chat/nicknames/NicknamesGui.java
Normal file
312
galaxy/src/main/java/com/alttd/chat/nicknames/NicknamesGui.java
Normal file
|
|
@ -0,0 +1,312 @@
|
||||||
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.database.Queries;
|
||||||
|
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;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import org.bukkit.inventory.meta.SkullMeta;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class NicknamesGui implements Listener {
|
||||||
|
|
||||||
|
private final Inventory inv;
|
||||||
|
private final int currentPage;
|
||||||
|
|
||||||
|
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").asComponent());
|
||||||
|
|
||||||
|
// Put the items into the inventory
|
||||||
|
currentPage = 1;
|
||||||
|
setItems(currentPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setItems(int currentPage) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
inv.clear();
|
||||||
|
NickUtilities.updateCache();
|
||||||
|
boolean hasNextPage = false;
|
||||||
|
int i = (currentPage - 1) * 27; //TODO set to 1 or 2 to test
|
||||||
|
int limit = i / 27;
|
||||||
|
|
||||||
|
for (Nick nick : Nicknames.getInstance().NickCache.values()) {
|
||||||
|
if (nick.hasRequest()) {
|
||||||
|
if (limit >= i / 27) {
|
||||||
|
inv.setItem(i % 27, createPlayerSkull(nick, Config.NICK_ITEM_LORE));
|
||||||
|
i++;
|
||||||
|
} else {
|
||||||
|
hasNextPage = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentPage != 1) {
|
||||||
|
inv.setItem(28, createGuiItem(Material.PAPER, "§bPrevious page",
|
||||||
|
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||||
|
"§aPrevious page: %previousPage%".replace("%previousPage%", String.valueOf(currentPage - 1))));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasNextPage) {
|
||||||
|
inv.setItem(36, createGuiItem(Material.PAPER, "§bNext page",
|
||||||
|
"§aCurrent page: %page%".replace("%page%", String.valueOf(currentPage)),
|
||||||
|
"§aNext page: §b%nextPage%".replace("%nextPage%", String.valueOf(currentPage + 1))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createPlayerSkull(Nick nick, List<String> lore) {
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
ItemStack playerHead = new ItemStack(Material.PLAYER_HEAD);
|
||||||
|
SkullMeta meta = (SkullMeta) playerHead.getItemMeta();
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(nick.getUuid());
|
||||||
|
|
||||||
|
meta.setOwningPlayer(offlinePlayer);
|
||||||
|
String name = offlinePlayer.getName();
|
||||||
|
if (name == null) {
|
||||||
|
meta.displayName(miniMessage.deserialize("UNKNOWN PLAYER NAME"));
|
||||||
|
} else {
|
||||||
|
meta.displayName(miniMessage.deserialize(offlinePlayer.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
TagResolver resolver = TagResolver.resolver(
|
||||||
|
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? "None" : nick.getCurrentNick())),
|
||||||
|
Placeholder.unparsed("lastchanged", nick.getLastChangedDate() == 0 ? "Not Applicable" : nick.getLastChangedDateFormatted()));
|
||||||
|
meta.lore(lore.stream().map(a -> miniMessage.deserialize(a, resolver)).collect(Collectors.toList()));
|
||||||
|
playerHead.setItemMeta(meta);
|
||||||
|
|
||||||
|
return playerHead;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nice little method to create a gui item with a custom name, and description
|
||||||
|
private ItemStack createGuiItem(final Material material, final String name, final String... lore) {
|
||||||
|
final ItemStack item = new ItemStack(material, 1);
|
||||||
|
final ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
|
// Set the name of the item
|
||||||
|
meta.displayName(Component.text(name));
|
||||||
|
|
||||||
|
// Set the lore of the item
|
||||||
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
meta.lore(Arrays.stream(lore).map(miniMessage::deserialize).collect(Collectors.toList()));
|
||||||
|
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can open the inventory with this
|
||||||
|
public void openInventory(final HumanEntity ent) {//Possibly with a boolean to show if it should get from cache or update cache
|
||||||
|
ent.openInventory(inv);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for clicks on items
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onInventoryClick(InventoryClickEvent e) {
|
||||||
|
if (e.getInventory() != inv) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
|
||||||
|
final ItemStack clickedItem = e.getCurrentItem();
|
||||||
|
|
||||||
|
if (clickedItem == null || clickedItem.getType() == Material.AIR) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Player p = (Player) e.getWhoClicked();
|
||||||
|
|
||||||
|
if (clickedItem.getType().equals(Material.PAPER)) {
|
||||||
|
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)) {
|
||||||
|
ItemMeta itemMeta = clickedItem.getItemMeta();
|
||||||
|
if (itemMeta == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SkullMeta meta = (SkullMeta) itemMeta;
|
||||||
|
if (meta.hasEnchants()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
OfflinePlayer owningPlayer = meta.getOwningPlayer();
|
||||||
|
|
||||||
|
if (owningPlayer == null) {
|
||||||
|
p.sendRichMessage(Config.NICK_USER_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NickUtilities.updateCache();
|
||||||
|
|
||||||
|
Nick nick;
|
||||||
|
UUID uniqueId = owningPlayer.getUniqueId();
|
||||||
|
if (Nicknames.getInstance().NickCache.containsKey(uniqueId)) {
|
||||||
|
nick = Nicknames.getInstance().NickCache.get(uniqueId);
|
||||||
|
} else {
|
||||||
|
nick = Queries.getNick(uniqueId);
|
||||||
|
}
|
||||||
|
Component itemDisplayName = itemMeta.displayName();
|
||||||
|
if (itemDisplayName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nick == null || !nick.hasRequest()) {
|
||||||
|
p.sendRichMessage(Config.NICK_ALREADY_HANDLED,
|
||||||
|
Placeholder.component("targetplayer", itemDisplayName))
|
||||||
|
;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.isLeftClick()) {
|
||||||
|
if (owningPlayer.hasPlayedBefore()) {
|
||||||
|
Queries.acceptNewNickname(uniqueId, nick.getNewNick());
|
||||||
|
|
||||||
|
String newNick = nick.getNewNick();
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.ACCEPTED);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
}
|
||||||
|
}.runTask(ChatPlugin.getInstance());
|
||||||
|
|
||||||
|
p.sendRichMessage(Config.NICK_ACCEPTED,
|
||||||
|
Placeholder.component("targetplayer", itemDisplayName),
|
||||||
|
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "Accepted");
|
||||||
|
|
||||||
|
nick.setCurrentNick(nick.getNewNick());
|
||||||
|
nick.setLastChangedDate(new Date().getTime());
|
||||||
|
nick.setNewNick(null);
|
||||||
|
nick.setRequestedDate(0);
|
||||||
|
|
||||||
|
Nicknames.getInstance().NickCache.put(uniqueId, nick);
|
||||||
|
|
||||||
|
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
itemMeta.displayName(itemMeta.displayName());
|
||||||
|
itemMeta.lore(clickedItem.lore());
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||||
|
p.updateInventory();
|
||||||
|
} else {
|
||||||
|
p.sendRichMessage(Config.NICK_PLAYER_NOT_ONLINE, Placeholder.component("player", itemDisplayName));
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (e.isRightClick()) {
|
||||||
|
if (owningPlayer.hasPlayedBefore()) {
|
||||||
|
Queries.denyNewNickname(uniqueId);
|
||||||
|
|
||||||
|
String newNick = nick.getNewNick();
|
||||||
|
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
NickEvent nickEvent = new NickEvent(e.getWhoClicked().getName(), itemMeta.getDisplayName(), newNick, NickEvent.NickEventType.DENIED);
|
||||||
|
nickEvent.callEvent();
|
||||||
|
}
|
||||||
|
}.runTask(ChatPlugin.getInstance());
|
||||||
|
|
||||||
|
p.sendMessage(MiniMessage.miniMessage().deserialize(Config.NICK_DENIED,
|
||||||
|
Placeholder.unparsed("targetplayer", owningPlayer.getName()),
|
||||||
|
Placeholder.component("newnick", Utility.applyColor(nick.getNewNick())),
|
||||||
|
Placeholder.component("oldnick", Utility.applyColor(nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick()))));
|
||||||
|
|
||||||
|
if (Nicknames.getInstance().NickCache.containsKey(uniqueId)
|
||||||
|
&& Nicknames.getInstance().NickCache.get(uniqueId).getCurrentNick() != null) {
|
||||||
|
nick.setNewNick(null);
|
||||||
|
nick.setRequestedDate(0);
|
||||||
|
Nicknames.getInstance().NickCache.put(uniqueId, nick);
|
||||||
|
} else {
|
||||||
|
Nicknames.getInstance().NickCache.remove(uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (owningPlayer.isOnline() && owningPlayer.getPlayer() != null) {
|
||||||
|
Nicknames.getInstance().setNick(owningPlayer.getPlayer(), nick.getCurrentNick() == null ? owningPlayer.getName() : nick.getCurrentNick());
|
||||||
|
owningPlayer.getPlayer().sendRichMessage(Config.NICK_NOT_CHANGED);
|
||||||
|
}
|
||||||
|
|
||||||
|
NickUtilities.bungeeMessageHandled(uniqueId, e.getWhoClicked().getServer().getPlayer(e.getWhoClicked().getName()), "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")) {
|
||||||
|
p.sendMessage(messageDenied);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ItemStack itemStack = new ItemStack(Material.SKELETON_SKULL);
|
||||||
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
|
itemMeta.displayName(itemDisplayName);
|
||||||
|
itemMeta.lore(clickedItem.lore());
|
||||||
|
itemStack.setItemMeta(itemMeta);
|
||||||
|
e.getInventory().setItem(e.getSlot(), itemStack);
|
||||||
|
p.updateInventory();
|
||||||
|
} else {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cancel dragging in our inventory
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onInventoryClick(InventoryDragEvent e) {
|
||||||
|
if (e.getInventory() == inv) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,30 +1,44 @@
|
||||||
package com.alttd.chat.util;
|
package com.alttd.chat.util;
|
||||||
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import net.kyori.adventure.text.Component;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.List;
|
||||||
|
|
||||||
public class GalaxyUtility {
|
public class GalaxyUtility {
|
||||||
public static void sendBlockedNotification(String prefix, Player player, Component input, String target) {
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
|
||||||
placeholders.put("prefix", Replacement.miniMessage(prefix));
|
|
||||||
placeholders.put("displayname", Replacement.miniMessage(Utility.getDisplayName(player.getUniqueId(), player.getName())));
|
|
||||||
placeholders.put("target", Replacement.miniMessage((target.isEmpty() ? "tried to say:" : " -> " + target + ": ")));
|
|
||||||
placeholders.put("input", Replacement.component(input));
|
|
||||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
|
||||||
|
|
||||||
Bukkit.getOnlinePlayers().forEach(a ->{
|
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)
|
||||||
|
);
|
||||||
|
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
||||||
|
|
||||||
|
Bukkit.getOnlinePlayers().forEach(a -> {
|
||||||
if (a.hasPermission("chat.alert-blocked")) {
|
if (a.hasPermission("chat.alert-blocked")) {
|
||||||
a.sendMessage(blockedNotification);
|
a.sendMessage(blockedNotification);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
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>"));
|
"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) {
|
||||||
|
List<String> completions = new ArrayList<>(RegexManager.emotesList);
|
||||||
|
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||||
|
if (player.hasPermission(perm)) {
|
||||||
|
completions.addAll(pair.getY());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
player.addCustomChatCompletions(completions);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
41
galaxy/src/main/java/com/alttd/chat/util/ServerName.java
Normal file
41
galaxy/src/main/java/com/alttd/chat/util/ServerName.java
Normal file
|
|
@ -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,49 @@
|
||||||
|
package com.alttd.chat.util;
|
||||||
|
|
||||||
|
import com.alttd.chat.ChatPlugin;
|
||||||
|
import com.alttd.chat.objects.Toggleable;
|
||||||
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class ToggleableForCustomChannel extends Toggleable {
|
||||||
|
|
||||||
|
private final CustomChannel customChannel;
|
||||||
|
|
||||||
|
public ToggleableForCustomChannel(CustomChannel customChannel) {
|
||||||
|
super();
|
||||||
|
this.customChannel = customChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final HashSet<UUID> toggledUsers = new HashSet<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isToggled(UUID uuid) {
|
||||||
|
return toggledUsers.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOff(UUID uuid) {
|
||||||
|
toggledUsers.remove(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOn(UUID uuid) {
|
||||||
|
disableToggles(uuid);
|
||||||
|
toggledUsers.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(Player player, String message) {
|
||||||
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ALogger.info(String.format("%s sent %s message: %s", player.getName(), customChannel.getChannelName(), message));
|
||||||
|
ChatPlugin.getInstance().getChatHandler().chatChannel(player, customChannel, message);
|
||||||
|
}
|
||||||
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
name: ChatPlugin
|
name: ChatPlugin
|
||||||
version: ${project.version}
|
version: 2.0.0-SNAPSHOT
|
||||||
main: com.alttd.chat.ChatPlugin
|
main: com.alttd.chat.ChatPlugin
|
||||||
api-version: 1.18
|
api-version: 1.19
|
||||||
authors: [Destro, Teriuihi]
|
authors: [Destro, Teriuihi]
|
||||||
depend: [LuckPerms]
|
depend: [LuckPerms]
|
||||||
|
loadbefore:
|
||||||
|
- mcMMO
|
||||||
|
- GriefPrevention
|
||||||
commands:
|
commands:
|
||||||
globalchat:
|
globalchat:
|
||||||
permission: command.chat.globalchat
|
permission: command.chat.globalchat
|
||||||
|
|
@ -19,6 +22,9 @@ commands:
|
||||||
reply:
|
reply:
|
||||||
permission: command.chat.message
|
permission: command.chat.message
|
||||||
aliases: r
|
aliases: r
|
||||||
|
continue:
|
||||||
|
permission: command.chat.message
|
||||||
|
aliases: c
|
||||||
ignore:
|
ignore:
|
||||||
permission: command.chat.ignore
|
permission: command.chat.ignore
|
||||||
unignore:
|
unignore:
|
||||||
|
|
@ -31,3 +37,8 @@ commands:
|
||||||
permission: command.chat.p
|
permission: command.chat.p
|
||||||
chatclear:
|
chatclear:
|
||||||
permission: chat.command.clear-chat
|
permission: chat.command.clear-chat
|
||||||
|
emoteslist:
|
||||||
|
permission: chat.command.emoteslist
|
||||||
|
aliases: [emotes]
|
||||||
|
nick:
|
||||||
|
permission: chat.command.nick
|
||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
|
|
@ -1,5 +1,7 @@
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
|
||||||
294
gradlew
vendored
294
gradlew
vendored
|
|
@ -1,7 +1,7 @@
|
||||||
#!/usr/bin/env sh
|
#!/bin/sh
|
||||||
|
|
||||||
#
|
#
|
||||||
# Copyright 2015 the original author or authors.
|
# Copyright © 2015-2021 the original authors.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
|
@ -17,67 +17,99 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
##
|
#
|
||||||
## Gradle start up script for UN*X
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
##
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
# Attempt to set APP_HOME
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
# Resolve links: $0 may be a link
|
# Resolve links: $0 may be a link
|
||||||
PRG="$0"
|
app_path=$0
|
||||||
# Need this for relative symlinks.
|
|
||||||
while [ -h "$PRG" ] ; do
|
# Need this for daisy-chained symlinks.
|
||||||
ls=`ls -ld "$PRG"`
|
while
|
||||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
if expr "$link" : '/.*' > /dev/null; then
|
[ -h "$app_path" ]
|
||||||
PRG="$link"
|
do
|
||||||
else
|
ls=$( ls -ld "$app_path" )
|
||||||
PRG=`dirname "$PRG"`"/$link"
|
link=${ls#*' -> '}
|
||||||
fi
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
SAVED="`pwd`"
|
|
||||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
|
||||||
APP_HOME="`pwd -P`"
|
|
||||||
cd "$SAVED" >/dev/null
|
|
||||||
|
|
||||||
APP_NAME="Gradle"
|
# This is normally unused
|
||||||
APP_BASE_NAME=`basename "$0"`
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD="maximum"
|
MAX_FD=maximum
|
||||||
|
|
||||||
warn () {
|
warn () {
|
||||||
echo "$*"
|
echo "$*"
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
die () {
|
die () {
|
||||||
echo
|
echo
|
||||||
echo "$*"
|
echo "$*"
|
||||||
echo
|
echo
|
||||||
exit 1
|
exit 1
|
||||||
}
|
} >&2
|
||||||
|
|
||||||
# OS specific support (must be 'true' or 'false').
|
# OS specific support (must be 'true' or 'false').
|
||||||
cygwin=false
|
cygwin=false
|
||||||
msys=false
|
msys=false
|
||||||
darwin=false
|
darwin=false
|
||||||
nonstop=false
|
nonstop=false
|
||||||
case "`uname`" in
|
case "$( uname )" in #(
|
||||||
CYGWIN* )
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
cygwin=true
|
Darwin* ) darwin=true ;; #(
|
||||||
;;
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
Darwin* )
|
NONSTOP* ) nonstop=true ;;
|
||||||
darwin=true
|
|
||||||
;;
|
|
||||||
MINGW* )
|
|
||||||
msys=true
|
|
||||||
;;
|
|
||||||
NONSTOP* )
|
|
||||||
nonstop=true
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
|
|
@ -87,9 +119,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
# IBM's JDK on AIX uses strange locations for the executables
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
else
|
else
|
||||||
JAVACMD="$JAVA_HOME/bin/java"
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
fi
|
fi
|
||||||
if [ ! -x "$JAVACMD" ] ; then
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
@ -98,88 +130,120 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
JAVACMD="java"
|
JAVACMD=java
|
||||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
Please set the JAVA_HOME variable in your environment to match the
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
location of your Java installation."
|
location of your Java installation."
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Increase the maximum file descriptors if we can.
|
# Increase the maximum file descriptors if we can.
|
||||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
MAX_FD_LIMIT=`ulimit -H -n`
|
case $MAX_FD in #(
|
||||||
if [ $? -eq 0 ] ; then
|
max*)
|
||||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
MAX_FD="$MAX_FD_LIMIT"
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
ulimit -n $MAX_FD
|
warn "Could not query maximum file descriptor limit"
|
||||||
if [ $? -ne 0 ] ; then
|
esac
|
||||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
case $MAX_FD in #(
|
||||||
fi
|
'' | soft) :;; #(
|
||||||
else
|
*)
|
||||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
fi
|
# shellcheck disable=SC2039,SC3045
|
||||||
fi
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
# For Darwin, add options to specify how the application appears in the dock
|
|
||||||
if $darwin; then
|
|
||||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
|
||||||
fi
|
|
||||||
|
|
||||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
|
||||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
|
||||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
|
||||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
|
||||||
|
|
||||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
|
||||||
|
|
||||||
# We build the pattern for arguments to be converted via cygpath
|
|
||||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
|
||||||
SEP=""
|
|
||||||
for dir in $ROOTDIRSRAW ; do
|
|
||||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
|
||||||
SEP="|"
|
|
||||||
done
|
|
||||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
|
||||||
# Add a user-defined pattern to the cygpath arguments
|
|
||||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
|
||||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
|
||||||
fi
|
|
||||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
|
||||||
i=0
|
|
||||||
for arg in "$@" ; do
|
|
||||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
|
||||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
|
||||||
|
|
||||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
|
||||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
|
||||||
else
|
|
||||||
eval `echo args$i`="\"$arg\""
|
|
||||||
fi
|
|
||||||
i=`expr $i + 1`
|
|
||||||
done
|
|
||||||
case $i in
|
|
||||||
0) set -- ;;
|
|
||||||
1) set -- "$args0" ;;
|
|
||||||
2) set -- "$args0" "$args1" ;;
|
|
||||||
3) set -- "$args0" "$args1" "$args2" ;;
|
|
||||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
|
||||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
|
||||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
|
||||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
|
||||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
|
||||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Escape application args
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
save () {
|
# * args from the command line
|
||||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
# * the main class name
|
||||||
echo " "
|
# * -classpath
|
||||||
}
|
# * -D...appname settings
|
||||||
APP_ARGS=`save "$@"`
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
org.gradle.wrapper.GradleWrapperMain \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
exec "$JAVACMD" "$@"
|
exec "$JAVACMD" "$@"
|
||||||
|
|
|
||||||
15
gradlew.bat
vendored
15
gradlew.bat
vendored
|
|
@ -14,7 +14,7 @@
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%" == "" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
@rem
|
@rem
|
||||||
@rem Gradle startup script for Windows
|
@rem Gradle startup script for Windows
|
||||||
|
|
@ -25,7 +25,8 @@
|
||||||
if "%OS%"=="Windows_NT" setlocal
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
set DIRNAME=%~dp0
|
set DIRNAME=%~dp0
|
||||||
if "%DIRNAME%" == "" set DIRNAME=.
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
set APP_BASE_NAME=%~n0
|
set APP_BASE_NAME=%~n0
|
||||||
set APP_HOME=%DIRNAME%
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
|
@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
set JAVA_EXE=java.exe
|
set JAVA_EXE=java.exe
|
||||||
%JAVA_EXE% -version >NUL 2>&1
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
if "%ERRORLEVEL%" == "0" goto execute
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
echo.
|
echo.
|
||||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||||
|
|
||||||
:end
|
:end
|
||||||
@rem End local scope for the variables with windows NT shell
|
@rem End local scope for the variables with windows NT shell
|
||||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
:fail
|
:fail
|
||||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
rem the _cmd.exe /c_ return code!
|
rem the _cmd.exe /c_ return code!
|
||||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
exit /b 1
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
:mainEnd
|
:mainEnd
|
||||||
if "%OS%"=="Windows_NT" endlocal
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
|
||||||
58
plugin
58
plugin
|
|
@ -1,58 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
# get base dir regardless of execution location
|
|
||||||
SOURCE="${BASH_SOURCE[0]}"
|
|
||||||
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
|
|
||||||
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
|
|
||||||
SOURCE="$(readlink "$SOURCE")"
|
|
||||||
[[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
|
|
||||||
done
|
|
||||||
SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}")
|
|
||||||
basedir=$(dirname "$SOURCE")
|
|
||||||
. "$basedir"/scripts/init.sh
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
"d" | "deploy") # deploy api to repo
|
|
||||||
;;
|
|
||||||
"b" | "build")
|
|
||||||
(
|
|
||||||
cd "$basedir"
|
|
||||||
mvn package
|
|
||||||
)
|
|
||||||
;;
|
|
||||||
"upload")
|
|
||||||
(
|
|
||||||
cd "$basedir"
|
|
||||||
scp ./galaxy/target/galaxy-chat.jar sid@leo:/home/sid/servers/meadowTest/plugins/galaxy-chat.jar
|
|
||||||
scp ./velocity/target/velocity-chat.jar sid@leo:/home/sid/servers/velocity/plugins/velocity-chat.jar
|
|
||||||
)
|
|
||||||
;;
|
|
||||||
"queue")
|
|
||||||
(
|
|
||||||
cd "$basedir"
|
|
||||||
scp ./galaxy/target/galaxy-chat.jar sid@lyra:/home/sid/share/updates/all/plugins/galaxy-chat.jar
|
|
||||||
scp ./velocity/target/velocity-chat.jar sid@lyra:/home/sid/share/updates/plugins/proxy/velocity-chat.jar
|
|
||||||
)
|
|
||||||
;;
|
|
||||||
"setup")
|
|
||||||
if [[ -f ~/.bashrc ]] ; then
|
|
||||||
NAME="${PLUGIN_NAME}"
|
|
||||||
if [[ ! -z "${2+x}" ]] ; then
|
|
||||||
NAME="$2"
|
|
||||||
fi
|
|
||||||
(grep "alias $NAME=" ~/.bashrc > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >> ~/.bashrc)
|
|
||||||
alias "$NAME=. $SOURCE"
|
|
||||||
echo "You can now just type '$NAME' at any time to access the build tool."
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "${PLUGIN_NAME} build tool. This provides a variety of commands to control the build."
|
|
||||||
echo "View below for details of the available commands."
|
|
||||||
echo ""
|
|
||||||
echo "Commands:"
|
|
||||||
echo " * b, build | Builds the project"
|
|
||||||
echo " * upload | uploads the lastest build to a testserver"
|
|
||||||
echo " * queue | queue the lastest build to Alttiude"
|
|
||||||
echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:"
|
|
||||||
echo " | . ./plugin setup"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
@ -4,17 +4,29 @@ include(":api")
|
||||||
include(":galaxy")
|
include(":galaxy")
|
||||||
include(":velocity")
|
include(":velocity")
|
||||||
|
|
||||||
|
val nexusUser = providers.gradleProperty("alttdSnapshotUsername").get()
|
||||||
|
val nexusPass = providers.gradleProperty("alttdSnapshotPassword").get()
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositories {
|
repositories {
|
||||||
// mavenLocal()
|
// mavenLocal()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
maven("https://repo.alttd.com/snapshots") // Altitude - Galaxy
|
||||||
|
maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
||||||
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
||||||
maven("https://nexus.velocitypowered.com/repository/") // Velocity
|
maven("https://nexus.velocitypowered.com/repository/") // Velocity
|
||||||
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
||||||
maven("https://repo.spongepowered.org/maven") // Configurate
|
maven("https://repo.spongepowered.org/maven") // Configurate
|
||||||
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
||||||
maven("https://jitpack.io")
|
maven("https://jitpack.io")
|
||||||
|
maven {
|
||||||
|
name = "nexus"
|
||||||
|
url = uri("https://repo.alttd.com/repository/alttd-snapshot/")
|
||||||
|
credentials {
|
||||||
|
username = nexusUser
|
||||||
|
password = nexusPass
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,32 @@
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("com.github.johnrengelman.shadow")
|
id("io.github.goooler.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api")) // API
|
implementation(project(":api")) // API
|
||||||
compileOnly("com.velocitypowered:velocity-api:3.0.1") // Velocity
|
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
annotationProcessor("com.velocitypowered:velocity-api:3.0.1")
|
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
|
||||||
implementation("mysql:mysql-connector-java:8.0.27") // mysql
|
implementation("mysql:mysql-connector-java:8.0.33") // mysql
|
||||||
implementation("org.spongepowered", "configurate-yaml", "4.1.2")
|
implementation("org.spongepowered", "configurate-yaml", "4.2.0")
|
||||||
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.0-BETA-SNAPSHOT")
|
compileOnly("net.kyori:adventure-text-minimessage:4.23.0")
|
||||||
implementation("net.kyori", "adventure-text-minimessage", "4.10.0-20220122.015731-43") { // Minimessage
|
|
||||||
exclude("net.kyori")
|
|
||||||
exclude("net.kyori.examination")
|
|
||||||
}
|
|
||||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5")
|
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5")
|
||||||
|
compileOnly("com.alttd.proxydiscordlink:ProxyDiscordLink:1.0.1-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
archiveFileName.set("${rootProject.name}-${project.name}-${project.version}.jar")
|
||||||
// minimize()
|
// minimize()
|
||||||
listOf(
|
listOf(
|
||||||
"net.kyori.adventure.text.minimessage",
|
// "net.kyori.adventure.text.minimessage",
|
||||||
"org.spongepowered.configurate"
|
"org.spongepowered.configurate"
|
||||||
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
|
).forEach { relocate(it, "${rootProject.group}.lib.${it.substringAfterLast(".")}") }
|
||||||
}
|
}
|
||||||
|
|
||||||
build {
|
build {
|
||||||
|
// setBuildDir("${rootProject.buildDir}")
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.alttd.chat.ChatImplementation;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import com.alttd.velocitychat.commands.*;
|
import com.alttd.velocitychat.commands.*;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.database.DatabaseConnection;
|
import com.alttd.chat.database.DatabaseConnection;
|
||||||
|
|
@ -81,9 +82,9 @@ public class VelocityChat {
|
||||||
ChatUserManager.addUser(console);
|
ChatUserManager.addUser(console);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReloadConfig() {
|
public void reloadConfig() {
|
||||||
chatAPI.ReloadConfig();
|
chatAPI.reloadConfig();
|
||||||
chatAPI.ReloadChatFilters();
|
chatAPI.reloadChatFilters();
|
||||||
serverHandler.cleanup();
|
serverHandler.cleanup();
|
||||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("reloadconfig");
|
buf.writeUTF("reloadconfig");
|
||||||
|
|
@ -108,10 +109,14 @@ public class VelocityChat {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadCommands() {
|
public void loadCommands() {
|
||||||
|
ChatLogHandler instance = ChatLogHandler.getInstance(false);
|
||||||
|
new SilentJoinCommand(server);
|
||||||
new GlobalAdminChat(server);
|
new GlobalAdminChat(server);
|
||||||
new Reload(server);
|
new Reload(server);
|
||||||
new MailCommand(server);
|
new MailCommand(server);
|
||||||
new Report(server);
|
new Report(server);
|
||||||
|
new VoteToMute(server, instance);
|
||||||
|
new VoteToMuteHelper(server);
|
||||||
server.getCommandManager().register("party", new PartyCommand());
|
server.getCommandManager().register("party", new PartyCommand());
|
||||||
// all (proxy)commands go here
|
// all (proxy)commands go here
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,27 @@ public class MailCommand {
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RequiredArgumentBuilder<CommandSource, String> playerNodeSender = RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("sender", StringArgumentType.string())
|
||||||
|
.suggests((context, builder) -> {
|
||||||
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
|
for (Player player : proxyServer.getAllPlayers()) {
|
||||||
|
possibleValues.add(player.getGameProfile().getName());
|
||||||
|
}
|
||||||
|
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||||
|
String remaining = builder.getRemaining().toLowerCase();
|
||||||
|
for (String str : possibleValues) {
|
||||||
|
if (str.toLowerCase().startsWith(remaining)) {
|
||||||
|
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
.<CommandSource>literal("mail")
|
.<CommandSource>literal("mail")
|
||||||
.requires(ctx -> ctx.hasPermission("command.chat.mail"))
|
.requires(ctx -> ctx.hasPermission("command.chat.mail"))
|
||||||
|
|
@ -79,8 +100,13 @@ public class MailCommand {
|
||||||
)
|
)
|
||||||
.then(playerNode
|
.then(playerNode
|
||||||
.requires(ctx -> ctx.hasPermission("command.chat.mail.list.other"))// TODO permission
|
.requires(ctx -> ctx.hasPermission("command.chat.mail.list.other"))// TODO permission
|
||||||
|
.then(playerNodeSender
|
||||||
|
.executes(context -> {
|
||||||
|
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("sender", String.class));
|
||||||
|
return 1;
|
||||||
|
}))
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class));
|
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), null);
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
import com.velocitypowered.api.command.SimpleCommand;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -39,12 +39,13 @@ public class PartyCommand implements SimpleCommand {
|
||||||
CommandSource source = invocation.source();
|
CommandSource source = invocation.source();
|
||||||
|
|
||||||
if (args.length < 1) {
|
if (args.length < 1) {
|
||||||
if (!source.hasPermission("party.use"))
|
if (!source.hasPermission("party.use")) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||||
else if (source instanceof Player)
|
} else if (source instanceof Player) {
|
||||||
source.sendMessage(getHelpMessage(source));
|
source.sendMessage(getHelpMessage(source));
|
||||||
else
|
} else {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
source.sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -52,11 +53,12 @@ public class PartyCommand implements SimpleCommand {
|
||||||
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
.filter(subCommand -> subCommand.getName().equalsIgnoreCase(args[0]))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.ifPresentOrElse(subCommand -> {
|
.ifPresentOrElse(subCommand -> {
|
||||||
if (source.hasPermission(subCommand.getPermission()))
|
if (source.hasPermission(subCommand.getPermission())) {
|
||||||
subCommand.execute(args, source);
|
subCommand.execute(args, source);
|
||||||
else
|
} else {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
source.sendMessage(Utility.parseMiniMessage(Config.NO_PERMISSION));
|
||||||
}, () -> source.sendMessage(getHelpMessage(source)));
|
}
|
||||||
|
}, () -> source.sendMessage(getHelpMessage(source)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -64,9 +66,9 @@ public class PartyCommand implements SimpleCommand {
|
||||||
String[] args = invocation.arguments();
|
String[] args = invocation.arguments();
|
||||||
List<String> suggest = new ArrayList<>();
|
List<String> suggest = new ArrayList<>();
|
||||||
|
|
||||||
if (!invocation.source().hasPermission("party.use"))
|
if (!invocation.source().hasPermission("party.use")) {
|
||||||
return suggest;
|
return suggest;
|
||||||
else if (args.length == 0) {
|
} else if (args.length == 0) {
|
||||||
subCommands.stream()
|
subCommands.stream()
|
||||||
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> invocation.source().hasPermission(subCommand.getPermission()))
|
||||||
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
.forEach(subCommand -> suggest.add(subCommand.getName()));
|
||||||
|
|
@ -83,10 +85,11 @@ public class PartyCommand implements SimpleCommand {
|
||||||
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
|
.ifPresent(subCommand -> suggest.addAll(subCommand.suggest(args, invocation.source())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.length == 0)
|
if (args.length == 0) {
|
||||||
return suggest;
|
return suggest;
|
||||||
else
|
} else {
|
||||||
return finalizeSuggest(suggest, args[args.length - 1]);
|
return finalizeSuggest(suggest, args[args.length - 1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> finalizeSuggest(List<String> possibleValues, String remaining) {
|
public List<String> finalizeSuggest(List<String> possibleValues, String remaining) {
|
||||||
|
|
@ -101,19 +104,21 @@ public class PartyCommand implements SimpleCommand {
|
||||||
return finalValues;
|
return finalValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getHelpMessage(CommandSource source) {
|
public ComponentLike getHelpMessage(CommandSource source) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
subCommands.stream()
|
subCommands.stream()
|
||||||
.filter(subCommand -> source.hasPermission(subCommand.getPermission()))
|
.filter(subCommand -> source.hasPermission(subCommand.getPermission()))
|
||||||
.forEach(subCommand -> stringBuilder.append(subCommand.getHelpMessage()).append("\n"));
|
.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");
|
stringBuilder.append(Config.PARTY_HELP_CHAT).append("\n");
|
||||||
if (stringBuilder.length() != 0)
|
}
|
||||||
|
if (!stringBuilder.isEmpty()) {
|
||||||
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
|
stringBuilder.replace(stringBuilder.length() - 1, stringBuilder.length(), "");
|
||||||
|
}
|
||||||
|
|
||||||
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER,
|
return Utility.parseMiniMessage(Config.PARTY_HELP_WRAPPER,
|
||||||
Placeholder.component("commands", Utility.parseMiniMessage(stringBuilder.toString()))
|
Placeholder.component("commands", Utility.parseMiniMessage(stringBuilder.toString()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,7 +15,7 @@ public class Reload {
|
||||||
.<CommandSource>literal("reloadchat")
|
.<CommandSource>literal("reloadchat")
|
||||||
.requires(ctx -> ctx.hasPermission("command.chat.reloadchat"))
|
.requires(ctx -> ctx.hasPermission("command.chat.reloadchat"))
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
VelocityChat.getPlugin().ReloadConfig();
|
VelocityChat.getPlugin().reloadConfig();
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@ package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.alttd.proxydiscordlink.DiscordLink;
|
|
||||||
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
|
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
|
||||||
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
|
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
import com.velocitypowered.api.command.BrigadierCommand;
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
|
@ -16,13 +20,16 @@ import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class Report {
|
public class Report {
|
||||||
|
|
||||||
// private static final MiniMessage miniMessage = MiniMessage.get();
|
|
||||||
|
|
||||||
public Report(ProxyServer proxyServer) {
|
public Report(ProxyServer proxyServer) {
|
||||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
.<CommandSource>literal("report")
|
.<CommandSource>literal("report")
|
||||||
|
|
@ -38,6 +45,11 @@ public class Report {
|
||||||
if (optionalServerConnection.isEmpty()) {
|
if (optionalServerConnection.isEmpty()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
String report = context.getArgument("report", String.class);
|
||||||
|
if (report.split(" ").length < 3) {
|
||||||
|
player.sendMessage(Utility.parseMiniMessage(Config.REPORT_TOO_SHORT));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
ServerConnection serverConnection = optionalServerConnection.get();
|
ServerConnection serverConnection = optionalServerConnection.get();
|
||||||
String serverName = serverConnection.getServer().getServerInfo().getName();
|
String serverName = serverConnection.getServer().getServerInfo().getName();
|
||||||
|
|
||||||
|
|
@ -46,7 +58,7 @@ public class Report {
|
||||||
embedBuilder.setTitle("Player Report");
|
embedBuilder.setTitle("Player Report");
|
||||||
embedBuilder.setColor(Color.CYAN);
|
embedBuilder.setColor(Color.CYAN);
|
||||||
embedBuilder.addField("Incident",
|
embedBuilder.addField("Incident",
|
||||||
context.getArgument("report", String.class),
|
report,
|
||||||
false);
|
false);
|
||||||
embedBuilder.addField("Server",
|
embedBuilder.addField("Server",
|
||||||
serverName.substring(0, 1).toUpperCase() + serverName.substring(1),
|
serverName.substring(0, 1).toUpperCase() + serverName.substring(1),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public class SilentJoinCommand {
|
||||||
|
|
||||||
|
public SilentJoinCommand(ProxyServer proxyServer) {
|
||||||
|
|
||||||
|
RequiredArgumentBuilder<CommandSource, String> serverNode = RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("server", StringArgumentType.string())
|
||||||
|
.suggests((context, builder) -> {
|
||||||
|
Collection<String> possibleValues = new ArrayList<>();
|
||||||
|
for (RegisteredServer server : proxyServer.getAllServers()) {
|
||||||
|
possibleValues.add(server.getServerInfo().getName());
|
||||||
|
}
|
||||||
|
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||||
|
String remaining = builder.getRemaining().toLowerCase();
|
||||||
|
for (String str : possibleValues) {
|
||||||
|
if (str.toLowerCase().startsWith(remaining)) {
|
||||||
|
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("silentjoin")
|
||||||
|
.requires(ctx -> ctx.hasPermission("command.chat.silent-join"))
|
||||||
|
.then(serverNode
|
||||||
|
.executes(context -> {
|
||||||
|
if (!(context.getSource() instanceof Player player)) {
|
||||||
|
context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (player.getCurrentServer().isEmpty()) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
String server = context.getArgument("server", String.class);
|
||||||
|
Optional<RegisteredServer> optionalServer = proxyServer.getServer(server);
|
||||||
|
if (optionalServer.isEmpty()) {
|
||||||
|
player.sendMessage(Utility.parseMiniMessage(Config.SILENT_JOIN_NO_SERVER));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
RegisteredServer registeredServer = optionalServer.get();
|
||||||
|
player.sendMessage(Utility.parseMiniMessage(Config.SILENT_JOIN_JOINING,
|
||||||
|
Placeholder.unparsed("server", registeredServer.getServerInfo().getName())));
|
||||||
|
ProxyPlayerListener.addSilentJoin(player.getUniqueId());
|
||||||
|
player.createConnectionRequest(registeredServer).connectWithIndication();
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
|
for (String alias : Config.SILENT_JOIN_COMMAND_ALIASES) {
|
||||||
|
metaBuilder.aliases(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendHelpMessage(CommandSource commandSource) {
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/silentjoin <server></gold>.</red>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,163 @@
|
||||||
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.velocitychat.commands.vote_to_mute.VoteToMuteStarter;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
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 net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class VoteToMute {
|
||||||
|
|
||||||
|
public VoteToMute(ProxyServer proxyServer, ChatLogHandler chatLogHandler) {
|
||||||
|
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||||
|
.suggests((context, builder) -> {
|
||||||
|
List<Player> possiblePlayers;
|
||||||
|
if (context.getSource() instanceof Player player) {
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isPresent()) {
|
||||||
|
possiblePlayers = getEligiblePlayers(currentServer.get().getServer());
|
||||||
|
} else {
|
||||||
|
possiblePlayers = getEligiblePlayers(proxyServer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
possiblePlayers = getEligiblePlayers(proxyServer);
|
||||||
|
}
|
||||||
|
Collection<String> possibleValues = possiblePlayers.stream()
|
||||||
|
.map(Player::getUsername)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (possibleValues.isEmpty())
|
||||||
|
return Suggestions.empty();
|
||||||
|
|
||||||
|
String remaining = builder.getRemaining().toLowerCase();
|
||||||
|
possibleValues.stream()
|
||||||
|
.filter(str -> str.toLowerCase().startsWith(remaining))
|
||||||
|
.map(StringArgumentType::escapeIfRequired)
|
||||||
|
.forEach(builder::suggest);
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("votetomute")
|
||||||
|
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||||
|
.requires(commandSource -> commandSource instanceof Player)
|
||||||
|
.then(playerNode
|
||||||
|
.suggests(((commandContext, suggestionsBuilder) -> {
|
||||||
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isEmpty()) {
|
||||||
|
sendHelpMessage(commandContext.getSource());
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}
|
||||||
|
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||||
|
currentServer.get().getServer().getPlayersConnected().stream()
|
||||||
|
.filter(connectedPlayer -> connectedPlayer.hasPermission("chat.affected-by-vote-to-mute"))
|
||||||
|
.map(Player::getUsername)
|
||||||
|
.filter((String str) -> str.toLowerCase().startsWith(remaining))
|
||||||
|
.map(StringArgumentType::escapeIfRequired)
|
||||||
|
.forEach(suggestionsBuilder::suggest);
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}))
|
||||||
|
.executes(commandContext -> {
|
||||||
|
String playerName = commandContext.getArgument("player", String.class);
|
||||||
|
Optional<Player> optionalPlayer = proxyServer.getPlayer(playerName);
|
||||||
|
if (optionalPlayer.isEmpty()) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<red>Player <player> is not online.</red>",
|
||||||
|
Placeholder.parsed("player", playerName)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Player voteTarget = optionalPlayer.get();
|
||||||
|
if (!voteTarget.hasPermission("chat.affected-by-vote-to-mute")) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<red>Player <player> can not be muted by a vote.</red>",
|
||||||
|
Placeholder.parsed("player", playerName)));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Player player = (Player) commandContext.getSource();
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isEmpty()) {
|
||||||
|
sendHelpMessage(commandContext.getSource());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
RegisteredServer server = currentServer.get().getServer();
|
||||||
|
if (currentServer.get().getServer().getPlayersConnected().stream().anyMatch(onlinePlayer -> onlinePlayer.hasPermission("chat.staff"))) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>There is a staff member online, so vote to mute can not be used. Please contact a staff member for help instead.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
boolean countLowerRanks = false;
|
||||||
|
long count = getTotalEligiblePlayers(server, false);
|
||||||
|
if (count < 6) {
|
||||||
|
countLowerRanks = true;
|
||||||
|
count = getTotalEligiblePlayers(server, true);
|
||||||
|
if (count < 6) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Not enough eligible players online to vote.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
new VoteToMuteStarter(chatLogHandler, voteTarget, player, server.getServerInfo().getName(), countLowerRanks)
|
||||||
|
.start();
|
||||||
|
return 1;
|
||||||
|
}))
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTotalEligiblePlayers(RegisteredServer server, boolean countLowerRanks) {
|
||||||
|
return (int) server.getPlayersConnected().stream()
|
||||||
|
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendHelpMessage(CommandSource commandSource) {
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/votetomute <player></gold>.</red>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Player> getEligiblePlayers(ProxyServer proxyServer) {
|
||||||
|
return proxyServer.getAllPlayers().stream()
|
||||||
|
.filter(player -> player.hasPermission("chat.affected-by-vote-to-mute"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Player> getEligiblePlayers(RegisteredServer registeredServer) {
|
||||||
|
return registeredServer.getPlayersConnected().stream()
|
||||||
|
.filter(player -> player.hasPermission("chat.affected-by-vote-to-mute"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,287 @@
|
||||||
|
package com.alttd.velocitychat.commands;
|
||||||
|
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.velocitychat.commands.vote_to_mute.ActiveVoteToMute;
|
||||||
|
import com.alttd.velocitychat.commands.vote_to_mute.VoteToMuteStarter;
|
||||||
|
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||||
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
|
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||||
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
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 net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class VoteToMuteHelper {
|
||||||
|
|
||||||
|
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||||
|
|
||||||
|
public VoteToMuteHelper(ProxyServer proxyServer) {
|
||||||
|
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||||
|
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||||
|
.suggests((context, builder) -> {
|
||||||
|
List<Player> possiblePlayers;
|
||||||
|
if (context.getSource() instanceof Player player) {
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isPresent()) {
|
||||||
|
possiblePlayers = getEligiblePlayers(currentServer.get().getServer());
|
||||||
|
} else {
|
||||||
|
possiblePlayers = getEligiblePlayers(proxyServer);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
possiblePlayers = getEligiblePlayers(proxyServer);
|
||||||
|
}
|
||||||
|
Collection<String> possibleValues = possiblePlayers.stream()
|
||||||
|
.map(Player::getUsername)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
if (possibleValues.isEmpty()) {
|
||||||
|
return Suggestions.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
String remaining = builder.getRemaining().toLowerCase();
|
||||||
|
possibleValues.stream()
|
||||||
|
.filter(str -> str.toLowerCase().startsWith(remaining))
|
||||||
|
.map(StringArgumentType::escapeIfRequired)
|
||||||
|
.forEach(builder::suggest);
|
||||||
|
return builder.buildFuture();
|
||||||
|
})
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
RequiredArgumentBuilder<CommandSource, String> yesNoNode = RequiredArgumentBuilder.
|
||||||
|
<CommandSource, String>argument("yesNo", StringArgumentType.string())
|
||||||
|
.suggests(((commandContext, suggestionsBuilder) -> {
|
||||||
|
List<String> yesNoValues = Arrays.asList("yes", "no");
|
||||||
|
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||||
|
yesNoValues.stream()
|
||||||
|
.filter((String str) -> str.toLowerCase().startsWith(remaining))
|
||||||
|
.map(StringArgumentType::escapeIfRequired)
|
||||||
|
.forEach(suggestionsBuilder::suggest);
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}));
|
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSource> pageNode = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("page")
|
||||||
|
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||||
|
.then(RequiredArgumentBuilder.<CommandSource, Integer>argument("page number", IntegerArgumentType.integer(1))
|
||||||
|
.suggests(((commandContext, suggestionsBuilder) -> {
|
||||||
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}
|
||||||
|
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||||
|
if (instance.isEmpty()) {
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}
|
||||||
|
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||||
|
String remaining = suggestionsBuilder.getRemaining().toLowerCase();
|
||||||
|
int totalPages = voteToMuteStarter.getTotalPages();
|
||||||
|
IntStream.range(1, totalPages + 1)
|
||||||
|
.mapToObj(String::valueOf)
|
||||||
|
.filter((String str) -> str.toLowerCase().startsWith(remaining))
|
||||||
|
.map(StringArgumentType::escapeIfRequired)
|
||||||
|
.forEach(suggestionsBuilder::suggest);
|
||||||
|
return suggestionsBuilder.buildFuture();
|
||||||
|
}))
|
||||||
|
.executes(commandContext -> {
|
||||||
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||||
|
if (instance.isEmpty()) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int pageNumber = commandContext.getArgument("page number", Integer.class);
|
||||||
|
instance.get().showPage(pageNumber);
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
).executes(commandContext -> {
|
||||||
|
sendHelpMessage(commandContext.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSource> enterMessagesNode = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("messages")
|
||||||
|
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||||
|
.then(RequiredArgumentBuilder.<CommandSource, String>argument("list of messages", StringArgumentType.greedyString())
|
||||||
|
.executes(commandContext -> {
|
||||||
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Only players can use this command.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Optional<VoteToMuteStarter> instance = VoteToMuteStarter.getInstance(player.getUniqueId());
|
||||||
|
if (instance.isEmpty()) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>You don't have an active vote to mute.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
String listOfPages = commandContext.getArgument("list of messages", String.class);
|
||||||
|
if (!listOfPages.matches("([1-9][0-9]*, )*[1-9][0-9]*")) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Please make sure to format the command correctly.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
VoteToMuteStarter voteToMuteStarter = instance.get();
|
||||||
|
|
||||||
|
List<Integer> collect = Arrays.stream(listOfPages.split(", "))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
Optional<Integer> max = collect.stream().max(Integer::compare);
|
||||||
|
if (max.isEmpty()) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
int highestLogEntry = max.get();
|
||||||
|
|
||||||
|
if (voteToMuteStarter.getTotalLogEntries() < highestLogEntry) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isEmpty()) {
|
||||||
|
sendHelpMessage(commandContext.getSource());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Component chatLogs = voteToMuteStarter.getChatLogsAndClose(collect);
|
||||||
|
RegisteredServer server = currentServer.get().getServer();
|
||||||
|
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
||||||
|
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
||||||
|
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs, player)
|
||||||
|
.start();
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
).executes(commandContext -> {
|
||||||
|
sendHelpMessage(commandContext.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
LiteralArgumentBuilder<CommandSource> voteNode = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("vote")
|
||||||
|
.then(playerNode
|
||||||
|
.then(yesNoNode
|
||||||
|
.executes(commandContext -> {
|
||||||
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<red>Only players are allowed to vote</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
String playerName = commandContext.getArgument("player", String.class);
|
||||||
|
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
||||||
|
if (optionalActiveVoteToMute.isEmpty()) {
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<red>This player does not have an active vote to mute them.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
||||||
|
|
||||||
|
if (!activeVoteToMute.countLowerRanks()) {
|
||||||
|
if (!player.hasPermission("chat.vote-to-mute")) {
|
||||||
|
player.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String vote = commandContext.getArgument("yesNo", String.class);
|
||||||
|
switch (vote.toLowerCase()) {
|
||||||
|
case "yes" -> {
|
||||||
|
activeVoteToMute.vote(player.getUniqueId(), true);
|
||||||
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<green>You voted to mute. Thanks for voting, staff will be online soon to review!</green>"));
|
||||||
|
player.getCurrentServer().ifPresent(serverConnection -> notifyEligiblePlayers(serverConnection.getServer(), activeVoteToMute));
|
||||||
|
}
|
||||||
|
case "no" -> {
|
||||||
|
activeVoteToMute.vote(player.getUniqueId(), false);
|
||||||
|
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(
|
||||||
|
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
})).executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
})).executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||||
|
.<CommandSource>literal("votetomutehelper")
|
||||||
|
.requires(commandSource -> commandSource.hasPermission("chat.backup-vote-to-mute"))
|
||||||
|
.requires(commandSource -> commandSource instanceof Player)
|
||||||
|
.then(voteNode)
|
||||||
|
.then(pageNode)
|
||||||
|
.then(enterMessagesNode)
|
||||||
|
.executes(context -> {
|
||||||
|
sendHelpMessage(context.getSource());
|
||||||
|
return 1;
|
||||||
|
})
|
||||||
|
.build();
|
||||||
|
|
||||||
|
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||||
|
|
||||||
|
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||||
|
|
||||||
|
CommandMeta meta = metaBuilder.build();
|
||||||
|
|
||||||
|
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTotalEligiblePlayers(RegisteredServer server, boolean countLowerRanks) {
|
||||||
|
return (int) server.getPlayersConnected().stream()
|
||||||
|
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||||
|
.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyEligiblePlayers(RegisteredServer server, ActiveVoteToMute activeVoteToMute) {
|
||||||
|
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())),
|
||||||
|
Placeholder.parsed("player", activeVoteToMute.getVotedPlayer().getUsername()));
|
||||||
|
boolean countLowerRanks = activeVoteToMute.countLowerRanks();
|
||||||
|
server.getPlayersConnected().stream()
|
||||||
|
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||||
|
.forEach(player -> player.sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendHelpMessage(CommandSource commandSource) {
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/votetomutehelper <player></gold>.</red>"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Player> getEligiblePlayers(ProxyServer proxyServer) {
|
||||||
|
return proxyServer.getAllPlayers().stream()
|
||||||
|
.filter(player -> player.hasPermission("chat.affected-by-vote-to-mute"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Player> getEligiblePlayers(RegisteredServer registeredServer) {
|
||||||
|
return registeredServer.getPlayersConnected().stream()
|
||||||
|
.filter(player -> player.hasPermission("chat.affected-by-vote-to-mute"))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ import com.alttd.chat.util.Utility;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -38,7 +38,7 @@ public class Create implements SubCommand {
|
||||||
}
|
}
|
||||||
if (PartyManager.getParty(args[1]) != null) {
|
if (PartyManager.getParty(args[1]) != null) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS,
|
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS,
|
||||||
Placeholder.miniMessage("party", args[1])
|
Placeholder.parsed("party", args[1])
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +47,8 @@ public class Create implements SubCommand {
|
||||||
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getUsername());
|
party.addUser(ChatUserManager.getChatUser(player.getUniqueId()), player.getUsername());
|
||||||
PartyManager.addParty(party);
|
PartyManager.addParty(party);
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.CREATED_PARTY,
|
source.sendMessage(Utility.parseMiniMessage(Config.CREATED_PARTY,
|
||||||
Placeholder.miniMessage("party_name", party.getPartyName()),
|
Placeholder.unparsed("party_name", party.getPartyName()),
|
||||||
Placeholder.miniMessage("party_password", party.getPartyPassword())));
|
Placeholder.unparsed("party_password", party.getPartyPassword())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -39,18 +39,19 @@ public class Disband implements SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.DISBAND_PARTY_CONFIRM, Placeholder.miniMessage("party", party.getPartyName())));
|
source.sendMessage(Utility.parseMiniMessage(Config.DISBAND_PARTY_CONFIRM, Placeholder.unparsed("party", party.getPartyName())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!args[1].equalsIgnoreCase("confirm") || !args[2].equals(party.getPartyName())) {
|
if (!args[1].equalsIgnoreCase("confirm") || !args[2].equals(party.getPartyName())) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
source.sendMessage(Utility.parseMiniMessage(getHelpMessage()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Utility.parseMiniMessage(Config.DISBANDED_PARTY,
|
.sendPartyMessage(party,
|
||||||
Placeholder.miniMessage("owner", player.getUsername()),
|
Utility.parseMiniMessage(Config.DISBANDED_PARTY,
|
||||||
Placeholder.miniMessage("party", party.getPartyName())
|
Placeholder.unparsed("owner", player.getUsername()),
|
||||||
), null);
|
Placeholder.unparsed("party", party.getPartyName())
|
||||||
|
).asComponent(), null);
|
||||||
party.delete();
|
party.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,21 @@ import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.Party;
|
import com.alttd.chat.objects.Party;
|
||||||
import com.alttd.chat.objects.PartyUser;
|
import com.alttd.chat.objects.PartyUser;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class Info implements SubCommand {
|
public class Info implements SubCommand {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "info";
|
return "info";
|
||||||
|
|
@ -34,15 +39,21 @@ public class Info implements SubCommand {
|
||||||
|
|
||||||
List<Component> displayNames = new ArrayList<>();
|
List<Component> displayNames = new ArrayList<>();
|
||||||
for (PartyUser partyUser : party.getPartyUsers()) {
|
for (PartyUser partyUser : party.getPartyUsers()) {
|
||||||
displayNames.add(partyUser.getDisplayName());
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(partyUser.getUuid());
|
||||||
|
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());
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_INFO,
|
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_INFO,
|
||||||
Placeholder.miniMessage("party", party.getPartyName()),
|
Placeholder.unparsed("party", party.getPartyName()),
|
||||||
Placeholder.miniMessage("password", party.getPartyPassword()),
|
Placeholder.unparsed("password", party.getPartyPassword()),
|
||||||
Placeholder.component("owner", party.getPartyUser(party.getOwnerUuid()).getDisplayName()),
|
Placeholder.component("owner", owner == null ? MiniMessage.miniMessage().deserialize("Unknown Owner") : owner.getDisplayName()),
|
||||||
Placeholder.component("members", Component.join(Component.text(", "), displayNames))
|
Placeholder.component("members", Component.join(JoinConfiguration.separator(Component.text(", ")), displayNames))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -50,17 +50,22 @@ public class Invite implements SubCommand {
|
||||||
|
|
||||||
if (!target.isActive()) {
|
if (!target.isActive()) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_ONLINE,
|
source.sendMessage(Utility.parseMiniMessage(Config.NOT_ONLINE,
|
||||||
Placeholder.miniMessage("player", target.getUsername())
|
Placeholder.unparsed("player", target.getUsername())
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
target.sendMessage(Utility.parseMiniMessage(Config.JOIN_PARTY_CLICK_MESSAGE,
|
target.sendMessage(Utility.parseMiniMessage(Config.JOIN_PARTY_CLICK_MESSAGE,
|
||||||
Placeholder.miniMessage("party", party.getPartyName()),
|
Placeholder.unparsed("party", party.getPartyName()),
|
||||||
Placeholder.miniMessage("party_password", party.getPartyPassword())
|
Placeholder.unparsed("party_password", party.getPartyPassword())
|
||||||
));
|
));
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
|
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
|
||||||
Placeholder.miniMessage("player", target.getUsername())
|
Placeholder.unparsed("player", target.getUsername()),
|
||||||
|
Placeholder.unparsed("party", party.getPartyName()),
|
||||||
|
Placeholder.unparsed("party_password", party.getPartyPassword())
|
||||||
|
));
|
||||||
|
source.sendMessage(Utility.parseMiniMessage(Config.SENT_PARTY_INV,
|
||||||
|
Placeholder.unparsed("player", target.getUsername())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.Template;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -44,19 +43,21 @@ public class Join implements SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
// party.addUser(ChatUserManager.getChatUser(player.getUniqueId())); //Removed until we can get nicknames to translate to colors correctly
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
|
|
||||||
if (chatUser.getPartyId() == party.getPartyId()) {
|
if (chatUser.getPartyId() == party.getPartyId()) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.ALREADY_IN_THIS_PARTY, Placeholder.miniMessage("party", party.getPartyName())));
|
source.sendMessage(Utility.parseMiniMessage(Config.ALREADY_IN_THIS_PARTY, Placeholder.parsed("party", party.getPartyName())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
party.addUser(chatUser, player.getUsername());
|
party.addUser(chatUser, player.getUsername());
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.miniMessage("party_name", party.getPartyName())));
|
source.sendMessage(Utility.parseMiniMessage(Config.JOINED_PARTY, Placeholder.parsed("party_name", party.getPartyName())));
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
|
.sendPartyMessage(party,
|
||||||
Placeholder.component("player_name", chatUser.getDisplayName()),
|
Utility.parseMiniMessage(Config.PLAYER_JOINED_PARTY,
|
||||||
Placeholder.miniMessage("party_name", party.getPartyName())
|
Placeholder.component("player_name", chatUser.getDisplayName()),
|
||||||
), null);
|
Placeholder.parsed("party_name", party.getPartyName())
|
||||||
|
).asComponent(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -35,28 +35,31 @@ public class Leave implements SubCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
if (currentServer.isEmpty())
|
if (currentServer.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
party.removeUser(player.getUniqueId());
|
party.removeUser(player.getUniqueId());
|
||||||
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
if (party.getOwnerUuid().equals(player.getUniqueId())) {
|
||||||
if (party.getPartyUsers().size() > 0) {
|
if (!party.getPartyUsers().isEmpty()) {
|
||||||
UUID uuid = party.setNewOwner();
|
UUID uuid = party.setNewOwner();
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
|
source.sendMessage(Utility.parseMiniMessage(Config.NOTIFY_FINDING_NEW_OWNER));
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY,
|
.sendPartyMessage(party,
|
||||||
Placeholder.miniMessage("old_owner", player.getUsername()),
|
Utility.parseMiniMessage(Config.OWNER_LEFT_PARTY,
|
||||||
Placeholder.miniMessage("new_owner", party.getPartyUser(uuid).getPlayerName())
|
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||||
), null);
|
Placeholder.unparsed("new_owner", party.getPartyUser(uuid).getPlayerName())
|
||||||
|
).asComponent(), null);
|
||||||
} else {
|
} else {
|
||||||
party.delete();
|
party.delete();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
source.sendMessage(Utility.parseMiniMessage(Config.LEFT_PARTY));
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Utility.parseMiniMessage(Config.PLAYER_LEFT_PARTY,
|
.sendPartyMessage(party,
|
||||||
Placeholder.miniMessage("player_name", player.getUsername())
|
Utility.parseMiniMessage(Config.PLAYER_LEFT_PARTY,
|
||||||
), null);
|
Placeholder.unparsed("player_name", player.getUsername())
|
||||||
|
).asComponent(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -45,18 +45,19 @@ public class Name implements SubCommand {
|
||||||
}
|
}
|
||||||
if (PartyManager.getParty(args[1]) != null) {
|
if (PartyManager.getParty(args[1]) != null) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS,
|
source.sendMessage(Utility.parseMiniMessage(Config.PARTY_EXISTS,
|
||||||
Placeholder.miniMessage("party", args[1])
|
Placeholder.unparsed("party", args[1])
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String oldName = party.getPartyName();
|
String oldName = party.getPartyName();
|
||||||
party.setPartyName(args[1]);
|
party.setPartyName(args[1]);
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Placeholder.component("owner", ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName()),
|
.sendPartyMessage(party, Utility.parseMiniMessage(Config.RENAMED_PARTY,
|
||||||
Placeholder.miniMessage("old_name", oldName),
|
Placeholder.component("owner", ChatUserManager.getChatUser(player.getUniqueId()).getDisplayName()),
|
||||||
Placeholder.miniMessage("new_name", args[1])
|
Placeholder.unparsed("old_name", oldName),
|
||||||
), null);
|
Placeholder.unparsed("new_name", args[1])
|
||||||
|
).asComponent(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,11 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Owner implements SubCommand {
|
public class Owner implements SubCommand {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -44,31 +43,36 @@ public class Owner implements SubCommand {
|
||||||
PartyUser partyUser = party.getPartyUser(args[1]);
|
PartyUser partyUser = party.getPartyUser(args[1]);
|
||||||
if (partyUser == null) {
|
if (partyUser == null) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
||||||
Placeholder.miniMessage("player", args[1])
|
Placeholder.unparsed("player", args[1])
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
party.setNewOwner(partyUser.getUuid());
|
party.setNewOwner(partyUser.getUuid());
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler()
|
||||||
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER,
|
.sendPartyMessage(party,
|
||||||
Placeholder.miniMessage("old_owner", player.getUsername()),
|
Utility.parseMiniMessage(Config.NEW_PARTY_OWNER,
|
||||||
Placeholder.miniMessage("new_owner", partyUser.getPlayerName())
|
Placeholder.unparsed("old_owner", player.getUsername()),
|
||||||
), null);
|
Placeholder.unparsed("new_owner", partyUser.getPlayerName())
|
||||||
|
).asComponent(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggest(String[] args, CommandSource source) {
|
public List<String> suggest(String[] args, CommandSource source) {
|
||||||
ArrayList<String> suggest = new ArrayList<>();
|
ArrayList<String> suggest = new ArrayList<>();
|
||||||
if (!(source instanceof Player player))
|
if (!(source instanceof Player player)) {
|
||||||
return suggest;
|
return suggest;
|
||||||
|
}
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
Party party = PartyManager.getParty(uuid);
|
Party party = PartyManager.getParty(uuid);
|
||||||
if (party == null)
|
if (party == null) {
|
||||||
return suggest;
|
return suggest;
|
||||||
if (args.length == 1 || args.length == 2)
|
}
|
||||||
|
if (args.length == 1 || args.length == 2) {
|
||||||
suggest.addAll(party.getPartyUsers().stream()
|
suggest.addAll(party.getPartyUsers().stream()
|
||||||
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
.filter(partyUser -> !partyUser.getUuid().equals(uuid))
|
||||||
.map(PartyUser::getPlayerName).collect(Collectors.toList()));
|
.map(PartyUser::getPlayerName)
|
||||||
|
.toList());
|
||||||
|
}
|
||||||
return suggest;
|
return suggest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.alttd.velocitychat.commands.SubCommand;
|
import com.alttd.velocitychat.commands.SubCommand;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -50,7 +50,7 @@ public class Remove implements SubCommand {
|
||||||
partyUser = party.getPartyUser(args[1]);
|
partyUser = party.getPartyUser(args[1]);
|
||||||
if (partyUser == null) {
|
if (partyUser == null) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
||||||
Placeholder.miniMessage("player", args[1])
|
Placeholder.unparsed("player", args[1])
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -59,26 +59,27 @@ public class Remove implements SubCommand {
|
||||||
partyUser = party.getPartyUser(onlinePlayer.getUniqueId());
|
partyUser = party.getPartyUser(onlinePlayer.getUniqueId());
|
||||||
if (partyUser == null) {
|
if (partyUser == null) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
source.sendMessage(Utility.parseMiniMessage(Config.NOT_A_PARTY_MEMBER,
|
||||||
Placeholder.miniMessage("player", onlinePlayer.getUsername())
|
Placeholder.unparsed("player", onlinePlayer.getUsername())
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
party.removeUser(ChatUserManager.getChatUser(partyUser.getUuid()));
|
|
||||||
|
|
||||||
if (partyUser.getUuid().equals(party.getOwnerUuid())) {
|
if (partyUser.getUuid().equals(party.getOwnerUuid())) {
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.CANT_REMOVE_PARTY_OWNER));
|
source.sendMessage(Utility.parseMiniMessage(Config.CANT_REMOVE_PARTY_OWNER));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
party.removeUser(ChatUserManager.getChatUser(partyUser.getUuid()));
|
||||||
|
|
||||||
|
|
||||||
if (onlinePlayer != null && onlinePlayer.isActive()) {
|
if (onlinePlayer != null && onlinePlayer.isActive()) {
|
||||||
onlinePlayer.sendMessage(Utility.parseMiniMessage(Config.REMOVED_FROM_PARTY,
|
onlinePlayer.sendMessage(Utility.parseMiniMessage(Config.REMOVED_FROM_PARTY,
|
||||||
Placeholder.miniMessage("party", party.getPartyName())
|
Placeholder.unparsed("party", party.getPartyName())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
source.sendMessage(Utility.parseMiniMessage(Config.REMOVED_USER_FROM_PARTY,
|
source.sendMessage(Utility.parseMiniMessage(Config.REMOVED_USER_FROM_PARTY,
|
||||||
Placeholder.miniMessage("player", onlinePlayer == null ? partyUser.getPlayerName() : onlinePlayer.getUsername())
|
Placeholder.unparsed("player", onlinePlayer == null ? partyUser.getPlayerName() : onlinePlayer.getUsername())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,244 @@
|
||||||
|
package com.alttd.velocitychat.commands.vote_to_mute;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
|
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
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 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;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
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>").asComponent();
|
||||||
|
|
||||||
|
private final Player votedPlayer;
|
||||||
|
private final Player startedByPlayer;
|
||||||
|
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;
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
private final Component chatLogs;
|
||||||
|
private boolean endedVote = false;
|
||||||
|
|
||||||
|
public static Optional<ActiveVoteToMute> getInstance(String 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")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player.hasPermission("chat.vote-to-mute")) {
|
||||||
|
instances.values().stream()
|
||||||
|
.filter(activeVoteToMute -> previousServer == null || activeVoteToMute.getServer().getServerInfo().hashCode() == previousServer.getServerInfo().hashCode())
|
||||||
|
.forEach(inst -> inst.removeEligibleVoter(player.getUniqueId()));
|
||||||
|
} else {
|
||||||
|
instances.values().stream()
|
||||||
|
.filter(ActiveVoteToMute::countLowerRanks)
|
||||||
|
.filter(activeVoteToMute -> previousServer == null || activeVoteToMute.getServer().getServerInfo().hashCode() == previousServer.getServerInfo().hashCode())
|
||||||
|
.forEach(inst -> inst.removeEligibleVoter(player.getUniqueId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addPotentialVoter(Player player, ServerConnection server) {
|
||||||
|
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())
|
||||||
|
.forEach(activeVoteToMute -> activeVoteToMute.addEligibleVoter(player));
|
||||||
|
} else {
|
||||||
|
instances.values().stream()
|
||||||
|
.filter(ActiveVoteToMute::countLowerRanks)
|
||||||
|
.filter(activeVoteToMute -> activeVoteToMute.getServer().getServerInfo().hashCode() == server.getServerInfo().hashCode())
|
||||||
|
.forEach(activeVoteToMute -> activeVoteToMute.addEligibleVoter(player));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ActiveVoteToMute(@NotNull Player votedPlayer, @NotNull RegisteredServer server, ProxyServer proxyServer, Duration duration,
|
||||||
|
int totalEligibleVoters, boolean countLowerRanks, Component chatLogs, @NotNull Player startedByPlayer) {
|
||||||
|
this.chatLogs = chatLogs;
|
||||||
|
this.votedPlayer = votedPlayer;
|
||||||
|
this.totalEligibleVoters = totalEligibleVoters;
|
||||||
|
this.countLowerRanks = countLowerRanks;
|
||||||
|
this.server = server;
|
||||||
|
this.proxyServer = proxyServer;
|
||||||
|
instances.put(votedPlayer.getUsername(), this);
|
||||||
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
executorService.schedule(this::endVote,
|
||||||
|
duration.toMinutes(), TimeUnit.MINUTES);
|
||||||
|
this.startedByPlayer = startedByPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RegisteredServer getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void endVote() {
|
||||||
|
if (endedVote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
instances.remove(votedPlayer.getUsername());
|
||||||
|
if (votePassed()) {
|
||||||
|
mutePlayer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
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"))
|
||||||
|
.forEach(player -> player.sendMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void vote(UUID uuid, boolean votedToMute) {
|
||||||
|
if (votedToMute) {
|
||||||
|
votedFor.add(uuid);
|
||||||
|
votedAgainst.remove(uuid);
|
||||||
|
if (!votePassed()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
endedVote = true;
|
||||||
|
instances.remove(votedPlayer.getUsername());
|
||||||
|
mutePlayer();
|
||||||
|
} else {
|
||||||
|
votedAgainst.add(uuid);
|
||||||
|
votedFor.remove(uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean votePassed() {
|
||||||
|
double totalVotes = (votedFor.size() + votedAgainst.size());
|
||||||
|
if (totalVotes == 0 || votedFor.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (totalVotes / totalEligibleVoters < 0.6) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return votedFor.size() / totalVotes > 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean countLowerRanks() {
|
||||||
|
return countLowerRanks;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mutePlayer() {
|
||||||
|
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"))
|
||||||
|
.forEach(player -> player.sendMessage(message));
|
||||||
|
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);
|
||||||
|
|
||||||
|
ALogger.info(String.format("Player %s muted by vote\nLogs:\n%s\n\nVotes for:\n%s\nVotes against:\n%s\n",
|
||||||
|
votedPlayer.getUsername(),
|
||||||
|
chatLogsString,
|
||||||
|
parseUUIDsToPlayerOrString(votedFor),
|
||||||
|
parseUUIDsToPlayerOrString(votedAgainst)
|
||||||
|
));
|
||||||
|
|
||||||
|
long id = Config.serverChannelId.get("general");
|
||||||
|
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(id, embedBuilder, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private EmbedBuilder buildMutedEmbed(String chatLogsString) {
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setAuthor(votedPlayer.getUsername(), null, "https://crafatar.com/avatars/" + votedPlayer.getUniqueId() + "?overlay");
|
||||||
|
embedBuilder.setTitle("Player muted by vote");
|
||||||
|
embedBuilder.setColor(Color.CYAN);
|
||||||
|
embedBuilder.addField("Logs",
|
||||||
|
chatLogsString.substring(0, Math.min(chatLogsString.length(), 1024)),
|
||||||
|
false);
|
||||||
|
embedBuilder.addField("Server",
|
||||||
|
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
||||||
|
true);
|
||||||
|
embedBuilder.addField("Started by",
|
||||||
|
String.format("Username: %s\nUUID: %s", startedByPlayer.getUsername(), startedByPlayer.getUniqueId().toString()),
|
||||||
|
true);
|
||||||
|
return embedBuilder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String parseUUIDsToPlayerOrString(Collection<UUID> uuids) {
|
||||||
|
return uuids.stream().map(uuid -> {
|
||||||
|
Optional<Player> player = proxyServer.getPlayer(uuid);
|
||||||
|
if (player.isPresent()) {
|
||||||
|
return player.get().getUsername();
|
||||||
|
}
|
||||||
|
return uuid.toString();
|
||||||
|
}).collect(Collectors.joining("\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEligibleVoter(Player player) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
if (votedAgainst.contains(uuid) || votedFor.contains(uuid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
totalEligibleVoters++;
|
||||||
|
player.sendMessage(getVoteStartMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeEligibleVoter(UUID uuid) {
|
||||||
|
if (votedFor.contains(uuid) || votedAgainst.contains(uuid)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
totalEligibleVoters--;
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
<logs>
|
||||||
|
<prefix> Click: <click:run_command:'/votetomutehelper vote %s yes'><red>Mute</red></click> --- <click:run_command:'/votetomutehelper vote %s no'><yellow>Don't mute</yellow></click>""",
|
||||||
|
votedPlayer.getUsername(), votedPlayer.getUsername()),
|
||||||
|
Placeholder.component("prefix", prefix),
|
||||||
|
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||||
|
Placeholder.component("logs", chatLogs));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getVotedPlayer() {
|
||||||
|
return votedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVotedFor() {
|
||||||
|
return votedFor.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalEligibleVoters() {
|
||||||
|
return totalEligibleVoters;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,132 @@
|
||||||
|
package com.alttd.velocitychat.commands.vote_to_mute;
|
||||||
|
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLog;
|
||||||
|
import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
|
import com.alttd.chat.util.Utility;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.JoinConfiguration;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class VoteToMuteStarter {
|
||||||
|
|
||||||
|
private static final HashMap<UUID, VoteToMuteStarter> instanceMap = new HashMap<>();
|
||||||
|
|
||||||
|
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>").asComponent();
|
||||||
|
private final ChatLogHandler chatLogHandler;
|
||||||
|
private final Player votedPlayer;
|
||||||
|
private final Player commandSource;
|
||||||
|
private final String serverName;
|
||||||
|
private List<Component> parsedChatLogs;
|
||||||
|
private final boolean countLowerRanks;
|
||||||
|
|
||||||
|
public static Optional<VoteToMuteStarter> getInstance(UUID uuid) {
|
||||||
|
if (!instanceMap.containsKey(uuid)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return Optional.of(instanceMap.get(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
public VoteToMuteStarter(ChatLogHandler chatLogHandler, Player votedPlayer, Player commandSource, String serverName, boolean countLowerRanks) {
|
||||||
|
this.chatLogHandler = chatLogHandler;
|
||||||
|
this.votedPlayer = votedPlayer;
|
||||||
|
this.commandSource = commandSource;
|
||||||
|
this.serverName = serverName;
|
||||||
|
this.countLowerRanks = countLowerRanks;
|
||||||
|
instanceMap.put(commandSource.getUniqueId(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(10), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
||||||
|
if (throwable != null) {
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage("<prefix> <red>Unable to retrieve messages</red> for player <player>",
|
||||||
|
Placeholder.component("prefix", prefix),
|
||||||
|
Placeholder.parsed("player", votedPlayer.getUsername())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
parseChatLogs(chatLogs);
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage(
|
||||||
|
"<prefix> <green>Please select up to 10 messages other players should see to decide their vote, seperated by comma's. " +
|
||||||
|
"Example: <gold>/votetomutehelper messages 1, 2, 5, 8</gold></green>", Placeholder.component("prefix", prefix)));
|
||||||
|
showPage(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseChatLogs(List<ChatLog> chatLogs) {
|
||||||
|
TagResolver.Single playerTag = Placeholder.parsed("player", votedPlayer.getUsername());
|
||||||
|
TagResolver.Single prefixTag = Placeholder.component("prefix", prefix);
|
||||||
|
chatLogs.sort(Comparator.comparing(ChatLog::getTimestamp).reversed());
|
||||||
|
parsedChatLogs = IntStream.range(0, chatLogs.size())
|
||||||
|
.mapToObj(i -> Utility.parseMiniMessage(
|
||||||
|
"<number>. <prefix> <player>: <message>",
|
||||||
|
TagResolver.resolver(
|
||||||
|
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||||
|
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||||
|
playerTag,
|
||||||
|
prefixTag
|
||||||
|
)).asComponent()
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void showPage(int page) {
|
||||||
|
List<Component> collect = parsedChatLogs.stream().skip((page - 1) * 10L).limit(10L).toList();
|
||||||
|
Component chatLogsComponent = Component.join(JoinConfiguration.newlines(), collect);
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("<prefix> ChatLogs for <player>\n<logs>\n");
|
||||||
|
if (page > 1) {
|
||||||
|
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||||
|
.append(page - 1)
|
||||||
|
.append("><hover:show_text:'<gold>Click to go to previous page'><gold><previous page></gold></hover></click> ");
|
||||||
|
}
|
||||||
|
if (parsedChatLogs.size() > page * 10) {
|
||||||
|
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||||
|
.append(page + 1)
|
||||||
|
.append("><hover:show_text:'<gold>Click to go to next page'><gold><next page></gold></hover></click> ");
|
||||||
|
}
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage(stringBuilder.toString(),
|
||||||
|
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||||
|
Placeholder.component("prefix", prefix),
|
||||||
|
Placeholder.component("logs", chatLogsComponent)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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) {
|
||||||
|
List<Component> selectedChatLogs = ids.stream()
|
||||||
|
.filter(id -> id >= 1 && id <= parsedChatLogs.size())
|
||||||
|
.map(id -> parsedChatLogs.get(id - 1))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
instanceMap.remove(commandSource.getUniqueId());
|
||||||
|
return Component.join(JoinConfiguration.newlines(), selectedChatLogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalPages() {
|
||||||
|
return (int) Math.ceil((double) parsedChatLogs.size() / 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Player getVotedPlayer() {
|
||||||
|
return votedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalLogEntries() {
|
||||||
|
return parsedChatLogs.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean countLowerRanks() {
|
||||||
|
return countLowerRanks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@ package com.alttd.velocitychat.data;
|
||||||
import com.alttd.chat.config.ServerConfig;
|
import com.alttd.chat.config.ServerConfig;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -31,8 +31,7 @@ public class ServerWrapper {
|
||||||
return serverName;
|
return serverName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean globalChat()
|
public boolean globalChat() {
|
||||||
{
|
|
||||||
return globalChat;
|
return globalChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,10 +39,11 @@ public class ServerWrapper {
|
||||||
return joinMessages;
|
return joinMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendJoinLeaveMessage(UUID uuid, Component component) {
|
public void sendJoinLeaveMessage(UUID uuid, ComponentLike component) {
|
||||||
if(joinMessages())
|
if (joinMessages()) {
|
||||||
getRegisteredServer().getPlayersConnected().stream()
|
getRegisteredServer().getPlayersConnected().stream()
|
||||||
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
.filter(p -> !ChatUserManager.getChatUser(p.getUniqueId()).getIgnoredPlayers().contains(uuid))
|
||||||
.forEach(p -> p.sendMessage(component));
|
.forEach(p -> p.sendMessage(component));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,7 @@ import com.alttd.chat.database.Queries;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.managers.PartyManager;
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.managers.RegexManager;
|
import com.alttd.chat.managers.RegexManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.*;
|
||||||
import com.alttd.chat.objects.Mail;
|
|
||||||
import com.alttd.chat.objects.ModifiableString;
|
|
||||||
import com.alttd.chat.objects.Party;
|
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.alttd.velocitychat.VelocityChat;
|
import com.alttd.velocitychat.VelocityChat;
|
||||||
|
|
@ -18,14 +15,20 @@ import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import net.kyori.adventure.text.Component;
|
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.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class ChatHandler {
|
public class ChatHandler {
|
||||||
|
|
||||||
|
|
@ -33,30 +36,33 @@ public class ChatHandler {
|
||||||
UUID uuid = UUID.fromString(sender);
|
UUID uuid = UUID.fromString(sender);
|
||||||
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
ChatUser senderUser = ChatUserManager.getChatUser(uuid);
|
||||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||||
if(optionalPlayer.isEmpty()) return;
|
if (optionalPlayer.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Player player = optionalPlayer.get();
|
Player player = optionalPlayer.get();
|
||||||
|
|
||||||
Optional<Player> optionalPlayer2 = VelocityChat.getPlugin().getProxy().getPlayer(target);
|
Optional<Player> optionalPlayer2 = VelocityChat.getPlugin().getProxy().getPlayer(target);
|
||||||
if(optionalPlayer2.isEmpty()) {
|
if (optionalPlayer2.isEmpty()) {
|
||||||
player.sendMessage(MiniMessage.markdown().parse(Config.RECEIVER_DOES_NOT_EXIST, Placeholder.miniMessage("player", target)));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player2 = optionalPlayer2.get();
|
Player player2 = optionalPlayer2.get();
|
||||||
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
ChatUser targetUser = ChatUserManager.getChatUser(player2.getUniqueId());
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
TagResolver Placeholders = TagResolver.resolver(
|
||||||
placeholders.put("sender", Replacement.component(senderUser.getDisplayName()));
|
Placeholder.component("sender", senderUser.getDisplayName()),
|
||||||
placeholders.put("sendername", Replacement.miniMessage(player.getUsername()));
|
Placeholder.unparsed("sendername", player.getUsername()),
|
||||||
placeholders.put("receiver", Replacement.component(targetUser.getDisplayName()));
|
Placeholder.component("receiver", targetUser.getDisplayName()),
|
||||||
placeholders.put("receivername", Replacement.miniMessage(player2.getUsername()));
|
Placeholder.unparsed("receivername", player2.getUsername()),
|
||||||
placeholders.put("message", Replacement.component(GsonComponentSerializer.gson().deserialize(message)));
|
Placeholder.component("message", GsonComponentSerializer.gson().deserialize(message)),
|
||||||
placeholders.put("server", Replacement.miniMessage(player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude"));
|
Placeholder.unparsed("server", player.getCurrentServer().isPresent() ? player.getCurrentServer().get().getServerInfo().getName() : "Altitude"));
|
||||||
|
|
||||||
ServerConnection serverConnection;
|
ServerConnection serverConnection;
|
||||||
if(player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
if (player.getCurrentServer().isPresent() && player2.getCurrentServer().isPresent()) {
|
||||||
// redirect to the sender
|
// redirect to the sender
|
||||||
serverConnection = player.getCurrentServer().get();
|
serverConnection = player.getCurrentServer().get();
|
||||||
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER, placeholders);
|
Component component = Utility.parseMiniMessage(Config.MESSAGESENDER
|
||||||
|
.replaceAll("<sendername>", player.getUsername())
|
||||||
|
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("privatemessageout");
|
buf.writeUTF("privatemessageout");
|
||||||
buf.writeUTF(player.getUniqueId().toString());
|
buf.writeUTF(player.getUniqueId().toString());
|
||||||
|
|
@ -67,7 +73,9 @@ public class ChatHandler {
|
||||||
|
|
||||||
//redirect to the receiver
|
//redirect to the receiver
|
||||||
serverConnection = player2.getCurrentServer().get();
|
serverConnection = player2.getCurrentServer().get();
|
||||||
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER, placeholders);
|
component = Utility.parseMiniMessage(Config.MESSAGERECIEVER
|
||||||
|
.replaceAll("<sendername>", player.getUsername())
|
||||||
|
.replaceAll("<receivername>", player2.getUsername()), Placeholders).asComponent();
|
||||||
buf = ByteStreams.newDataOutput();
|
buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("privatemessagein");
|
buf.writeUTF("privatemessagein");
|
||||||
buf.writeUTF(player2.getUniqueId().toString());
|
buf.writeUTF(player2.getUniqueId().toString());
|
||||||
|
|
@ -80,38 +88,43 @@ public class ChatHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendBlockedNotification(String prefix, Player player, String input, String target, ServerConnection serverConnection) {
|
public static void sendBlockedNotification(String prefix, Player player, String input, String target, ServerConnection serverConnection) {
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
TagResolver Placeholders = TagResolver.resolver(
|
||||||
placeholders.put("prefix", Replacement.miniMessage(prefix));
|
Placeholder.unparsed("prefix", prefix),
|
||||||
placeholders.put("displayname", Replacement.miniMessage(Utility.getDisplayName(player.getUniqueId(), player.getUsername())));
|
Placeholder.parsed("displayname", Utility.getDisplayName(player.getUniqueId(), player.getUsername())),
|
||||||
placeholders.put("target", Replacement.miniMessage((target.isEmpty() ? " tried to say: " : " -> " + target + ": ")));
|
Placeholder.unparsed("target", (target.isEmpty() ? " tried to say: " : " -> " + target + ": ")),
|
||||||
placeholders.put("input", Replacement.miniMessage(input));
|
Placeholder.unparsed("input", input)
|
||||||
Component blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, placeholders);
|
);
|
||||||
|
ComponentLike blockedNotification = Utility.parseMiniMessage(Config.NOTIFICATIONFORMAT, Placeholders);
|
||||||
|
|
||||||
serverConnection.getServer().getPlayersConnected().forEach(pl ->{
|
serverConnection.getServer().getPlayersConnected().forEach(pl -> {
|
||||||
if (pl.hasPermission("chat.alert-blocked")) {
|
if (pl.hasPermission("chat.alert-blocked")) {
|
||||||
pl.sendMessage(blockedNotification);
|
pl.sendMessage(blockedNotification);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
player.sendMessage(Utility.parseMiniMessage("<red>The language you used in your message is not allowed, " +
|
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>"));
|
"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()
|
VelocityChat.getPlugin().getProxy().getAllPlayers().stream()
|
||||||
.filter(pl -> {
|
.filter(pl -> {
|
||||||
UUID uuid = pl.getUniqueId();
|
UUID uuid = pl.getUniqueId();
|
||||||
if (ignoredPlayers != null && ignoredPlayers.contains(uuid))
|
if (ignoredPlayers != null && ignoredPlayers.contains(uuid)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
|
return party.getPartyUsers().stream().anyMatch(pu -> pu.getUuid().equals(uuid));
|
||||||
}).forEach(pl -> {
|
}).forEach(pl -> {
|
||||||
pl.sendMessage(message);
|
pl.sendMessage(message);
|
||||||
|
// TODO forward sound to backend server.
|
||||||
|
// https://canary.discord.com/channels/514920774923059209/1020498592219271189
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPartyMessage(UUID uuid, String message, Component item, ServerConnection serverConnection) {
|
public void sendPartyMessage(UUID uuid, String message, Component item, ServerConnection serverConnection) {
|
||||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(uuid);
|
||||||
if (optionalPlayer.isEmpty()) return;
|
if (optionalPlayer.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Player player = optionalPlayer.get();
|
Player player = optionalPlayer.get();
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
Party party = PartyManager.getParty(user.getPartyId());
|
Party party = PartyManager.getParty(user.getPartyId());
|
||||||
|
|
@ -119,86 +132,80 @@ public class ChatHandler {
|
||||||
player.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
player.sendMessage(Utility.parseMiniMessage(Config.NOT_IN_A_PARTY));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Component senderName = user.getDisplayName();
|
ComponentLike senderName = user.getDisplayName();
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(message);
|
TagResolver Placeholders = TagResolver.resolver(
|
||||||
if (!RegexManager.filterText(player.getUsername(), uuid, modifiableString, "partychat")) {
|
Placeholder.component("sender", senderName),
|
||||||
sendBlockedNotification("Party Language",
|
Placeholder.component("sendername", senderName),
|
||||||
player,
|
Placeholder.unparsed("partyname", party.getPartyName()),
|
||||||
modifiableString.string(),
|
Placeholder.component("message", parseMessageContent(player, message)),
|
||||||
"",
|
Placeholder.unparsed("server", serverConnection.getServer().getServerInfo().getName())
|
||||||
serverConnection);
|
);
|
||||||
|
|
||||||
|
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, Placeholders).asComponent()
|
||||||
|
.replaceText(TextReplacementConfig.builder().once().matchLiteral("[i]").replacement(item).build());
|
||||||
|
|
||||||
|
ModifiableString modifiableString = new ModifiableString(partyMessage);
|
||||||
|
if (!RegexManager.filterText(player.getUsername(), uuid, modifiableString, "party")) {
|
||||||
|
sendBlockedNotification("Party Language", player, message, "", serverConnection);
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
|
||||||
String updatedMessage = modifiableString.string();
|
partyMessage = modifiableString.component();
|
||||||
if(!player.hasPermission("chat.format")) {
|
|
||||||
updatedMessage = Utility.stripTokens(updatedMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(updatedMessage.contains("[i]")) updatedMessage = updatedMessage.replace("[i]", "<[i]>");
|
|
||||||
|
|
||||||
updatedMessage = Utility.formatText(updatedMessage);
|
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
|
||||||
placeholders.put("sender", Replacement.component(senderName));
|
|
||||||
placeholders.put("username", Replacement.miniMessage(player.getUsername()));
|
|
||||||
placeholders.put("party", Replacement.miniMessage(party.getPartyName()));
|
|
||||||
placeholders.put("message", Replacement.miniMessage(updatedMessage));
|
|
||||||
placeholders.put("server", Replacement.miniMessage(serverConnection.getServer().getServerInfo().getName()));
|
|
||||||
placeholders.put("[i]", Replacement.component(item));
|
|
||||||
|
|
||||||
Component partyMessage = Utility.parseMiniMessage(Config.PARTY_FORMAT, placeholders);
|
|
||||||
sendPartyMessage(party, partyMessage, user.getIgnoredBy());
|
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()) {
|
for (Player pl : serverConnection.getServer().getPlayersConnected()) {
|
||||||
if(pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
if (pl.hasPermission(Config.SPYPERMISSION) && !party.getPartyUsersUuid().contains(pl.getUniqueId())) {
|
||||||
pl.sendMessage(spyMessage);
|
pl.sendMessage(spyMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ALogger.info(PlainTextComponentSerializer.plainText().serialize(partyMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void globalAdminChat(String message) {
|
public void globalAdminChat(String message) {
|
||||||
Component component = GsonComponentSerializer.gson().deserialize(message);
|
Component component = GsonComponentSerializer.gson().deserialize(message);
|
||||||
|
|
||||||
VelocityChat.getPlugin().getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")/*TODO permission*/).forEach(target -> {
|
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||||
target.sendMessage(component);
|
.stream()
|
||||||
});
|
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||||
|
.forEach(target -> target.sendMessage(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void globalAdminChat(CommandSource commandSource, String message) {
|
public void globalAdminChat(CommandSource commandSource, String message) {
|
||||||
Component senderName = Component.text(Config.CONSOLENAME);
|
ComponentLike senderName = Component.text(Config.CONSOLENAME);
|
||||||
String serverName = "Altitude";
|
String serverName = "Altitude";
|
||||||
if (commandSource instanceof Player) {
|
if (commandSource instanceof Player sender) {
|
||||||
Player sender = (Player) commandSource;
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(sender.getUniqueId());
|
||||||
if(user == null) return;
|
if (user == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
senderName = user.getDisplayName();
|
senderName = user.getDisplayName();
|
||||||
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
serverName = sender.getCurrentServer().isPresent() ? sender.getCurrentServer().get().getServerInfo().getName() : "Altitude";
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
TagResolver Placeholders = TagResolver.resolver(
|
||||||
placeholders.put("message", Replacement.miniMessage(Utility.formatText(message)));
|
Placeholder.component("message", parseMessageContent(commandSource, message)),
|
||||||
placeholders.put("sender", Replacement.component(senderName));
|
Placeholder.component("sender", senderName),
|
||||||
placeholders.put("server", Replacement.miniMessage(serverName));
|
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 -> {
|
VelocityChat.getPlugin().getProxy().getAllPlayers()
|
||||||
target.sendMessage(component);
|
.stream()
|
||||||
});
|
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||||
|
.forEach(target -> target.sendMessage(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
public void sendMail(CommandSource commandSource, String recipient, String message) {
|
||||||
UUID uuid = Config.CONSOLEUUID;;
|
UUID uuid = Config.CONSOLEUUID;
|
||||||
String senderName = Config.CONSOLENAME;
|
String senderName = Config.CONSOLENAME;
|
||||||
UUID targetUUID;
|
UUID targetUUID;
|
||||||
if (commandSource instanceof Player player) {
|
if (commandSource instanceof Player player) {
|
||||||
uuid = player.getUniqueId();
|
uuid = player.getUniqueId();
|
||||||
senderName = player.getUsername();
|
senderName = player.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient);
|
Optional<Player> optionalPlayer = VelocityChat.getPlugin().getProxy().getPlayer(recipient);
|
||||||
if (optionalPlayer.isEmpty()) {
|
if (optionalPlayer.isEmpty()) {
|
||||||
targetUUID = ServerHandler.getPlayerUUID(recipient);
|
targetUUID = ServerHandler.getPlayerUUID(recipient);
|
||||||
|
|
@ -209,33 +216,41 @@ public class ChatHandler {
|
||||||
} else {
|
} else {
|
||||||
targetUUID = optionalPlayer.get().getUniqueId();
|
targetUUID = optionalPlayer.get().getUniqueId();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!commandSource.hasPermission("chat.format"))
|
|
||||||
message = Utility.stripTokens(message);
|
|
||||||
else
|
|
||||||
message = Utility.parseColors(message);
|
|
||||||
|
|
||||||
Mail mail = new Mail(targetUUID, uuid, message);
|
Mail mail = new Mail(targetUUID, uuid, message);
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(targetUUID);
|
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);
|
chatUser.addMail(mail);
|
||||||
// TODO load from config
|
// TODO load from config
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
String finalSenderName = senderName;
|
||||||
placeholders.put("sender", Replacement.miniMessage(senderName));
|
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage("<yellow>New mail from " + finalSenderName)));
|
||||||
optionalPlayer.ifPresent(player -> player.sendMessage(Utility.parseMiniMessage(Config.mailReceived, placeholders)));
|
commandSource.sendMessage(Utility.parseMiniMessage("<yellow>Sent mail to " + recipient + "!"));
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailSent,
|
|
||||||
Placeholder.component("player_name", chatUser.getDisplayName()),
|
|
||||||
Placeholder.miniMessage("message", message)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readMail(CommandSource commandSource, String targetPlayer) {
|
public void readMail(CommandSource commandSource, String targetPlayer, String senderPlayer) {
|
||||||
UUID uuid = ServerHandler.getPlayerUUID(targetPlayer);
|
UUID uuid = ServerHandler.getPlayerUUID(targetPlayer);
|
||||||
if (uuid == null) {
|
if (uuid == null) {
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
|
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||||
commandSource.sendMessage(parseMails(chatUser.getMails(), false));
|
if (senderPlayer == null) {
|
||||||
|
commandSource.sendMessage(parseMails(chatUser.getMails(), false));
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID sender = ServerHandler.getPlayerUUID(senderPlayer);
|
||||||
|
if (sender == null) {
|
||||||
|
commandSource.sendMessage(Utility.parseMiniMessage(Config.mailNoUser));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Mail> mails = chatUser.getMails().stream()
|
||||||
|
.filter(mail -> mail.getSender().equals(sender))
|
||||||
|
.toList();
|
||||||
|
commandSource.sendMessage(parseMails(mails, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readMail(CommandSource commandSource, boolean unread) {
|
public void readMail(CommandSource commandSource, boolean unread) {
|
||||||
|
|
@ -246,45 +261,67 @@ public class ChatHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component parseMails(List<Mail> mails, boolean mark) {
|
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) {
|
for (Mail mail : mails) {
|
||||||
if (mail.isUnRead() && mark) {
|
if (mail.isUnRead() && mark) {
|
||||||
mail.setReadTime(System.currentTimeMillis());
|
mail.setReadTime(System.currentTimeMillis());
|
||||||
Queries.markMailRead(mail);
|
Queries.markMailRead(mail);
|
||||||
}
|
}
|
||||||
|
Date date = new Date(mail.getSendTime());
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender());
|
ChatUser chatUser = ChatUserManager.getChatUser(mail.getSender());
|
||||||
Date sentTime = new Date(mail.getSendTime());
|
TagResolver Placeholders = TagResolver.resolver(
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
Placeholder.component("staffprefix", chatUser.getStaffPrefix()),
|
||||||
placeholders.put("staffprefix", Replacement.component(chatUser.getStaffPrefix()));
|
Placeholder.component("sender", chatUser.getDisplayName()),
|
||||||
placeholders.put("sender", Replacement.component(chatUser.getDisplayName()));
|
Placeholder.component("message", Utility.parseMiniMessage(mail.getMessage())),
|
||||||
placeholders.put("message", Replacement.miniMessage(mail.getMessage()));
|
Placeholder.unparsed("date", date.toString()),
|
||||||
placeholders.put("date", Replacement.miniMessage(sentTime.toString()));
|
Placeholder.unparsed("time_ago", getTimeAgo(Duration.between(date.toInstant(), new Date().toInstant())))
|
||||||
placeholders.put("time_ago", Replacement.miniMessage(String.valueOf(TimeUnit.MILLISECONDS.toDays(new Date().getTime() - sentTime.getTime()))));
|
);
|
||||||
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(mailMessage);
|
||||||
}
|
}
|
||||||
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));
|
component = component.append(Component.newline()).append(Utility.parseMiniMessage(Config.mailFooter));
|
||||||
return component;
|
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) {
|
public void mutePlayer(String uuid, boolean muted) {
|
||||||
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
ByteArrayDataOutput buf = ByteStreams.newDataOutput();
|
||||||
buf.writeUTF("chatpunishments");
|
buf.writeUTF("chatpunishments");
|
||||||
buf.writeUTF(uuid);
|
buf.writeUTF(uuid);
|
||||||
buf.writeBoolean(muted);
|
buf.writeBoolean(muted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTimeAgo(Duration duration) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
if (duration.toDays() != 0) {
|
||||||
|
stringBuilder.append(duration.toDays()).append("d ");
|
||||||
|
}
|
||||||
|
if (duration.toHoursPart() != 0 || !stringBuilder.isEmpty()) {
|
||||||
|
stringBuilder.append(duration.toHoursPart()).append("h ");
|
||||||
|
}
|
||||||
|
stringBuilder.append(duration.toMinutesPart()).append("m ago");
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Component parseMessageContent(CommandSource source, String rawMessage) {
|
||||||
|
TagResolver.Builder tagResolver = TagResolver.builder();
|
||||||
|
|
||||||
|
Utility.formattingPerms.forEach((perm, pair) -> {
|
||||||
|
if (source.hasPermission(perm)) {
|
||||||
|
tagResolver.resolver(pair.getX());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
MiniMessage miniMessage = MiniMessage.builder().tags(tagResolver.build()).build();
|
||||||
|
Component component = miniMessage.deserialize(rawMessage);
|
||||||
|
for (ChatFilter chatFilter : RegexManager.getEmoteFilters()) {
|
||||||
|
component = component.replaceText(
|
||||||
|
TextReplacementConfig.builder()
|
||||||
|
.times(Config.EMOTELIMIT)
|
||||||
|
.match(chatFilter.getRegex())
|
||||||
|
.replacement(chatFilter.getReplacement()).build());
|
||||||
|
}
|
||||||
|
|
||||||
|
return component;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,15 +8,12 @@ import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.event.PostOrder;
|
import com.velocitypowered.api.event.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.ComponentLike;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
// TODO code CLEANUP
|
|
||||||
public class ChatListener {
|
public class ChatListener {
|
||||||
|
|
||||||
private VelocityChat plugin;
|
private final VelocityChat plugin;
|
||||||
|
|
||||||
public ChatListener() {
|
public ChatListener() {
|
||||||
plugin = VelocityChat.getPlugin();
|
plugin = VelocityChat.getPlugin();
|
||||||
|
|
@ -30,18 +27,20 @@ public class ChatListener {
|
||||||
if (commandSource instanceof Player) {
|
if (commandSource instanceof Player) {
|
||||||
Player sender = (Player) event.getSender();
|
Player sender = (Player) event.getSender();
|
||||||
senderName = sender.getUsername();
|
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.miniMessage("sender", senderName),
|
Placeholder.parsed("sender", senderName),
|
||||||
Placeholder.miniMessage("message", event.getMessage()),
|
Placeholder.component("message", Utility.parseMiniMessage(event.getMessage())),
|
||||||
Placeholder.miniMessage("server", serverName)
|
Placeholder.parsed("server", serverName)
|
||||||
);
|
);
|
||||||
|
|
||||||
plugin.getProxy().getAllPlayers().stream().filter(target -> target.hasPermission("command.chat.globaladminchat")).forEach(target -> {
|
plugin.getProxy().getAllPlayers()
|
||||||
target.sendMessage(message);
|
.stream()
|
||||||
});
|
.filter(target -> target.hasPermission("command.chat.globaladminchat"))
|
||||||
|
.forEach(target -> target.sendMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,16 @@ package com.alttd.velocitychat.listeners;
|
||||||
|
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.velocitychat.VelocityChat;
|
|
||||||
import com.alttd.chat.database.Queries;
|
|
||||||
import com.alttd.chat.objects.channels.CustomChannel;
|
import com.alttd.chat.objects.channels.CustomChannel;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
|
import com.alttd.proxydiscordlink.lib.net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
import com.alttd.velocitychat.VelocityChat;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||||
|
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.proxy.ServerConnection;
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
|
|
@ -17,13 +19,14 @@ import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class PluginMessageListener {
|
public class PluginMessageListener {
|
||||||
|
|
||||||
//todo add an extra listener for nicknames?
|
|
||||||
private final ChannelIdentifier identifier;
|
private final ChannelIdentifier identifier;
|
||||||
|
|
||||||
public PluginMessageListener(ChannelIdentifier identifier){
|
public PluginMessageListener(ChannelIdentifier identifier){
|
||||||
|
|
@ -45,38 +48,33 @@ public class PluginMessageListener {
|
||||||
String channel = in.readUTF();
|
String channel = in.readUTF();
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case "globalchat":
|
case "globalchat" -> VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
||||||
VelocityChat.getPlugin().getServerHandler().sendGlobalChat(in.readUTF(), in.readUTF());
|
case "globaladminchat" -> VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
||||||
break;
|
case "privatemessage" ->
|
||||||
case "globaladminchat":
|
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
||||||
VelocityChat.getPlugin().getChatHandler().globalAdminChat(in.readUTF());
|
case "chatchannel" -> {
|
||||||
break;
|
|
||||||
case "privatemessage":
|
|
||||||
VelocityChat.getPlugin().getChatHandler().privateMessage(in.readUTF(), in.readUTF(), in.readUTF());
|
|
||||||
break;
|
|
||||||
case "chatchannel": {
|
|
||||||
String channelName = in.readUTF();
|
String channelName = in.readUTF();
|
||||||
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
CustomChannel chatChannel = (CustomChannel) CustomChannel.getChatChannel(channelName);
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
ALogger.warn("Received non existent channel" + channelName +".");
|
ALogger.warn("Received non existent channel" + channelName + ".");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
chatChannel.getServers().forEach(server -> proxy.getServer(server).ifPresent(registeredServer ->
|
chatChannel.getServers().forEach(server -> proxy.getServer(server).ifPresent(registeredServer ->
|
||||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData())));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "party": {
|
case "party" -> {
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(
|
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(
|
||||||
UUID.fromString(in.readUTF()),
|
UUID.fromString(in.readUTF()),
|
||||||
in.readUTF(),
|
in.readUTF(),
|
||||||
GsonComponentSerializer.gson().deserialize(in.readUTF()),
|
GsonComponentSerializer.gson().deserialize(in.readUTF()),
|
||||||
serverConnection);
|
serverConnection);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
case "NickNameAccepted": {
|
|
||||||
|
// nicknames WIP
|
||||||
|
case "NickNameAccepted", "NickNameSet" -> {
|
||||||
try {
|
try {
|
||||||
short len = in.readShort();
|
short len = in.readShort();
|
||||||
byte[] msgbytes = new byte[len];
|
byte[] msgbytes = new byte[len];
|
||||||
|
|
@ -91,15 +89,36 @@ public class PluginMessageListener {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
|
proxy.getAllServers().forEach(registeredServer ->
|
||||||
|
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||||
}
|
}
|
||||||
default:
|
case "NickNameRequest", "NickNameDenied" -> {
|
||||||
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
|
proxy.getAllServers().forEach(registeredServer ->
|
||||||
|
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData()));
|
||||||
|
}
|
||||||
|
case "punish" -> {
|
||||||
|
String playerName = in.readUTF();
|
||||||
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
|
ConsoleCommandSource consoleCommandSource = proxy.getConsoleCommandSource();
|
||||||
|
proxy.getCommandManager().executeAsync(consoleCommandSource, String.format("ban %s Automatic ban, please appeal if you feel review is needed.", playerName));
|
||||||
|
ALogger.info(String.format("Auto banned %s due to violating the `punish` filter.", playerName));
|
||||||
|
|
||||||
|
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||||
|
embedBuilder.setTitle("Automatic ban through the chat filter");
|
||||||
|
embedBuilder.setAuthor(playerName, null, "https://crafatar.com/avatars/" + in.readUTF() + "?overlay");
|
||||||
|
embedBuilder.setDescription(String.format("`%s`\n\n Auto permanent ban\n\n Auto banned for violating the `punish` chat filter. This could be a false positive! Their message was\n||%s||", playerName, in.readUTF()));
|
||||||
|
embedBuilder.setColor(Color.RED);
|
||||||
|
DiscordLink.getPlugin().getBot().sendEmbedToDiscord(514922317923614728L, embedBuilder, -1);
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
VelocityChat.getPlugin().getLogger().info("server " + event.getSource());
|
||||||
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
ProxyServer proxy = VelocityChat.getPlugin().getProxy();
|
||||||
|
|
||||||
for (RegisteredServer registeredServer : proxy.getAllServers()) {
|
for (RegisteredServer registeredServer : proxy.getAllServers()) {
|
||||||
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData());
|
registeredServer.sendPluginMessage(VelocityChat.getPlugin().getChannelIdentifier(), event.getData());
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,16 @@
|
||||||
package com.alttd.velocitychat.listeners;
|
package com.alttd.velocitychat.listeners;
|
||||||
|
|
||||||
|
import com.alttd.chat.config.Config;
|
||||||
import com.alttd.chat.managers.ChatUserManager;
|
import com.alttd.chat.managers.ChatUserManager;
|
||||||
|
import com.alttd.chat.managers.PartyManager;
|
||||||
import com.alttd.chat.objects.ChatUser;
|
import com.alttd.chat.objects.ChatUser;
|
||||||
import com.alttd.chat.objects.Mail;
|
import com.alttd.chat.objects.Mail;
|
||||||
|
import com.alttd.chat.objects.Party;
|
||||||
import com.alttd.chat.util.Utility;
|
import com.alttd.chat.util.Utility;
|
||||||
import com.alttd.velocitychat.VelocityChat;
|
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.data.ServerWrapper;
|
||||||
import com.alttd.velocitychat.handlers.ServerHandler;
|
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.PostOrder;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||||
|
|
@ -17,11 +18,19 @@ import com.velocitypowered.api.event.connection.LoginEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import com.velocitypowered.api.proxy.ServerConnection;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Placeholder;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.placeholder.Replacement;
|
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 {
|
public class ProxyPlayerListener {
|
||||||
|
|
||||||
|
|
@ -30,15 +39,18 @@ public class ProxyPlayerListener {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||||
if (party == null) return;
|
if (party == null) {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
|
||||||
if (chatUser == null)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||||
|
if (chatUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_ON,
|
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_ON,
|
||||||
Placeholder.component("player", chatUser.getDisplayName())
|
Placeholder.component("player", chatUser.getDisplayName())
|
||||||
),
|
).asComponent(),
|
||||||
chatUser.getIgnoredPlayers());
|
chatUser.getIgnoredPlayers());
|
||||||
// TODO setup ChatUser on Proxy
|
// TODO setup ChatUser on Proxy
|
||||||
//VelocityChat.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
//VelocityChat.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||||
|
|
||||||
|
|
@ -47,61 +59,113 @@ public class ProxyPlayerListener {
|
||||||
|
|
||||||
@Subscribe(order = PostOrder.LAST)
|
@Subscribe(order = PostOrder.LAST)
|
||||||
public void afterPlayerLogin(ServerPostConnectEvent event) {
|
public void afterPlayerLogin(ServerPostConnectEvent event) {
|
||||||
if (event.getPreviousServer() != null)
|
|
||||||
return;
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
RegisteredServer previousServer = event.getPreviousServer();
|
||||||
|
if (previousServer != null) {
|
||||||
|
ActiveVoteToMute.removePotentialVoter(player, previousServer);
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Optional<ServerConnection> currentServer = player.getCurrentServer();
|
||||||
|
if (currentServer.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ActiveVoteToMute.addPotentialVoter(player, currentServer.get());
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser chatUser = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
List<Mail> unReadMail = chatUser.getUnReadMail();
|
List<Mail> unReadMail = chatUser.getUnReadMail();
|
||||||
if (unReadMail.isEmpty())
|
if (unReadMail.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
player.sendMessage(Utility.parseMiniMessage(Config.mailUnread,
|
}
|
||||||
Placeholder.miniMessage("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
|
@Subscribe
|
||||||
public void quitEvent(DisconnectEvent event) {
|
public void quitEvent(DisconnectEvent event) {
|
||||||
|
ActiveVoteToMute.removePotentialVoter(event.getPlayer(), null);
|
||||||
UUID uuid = event.getPlayer().getUniqueId();
|
UUID uuid = event.getPlayer().getUniqueId();
|
||||||
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
Party party = PartyManager.getParty(event.getPlayer().getUniqueId());
|
||||||
if (party == null) return;
|
if (party == null) {
|
||||||
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
|
||||||
if (chatUser == null)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
ChatUser chatUser = ChatUserManager.getChatUser(uuid);
|
||||||
|
if (chatUser == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
VelocityChat.getPlugin().getChatHandler().sendPartyMessage(party,
|
||||||
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_OFF,
|
Utility.parseMiniMessage(Config.PARTY_MEMBER_LOGGED_OFF,
|
||||||
Placeholder.component("player", chatUser.getDisplayName())
|
Placeholder.component("player", chatUser.getDisplayName())
|
||||||
),
|
).asComponent(),
|
||||||
chatUser.getIgnoredPlayers());
|
chatUser.getIgnoredPlayers());
|
||||||
// TODO setup ChatUser on Proxy
|
// TODO setup ChatUser on Proxy
|
||||||
//VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
//VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HashSet<UUID> silentJoin = new HashSet<>();
|
||||||
|
|
||||||
|
public static void addSilentJoin(UUID uuid) {
|
||||||
|
silentJoin.add(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
// Server Join and Leave messages
|
// Server Join and Leave messages
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void serverConnected(ServerConnectedEvent event) {
|
public void serverConnected(ServerConnectedEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
|
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
|
||||||
if (event.getPreviousServer().isPresent()) {
|
if (event.getPreviousServer().isPresent()) {
|
||||||
RegisteredServer previousServer = event.getPreviousServer().get();
|
RegisteredServer previousServer = event.getPreviousServer().get();
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
TagResolver placeholders = TagResolver.resolver(
|
||||||
|
Placeholder.parsed("player", player.getUsername()),
|
||||||
|
Placeholder.parsed("from_server", previousServer.getServerInfo().getName()),
|
||||||
|
Placeholder.parsed("to_server", event.getServer().getServerInfo().getName())
|
||||||
|
);
|
||||||
|
|
||||||
Map<String, Replacement<?>> placeholders = new HashMap<>();
|
if (silentJoin.remove(uuid)) {
|
||||||
placeholders.put("player", Replacement.miniMessage(player.getUsername()));
|
ComponentLike message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||||
placeholders.put("from_server", Replacement.miniMessage(previousServer.getServerInfo().getName()));
|
placeholders);
|
||||||
placeholders.put("to_server", Replacement.miniMessage(event.getServer().getServerInfo().getName()));
|
event.getServer().getPlayersConnected().stream()
|
||||||
|
.filter(player1 -> player1.hasPermission("command.chat.silent-join-notify"))
|
||||||
|
.forEach(player1 -> player1.sendMessage(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
|
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
|
||||||
if(wrapper != null) {
|
if (wrapper != null) {
|
||||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, placeholders));
|
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, placeholders));
|
||||||
}
|
}
|
||||||
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||||
if(wrapper != null) {
|
if (wrapper != null) {
|
||||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, placeholders));
|
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, placeholders));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (silentJoin.remove(uuid)) {
|
||||||
|
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"))
|
||||||
|
.forEach(player1 -> player1.sendMessage(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||||
if(wrapper != null) {
|
if (wrapper != null) {
|
||||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, Placeholder.miniMessage("player", event.getPlayer().getUsername())));
|
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, Placeholder.unparsed("player", player.getUsername())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -113,11 +177,11 @@ public class ProxyPlayerListener {
|
||||||
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
|
RegisteredServer registeredServer = event.getPlayer().getCurrentServer().get().getServer();
|
||||||
|
|
||||||
ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().getName());
|
ServerWrapper wrapper = serverHandler.getWrapper(registeredServer.getServerInfo().getName());
|
||||||
if(wrapper != null) {
|
if (wrapper != null) {
|
||||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERLEAVEMESSAGE,
|
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERLEAVEMESSAGE,
|
||||||
Placeholder.miniMessage("player", event.getPlayer().getUsername()),
|
Placeholder.unparsed("player", event.getPlayer().getUsername()),
|
||||||
Placeholder.miniMessage("from_server", registeredServer.getServerInfo().getName())
|
Placeholder.unparsed("from_server", registeredServer.getServerInfo().getName())
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user