added sendall command, minimessage support

This commit is contained in:
FeuSalamander 2023-01-28 21:09:02 +01:00
parent beb4a9a531
commit 5513184ce4
8 changed files with 97 additions and 36 deletions

View File

@ -3,7 +3,8 @@
**Ever wanted to have your messages sent globally across your Velocity proxy with LuckPerms ranks ? Here's a simple plugin to do just that!**
- No Setup required, but you can still customize it with the config file
- LuckPerms Prefix Support
- LuckPerms Prefix and Suffix Support
- Velocity only
- Reload command: "/vmessage reload", permission: "*"
- Global message command: "/sendall"
- You can also check my Bukkit plugin https://github.com/FeuSalamander/MiniWalls

View File

@ -166,5 +166,10 @@
<version>5.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.12.0</version>
</dependency>
</dependencies>
</project>

View File

@ -21,6 +21,7 @@ public final class Configuration {
private boolean joinEnabled;
private boolean leaveEnabled;
private boolean changeEnabled;
private boolean minimessage;
private Toml config;
private static File file;
@ -34,6 +35,8 @@ public final class Configuration {
joinEnabled = config.getBoolean("Join.enabled", false);
leaveEnabled = config.getBoolean("Leave.enabled", false);
changeEnabled = config.getBoolean("Server-change.enabled", false);
minimessage = config.getBoolean("Message-format.minimessage");
this.config = config;
}
@ -96,6 +99,9 @@ public final class Configuration {
public boolean isChangeEnabled() {
return this.changeEnabled;
}
public boolean isMinimessageEnabled(){
return this.minimessage;
}
void reload(){
config = config.read(file);
this.messageFormat = config.getString("Message.format");
@ -107,5 +113,7 @@ public final class Configuration {
this.joinEnabled = config.getBoolean("Join.enabled");
this.leaveEnabled = config.getBoolean("Leave.enabled");
this.changeEnabled = config.getBoolean("Server-change.enabled");
this.minimessage = config.getBoolean("Message-format.minimessage");
}
}

View File

@ -12,6 +12,7 @@ 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.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
@ -27,6 +28,7 @@ public final class Listeners {
.character('&')
.hexColors()
.build();
public static final MiniMessage mm = MiniMessage.miniMessage();
private LuckPerms luckPermsAPI;
private final Configuration configuration;
private final ProxyServer proxyServer;
@ -44,21 +46,7 @@ public final class Listeners {
if (!configuration.isMessageEnabled()) {
return;
}
Player p = e.getPlayer();
String m = e.getMessage();
String message = configuration.getMessageFormat()
.replace("#player#", p.getUsername())
.replace("#message#", m)
.replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName());
if (luckPermsAPI != null){
message = luckperms(message, p);
}
final String finalMessage = message;
proxyServer.getAllServers().forEach(server -> {
if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())){
server.sendMessage(SERIALIZER.deserialize(finalMessage));
}
});
message(e.getPlayer(), e.getMessage());
}
@Subscribe
private void onLeave(DisconnectEvent e){
@ -74,9 +62,14 @@ public final class Listeners {
if (luckPermsAPI != null){
message = luckperms(message, p);
}
if(configuration.isMinimessageEnabled()){
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
}else{
proxyServer.sendMessage(SERIALIZER.deserialize(message));
}
}
@Subscribe
private void onChange(ServerConnectedEvent e){
if (!configuration.isChangeEnabled()&&!configuration.isJoinEnabled()) {
@ -97,7 +90,11 @@ public final class Listeners {
if (luckPermsAPI != null){
message = luckperms(message, p);
}
if(configuration.isMinimessageEnabled()){
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
}else{
proxyServer.sendMessage(SERIALIZER.deserialize(message));
}
}else{
if (!configuration.isJoinEnabled()) {
return;
@ -106,9 +103,13 @@ public final class Listeners {
if (luckPermsAPI != null){
message = luckperms(message, p);
}
if(configuration.isMinimessageEnabled()){
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
}else{
proxyServer.sendMessage(SERIALIZER.deserialize(message));
}
}
}
private String luckperms(String message, Player p){
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p);
if(message.contains("#prefix#")){
@ -119,4 +120,23 @@ public final class Listeners {
}
return message;
}
public void message(Player p, String m){
String message = configuration.getMessageFormat()
.replace("#player#", p.getUsername())
.replace("#message#", m)
.replace("#server#", p.getCurrentServer().orElseThrow().getServerInfo().getName());
if (luckPermsAPI != null){
message = luckperms(message, p);
}
final String finalMessage = message;
proxyServer.getAllServers().forEach(server -> {
if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())){
if(configuration.isMinimessageEnabled()){
server.sendMessage(mm.deserialize(finalMessage.replaceAll("§", "")));
}else{
server.sendMessage(SERIALIZER.deserialize(finalMessage));
}
}
});
}
}

View File

@ -34,19 +34,4 @@ public final class ReloadCommand implements SimpleCommand {
source.sendMessage(Component.text("The Vmessage's config has been succefully reloaded"));
}
}
@Override
public boolean hasPermission(final Invocation invocation) {
return invocation.source().hasPermission("*");
}
@Override
public List<String> suggest(final Invocation invocation) {
return List.of("reload");
}
@Override
public CompletableFuture<List<String>> suggestAsync(final Invocation invocation) {
return CompletableFuture.completedFuture(List.of("reload"));
}
}

View File

@ -0,0 +1,32 @@
package me.feusalamander.vmessage;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public final class SendCommand implements SimpleCommand {
VMessage main;
SendCommand(VMessage main){
this.main = main;
}
@Override
public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
if(!(source instanceof Player)){
return;
}
if(args.length == 0){
source.sendMessage(Component.text("§cUsage: /sendall *your message*"));
return;
}
Player p = (Player)source;
String s = args[0];
main.listeners.message(p, s);
}
}

View File

@ -16,7 +16,7 @@ import java.nio.file.Path;
@Plugin(
id = "vmessage",
name = "Vmessage",
version = "1.4",
version = "1.5",
description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"},
dependencies = { @Dependency(id = "luckperms", optional = true) }
@ -26,6 +26,7 @@ public class VMessage {
private final Logger logger;
private final Metrics.Factory metricsFactory;
private final Path dataDirectory;
public Listeners listeners;
@Inject
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
@ -42,7 +43,8 @@ public class VMessage {
return;
}
metricsFactory.make(this, 16527);
proxy.getEventManager().register(this, new Listeners(proxy, configuration));
listeners = new Listeners(proxy, configuration);
proxy.getEventManager().register(this, listeners);
logger.info("Vmessage by FeuSalamander is working !");
CommandManager commandManager = proxy.getCommandManager();
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
@ -50,5 +52,10 @@ public class VMessage {
.build();
SimpleCommand command = new ReloadCommand(dataDirectory, configuration);
commandManager.register(commandMeta, command);
CommandMeta sendmeta = commandManager.metaBuilder("sendall")
.plugin(this)
.build();
SimpleCommand sendcommand = new SendCommand(this);
commandManager.register(sendmeta, sendcommand);
}
}

View File

@ -1,3 +1,6 @@
[Message-format]
#set it to true to use MiniMessage and false to use hex colors
minimessage = false
[Message]
#place holders:
#- "#player#" : return the player name