added sendall command, minimessage support
This commit is contained in:
parent
beb4a9a531
commit
5513184ce4
@ -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!**
|
**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
|
- No Setup required, but you can still customize it with the config file
|
||||||
- LuckPerms Prefix Support
|
- LuckPerms Prefix and Suffix Support
|
||||||
- Velocity only
|
- Velocity only
|
||||||
- Reload command: "/vmessage reload", permission: "*"
|
- Reload command: "/vmessage reload", permission: "*"
|
||||||
|
- Global message command: "/sendall"
|
||||||
- You can also check my Bukkit plugin https://github.com/FeuSalamander/MiniWalls
|
- You can also check my Bukkit plugin https://github.com/FeuSalamander/MiniWalls
|
||||||
|
5
pom.xml
5
pom.xml
@ -166,5 +166,10 @@
|
|||||||
<version>5.4</version>
|
<version>5.4</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.12.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -21,6 +21,7 @@ public final class Configuration {
|
|||||||
private boolean joinEnabled;
|
private boolean joinEnabled;
|
||||||
private boolean leaveEnabled;
|
private boolean leaveEnabled;
|
||||||
private boolean changeEnabled;
|
private boolean changeEnabled;
|
||||||
|
private boolean minimessage;
|
||||||
private Toml config;
|
private Toml config;
|
||||||
private static File file;
|
private static File file;
|
||||||
|
|
||||||
@ -34,6 +35,8 @@ public final class Configuration {
|
|||||||
joinEnabled = config.getBoolean("Join.enabled", false);
|
joinEnabled = config.getBoolean("Join.enabled", false);
|
||||||
leaveEnabled = config.getBoolean("Leave.enabled", false);
|
leaveEnabled = config.getBoolean("Leave.enabled", false);
|
||||||
changeEnabled = config.getBoolean("Server-change.enabled", false);
|
changeEnabled = config.getBoolean("Server-change.enabled", false);
|
||||||
|
|
||||||
|
minimessage = config.getBoolean("Message-format.minimessage");
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +99,9 @@ public final class Configuration {
|
|||||||
public boolean isChangeEnabled() {
|
public boolean isChangeEnabled() {
|
||||||
return this.changeEnabled;
|
return this.changeEnabled;
|
||||||
}
|
}
|
||||||
|
public boolean isMinimessageEnabled(){
|
||||||
|
return this.minimessage;
|
||||||
|
}
|
||||||
void reload(){
|
void reload(){
|
||||||
config = config.read(file);
|
config = config.read(file);
|
||||||
this.messageFormat = config.getString("Message.format");
|
this.messageFormat = config.getString("Message.format");
|
||||||
@ -107,5 +113,7 @@ public final class Configuration {
|
|||||||
this.joinEnabled = config.getBoolean("Join.enabled");
|
this.joinEnabled = config.getBoolean("Join.enabled");
|
||||||
this.leaveEnabled = config.getBoolean("Leave.enabled");
|
this.leaveEnabled = config.getBoolean("Leave.enabled");
|
||||||
this.changeEnabled = config.getBoolean("Server-change.enabled");
|
this.changeEnabled = config.getBoolean("Server-change.enabled");
|
||||||
|
|
||||||
|
this.minimessage = config.getBoolean("Message-format.minimessage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,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 net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.luckperms.api.LuckPerms;
|
import net.luckperms.api.LuckPerms;
|
||||||
import net.luckperms.api.LuckPermsProvider;
|
import net.luckperms.api.LuckPermsProvider;
|
||||||
@ -27,6 +28,7 @@ public final class Listeners {
|
|||||||
.character('&')
|
.character('&')
|
||||||
.hexColors()
|
.hexColors()
|
||||||
.build();
|
.build();
|
||||||
|
public static final MiniMessage mm = MiniMessage.miniMessage();
|
||||||
private LuckPerms luckPermsAPI;
|
private LuckPerms luckPermsAPI;
|
||||||
private final Configuration configuration;
|
private final Configuration configuration;
|
||||||
private final ProxyServer proxyServer;
|
private final ProxyServer proxyServer;
|
||||||
@ -44,21 +46,7 @@ public final class Listeners {
|
|||||||
if (!configuration.isMessageEnabled()) {
|
if (!configuration.isMessageEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player p = e.getPlayer();
|
message(e.getPlayer(), e.getMessage());
|
||||||
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));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onLeave(DisconnectEvent e){
|
private void onLeave(DisconnectEvent e){
|
||||||
@ -74,9 +62,14 @@ public final class Listeners {
|
|||||||
if (luckPermsAPI != null){
|
if (luckPermsAPI != null){
|
||||||
message = luckperms(message, p);
|
message = luckperms(message, p);
|
||||||
}
|
}
|
||||||
|
if(configuration.isMinimessageEnabled()){
|
||||||
|
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
|
||||||
|
}else{
|
||||||
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void onChange(ServerConnectedEvent e){
|
private void onChange(ServerConnectedEvent e){
|
||||||
if (!configuration.isChangeEnabled()&&!configuration.isJoinEnabled()) {
|
if (!configuration.isChangeEnabled()&&!configuration.isJoinEnabled()) {
|
||||||
@ -97,7 +90,11 @@ public final class Listeners {
|
|||||||
if (luckPermsAPI != null){
|
if (luckPermsAPI != null){
|
||||||
message = luckperms(message, p);
|
message = luckperms(message, p);
|
||||||
}
|
}
|
||||||
|
if(configuration.isMinimessageEnabled()){
|
||||||
|
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
|
||||||
|
}else{
|
||||||
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
if (!configuration.isJoinEnabled()) {
|
if (!configuration.isJoinEnabled()) {
|
||||||
return;
|
return;
|
||||||
@ -106,9 +103,13 @@ public final class Listeners {
|
|||||||
if (luckPermsAPI != null){
|
if (luckPermsAPI != null){
|
||||||
message = luckperms(message, p);
|
message = luckperms(message, p);
|
||||||
}
|
}
|
||||||
|
if(configuration.isMinimessageEnabled()){
|
||||||
|
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
|
||||||
|
}else{
|
||||||
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
proxyServer.sendMessage(SERIALIZER.deserialize(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private String luckperms(String message, Player p){
|
private String luckperms(String message, Player p){
|
||||||
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p);
|
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(p);
|
||||||
if(message.contains("#prefix#")){
|
if(message.contains("#prefix#")){
|
||||||
@ -119,4 +120,23 @@ public final class Listeners {
|
|||||||
}
|
}
|
||||||
return message;
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,19 +34,4 @@ public final class ReloadCommand implements SimpleCommand {
|
|||||||
source.sendMessage(Component.text("The Vmessage's config has been succefully reloaded"));
|
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"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
32
src/main/java/me/feusalamander/vmessage/SendCommand.java
Normal file
32
src/main/java/me/feusalamander/vmessage/SendCommand.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ import java.nio.file.Path;
|
|||||||
@Plugin(
|
@Plugin(
|
||||||
id = "vmessage",
|
id = "vmessage",
|
||||||
name = "Vmessage",
|
name = "Vmessage",
|
||||||
version = "1.4",
|
version = "1.5",
|
||||||
description = "A velocity plugin that creates a multi server chat for the network",
|
description = "A velocity plugin that creates a multi server chat for the network",
|
||||||
authors = {"FeuSalamander"},
|
authors = {"FeuSalamander"},
|
||||||
dependencies = { @Dependency(id = "luckperms", optional = true) }
|
dependencies = { @Dependency(id = "luckperms", optional = true) }
|
||||||
@ -26,6 +26,7 @@ public class VMessage {
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
private final Metrics.Factory metricsFactory;
|
private final Metrics.Factory metricsFactory;
|
||||||
private final Path dataDirectory;
|
private final Path dataDirectory;
|
||||||
|
public Listeners listeners;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
|
public VMessage(ProxyServer proxy, Logger logger, Metrics.Factory metricsFactory, @DataDirectory Path dataDirectory) {
|
||||||
@ -42,7 +43,8 @@ public class VMessage {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
metricsFactory.make(this, 16527);
|
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 !");
|
logger.info("Vmessage by FeuSalamander is working !");
|
||||||
CommandManager commandManager = proxy.getCommandManager();
|
CommandManager commandManager = proxy.getCommandManager();
|
||||||
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
|
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
|
||||||
@ -50,5 +52,10 @@ public class VMessage {
|
|||||||
.build();
|
.build();
|
||||||
SimpleCommand command = new ReloadCommand(dataDirectory, configuration);
|
SimpleCommand command = new ReloadCommand(dataDirectory, configuration);
|
||||||
commandManager.register(commandMeta, command);
|
commandManager.register(commandMeta, command);
|
||||||
|
CommandMeta sendmeta = commandManager.metaBuilder("sendall")
|
||||||
|
.plugin(this)
|
||||||
|
.build();
|
||||||
|
SimpleCommand sendcommand = new SendCommand(this);
|
||||||
|
commandManager.register(sendmeta, sendcommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
[Message-format]
|
||||||
|
#set it to true to use MiniMessage and false to use hex colors
|
||||||
|
minimessage = false
|
||||||
[Message]
|
[Message]
|
||||||
#place holders:
|
#place holders:
|
||||||
#- "#player#" : return the player name
|
#- "#player#" : return the player name
|
||||||
|
Loading…
Reference in New Issue
Block a user