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());
}
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);
}
}
}
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));
}
}
}
Aggregations