Added silent join
This commit is contained in:
parent
faa0435131
commit
408d38fb78
|
|
@ -440,6 +440,20 @@ public final class Config {
|
|||
REPORT_TOO_SHORT = getString("messages.report-too-short", REPORT_TOO_SHORT);
|
||||
}
|
||||
|
||||
public static List<String> SILENT_JOIN_COMMAND_ALIASES = new ArrayList<>();
|
||||
public static String SILENT_JOIN_NO_SERVER = "<red>Unable to find destination server</red>";
|
||||
public static String SILENT_JOIN_JOINING = "<green>Sending you to <server> silently.</green>";
|
||||
public static String SILENT_JOIN_JOINED_FROM = "<gold>* <player> silent joined from <from_server>...</gold>";
|
||||
public static String SILENT_JOIN_JOINED = "<gold>* <player> silent joined...</gold>";
|
||||
|
||||
private static void silentJoinCommand() {
|
||||
SILENT_JOIN_COMMAND_ALIASES = getList("commands.silent-join.aliases", Lists.newArrayList("sj"));
|
||||
SILENT_JOIN_NO_SERVER = getString("commands.silent-join.no-server", SILENT_JOIN_NO_SERVER);
|
||||
SILENT_JOIN_JOINING = getString("commands.silent-join.joining", SILENT_JOIN_JOINING);
|
||||
SILENT_JOIN_JOINED_FROM = getString("commands.silent-join.joined-from", SILENT_JOIN_JOINED_FROM);
|
||||
SILENT_JOIN_JOINED = getString("commands.silent-join.joined", SILENT_JOIN_JOINED);
|
||||
}
|
||||
|
||||
public static String HELP_REPORT = "<red>/report <message></red>";
|
||||
private static void loadMessages() {
|
||||
HELP_REPORT = getString("settings.mail.mail-sent", HELP_REPORT);
|
||||
|
|
|
|||
101
velocity/src/main/java/com/alttd/velocitychat/commands/SilentJoinCommand.java
Executable file
101
velocity/src/main/java/com/alttd/velocitychat/commands/SilentJoinCommand.java
Executable file
|
|
@ -0,0 +1,101 @@
|
|||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.util.Utility;
|
||||
import com.alttd.velocitychat.listeners.ProxyPlayerListener;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
public class SilentJoinCommand {
|
||||
|
||||
public SilentJoinCommand(ProxyServer proxyServer) {
|
||||
|
||||
RequiredArgumentBuilder<CommandSource, String> serverNode = RequiredArgumentBuilder
|
||||
.<CommandSource, String>argument("server", StringArgumentType.string())
|
||||
.suggests((context, builder) -> {
|
||||
Collection<String> possibleValues = new ArrayList<>();
|
||||
for (RegisteredServer server : proxyServer.getAllServers()) {
|
||||
possibleValues.add(server.getServerInfo().getName());
|
||||
}
|
||||
if(possibleValues.isEmpty()) return Suggestions.empty();
|
||||
String remaining = builder.getRemaining().toLowerCase();
|
||||
for (String str : possibleValues) {
|
||||
if (str.toLowerCase().startsWith(remaining)) {
|
||||
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
|
||||
}
|
||||
}
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.executes(context -> {
|
||||
sendHelpMessage(context.getSource());
|
||||
return 1;
|
||||
});
|
||||
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("silentjoin")
|
||||
.requires(ctx -> ctx.hasPermission("command.chat.silent-join"))
|
||||
.then(serverNode
|
||||
.executes(context -> {
|
||||
if (!(context.getSource() instanceof Player player)) {
|
||||
context.getSource().sendMessage(Utility.parseMiniMessage(Config.NO_CONSOLE));
|
||||
return 1;
|
||||
}
|
||||
if (player.getCurrentServer().isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
String server = context.getArgument("server", String.class);
|
||||
Optional<RegisteredServer> optionalServer = proxyServer.getServer(server);
|
||||
if (optionalServer.isEmpty()) {
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.SILENT_JOIN_NO_SERVER));
|
||||
return 1;
|
||||
}
|
||||
RegisteredServer registeredServer = optionalServer.get();
|
||||
player.sendMessage(Utility.parseMiniMessage(Config.SILENT_JOIN_JOINING,
|
||||
Placeholder.unparsed("server", registeredServer.getServerInfo().getName())));
|
||||
ProxyPlayerListener.addSilentJoin(player.getUniqueId());
|
||||
player.createConnectionRequest(registeredServer);
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.executes(context -> {
|
||||
sendHelpMessage(context.getSource());
|
||||
return 1;
|
||||
})
|
||||
.build();
|
||||
|
||||
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||
|
||||
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||
|
||||
for (String alias : Config.SILENT_JOIN_COMMAND_ALIASES) {
|
||||
metaBuilder.aliases(alias);
|
||||
}
|
||||
|
||||
CommandMeta meta = metaBuilder.build();
|
||||
|
||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||
}
|
||||
|
||||
private void sendHelpMessage(CommandSource commandSource) {
|
||||
|
||||
}
|
||||
|
||||
private void sendAdminHelpMessage(CommandSource commandSource) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
|||
import com.velocitypowered.api.event.player.ServerPostConnectEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
|
|
@ -76,33 +77,59 @@ public class ProxyPlayerListener {
|
|||
//VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
|
||||
private static final HashSet<UUID> silentJoin = new HashSet<>();
|
||||
|
||||
public static void addSilentJoin(UUID uuid)
|
||||
{
|
||||
silentJoin.add(uuid);
|
||||
}
|
||||
|
||||
// Server Join and Leave messages
|
||||
@Subscribe
|
||||
public void serverConnected(ServerConnectedEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
UUID uuid = player.getUniqueId();
|
||||
ServerHandler serverHandler = VelocityChat.getPlugin().getServerHandler();
|
||||
if (event.getPreviousServer().isPresent()) {
|
||||
RegisteredServer previousServer = event.getPreviousServer().get();
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
TagResolver placeholders = TagResolver.resolver(
|
||||
Placeholder.parsed("player", player.getUsername()),
|
||||
Placeholder.parsed("from_server", previousServer.getServerInfo().getName()),
|
||||
Placeholder.parsed("to_server", event.getServer().getServerInfo().getName())
|
||||
);
|
||||
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED_FROM,
|
||||
placeholders);
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player.hasPermission("command.chat.silent-join-notify"))
|
||||
.forEach(player1 -> player1.sendMessage(message));
|
||||
return;
|
||||
}
|
||||
|
||||
ServerWrapper wrapper = serverHandler.getWrapper(previousServer.getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, placeholders));
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGETO, placeholders));
|
||||
}
|
||||
wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, placeholders));
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERSWTICHMESSAGEFROM, placeholders));
|
||||
}
|
||||
} else {
|
||||
if (silentJoin.remove(uuid)) {
|
||||
Component message = Utility.parseMiniMessage(Config.SILENT_JOIN_JOINED,
|
||||
Placeholder.unparsed("player", player.getUsername()));
|
||||
event.getServer().getPlayersConnected().stream()
|
||||
.filter(player1 -> player.hasPermission("command.chat.silent-join-notify"))
|
||||
.forEach(player1 -> player1.sendMessage(message));
|
||||
return;
|
||||
}
|
||||
|
||||
ServerWrapper wrapper = serverHandler.getWrapper(event.getServer().getServerInfo().getName());
|
||||
if(wrapper != null) {
|
||||
wrapper.sendJoinLeaveMessage(event.getPlayer().getUniqueId(), Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, Placeholder.unparsed("player", event.getPlayer().getUsername())));
|
||||
wrapper.sendJoinLeaveMessage(uuid, Utility.parseMiniMessage(Config.SERVERJOINMESSAGE, Placeholder.unparsed("player", player.getUsername())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user