Пожалуйста, расскажи как работает плагин на личные сообщения сквозь свзяку серверов…
- User
Пожалуйста, расскажи как работает плагин на личные сообщения сквозь свзяку серверов Velocity в Minecraft. Вот код в Commands.java: import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.server.RegisteredServer; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.minimessage.MiniMessage;
import java.util.*; import java.util.stream.Collectors;
public class Commands {
codeprivate static final Map<Player, Player> lastMessaged = new HashMap<>(); private static final MiniMessage miniMessage = MiniMessage.miniMessage(); private static final Random random = new Random(); public static class MsgCommand implements SimpleCommand { private final ProxyServer server; public MsgCommand(ProxyServer server) { this.server = server; } @Override public void execute(Invocation invocation) { CommandSource source = invocation.source(); String[] args = invocation.arguments(); if (args.length < 2) { source.sendMessage(Component.text("Usage: /msg <selector> <message>", NamedTextColor.RED)); return; } String selector = args[0]; String message = String.join(" ", Arrays.copyOfRange(args, 1, args.length)); List<Player> targets = resolveSelector(selector, source); if (targets.isEmpty()) { source.sendMessage(Component.text("Player not found.", NamedTextColor.RED)); return; } for (Player target : targets) { if (source instanceof Player playerSource) { lastMessaged.put(target, playerSource); lastMessaged.put(playerSource, target); } String formattedMsgTo = "<#ff6f00>[MSG To] <dark_gray>•</dark_gray> <white>" + target.getUsername() + "</white> <#ff6f00>" + message; String formattedMsgFrom = "<#ff6f00>[MSG From] <dark_gray>•</dark_gray> <white>" + (source instanceof Player ? ((Player) source).getUsername() : "<bold>Server</bold>") + "</white> <#ff6f00>" + message; source.sendMessage(miniMessage.deserialize(formattedMsgTo)); target.sendMessage(miniMessage.deserialize(formattedMsgFrom)); } } @Override public List<String> suggest(Invocation invocation) { String[] args = invocation.arguments(); List<String> suggestions = new ArrayList<>(); if (args.length == 0 || args.length == 1) { suggestions.add("@a"); suggestions.add("@r"); suggestions.add("@s"); CommandSource finalSource = invocation.source(); suggestions.addAll(server.getAllPlayers().stream() .map(Player::getUsername) - Assistant