diff --git a/src/main/java/de/strifel/VTools/listeners/GlobalChat.java b/src/main/java/de/strifel/VTools/listeners/GlobalChat.java index 7dc4c60..4954a8b 100644 --- a/src/main/java/de/strifel/VTools/listeners/GlobalChat.java +++ b/src/main/java/de/strifel/VTools/listeners/GlobalChat.java @@ -39,6 +39,8 @@ public class GlobalChat { } } } - TGBridge.INSTANCE.outbound(String.format("[%s] <%s> %s", senderServer == null ? "null" : senderServer.getServerInfo().getName(), event.getPlayer().getUsername(), event.getMessage())); + if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge")) { + TGBridge.INSTANCE.outbound(String.format("[%s] <%s> %s", senderServer == null ? "null" : senderServer.getServerInfo().getName(), event.getPlayer().getUsername(), event.getMessage())); + } } } diff --git a/src/main/java/de/strifel/VTools/listeners/TGBridge.java b/src/main/java/de/strifel/VTools/listeners/TGBridge.java index 3a54e71..fe992aa 100644 --- a/src/main/java/de/strifel/VTools/listeners/TGBridge.java +++ b/src/main/java/de/strifel/VTools/listeners/TGBridge.java @@ -1,9 +1,11 @@ package de.strifel.VTools.listeners; +import com.google.common.collect.ImmutableList; import com.pengrad.telegrambot.Callback; import com.pengrad.telegrambot.TelegramBot; import com.pengrad.telegrambot.UpdatesListener; import com.pengrad.telegrambot.model.Update; +import com.pengrad.telegrambot.model.User; import com.pengrad.telegrambot.request.SendMessage; import com.pengrad.telegrambot.response.SendResponse; import com.velocitypowered.api.event.Subscribe; @@ -12,6 +14,7 @@ import com.velocitypowered.api.event.player.ServerConnectedEvent; import com.velocitypowered.api.event.proxy.ProxyShutdownEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; import de.strifel.VTools.VTools; import net.kyori.adventure.text.Component; import org.yaml.snakeyaml.Yaml; @@ -21,7 +24,10 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class TGBridge { private final VTools plugin; @@ -79,11 +85,45 @@ public class TGBridge { update.message() != null && update.message().chat() != null && update.message().chat().id() == CHAT_ID && - update.message().text() != null && - !update.message().text().isEmpty() && update.message().from() != null ) { - inbound(String.format("[tg] <%s> %s", update.message().from().lastName() == null ? update.message().from().firstName(): String.format("%s %s", update.message().from().firstName(), update.message().from().lastName()), update.message().text())); + if (update.message().text() != null && !update.message().text().isEmpty()) { + String msg = update.message().text(); + if (msg.equals("/list")) { + ArrayList out = new ArrayList<>(); + String fmt = server.getAllPlayers().size() > 1 ? "%d players are currently connected to the proxy." : "%d player is currently connected to the proxy."; + out.add(String.format(fmt, server.getAllPlayers().size())); + List servers = new ArrayList<>(server.getAllServers()); + for (RegisteredServer server : servers) { + List onServer = ImmutableList.copyOf(server.getPlayersConnected()); + if (!onServer.isEmpty()) { + out.add(String.format("[%s] (%d): %s", + server.getServerInfo().getName(), + onServer.size(), + onServer.stream().map(Player::getUsername).collect(Collectors.joining(", "))) + ); + + } + } + outbound(String.join("\n", out)); + } + tgInbound(update.message().from(), msg); + } + else if (update.message().sticker() != null) { + tgInbound(update.message().from(), "[sticker]"); + } + else if (update.message().photo() != null) { + tgInbound(update.message().from(), "[photo]"); + } + else if (update.message().audio() != null) { + tgInbound(update.message().from(), "[audio]"); + } + else if (update.message().voice() != null) { + tgInbound(update.message().from(), "[voice]"); + } + else if (update.message().document() != null) { + tgInbound(update.message().from(), "[document]"); + } } } catch (Exception e) { @@ -102,6 +142,10 @@ public class TGBridge { }); } + protected void tgInbound(User user, String content) { + inbound(String.format("[tg] <%s> %s", user.lastName() == null ? user.firstName() : String.format("%s %s", user.firstName(), user.lastName()), content)); + } + protected void inbound(String content) { for (Player player : server.getAllPlayers()) { if (player.getCurrentServer().isPresent()) { @@ -140,12 +184,16 @@ public class TGBridge { @Subscribe public void onServerConnected(ServerConnectedEvent event) { if (event.getPreviousServer().isEmpty()) { - outbound(String.format("%s joined the proxy", event.getPlayer().getUsername())); + if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { + outbound(String.format("%s joined the proxy", event.getPlayer().getUsername())); + } } } @Subscribe public void onDisconnect(DisconnectEvent event) { - outbound(String.format("%s left the proxy", event.getPlayer().getUsername())); + if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { + outbound(String.format("%s left the proxy", event.getPlayer().getUsername())); + } } }