Fork changes

This commit is contained in:
Evert Prants 2024-04-14 09:54:38 +03:00
parent 6da6b227b6
commit b06c38a271
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
9 changed files with 8 additions and 229 deletions

View File

@ -1,17 +1,14 @@
![](https://github.com/FeuSalamander/Vmessage/blob/main/src/main/resources/Vmessage_desc.jpg?raw=true)
**Ever wanted to have your messages sent globally across your Velocity proxy with LuckPerms ranks ? Here's a simple plugin to do just that!**
![](https://github.com/FeuSalamander/Vmessage/blob/main/src/main/resources/features.png?raw=true)
- **4 Events with custom messages for each**
- **Player Message**
# Vmessage fork
**Join/leave/change messages**
## Features
- **3 Events with custom messages for each**
- **Player join the network**
- **Player left the network**
- **Player server change**
- **LuckPerms Prefix and Suffix Support**
- **Reload command: "/vmessage reload"**
- **Global message command: "/sendall"**
- **MiniMessage support**
- **Discord Integration with this another plugin: https://github.com/fooooooooooooooo/VelocityDiscord**
![](https://github.com/FeuSalamander/Vmessage/blob/main/src/main/resources/permissions.png?raw=true)
## Permissions
- **"vmessage.reload" to access to the reload command**
- **"vmessage.minimessage" the player needs to have it to use MiniMessage in his messages**
- **"vmessage.silent. leave,change, join" if the player have it/them, no message will be sent**

View File

@ -10,21 +10,17 @@ import java.util.List;
import java.util.Objects;
public final class Configuration {
private String messageFormat;
private String joinFormat;
private String leaveFormat;
private String kickFormat;
private String changeFormat;
private boolean messageEnabled;
private boolean joinEnabled;
private boolean leaveEnabled;
private boolean kickEnabled;
private boolean changeEnabled;
private boolean minimessage;
private boolean all;
private Toml config;
private static File file;
private List<String> messagecmd;
private List<String> joincmd;
private List<String> leavecmd;
private List<String> kickcmd;
@ -34,13 +30,11 @@ public final class Configuration {
private Toml aliases;
Configuration(Toml config) {
messageFormat = config.getString("Message.format", "");
joinFormat = config.getString("Join.format", "");
leaveFormat = config.getString("Leave.format", "");
kickFormat = config.getString("Kick.format", "");
changeFormat = config.getString("Server-change.format", "");
messageEnabled = config.getBoolean("Message.enabled", false);
joinEnabled = config.getBoolean("Join.enabled", false);
leaveEnabled = config.getBoolean("Leave.enabled", false);
kickEnabled = config.getBoolean("Kick.enabled", false);
@ -48,13 +42,11 @@ public final class Configuration {
aliases = config.getTable("Aliases");
messagecmd = config.getList("Message.commands");
joincmd = config.getList("Join.commands");
leavecmd = config.getList("Leave.commands");
kickcmd = config.getList("Kick.commands");
changecmd = config.getList("Server-change.commands");
minimessage = config.getBoolean("Message-format.minimessage");
all = config.getBoolean("Message.all", false);
custom1 = config.getString("Custom-Meta.custom1", "");
custom2 = config.getString("Custom-Meta.custom2", "");
@ -89,10 +81,6 @@ public final class Configuration {
}
}
public String getMessageFormat() {
return this.messageFormat;
}
public String getJoinFormat() {
return this.joinFormat;
}
@ -108,10 +96,6 @@ public final class Configuration {
return this.changeFormat;
}
public boolean isMessageEnabled() {
return this.messageEnabled;
}
public boolean isJoinEnabled() {
return this.joinEnabled;
}
@ -129,12 +113,6 @@ public final class Configuration {
public boolean isMinimessageEnabled(){
return this.minimessage;
}
public boolean isAllEnabled(){
return this.all;
}
public List<String> getMessagecmd(){
return this.messagecmd;
}
public List<String> getJoincmd(){
return this.joincmd;
}
@ -159,13 +137,11 @@ public final class Configuration {
void reload(){
config = config.read(file);
this.messageFormat = config.getString("Message.format");
this.joinFormat = config.getString("Join.format");
this.leaveFormat = config.getString("Leave.format");
this.kickFormat = config.getString("Kick.format");
this.changeFormat = config.getString("Server-change.format");
this.messageEnabled = config.getBoolean("Message.enabled");
this.joinEnabled = config.getBoolean("Join.enabled");
this.leaveEnabled = config.getBoolean("Leave.enabled");
this.kickEnabled = config.getBoolean("Kick.enabled");
@ -173,14 +149,12 @@ public final class Configuration {
this.aliases = config.getTable("Aliases");
this.messagecmd = config.getList("Message.commands");
this.joincmd = config.getList("Join.commands");
this.leavecmd = config.getList("Leave.commands");
this.kickcmd = config.getList("Kick.commands");
this.changecmd = config.getList("Server-change.commands");
this.minimessage = config.getBoolean("Message-format.minimessage");
this.all = config.getBoolean("Message.all", false);
this.custom1 = config.getString("Custom-Meta.custom1");
this.custom2 = config.getString("Custom-Meta.custom2");

View File

@ -15,7 +15,6 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.cacheddata.CachedMetaData;
import ooo.foooooooooooo.velocitydiscord.VelocityDiscord;
import java.util.Arrays;
import java.util.Objects;
@ -39,16 +38,7 @@ public final class Listeners {
this.configuration = configuration;
this.proxyServer = proxyServer;
}
@Subscribe
private void onMessage(final PlayerChatEvent e) {
if (!configuration.isMessageEnabled()) {
return;
}
if(configuration.isAllEnabled()){
e.setResult(PlayerChatEvent.ChatResult.denied());
}
message(e.getPlayer(), e.getMessage());
}
@Subscribe
private void onLeave(final DisconnectEvent e) {
if (!configuration.isLeaveEnabled()) {
@ -87,25 +77,10 @@ public final class Listeners {
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
String discordRaw;
if(VMessage.isDiscord()){
String dump = "";
String[] dump2 = message.replace("&", "§").split("§");
proxyServer.sendMessage(Component.text(Arrays.toString(dump2)));
for(String string : dump2){
if(string.length() >1)
dump = dump+string.substring(1);
}
discordRaw = dump;
} else {
discordRaw = message;
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
}
@ -144,25 +119,10 @@ public final class Listeners {
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
String discordRaw;
if(VMessage.isDiscord()){
String dump = "";
String[] dump2 = message.replace("&", "§").split("§");
proxyServer.sendMessage(Component.text(Arrays.toString(dump2)));
for(String string : dump2){
if(string.length() >1)
dump = dump+string.substring(1);
}
discordRaw = dump;
} else {
discordRaw = message;
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
}
@ -210,25 +170,10 @@ public final class Listeners {
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
String discordRaw;
if(VMessage.isDiscord()){
String dump = "";
String[] dump2 = message.replace("&", "§").split("§");
proxyServer.sendMessage(Component.text(Arrays.toString(dump2)));
for(String string : dump2){
if(string.length() >1)
dump = dump+string.substring(1);
}
discordRaw = dump;
} else {
discordRaw = message;
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
} else if (serverConnection.isPresent()){
if (!configuration.isJoinEnabled()) {
@ -259,25 +204,10 @@ public final class Listeners {
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
String discordRaw;
if(VMessage.isDiscord()){
String dump = "";
String[] dump2 = message.replace("&", "§").split("§");
proxyServer.sendMessage(Component.text(Arrays.toString(dump2)));
for(String string : dump2){
if(string.length() >1)
dump = dump+string.substring(1);
}
discordRaw = dump;
} else {
discordRaw = message;
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
}
}
@ -303,63 +233,4 @@ public final class Listeners {
message = message.replace("#prefix#", "").replace("#suffix#", "").replace("#custom1#","").replace("#custom2#","");
return message;
}
public void message(final Player p, final String m) {
String actualservername = p.getCurrentServer().orElseThrow().getServerInfo().getName();
if(configuration.getAliases().contains(actualservername)){
actualservername = configuration.getAliases().getString(actualservername);
}
if(configuration.getMessagecmd() != null&&!configuration.getMessagecmd().isEmpty())
for(String s : configuration.getMessagecmd()){
s = s
.replace("#player#", p.getUsername())
.replace("#server#", actualservername);
if (luckPermsAPI != null) {
s = luckperms(s, p);
}
proxyServer.getCommandManager().executeAsync(proxyServer.getConsoleCommandSource(), s);
}
String message = configuration.getMessageFormat();
if(message.isEmpty())return;
final boolean permission = p.hasPermission("vmessage.minimessage");
message = message
.replace("#player#", p.getUsername())
.replace("#server#", actualservername);
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
if(permission)message = message.replace("#message#", m);
Component finalMessage;
if (configuration.isMinimessageEnabled()) {
finalMessage = mm.deserialize(message.replace("§", ""));
} else {
finalMessage = SERIALIZER.deserialize(message);
}
if(!permission)finalMessage = finalMessage.replaceText("#message#", Component.text(m));
String discordRaw;
if(VMessage.isDiscord()){
String dump = "";
String[] dump2 = message.replace("&", "§").split("§");
proxyServer.sendMessage(Component.text(Arrays.toString(dump2)));
for(String string : dump2){
if(string.length() >1)
dump = dump+string.substring(1);
}
discordRaw = dump;
} else {
discordRaw = message;
}
if(configuration.isAllEnabled()){
proxyServer.sendMessage(finalMessage);
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}else {
final Component FMessage = finalMessage;
proxyServer.getAllServers().forEach(server -> {
if (!Objects.equals(p.getCurrentServer().map(ServerConnection::getServerInfo).orElse(null), server.getServerInfo())) {
server.sendMessage(FMessage);
if(VMessage.isDiscord())VelocityDiscord.getDiscord().sendMessage(discordRaw);
}
});
}
}
}

View File

@ -1,36 +0,0 @@
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 net.kyori.adventure.text.format.NamedTextColor;
public final class SendCommand implements SimpleCommand {
private final VMessage main;
SendCommand(VMessage main) {
this.main = main;
}
@Override
public void execute(final Invocation invocation) {
if(!hasPermission(invocation)){
return;
}
final CommandSource source = invocation.source();
final String[] args = invocation.arguments();
if (args.length == 0) {
source.sendMessage(Component.text("Usage: /sendall *your message*", NamedTextColor.RED));
return;
}
final Player p = (Player) source;
final String s = args[0];
main.listeners.message(p, s);
}
@Override
public boolean hasPermission(final Invocation invocation) {
return invocation.source() instanceof Player;
}
}

View File

@ -22,25 +22,20 @@ import java.nio.file.Path;
description = "A velocity plugin that creates a multi server chat for the network",
authors = {"FeuSalamander"},
dependencies = {
@Dependency(id = "luckperms", optional = true),
@Dependency(id = "discord",optional = true)
@Dependency(id = "luckperms", optional = true)
}
)
public class VMessage {
private final ProxyServer proxy;
private final Logger logger;
private final Metrics.Factory metricsFactory;
private final Path dataDirectory;
public Listeners listeners;
private static boolean discord;
@Inject
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
public VMessage(ProxyServer proxy, Logger logger, @DataDirectory Path dataDirectory) {
this.proxy = proxy;
this.logger = logger;
this.metricsFactory = metricsFactory;
this.dataDirectory = dataDirectory;
this.discord = proxy.getPluginManager().isLoaded("discord");
}
@Subscribe
@ -49,7 +44,6 @@ public class VMessage {
if (configuration == null) {
return;
}
metricsFactory.make(this, 16527);
listeners = new Listeners(proxy, configuration);
proxy.getEventManager().register(this, listeners);
CommandManager commandManager = proxy.getCommandManager();
@ -58,14 +52,6 @@ public class VMessage {
.build();
SimpleCommand command = new ReloadCommand(configuration);
commandManager.register(commandMeta, command);
CommandMeta sendmeta = commandManager.metaBuilder("sendall")
.plugin(this)
.build();
SimpleCommand sendcommand = new SendCommand(this);
commandManager.register(sendmeta, sendcommand);
logger.info("Vmessage by FeuSalamander is working !");
}
public static boolean isDiscord(){
return discord;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -2,19 +2,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
#- "#prefix#" : return the player's luckperms prefix
#- "#suffix#" : return the player's luckperms suffix
#- "#message#" : return the player's message
#- "#server#" : return the player's server name
#- "#custom1#" : return the player's custom defined luckperms meta keys
#- "#custom2#" : return the player's custom defined luckperms meta keys
format = "&a(#server#) #prefix# #player# &8&l> &r#message#"
all = false #if the formated message is sent even in the server where the player is located (can cause some issues with other plugins)
commands = []
enabled = true
[Join]
#place holders:
#- "#player#" : return the player name

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 927 KiB