Search in sources :

Example 1 with SyncProxyMotd

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd in project CloudNet-v3 by CloudNetService.

the class ProxySPExample method changeLocalMOTD.

/**
 * Changes the MOTD for the group of the current proxy
 */
public void changeLocalMOTD() {
    SyncProxyProxyLoginConfiguration loginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    loginConfiguration.setMotds(Collections.singletonList(new SyncProxyMotd("Welcome to my server!", "You'll connect to %proxy%", true, 1, new String[0], null)));
    // updating in cluster
    SyncProxyConfiguration.updateSyncProxyConfigurationInNetwork(this.syncProxyManagement.getSyncProxyConfiguration());
}
Also used : SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration)

Example 2 with SyncProxyMotd

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd in project CloudNet-v3 by CloudNetService.

the class BungeeSyncProxyPlayerListener method handle.

@EventHandler
public void handle(ProxyPingEvent event) {
    SyncProxyProxyLoginConfiguration syncProxyProxyLoginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    if (syncProxyProxyLoginConfiguration != null) {
        SyncProxyMotd syncProxyMotd = this.syncProxyManagement.getRandomMotd();
        if (syncProxyMotd != null) {
            String protocolText = syncProxyMotd.getProtocolText();
            String motd = ChatColor.translateAlternateColorCodes('&', syncProxyMotd.getFirstLine() + "\n" + syncProxyMotd.getSecondLine()).replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId());
            int onlinePlayers = this.syncProxyManagement.getSyncProxyOnlineCount();
            int maxPlayers = syncProxyMotd.isAutoSlot() ? Math.min(this.syncProxyManagement.getLoginConfiguration().getMaxPlayers(), onlinePlayers + syncProxyMotd.getAutoSlotMaxPlayersDistance()) : this.syncProxyManagement.getLoginConfiguration().getMaxPlayers();
            ServerPing.PlayerInfo[] playerInfo = new ServerPing.PlayerInfo[syncProxyMotd.getPlayerInfo() != null ? syncProxyMotd.getPlayerInfo().length : 0];
            for (int i = 0; i < playerInfo.length; i++) {
                playerInfo[i] = new ServerPing.PlayerInfo(ChatColor.translateAlternateColorCodes('&', syncProxyMotd.getPlayerInfo()[i]), UUID.randomUUID().toString());
            }
            ServerPing serverPing = new ServerPing(new ServerPing.Protocol(ChatColor.translateAlternateColorCodes('&', (protocolText == null ? event.getResponse().getVersion().getName() : protocolText).replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId()).replace("%online_players%", String.valueOf(onlinePlayers)).replace("%max_players%", String.valueOf(maxPlayers))), (protocolText == null ? event.getResponse().getVersion().getProtocol() : 1)), new ServerPing.Players(maxPlayers, onlinePlayers, playerInfo), new TextComponent(TextComponent.fromLegacyText(motd)), event.getResponse().getFaviconObject());
            event.setResponse(serverPing);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) ServerPing(net.md_5.bungee.api.ServerPing) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with SyncProxyMotd

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd in project CloudNet-v3 by CloudNetService.

the class VelocitySyncProxyPlayerListener method handle.

@Subscribe
public void handle(ProxyPingEvent event) {
    SyncProxyProxyLoginConfiguration syncProxyProxyLoginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    if (syncProxyProxyLoginConfiguration != null) {
        SyncProxyMotd syncProxyMotd = this.syncProxyManagement.getRandomMotd();
        if (syncProxyMotd != null) {
            int onlinePlayers = this.syncProxyManagement.getSyncProxyOnlineCount();
            int maxPlayers = syncProxyMotd.isAutoSlot() ? Math.min(this.syncProxyManagement.getLoginConfiguration().getMaxPlayers(), onlinePlayers + syncProxyMotd.getAutoSlotMaxPlayersDistance()) : this.syncProxyManagement.getLoginConfiguration().getMaxPlayers();
            event.setPing(new ServerPing(syncProxyMotd.getProtocolText() != null ? new ServerPing.Version(1, syncProxyMotd.getProtocolText().replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId()).replace("%online_players%", String.valueOf(onlinePlayers)).replace("%max_players%", String.valueOf(maxPlayers)).replace("&", "§")) : event.getPing().getVersion(), new ServerPing.Players(onlinePlayers, maxPlayers, syncProxyMotd.getPlayerInfo() != null ? Arrays.stream(syncProxyMotd.getPlayerInfo()).map(s -> new ServerPing.SamplePlayer(s.replace("&", "§"), UUID.randomUUID())).collect(Collectors.toList()) : Collections.EMPTY_LIST), LegacyComponentSerializer.legacyLinking().deserialize((syncProxyMotd.getFirstLine() + "\n" + syncProxyMotd.getSecondLine()).replace("%proxy%", Wrapper.getInstance().getServiceId().getName()).replace("%proxy_uniqueId%", String.valueOf(Wrapper.getInstance().getServiceId().getUniqueId())).replace("%task%", Wrapper.getInstance().getServiceId().getTaskName()).replace("%node%", Wrapper.getInstance().getServiceId().getNodeUniqueId()).replace("&", "§")), event.getPing().getFavicon().isPresent() ? event.getPing().getFavicon().get() : null, event.getPing().getModinfo().isPresent() ? event.getPing().getModinfo().get() : null));
        }
    }
}
Also used : Arrays(java.util.Arrays) Wrapper(de.dytanic.cloudnet.wrapper.Wrapper) SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) VelocitySyncProxyManagement(de.dytanic.cloudnet.ext.syncproxy.velocity.VelocitySyncProxyManagement) ProxyPingEvent(com.velocitypowered.api.event.proxy.ProxyPingEvent) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) ServerConnectedEvent(com.velocitypowered.api.event.player.ServerConnectedEvent) Subscribe(com.velocitypowered.api.event.Subscribe) LoginEvent(com.velocitypowered.api.event.connection.LoginEvent) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) Collections(java.util.Collections) LegacyComponentSerializer(net.kyori.text.serializer.legacy.LegacyComponentSerializer) SyncProxyMotd(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) ServerPing(com.velocitypowered.api.proxy.server.ServerPing) Subscribe(com.velocitypowered.api.event.Subscribe)

Aggregations

SyncProxyMotd (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd)3 SyncProxyProxyLoginConfiguration (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration)3 Subscribe (com.velocitypowered.api.event.Subscribe)1 LoginEvent (com.velocitypowered.api.event.connection.LoginEvent)1 ServerConnectedEvent (com.velocitypowered.api.event.player.ServerConnectedEvent)1 ProxyPingEvent (com.velocitypowered.api.event.proxy.ProxyPingEvent)1 ServerPing (com.velocitypowered.api.proxy.server.ServerPing)1 VelocitySyncProxyManagement (de.dytanic.cloudnet.ext.syncproxy.velocity.VelocitySyncProxyManagement)1 Wrapper (de.dytanic.cloudnet.wrapper.Wrapper)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 LegacyComponentSerializer (net.kyori.text.serializer.legacy.LegacyComponentSerializer)1 ServerPing (net.md_5.bungee.api.ServerPing)1 TextComponent (net.md_5.bungee.api.chat.TextComponent)1 EventHandler (net.md_5.bungee.event.EventHandler)1