Compare commits
28 Commits
3b2aa84164
...
3275db13d0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3275db13d0 | ||
|
|
c5eebb7e88 | ||
|
|
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 |
20
Jenkinsfile
vendored
Normal file
20
Jenkinsfile
vendored
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
stages {
|
||||||
|
stage('Gradle') {
|
||||||
|
steps {
|
||||||
|
sh './gradlew build'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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,7 +3,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT") {
|
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") {
|
||||||
// exclude("net.kyori")
|
// exclude("net.kyori")
|
||||||
}
|
}
|
||||||
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
compileOnly("org.spongepowered:configurate-yaml:4.1.2") // Configurate
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ public final class Config {
|
||||||
|
|
||||||
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)
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,10 @@ public class ChatLogHandler {
|
||||||
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
|
private final HashMap<UUID, List<ChatLog>> chatLogs = new HashMap<>();
|
||||||
|
|
||||||
public ChatLogHandler(boolean enableLogging) {
|
public ChatLogHandler(boolean enableLogging) {
|
||||||
if (!enableLogging)
|
if (!enableLogging) {
|
||||||
|
ALogger.info("Logging is not enabled on this server.");
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
Duration deleteThreshold = Duration.ofDays(Config.CHAT_LOG_DELETE_OLDER_THAN_DAYS);
|
||||||
ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> {
|
ChatLogQueries.deleteOldMessages(deleteThreshold).thenAccept(success -> {
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
@ -39,8 +41,12 @@ public class ChatLogHandler {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
executorService = Executors.newSingleThreadScheduledExecutor();
|
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
executorService.scheduleAtFixedRate(() -> saveToDatabase(false),
|
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);
|
Config.CHAT_LOG_SAVE_DELAY_MINUTES, Config.CHAT_LOG_SAVE_DELAY_MINUTES, TimeUnit.MINUTES);
|
||||||
|
ALogger.info("Logging has started!");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,19 +76,27 @@ public class ChatLogHandler {
|
||||||
|
|
||||||
private void saveToDatabase(boolean onMainThread) {
|
private void saveToDatabase(boolean onMainThread) {
|
||||||
savingToDatabase(true);
|
savingToDatabase(true);
|
||||||
|
ALogger.info(String.format("Saving %d messages to database", chatLogs.size()));
|
||||||
CompletableFuture<Boolean> booleanCompletableFuture = ChatLogQueries.storeMessages(chatLogs);
|
CompletableFuture<Boolean> booleanCompletableFuture = ChatLogQueries.storeMessages(chatLogs);
|
||||||
if (onMainThread) {
|
if (onMainThread) {
|
||||||
booleanCompletableFuture.join();
|
booleanCompletableFuture.join();
|
||||||
|
ALogger.info("Finished saving messages on main thread");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
booleanCompletableFuture.whenComplete((result, throwable) -> {
|
booleanCompletableFuture.whenComplete((result, throwable) -> {
|
||||||
if (throwable == null && result) {
|
if (throwable == null && result) {
|
||||||
chatLogs.clear();
|
chatLogs.clear();
|
||||||
|
} else {
|
||||||
|
ALogger.error("Failed to save chat messages.");
|
||||||
}
|
}
|
||||||
savingToDatabase(false);
|
savingToDatabase(false);
|
||||||
|
if (!chatLogQueue.isEmpty()) {
|
||||||
|
ALogger.info("Adding back messages from queue to chatLogs map");
|
||||||
|
}
|
||||||
while (!chatLogQueue.isEmpty()) {
|
while (!chatLogQueue.isEmpty()) {
|
||||||
addLog(chatLogQueue.remove());
|
addLog(chatLogQueue.remove());
|
||||||
}
|
}
|
||||||
|
ALogger.info("Finished saving messages");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,25 +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"
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "com.alttd.chat"
|
group = "com.alttd.chat"
|
||||||
version = "2.0.0-SNAPSHOT"
|
version = "2.0.0-SNAPSHOT"
|
||||||
description = "All in one minecraft chat plugin"
|
description = "All in one minecraft chat plugin"
|
||||||
|
|
||||||
// repositories {
|
|
||||||
// mavenCentral()
|
|
||||||
// maven("https://repo.destro.xyz/snapshots") // Altitude - Galaxy
|
|
||||||
// maven("https://oss.sonatype.org/content/groups/public/") // Adventure
|
|
||||||
// maven("https://oss.sonatype.org/content/repositories/snapshots/") // Minimessage
|
|
||||||
// maven("https://oss.sonatype.org/content/repositories/") // Minimessage
|
|
||||||
// maven("https://nexus.velocitypowered.com/repository/") // Velocity
|
|
||||||
// maven("https://nexus.velocitypowered.com/repository/maven-public/") // Velocity
|
|
||||||
// maven("https://repo.spongepowered.org/maven") // Configurate
|
|
||||||
// maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") // Papi
|
|
||||||
// maven("https://jitpack.io")
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
|
@ -27,7 +14,7 @@ subprojects {
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
languageVersion.set(JavaLanguageVersion.of(17))
|
languageVersion.set(JavaLanguageVersion.of(21))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,24 @@
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.net.URL
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("com.github.johnrengelman.shadow")
|
id("io.github.goooler.shadow")
|
||||||
id("xyz.jpenilla.run-paper") version "1.0.6"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":api")) // API
|
implementation(project(":api")) // API
|
||||||
compileOnly("com.alttd:Galaxy-API:1.20.4-R0.1-SNAPSHOT") // Galaxy
|
compileOnly("com.alttd:Galaxy-API:1.21-R0.1-SNAPSHOT") // Galaxy
|
||||||
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
compileOnly("com.gitlab.ruany:LiteBansAPI:0.3.5") // move to proxy
|
||||||
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
|
compileOnly("org.apache.commons:commons-lang3:3.12.0") // needs an alternative, already removed from upstream api and will be removed in server
|
||||||
compileOnly("net.luckperms:api:5.3") // Luckperms
|
compileOnly("net.luckperms:api:5.3") // Luckperms
|
||||||
compileOnly(files("../libs/CMI.jar"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveFileName.set("${rootProject.name}-${project.name}-${project.version}.jar")
|
archiveFileName.set("${rootProject.name}-${project.name}-${project.version}.jar")
|
||||||
// minimize()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
build {
|
build {
|
||||||
// setBuildDir("${rootProject.buildDir}")
|
|
||||||
dependsOn(shadowJar)
|
dependsOn(shadowJar)
|
||||||
}
|
}
|
||||||
|
|
||||||
runServer {
|
|
||||||
val dir = File(System.getProperty("user.home") + "/share/devserver/");
|
|
||||||
if (!dir.parentFile.exists()) {
|
|
||||||
dir.parentFile.mkdirs()
|
|
||||||
}
|
|
||||||
runDirectory.set(dir)
|
|
||||||
|
|
||||||
val fileName = "/galaxy.jar"
|
|
||||||
var file = File(dir.path + fileName)
|
|
||||||
|
|
||||||
if (!file.parentFile.exists()) {
|
|
||||||
file.parentFile.mkdirs()
|
|
||||||
}
|
|
||||||
if (!file.exists()) {
|
|
||||||
download("https://repo.destro.xyz/snapshots/com/alttd/Galaxy-Server/Galaxy-paperclip-1.19.2-R0.1-SNAPSHOT-reobf.jar", file)
|
|
||||||
}
|
|
||||||
serverJar(file)
|
|
||||||
minecraftVersion("1.19.2")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun download(link: String, path: File) {
|
|
||||||
URL(link).openStream().use { input ->
|
|
||||||
FileOutputStream(path).use { output ->
|
|
||||||
input.copyTo(output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +40,7 @@ public class ChatPlugin extends JavaPlugin {
|
||||||
DatabaseConnection.initialize();
|
DatabaseConnection.initialize();
|
||||||
serverConfig = new ServerConfig(Bukkit.getServerName());
|
serverConfig = new ServerConfig(Bukkit.getServerName());
|
||||||
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
ChatLogHandler chatLogHandler = ChatLogHandler.getInstance(true);
|
||||||
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler));
|
registerListener(new PlayerListener(serverConfig), new ChatListener(chatLogHandler), new BookListener(), new ShutdownListener(chatLogHandler, this));
|
||||||
if(serverConfig.GLOBALCHAT) {
|
if(serverConfig.GLOBALCHAT) {
|
||||||
registerCommand("globalchat", new GlobalChat());
|
registerCommand("globalchat", new GlobalChat());
|
||||||
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
registerCommand("toggleglobalchat", new ToggleGlobalChat());
|
||||||
|
|
|
||||||
|
|
@ -82,11 +82,6 @@ public class ChatListener implements Listener {
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
Set<Player> receivers = event.viewers().stream().filter(audience -> audience instanceof Player)
|
|
||||||
.map(audience -> (Player) audience)
|
|
||||||
.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
|
|
||||||
Component input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
Component input = event.message().colorIfAbsent(NamedTextColor.WHITE);
|
||||||
|
|
||||||
ModifiableString modifiableString = new ModifiableString(input);
|
ModifiableString modifiableString = new ModifiableString(input);
|
||||||
|
|
@ -112,6 +107,11 @@ public class ChatListener implements Listener {
|
||||||
return; // the message was blocked
|
return; // the message was blocked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Set<Player> receivers = event.viewers().stream().filter(audience -> audience instanceof Player)
|
||||||
|
.map(audience -> (Player) audience)
|
||||||
|
.filter(receiver -> !ChatUserManager.getChatUser(receiver.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
Set<Player> playersToPing = new HashSet<>();
|
Set<Player> playersToPing = new HashSet<>();
|
||||||
pingPlayers(playersToPing, modifiableString, player);
|
pingPlayers(playersToPing, modifiableString, player);
|
||||||
|
|
||||||
|
|
@ -136,11 +136,12 @@ public class ChatListener implements Listener {
|
||||||
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
Pattern nickPattern = Pattern.compile("\\b(?<!\\\\)" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
// Pattern escapedNickPattern = Pattern.compile("\\b\\\\" + nickName + "\\b", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
ChatUser onlinePlayerUser = ChatUserManager.getChatUser(onlinePlayer.getUniqueId());
|
||||||
if (namePattern.matcher(modifiableString.string()).find()) {
|
if (namePattern.matcher(modifiableString.string()).find()) {
|
||||||
modifiableString.replace(TextReplacementConfig.builder()
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
.once()
|
.once()
|
||||||
.match(namePattern)
|
.match(namePattern)
|
||||||
.replacement(mention.append(onlinePlayer.displayName()))
|
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||||
.build());
|
.build());
|
||||||
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
//TODO replace all instances of \name with just name but using the match result so the capitalization doesn't change
|
||||||
// modifiableString.replace(TextReplacementConfig.builder()
|
// modifiableString.replace(TextReplacementConfig.builder()
|
||||||
|
|
@ -156,7 +157,7 @@ public class ChatListener implements Listener {
|
||||||
modifiableString.replace(TextReplacementConfig.builder()
|
modifiableString.replace(TextReplacementConfig.builder()
|
||||||
.once()
|
.once()
|
||||||
.match(nickPattern)
|
.match(nickPattern)
|
||||||
.replacement(mention.append(onlinePlayer.displayName()))
|
.replacement(mention.append(onlinePlayerUser.getDisplayName()))
|
||||||
.build());
|
.build());
|
||||||
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
|
if (!ChatUserManager.getChatUser(onlinePlayer.getUniqueId()).getIgnoredPlayers().contains(player.getUniqueId()))
|
||||||
playersToPing.add(onlinePlayer);
|
playersToPing.add(onlinePlayer);
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,13 @@ 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.TextReplacementConfig;
|
||||||
import net.kyori.adventure.text.format.Style;
|
import net.kyori.adventure.text.format.Style;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import net.kyori.adventure.text.format.TextDecoration;
|
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.tag.resolver.Placeholder;
|
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.EventPriority;
|
||||||
|
|
@ -48,8 +50,8 @@ public class PlayerListener implements Listener {
|
||||||
UUID uuid = player.getUniqueId();
|
UUID uuid = player.getUniqueId();
|
||||||
Toggleable.disableToggles(uuid);
|
Toggleable.disableToggles(uuid);
|
||||||
|
|
||||||
if (serverConfig.FIRST_JOIN_MESSAGES && System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(10)) {
|
if (serverConfig.FIRST_JOIN_MESSAGES && (!player.hasPlayedBefore() || System.currentTimeMillis() - player.getFirstPlayed() < TimeUnit.SECONDS.toMillis(10))) {
|
||||||
player.getServer().sendMessage(MiniMessage.miniMessage().deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize(Config.FIRST_JOIN, Placeholder.parsed("player", player.getName())));
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatUser user = ChatUserManager.getChatUser(uuid);
|
ChatUser user = ChatUserManager.getChatUser(uuid);
|
||||||
|
|
@ -103,22 +105,36 @@ public class PlayerListener implements Listener {
|
||||||
Stack<Instant> playerDeathsStack = sendPlayerDeaths.computeIfAbsent(uuid, key -> new Stack<>());
|
Stack<Instant> playerDeathsStack = sendPlayerDeaths.computeIfAbsent(uuid, key -> new Stack<>());
|
||||||
Instant cutOff = Instant.now().minus(Config.DEATH_MESSAGES_LIMIT_PERIOD_MINUTES, ChronoUnit.MINUTES);
|
Instant cutOff = Instant.now().minus(Config.DEATH_MESSAGES_LIMIT_PERIOD_MINUTES, ChronoUnit.MINUTES);
|
||||||
|
|
||||||
while (playerDeathsStack.peek().isBefore(cutOff)) {
|
while (!playerDeathsStack.isEmpty() && playerDeathsStack.peek().isBefore(cutOff)) {
|
||||||
playerDeathsStack.pop();
|
playerDeathsStack.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playerDeathsStack.size() > Config.DEATH_MESSAGES_MAX_PER_PERIOD || serverConfig.MUTED) {
|
if (playerDeathsStack.size() > Config.DEATH_MESSAGES_MAX_PER_PERIOD || serverConfig.MUTED) {
|
||||||
event.deathMessage(Component.empty());
|
event.deathMessage(Component.empty());
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
Component component = event.deathMessage();
|
Component component = event.deathMessage();
|
||||||
if (component != null) {
|
|
||||||
component = Component.text("* ").append(component);
|
|
||||||
component = component.style(Style.style(TextColor.color(82, 80, 77), TextDecoration.ITALIC));
|
|
||||||
event.deathMessage(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerDeathsStack.push(Instant.now());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,23 @@ import com.alttd.chat.objects.chat_log.ChatLogHandler;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
public class ShutdownListener implements Listener {
|
public class ShutdownListener implements Listener {
|
||||||
|
|
||||||
private final ChatLogHandler chatLogHandler;
|
private final ChatLogHandler chatLogHandler;
|
||||||
|
private final Plugin thisPlugin;
|
||||||
|
|
||||||
public ShutdownListener(ChatLogHandler chatLogHandler) {
|
public ShutdownListener(ChatLogHandler chatLogHandler, Plugin thisPlugin) {
|
||||||
this.chatLogHandler = chatLogHandler;
|
this.chatLogHandler = chatLogHandler;
|
||||||
|
this.thisPlugin = thisPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onShutdown(PluginDisableEvent event) {
|
public void onShutdown(PluginDisableEvent event) {
|
||||||
|
if (!event.getPlugin().getName().equals(thisPlugin.getName())){
|
||||||
|
return;
|
||||||
|
}
|
||||||
chatLogHandler.shutDown();
|
chatLogHandler.shutDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package com.alttd.chat.nicknames;
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
import com.Zrips.CMI.CMI;
|
|
||||||
import com.Zrips.CMI.Containers.CMIUser;
|
|
||||||
import com.alttd.chat.ChatAPI;
|
import com.alttd.chat.ChatAPI;
|
||||||
import com.alttd.chat.ChatPlugin;
|
import com.alttd.chat.ChatPlugin;
|
||||||
import com.alttd.chat.config.Config;
|
import com.alttd.chat.config.Config;
|
||||||
|
|
@ -13,7 +11,6 @@ import com.alttd.chat.objects.Nick;
|
||||||
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.minimessage.MiniMessage;
|
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
|
|
@ -384,7 +381,7 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
user.setDisplayName(player.getName());
|
user.setDisplayName(player.getName());
|
||||||
player.displayName(user.getDisplayName());
|
player.displayName(user.getDisplayName());
|
||||||
updateCMIUser(player, null);
|
// updateCMIUser(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNick(final Player player) {
|
public String getNick(final Player player) {
|
||||||
|
|
@ -399,25 +396,25 @@ public class Nicknames implements CommandExecutor, TabCompleter {
|
||||||
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
ChatUser user = ChatUserManager.getChatUser(player.getUniqueId());
|
||||||
user.setDisplayName(nickName);
|
user.setDisplayName(nickName);
|
||||||
player.displayName(user.getDisplayName());
|
player.displayName(user.getDisplayName());
|
||||||
updateCMIUser(player, nickName);
|
// updateCMIUser(player, nickName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static String format(final String m) {
|
// public static String format(final String m) {
|
||||||
// return NickUtilities.applyColor(m);
|
// return NickUtilities.applyColor(m);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void updateCMIUser(Player player, String nickName) {
|
// public void updateCMIUser(Player player, String nickName) {
|
||||||
if (!isCMIEnabled())
|
// if (!isCMIEnabled())
|
||||||
return;
|
// return;
|
||||||
|
//
|
||||||
CMIUser cmiUser = CMI.getInstance().getPlayerManager().getUser(player);
|
// CMIUser cmiUser = CMI.getInstance().getPlayerManager().getUser(player);
|
||||||
if (nickName == null){
|
// if (nickName == null){
|
||||||
cmiUser.setNickName(null, true);
|
// cmiUser.setNickName(null, true);
|
||||||
} else {
|
// } else {
|
||||||
cmiUser.setNickName(NickUtilities.applyColor(nickName), true);
|
// cmiUser.setNickName(NickUtilities.applyColor(nickName), true);
|
||||||
}
|
// }
|
||||||
cmiUser.updateDisplayName();
|
// cmiUser.updateDisplayName();
|
||||||
}
|
// }
|
||||||
|
|
||||||
private Boolean isCMIEnabled = null;
|
private Boolean isCMIEnabled = null;
|
||||||
private Boolean isCMIEnabled() {
|
private Boolean isCMIEnabled() {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
package com.alttd.chat.nicknames;
|
package com.alttd.chat.nicknames;
|
||||||
|
|
||||||
import com.Zrips.CMI.commands.list.colorlimits;
|
|
||||||
import com.Zrips.CMI.utils.Util;
|
|
||||||
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.managers.ChatUserManager;
|
|
||||||
import com.alttd.chat.objects.ChatUser;
|
|
||||||
import com.alttd.chat.objects.Nick;
|
import com.alttd.chat.objects.Nick;
|
||||||
import com.alttd.chat.util.ALogger;
|
import com.alttd.chat.util.ALogger;
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ public class ToggleableForCustomChannel extends Toggleable {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
ALogger.info(String.format("%s sent %s message: %s", player.getName(), customChannel.getChannelName(), message));
|
||||||
ChatPlugin.getInstance().getChatHandler().chatChannel(player, customChannel, message);
|
ChatPlugin.getInstance().getChatHandler().chatChannel(player, customChannel, message);
|
||||||
}
|
}
|
||||||
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
}.runTaskAsynchronously(ChatPlugin.getInstance());
|
||||||
|
|
|
||||||
BIN
libs/CMI.jar
BIN
libs/CMI.jar
Binary file not shown.
|
|
@ -1,6 +1,6 @@
|
||||||
plugins {
|
plugins {
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
id("com.github.johnrengelman.shadow")
|
id("io.github.goooler.shadow")
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
|
||||||
|
|
@ -110,10 +110,10 @@ public class VoteToMute {
|
||||||
}
|
}
|
||||||
boolean countLowerRanks = false;
|
boolean countLowerRanks = false;
|
||||||
long count = getTotalEligiblePlayers(server, false);
|
long count = getTotalEligiblePlayers(server, false);
|
||||||
if (count < 10) {
|
if (count < 6) {
|
||||||
countLowerRanks = true;
|
countLowerRanks = true;
|
||||||
count = getTotalEligiblePlayers(server, true);
|
count = getTotalEligiblePlayers(server, true);
|
||||||
if (count < 10) {
|
if (count < 6) {
|
||||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Not enough eligible players online to vote.</red>"));
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Not enough eligible players online to vote.</red>"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ 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;
|
||||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||||
|
import jdk.jshell.execution.Util;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
|
||||||
|
|
@ -29,6 +30,8 @@ import java.util.stream.IntStream;
|
||||||
|
|
||||||
public class VoteToMuteHelper {
|
public class VoteToMuteHelper {
|
||||||
|
|
||||||
|
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||||
|
|
||||||
public VoteToMuteHelper(ProxyServer proxyServer) {
|
public VoteToMuteHelper(ProxyServer proxyServer) {
|
||||||
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
|
||||||
.<CommandSource, String>argument("player", StringArgumentType.string())
|
.<CommandSource, String>argument("player", StringArgumentType.string())
|
||||||
|
|
@ -116,7 +119,7 @@ public class VoteToMuteHelper {
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
LiteralArgumentBuilder<CommandSource> enterPageNode = LiteralArgumentBuilder
|
LiteralArgumentBuilder<CommandSource> enterMessagesNode = LiteralArgumentBuilder
|
||||||
.<CommandSource>literal("messages")
|
.<CommandSource>literal("messages")
|
||||||
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
.requires(commandSource -> commandSource.hasPermission("chat.vote-to-mute"))
|
||||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("list of messages", StringArgumentType.greedyString())
|
.then(RequiredArgumentBuilder.<CommandSource, String>argument("list of messages", StringArgumentType.greedyString())
|
||||||
|
|
@ -147,7 +150,7 @@ public class VoteToMuteHelper {
|
||||||
}
|
}
|
||||||
int highestLogEntry = max.get();
|
int highestLogEntry = max.get();
|
||||||
|
|
||||||
if (voteToMuteStarter.getTotalLogEntries() > highestLogEntry) {
|
if (voteToMuteStarter.getTotalLogEntries() < highestLogEntry) {
|
||||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage("<red>Some of your selected messages do not exist.</red>"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -162,7 +165,7 @@ public class VoteToMuteHelper {
|
||||||
RegisteredServer server = currentServer.get().getServer();
|
RegisteredServer server = currentServer.get().getServer();
|
||||||
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
long count = getTotalEligiblePlayers(server, voteToMuteStarter.countLowerRanks());
|
||||||
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
new ActiveVoteToMute(voteToMuteStarter.getVotedPlayer(), server, proxyServer, Duration.ofMinutes(5),
|
||||||
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs)
|
(int) count, voteToMuteStarter.countLowerRanks(), chatLogs, player)
|
||||||
.start();
|
.start();
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
|
|
@ -176,11 +179,11 @@ public class VoteToMuteHelper {
|
||||||
.then(playerNode
|
.then(playerNode
|
||||||
.then(yesNoNode
|
.then(yesNoNode
|
||||||
.executes(commandContext -> {
|
.executes(commandContext -> {
|
||||||
if (!(commandContext.getSource() instanceof Player)) {
|
if (!(commandContext.getSource() instanceof Player player)) {
|
||||||
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
"<red>Only players are allowed to vote</red>"));
|
"<red>Only players are allowed to vote</red>"));
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
Player source = (Player) commandContext.getSource();
|
|
||||||
String playerName = commandContext.getArgument("player", String.class);
|
String playerName = commandContext.getArgument("player", String.class);
|
||||||
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
Optional<ActiveVoteToMute> optionalActiveVoteToMute = ActiveVoteToMute.getInstance(playerName);
|
||||||
if (optionalActiveVoteToMute.isEmpty()) {
|
if (optionalActiveVoteToMute.isEmpty()) {
|
||||||
|
|
@ -191,16 +194,25 @@ public class VoteToMuteHelper {
|
||||||
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
ActiveVoteToMute activeVoteToMute = optionalActiveVoteToMute.get();
|
||||||
|
|
||||||
if (!activeVoteToMute.countLowerRanks()) {
|
if (!activeVoteToMute.countLowerRanks()) {
|
||||||
if (!source.hasPermission("chat.vote-to-mute")) {
|
if (!player.hasPermission("chat.vote-to-mute")) {
|
||||||
source.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
player.sendMessage(Utility.parseMiniMessage("<red>You are not eligible to vote.</red>"));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String vote = commandContext.getArgument("yesno", String.class);
|
String vote = commandContext.getArgument("yesNo", String.class);
|
||||||
switch (vote.toLowerCase()) {
|
switch (vote.toLowerCase()) {
|
||||||
case "yes" -> activeVoteToMute.vote(source.getUniqueId(), true);
|
case "yes" -> {
|
||||||
case "no" -> activeVoteToMute.vote(source.getUniqueId(), false);
|
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(
|
default -> commandContext.getSource().sendMessage(Utility.parseMiniMessage(
|
||||||
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
"<red><vote> is not a valid vote option</red>", Placeholder.parsed("vote", vote)));
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +231,7 @@ public class VoteToMuteHelper {
|
||||||
.requires(commandSource -> commandSource instanceof Player)
|
.requires(commandSource -> commandSource instanceof Player)
|
||||||
.then(voteNode)
|
.then(voteNode)
|
||||||
.then(pageNode)
|
.then(pageNode)
|
||||||
.then(enterPageNode)
|
.then(enterMessagesNode)
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
sendHelpMessage(context.getSource());
|
sendHelpMessage(context.getSource());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -241,6 +253,18 @@ public class VoteToMuteHelper {
|
||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void notifyEligiblePlayers(RegisteredServer server, ActiveVoteToMute activeVoteToMute) {
|
||||||
|
Component message = Utility.parseMiniMessage("<prefix><green><voted_for> out of <total_votes> players have voted to mute <player></green>",
|
||||||
|
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) {
|
private void sendHelpMessage(CommandSource commandSource) {
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/votetomutehelper <player></gold>.</red>"));
|
commandSource.sendMessage(Utility.parseMiniMessage("<red>Use: <gold>/votetomutehelper <player></gold>.</red>"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import org.jetbrains.annotations.NotNull;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
@ -29,6 +28,7 @@ public class ActiveVoteToMute {
|
||||||
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
private static final Component prefix = Utility.parseMiniMessage("<gold>[VoteMute]</gold>");
|
||||||
|
|
||||||
private final Player votedPlayer;
|
private final Player votedPlayer;
|
||||||
|
private final Player startedByPlayer;
|
||||||
private HashSet<UUID> votedFor = new HashSet<>();
|
private HashSet<UUID> votedFor = new HashSet<>();
|
||||||
private HashSet<UUID> votedAgainst = new HashSet<>();
|
private HashSet<UUID> votedAgainst = new HashSet<>();
|
||||||
private int totalEligibleVoters;
|
private int totalEligibleVoters;
|
||||||
|
|
@ -36,6 +36,7 @@ public class ActiveVoteToMute {
|
||||||
private final RegisteredServer server;
|
private final RegisteredServer server;
|
||||||
private final ProxyServer proxyServer;
|
private final ProxyServer proxyServer;
|
||||||
private final Component chatLogs;
|
private final Component chatLogs;
|
||||||
|
private boolean endedVote = false;
|
||||||
|
|
||||||
public static Optional<ActiveVoteToMute> getInstance(String username) {
|
public static Optional<ActiveVoteToMute> getInstance(String username) {
|
||||||
if (!instances.containsKey(username))
|
if (!instances.containsKey(username))
|
||||||
|
|
@ -74,7 +75,7 @@ public class ActiveVoteToMute {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActiveVoteToMute(@NotNull Player votedPlayer, @NotNull RegisteredServer server, ProxyServer proxyServer, Duration duration,
|
public ActiveVoteToMute(@NotNull Player votedPlayer, @NotNull RegisteredServer server, ProxyServer proxyServer, Duration duration,
|
||||||
int totalEligibleVoters, boolean countLowerRanks, Component chatLogs) {
|
int totalEligibleVoters, boolean countLowerRanks, Component chatLogs, @NotNull Player startedByPlayer) {
|
||||||
this.chatLogs = chatLogs;
|
this.chatLogs = chatLogs;
|
||||||
this.votedPlayer = votedPlayer;
|
this.votedPlayer = votedPlayer;
|
||||||
this.totalEligibleVoters = totalEligibleVoters;
|
this.totalEligibleVoters = totalEligibleVoters;
|
||||||
|
|
@ -85,6 +86,7 @@ public class ActiveVoteToMute {
|
||||||
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
executorService.schedule(this::endVote,
|
executorService.schedule(this::endVote,
|
||||||
duration.toMinutes(), TimeUnit.MINUTES);
|
duration.toMinutes(), TimeUnit.MINUTES);
|
||||||
|
this.startedByPlayer = startedByPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RegisteredServer getServer() {
|
private RegisteredServer getServer() {
|
||||||
|
|
@ -92,12 +94,14 @@ public class ActiveVoteToMute {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endVote() {
|
private void endVote() {
|
||||||
|
if (endedVote)
|
||||||
|
return;
|
||||||
instances.remove(votedPlayer.getUsername());
|
instances.remove(votedPlayer.getUsername());
|
||||||
if (votePassed()) {
|
if (votePassed()) {
|
||||||
mutePlayer();
|
mutePlayer();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Component message = Utility.parseMiniMessage("<prefix> <red>The vote to mute <player> has failed, they will not be muted.</green>",
|
Component 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()));
|
Placeholder.component("prefix", prefix), Placeholder.parsed("player", votedPlayer.getUsername()));
|
||||||
server.getPlayersConnected().stream()
|
server.getPlayersConnected().stream()
|
||||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||||
|
|
@ -118,6 +122,7 @@ public class ActiveVoteToMute {
|
||||||
if (!votePassed()) {
|
if (!votePassed()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
endedVote = true;
|
||||||
instances.remove(votedPlayer.getUsername());
|
instances.remove(votedPlayer.getUsername());
|
||||||
mutePlayer();
|
mutePlayer();
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -128,6 +133,9 @@ public class ActiveVoteToMute {
|
||||||
|
|
||||||
public boolean votePassed() {
|
public boolean votePassed() {
|
||||||
double totalVotes = (votedFor.size() + votedAgainst.size());
|
double totalVotes = (votedFor.size() + votedAgainst.size());
|
||||||
|
if (totalVotes == 0 || votedFor.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (totalVotes / totalEligibleVoters < 0.6) {
|
if (totalVotes / totalEligibleVoters < 0.6) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -145,7 +153,7 @@ public class ActiveVoteToMute {
|
||||||
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
.filter(player -> countLowerRanks ? player.hasPermission("chat.backup-vote-to-mute") : player.hasPermission("chat.vote-to-mute"))
|
||||||
.forEach(player -> player.sendMessage(message));
|
.forEach(player -> player.sendMessage(message));
|
||||||
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(),
|
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(),
|
||||||
String.format("tempmute %s 1h Muted by the community - under review.", votedPlayer.getUsername()));
|
String.format("tempmute %s 1h Muted by the community - under review. -p", votedPlayer.getUsername()));
|
||||||
|
|
||||||
|
|
||||||
String chatLogsString = PlainTextComponentSerializer.plainText().serialize(chatLogs);
|
String chatLogsString = PlainTextComponentSerializer.plainText().serialize(chatLogs);
|
||||||
|
|
@ -173,7 +181,10 @@ public class ActiveVoteToMute {
|
||||||
false);
|
false);
|
||||||
embedBuilder.addField("Server",
|
embedBuilder.addField("Server",
|
||||||
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
server.getServerInfo().getName().substring(0, 1).toUpperCase() + server.getServerInfo().getName().substring(1),
|
||||||
false);
|
true);
|
||||||
|
embedBuilder.addField("Started by",
|
||||||
|
String.format("Username: %s\nUUID: %s", startedByPlayer.getUsername(), startedByPlayer.getUniqueId().toString()),
|
||||||
|
true);
|
||||||
return embedBuilder;
|
return embedBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,7 +215,7 @@ public class ActiveVoteToMute {
|
||||||
private Component getVoteStartMessage() {
|
private Component getVoteStartMessage() {
|
||||||
return Utility.parseMiniMessage(
|
return Utility.parseMiniMessage(
|
||||||
String.format("""
|
String.format("""
|
||||||
<prefix> <gold>[VoteMute]</gold> <green>A vote to mute <player> for one hour has been started, please read the logs below before voting.</green>
|
<prefix> <green>A vote to mute <player> for one hour has been started, please read the logs below before voting.</green>
|
||||||
<logs>
|
<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>""",
|
<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()),
|
votedPlayer.getUsername(), votedPlayer.getUsername()),
|
||||||
|
|
@ -212,4 +223,16 @@ public class ActiveVoteToMute {
|
||||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||||
Placeholder.component("logs", chatLogs));
|
Placeholder.component("logs", chatLogs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player getVotedPlayer() {
|
||||||
|
return votedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVotedFor() {
|
||||||
|
return votedFor.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalEligibleVoters() {
|
||||||
|
return totalEligibleVoters;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class VoteToMuteStarter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(5), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
chatLogHandler.retrieveChatLogs(votedPlayer.getUniqueId(), Duration.ofMinutes(10), serverName).whenCompleteAsync((chatLogs, throwable) -> {
|
||||||
if (throwable != null) {
|
if (throwable != null) {
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage("<prefix> <red>Unable to retrieve messages</red> for player <player>",
|
commandSource.sendMessage(Utility.parseMiniMessage("<prefix> <red>Unable to retrieve messages</red> for player <player>",
|
||||||
Placeholder.component("prefix", prefix),
|
Placeholder.component("prefix", prefix),
|
||||||
|
|
@ -52,40 +52,41 @@ public class VoteToMuteStarter {
|
||||||
parseChatLogs(chatLogs);
|
parseChatLogs(chatLogs);
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage(
|
commandSource.sendMessage(Utility.parseMiniMessage(
|
||||||
"<prefix> <green>Please select up to 10 messages other players should see to decide their vote, seperated by comma's. " +
|
"<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>"));
|
"Example: <gold>/votetomutehelper messages 1, 2, 5, 8</gold></green>", Placeholder.component("prefix", prefix)));
|
||||||
showPage(0);
|
showPage(1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseChatLogs(List<ChatLog> chatLogs) {
|
private void parseChatLogs(List<ChatLog> chatLogs) {
|
||||||
TagResolver.Single playerTag = Placeholder.parsed("player", votedPlayer.getUsername());
|
TagResolver.Single playerTag = Placeholder.parsed("player", votedPlayer.getUsername());
|
||||||
chatLogs.sort(Comparator.comparing(ChatLog::getTimestamp));
|
TagResolver.Single prefixTag = Placeholder.component("prefix", prefix);
|
||||||
|
chatLogs.sort(Comparator.comparing(ChatLog::getTimestamp).reversed());
|
||||||
parsedChatLogs = IntStream.range(0, chatLogs.size())
|
parsedChatLogs = IntStream.range(0, chatLogs.size())
|
||||||
.mapToObj(i -> Utility.parseMiniMessage(
|
.mapToObj(i -> Utility.parseMiniMessage(
|
||||||
"<number>. [ChatLog] <player>: <message>",
|
"<number>. <prefix> <player>: <message>",
|
||||||
TagResolver.resolver(
|
TagResolver.resolver(
|
||||||
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
Placeholder.unparsed("message", chatLogs.get(i).getMessage()),
|
||||||
Placeholder.parsed("number", String.valueOf(i + 1)),
|
Placeholder.parsed("number", String.valueOf(i + 1)),
|
||||||
playerTag
|
playerTag, prefixTag
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPage(int page) {
|
public void showPage(int page) {
|
||||||
List<Component> collect = parsedChatLogs.stream().skip(page * 10L).limit(page).toList();
|
List<Component> collect = parsedChatLogs.stream().skip((page - 1) * 10L).limit(10L).toList();
|
||||||
Component chatLogsComponent = Component.join(JoinConfiguration.newlines(), collect);
|
Component chatLogsComponent = Component.join(JoinConfiguration.newlines(), collect);
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
stringBuilder.append("<prefix> ChatLogs for <player>\n<logs>\n");
|
stringBuilder.append("<prefix> ChatLogs for <player>\n<logs>\n");
|
||||||
if (page != 0) {
|
if (page > 1) {
|
||||||
stringBuilder.append("<click:run_command:/votetomute page ")
|
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||||
.append(page - 1)
|
.append(page - 1)
|
||||||
.append("><hover:show_text:'<gold>Click to go to previous page'><gold><previous page></gold></hover></click> ");
|
.append("><hover:show_text:'<gold>Click to go to previous page'><gold><previous page></gold></hover></click> ");
|
||||||
}
|
}
|
||||||
if (parsedChatLogs.size() > page * 10) {
|
if (parsedChatLogs.size() > page * 10) {
|
||||||
stringBuilder.append("<click:run_command:/votetomute page ")
|
stringBuilder.append("<click:run_command:/votetomutehelper page ")
|
||||||
.append(page + 1)
|
.append(page + 1)
|
||||||
.append("><hover:show_text:'<gold>Click to go to next page'><gold><previous page></gold></hover></click> ");
|
.append("><hover:show_text:'<gold>Click to go to next page'><gold><next page></gold></hover></click> ");
|
||||||
}
|
}
|
||||||
commandSource.sendMessage(Utility.parseMiniMessage(stringBuilder.toString(),
|
commandSource.sendMessage(Utility.parseMiniMessage(stringBuilder.toString(),
|
||||||
Placeholder.parsed("player", votedPlayer.getUsername()),
|
Placeholder.parsed("player", votedPlayer.getUsername()),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user