Fix some messages not being disabled by setting it to ""
This commit is contained in:
15
README.md
15
README.md
@@ -5,17 +5,30 @@ An extremely simple and lightweight plugin, designed to clear chat on the proxy
|
|||||||
You are also able to clear on server swap, which may be useful to some users. Read the configuration for more info. Default configuration can be found here:
|
You are also able to clear on server swap, which may be useful to some users. Read the configuration for more info. Default configuration can be found here:
|
||||||
|
|
||||||
```hocon
|
```hocon
|
||||||
|
# Velocity Clear Chat Configuration
|
||||||
|
# This file contains settings for the chat clearing plugin.
|
||||||
|
# Modify these values as needed.
|
||||||
|
#
|
||||||
|
# If there is a message, you can set it to "" to disable it, you can use MiniMessage too.
|
||||||
|
|
||||||
# If velocity returns invalid information, this message will be displayed.
|
# If velocity returns invalid information, this message will be displayed.
|
||||||
chat-clear-failed-message="<red>Failed to get server info</red>"
|
chat-clear-failed-message="<red>Failed to get server info</red>"
|
||||||
|
|
||||||
# The message to send when the chat is cleared by an admin.
|
# The message to send when the chat is cleared by an admin.
|
||||||
# You can use <player> if you would like to display who cleared the chat.
|
# You can use <player> if you would like to display who cleared the chat.
|
||||||
chat-cleared-message="<green>Chat has been cleared by an admin</green>"
|
chat-cleared-message="<green>Chat has been cleared by an admin</green>"
|
||||||
|
|
||||||
# On player swap, should we clear the chat history?
|
# On player swap, should we clear the chat history?
|
||||||
clear-on-server-swap=true
|
clear-on-server-swap=true
|
||||||
# The message to display if "clear-on-server-swap" is enabled, set to "" to disable it.
|
|
||||||
|
# The message to display if "clear-on-server-swap" is enabled
|
||||||
clear-on-server-swap-message=""
|
clear-on-server-swap-message=""
|
||||||
|
|
||||||
# The permission an admin needs to clear the chat.
|
# The permission an admin needs to clear the chat.
|
||||||
clear-permission="lncvrt.velocityclearchat.clear"
|
clear-permission="lncvrt.velocityclearchat.clear"
|
||||||
|
|
||||||
# The number of lines the chat clearer will send.
|
# The number of lines the chat clearer will send.
|
||||||
lines=100
|
lines=100
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**If you are wondering why this *velocity plugin* is not supported on BungeeCord/Waterfall, WaterFall is EOL and BungeeCord is obsolete. Velocity is the best server proxy solution out there at the moment.**
|
||||||
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'xyz.lncvrt'
|
group = 'xyz.lncvrt'
|
||||||
version = '1.0.0'
|
version = '1.0.1'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
|||||||
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
import org.spongepowered.configurate.loader.ConfigurationLoader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private final Path configPath;
|
private final Path configPath;
|
||||||
@@ -19,45 +21,33 @@ public class ConfigManager {
|
|||||||
public ConfigManager(@DataDirectory Path dataDirectory) {
|
public ConfigManager(@DataDirectory Path dataDirectory) {
|
||||||
this.configPath = dataDirectory.resolve("config.conf");
|
this.configPath = dataDirectory.resolve("config.conf");
|
||||||
this.loader = HoconConfigurationLoader.builder().path(configPath).build();
|
this.loader = HoconConfigurationLoader.builder().path(configPath).build();
|
||||||
|
ensureConfigExists();
|
||||||
loadConfig();
|
loadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ensureConfigExists() {
|
||||||
|
if (Files.notExists(configPath)) {
|
||||||
|
try (InputStream defaultConfig = getClass().getClassLoader().getResourceAsStream("config.conf")) {
|
||||||
|
if (defaultConfig != null) {
|
||||||
|
Files.createDirectories(configPath.getParent());
|
||||||
|
Files.copy(defaultConfig, configPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} else {
|
||||||
|
System.err.println("Default config.conf not found in resources!");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadConfig() {
|
private void loadConfig() {
|
||||||
try {
|
try {
|
||||||
if (Files.notExists(configPath)) {
|
|
||||||
saveDefaultConfig();
|
|
||||||
}
|
|
||||||
root = loader.load();
|
root = loader.load();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveDefaultConfig() throws IOException {
|
|
||||||
Files.createDirectories(configPath.getParent());
|
|
||||||
|
|
||||||
root = loader.load();
|
|
||||||
root.node("lines")
|
|
||||||
.set(100)
|
|
||||||
.comment("The number of lines the chat clearer will send.");
|
|
||||||
root.node("chat-cleared-message")
|
|
||||||
.set("<green>Chat has been cleared by an admin</green>")
|
|
||||||
.comment("The message to send when the chat is cleared by an admin.\nYou can use <player> if you would like to display who cleared the chat.");
|
|
||||||
root.node("chat-clear-failed-message")
|
|
||||||
.set("<red>Failed to get server info</red>")
|
|
||||||
.comment("If velocity returns invalid information, this message will be displayed.");
|
|
||||||
root.node("clear-permission")
|
|
||||||
.set("lncvrt.velocityclearchat.clear")
|
|
||||||
.comment("The permission an admin needs to clear the chat.");
|
|
||||||
root.node("clear-on-server-swap")
|
|
||||||
.set(true)
|
|
||||||
.comment("On player swap, should we clear the chat history?");
|
|
||||||
root.node("clear-on-server-swap-message")
|
|
||||||
.set("")
|
|
||||||
.comment("The message to display if \"clear-on-server-swap\" is enabled, set to \"\" to disable it.");
|
|
||||||
loader.save(root);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getLines() {
|
public int getLines() {
|
||||||
return root.node("lines").getInt(1000);
|
return root.node("lines").getInt(1000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,14 +19,12 @@ import java.nio.file.Path;
|
|||||||
|
|
||||||
@Plugin(id = "velocityclearchat", name = "VelocityClearChat", authors = {"Lncvrt"}, version = BuildConstants.VERSION)
|
@Plugin(id = "velocityclearchat", name = "VelocityClearChat", authors = {"Lncvrt"}, version = BuildConstants.VERSION)
|
||||||
public class VelocityClearChat {
|
public class VelocityClearChat {
|
||||||
private final Logger logger;
|
|
||||||
private final ProxyServer proxyServer;
|
private final ProxyServer proxyServer;
|
||||||
public ConfigManager configManager;
|
public ConfigManager configManager;
|
||||||
public final MiniMessage miniMessage = MiniMessage.miniMessage();
|
public final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public VelocityClearChat(Logger logger, ProxyServer proxyServer, @DataDirectory Path dataDirectory) {
|
public VelocityClearChat(Logger logger, ProxyServer proxyServer, @DataDirectory Path dataDirectory) {
|
||||||
this.logger = logger;
|
|
||||||
this.proxyServer = proxyServer;
|
this.proxyServer = proxyServer;
|
||||||
this.configManager = new ConfigManager(dataDirectory);
|
this.configManager = new ConfigManager(dataDirectory);
|
||||||
}
|
}
|
||||||
@@ -49,9 +47,7 @@ public class VelocityClearChat {
|
|||||||
if (configManager.getClearOnSwap()) {
|
if (configManager.getClearOnSwap()) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
for (int i = 0; i < configManager.getLines(); i++) player.sendMessage(miniMessage.deserialize(" ".repeat((i % 10) + 1)));
|
for (int i = 0; i < configManager.getLines(); i++) player.sendMessage(miniMessage.deserialize(" ".repeat((i % 10) + 1)));
|
||||||
if (!configManager.getClearOnSwapMessage().isEmpty()) {
|
if (!configManager.getClearOnSwapMessage().isEmpty()) player.sendMessage(miniMessage.deserialize(configManager.getClearOnSwapMessage()));
|
||||||
player.sendMessage(miniMessage.deserialize(configManager.getClearOnSwapMessage()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,18 +30,18 @@ public class ClearChat implements SimpleCommand {
|
|||||||
//no idea how to make this not so shitty
|
//no idea how to make this not so shitty
|
||||||
ServerConnection server = player.getCurrentServer().orElse(null);
|
ServerConnection server = player.getCurrentServer().orElse(null);
|
||||||
if (server == null) {
|
if (server == null) {
|
||||||
player.sendMessage(miniMessage.deserialize(configManager.getClearFailed()));
|
if (!configManager.getClearFailed().isEmpty()) player.sendMessage(miniMessage.deserialize(configManager.getClearFailed()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RegisteredServer registeredServer = server.getServer();
|
RegisteredServer registeredServer = server.getServer();
|
||||||
if (registeredServer == null) {
|
if (registeredServer == null) {
|
||||||
player.sendMessage(miniMessage.deserialize(configManager.getClearFailed()));
|
if (!configManager.getClearFailed().isEmpty()) player.sendMessage(miniMessage.deserialize(configManager.getClearFailed()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Collection<Player> players = registeredServer.getPlayersConnected();
|
Collection<Player> players = registeredServer.getPlayersConnected();
|
||||||
for (Player targetPlayer : players) {
|
for (Player targetPlayer : players) {
|
||||||
for (int i = 0; i < configManager.getLines(); i++) targetPlayer.sendMessage(miniMessage.deserialize(" ".repeat((i % 10) + 1)));
|
for (int i = 0; i < configManager.getLines(); i++) targetPlayer.sendMessage(miniMessage.deserialize(" ".repeat((i % 10) + 1)));
|
||||||
targetPlayer.sendMessage(miniMessage.deserialize(configManager.getClearedMessage().replace("<player>", player.getUsername())));
|
if (!configManager.getClearedMessage().isEmpty()) targetPlayer.sendMessage(miniMessage.deserialize(configManager.getClearedMessage().replace("<player>", player.getUsername())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
src/main/resources/config.conf
Normal file
24
src/main/resources/config.conf
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Velocity Clear Chat Configuration
|
||||||
|
# This file contains settings for the chat clearing plugin.
|
||||||
|
# Modify these values as needed.
|
||||||
|
#
|
||||||
|
# If there is a message, you can set it to "" to disable it, you can use MiniMessage too.
|
||||||
|
|
||||||
|
# If velocity returns invalid information, this message will be displayed.
|
||||||
|
chat-clear-failed-message="<red>Failed to get server info</red>"
|
||||||
|
|
||||||
|
# The message to send when the chat is cleared by an admin.
|
||||||
|
# You can use <player> if you would like to display who cleared the chat.
|
||||||
|
chat-cleared-message="<green>Chat has been cleared by an admin</green>"
|
||||||
|
|
||||||
|
# On player swap, should we clear the chat history?
|
||||||
|
clear-on-server-swap=true
|
||||||
|
|
||||||
|
# The message to display if "clear-on-server-swap" is enabled
|
||||||
|
clear-on-server-swap-message=""
|
||||||
|
|
||||||
|
# The permission an admin needs to clear the chat.
|
||||||
|
clear-permission="lncvrt.velocityclearchat.clear"
|
||||||
|
|
||||||
|
# The number of lines the chat clearer will send.
|
||||||
|
lines=100
|
||||||
Reference in New Issue
Block a user