Search in sources :

Example 1 with SyncProxyProxyLoginConfiguration

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

the class ProxySPExample method changeLocalMaintenance.

/**
 * Actives maintenance for the group of the current proxy
 */
public void changeLocalMaintenance() {
    SyncProxyProxyLoginConfiguration loginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    loginConfiguration.setMaintenance(true);
    // updating in cluster
    SyncProxyConfiguration.updateSyncProxyConfigurationInNetwork(this.syncProxyManagement.getSyncProxyConfiguration());
}
Also used : SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration)

Example 2 with SyncProxyProxyLoginConfiguration

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration 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 3 with SyncProxyProxyLoginConfiguration

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration 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 4 with SyncProxyProxyLoginConfiguration

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

the class BungeeSyncProxyPlayerListener method handle.

@EventHandler
public void handle(LoginEvent event) {
    SyncProxyProxyLoginConfiguration syncProxyProxyLoginConfiguration = this.syncProxyManagement.getLoginConfiguration();
    if (syncProxyProxyLoginConfiguration != null) {
        ProxiedPlayer loginProxiedPlayer = new LoginProxiedPlayer(event.getConnection());
        if (syncProxyProxyLoginConfiguration.isMaintenance() && syncProxyProxyLoginConfiguration.getWhitelist() != null) {
            if (syncProxyProxyLoginConfiguration.getWhitelist().contains(event.getConnection().getName())) {
                return;
            }
            UUID uniqueId = loginProxiedPlayer.getUniqueId();
            if ((uniqueId != null && syncProxyProxyLoginConfiguration.getWhitelist().contains(uniqueId.toString())) || loginProxiedPlayer.hasPermission("cloudnet.syncproxy.maintenance")) {
                return;
            }
            event.setCancelled(true);
            event.setCancelReason(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', this.syncProxyManagement.getSyncProxyConfiguration().getMessages().get("player-login-not-whitelisted"))));
            return;
        }
        if (this.syncProxyManagement.getSyncProxyOnlineCount() >= this.syncProxyManagement.getLoginConfiguration().getMaxPlayers() && !loginProxiedPlayer.hasPermission("cloudnet.syncproxy.fulljoin")) {
            event.setCancelled(true);
            event.setCancelReason(TextComponent.fromLegacyText(ChatColor.translateAlternateColorCodes('&', this.syncProxyManagement.getSyncProxyConfiguration().getMessages().getOrDefault("player-login-full-server", "&cThe network is currently full. You need extra permissions to enter the network"))));
        }
    }
}
Also used : LoginProxiedPlayer(de.dytanic.cloudnet.ext.syncproxy.bungee.util.LoginProxiedPlayer) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) LoginProxiedPlayer(de.dytanic.cloudnet.ext.syncproxy.bungee.util.LoginProxiedPlayer) SyncProxyProxyLoginConfiguration(de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration) UUID(java.util.UUID) EventHandler(net.md_5.bungee.event.EventHandler)

Example 5 with SyncProxyProxyLoginConfiguration

use of de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration 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

SyncProxyProxyLoginConfiguration (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyProxyLoginConfiguration)5 SyncProxyMotd (de.dytanic.cloudnet.ext.syncproxy.configuration.SyncProxyMotd)3 UUID (java.util.UUID)2 EventHandler (net.md_5.bungee.event.EventHandler)2 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 LoginProxiedPlayer (de.dytanic.cloudnet.ext.syncproxy.bungee.util.LoginProxiedPlayer)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 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 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1