Merge pull request #5 from 4drian3d/main

Improved MiniMessage integration and more
This commit is contained in:
FeuSalamander 2023-01-30 18:27:59 +01:00 committed by GitHub
commit 389ccd5adf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 82 additions and 81 deletions

View File

@ -157,7 +157,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.1</version>
<version>3.1.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@ -166,10 +166,5 @@
<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

@ -1,10 +1,6 @@
package me.feusalamander.vmessage;
import com.moandjiezana.toml.Toml;
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.io.File;
import java.io.InputStream;

View File

@ -2,24 +2,19 @@ package me.feusalamander.vmessage;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.DisconnectEvent;
import com.velocitypowered.api.event.connection.PostLoginEvent;
import com.velocitypowered.api.event.connection.PreLoginEvent;
import com.velocitypowered.api.event.player.PlayerChatEvent;
import com.velocitypowered.api.event.player.ServerConnectedEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.proxy.LoginPhaseConnection;
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.Component;
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;
import net.luckperms.api.model.user.User;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
@ -48,6 +43,7 @@ public final class Listeners {
}
message(e.getPlayer(), e.getMessage());
}
@Subscribe
private void onLeave(DisconnectEvent e) {
if (!configuration.isLeaveEnabled()) {
@ -63,7 +59,7 @@ public final class Listeners {
message = luckperms(message, p);
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
}
@ -91,7 +87,7 @@ public final class Listeners {
message = luckperms(message, p);
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
} else {
proxyServer.sendMessage(SERIALIZER.deserialize(message));
}
@ -104,12 +100,13 @@ public final class Listeners {
message = luckperms(message, p);
}
if (configuration.isMinimessageEnabled()) {
proxyServer.sendMessage(mm.deserialize(message.replaceAll("§", "")));
proxyServer.sendMessage(mm.deserialize(message.replace("§", "")));
} 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#")) {
@ -120,6 +117,7 @@ public final class Listeners {
}
return message;
}
public void message(Player p, String m) {
String message = configuration.getMessageFormat()
.replace("#player#", p.getUsername())
@ -128,14 +126,15 @@ public final class Listeners {
if (luckPermsAPI != null) {
message = luckperms(message, p);
}
final String finalMessage = message;
final Component finalMessage;
if (configuration.isMinimessageEnabled()) {
finalMessage = mm.deserialize(message.replace("§", ""));
} else {
finalMessage = SERIALIZER.deserialize(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));
}
server.sendMessage(finalMessage);
}
});
}

View File

@ -1,37 +1,47 @@
package me.feusalamander.vmessage;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.NamedTextColor;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.List;
public final class ReloadCommand implements SimpleCommand {
final Path dataDirectory;
final Configuration config;
ReloadCommand(Path dataDirectory, Configuration config){
this.dataDirectory = dataDirectory;
private final Configuration config;
ReloadCommand(Configuration config) {
this.config = config;
}
@Override
public void execute(final Invocation invocation) {
CommandSource source = invocation.source();
String[] args = invocation.arguments();
final CommandSource source = invocation.source();
final String[] args = invocation.arguments();
if (args.length == 0) {
source.sendMessage(Component.text("§cUsage: /vmessage reload"));
source.sendMessage(Component.text("Usage: /vmessage reload", NamedTextColor.RED));
return;
}
String s = args[0];
final String s = args[0];
if (s.equalsIgnoreCase("reload")) {
if(!source.hasPermission("*")){
source.sendMessage(Component.text("§cYou don't have the permission to do that"));
return;
}
config.reload();
source.sendMessage(Component.text("The Vmessage's config has been succefully reloaded"));
}
}
@Override
public boolean hasPermission(final Invocation invocation) {
return invocation.source().hasPermission("vmessage.command");
}
private static final List<String> suggestion = List.of("reload");
@Override
public List<String> suggest(final Invocation invocation) {
final String[] args = invocation.arguments();
if (args.length == 0 || (args.length == 1 && "reload".startsWith(args[0]))) {
return suggestion;
}
return List.of();
}
}

View File

@ -4,29 +4,30 @@ 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;
import net.kyori.adventure.text.format.NamedTextColor;
public final class SendCommand implements SimpleCommand {
VMessage main;
private final 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;
}
final CommandSource source = invocation.source();
final String[] args = invocation.arguments();
if (args.length == 0) {
source.sendMessage(Component.text("§cUsage: /sendall *your message*"));
source.sendMessage(Component.text("Usage: /sendall *your message*", NamedTextColor.RED));
return;
}
Player p = (Player)source;
String s = args[0];
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

@ -50,7 +50,7 @@ public class VMessage {
CommandMeta commandMeta = commandManager.metaBuilder("Vmessage")
.plugin(this)
.build();
SimpleCommand command = new ReloadCommand(dataDirectory, configuration);
SimpleCommand command = new ReloadCommand(configuration);
commandManager.register(commandMeta, command);
CommandMeta sendmeta = commandManager.metaBuilder("sendall")
.plugin(this)