コード例 #1
0
ファイル: Events.java プロジェクト: BenLoe/BungeePlugins
 @EventHandler
 public void ProxyPing(ProxyPingEvent event) {
   if (newmotd != "unset") {
     ServerPing newPing = event.getResponse();
     newPing.setDescription(newmotd.replaceAll("&", "\u00A7"));
     event.setResponse(newPing);
   }
 }
コード例 #2
0
    @EventHandler
    public void onProxyPing(ProxyPingEvent event) {
      if (event.getResponse() == null) return; // Check if response is not empty

      PendingConnection con = event.getConnection();
      StatusRequest request = core.createRequest(con.getAddress().getAddress());

      request.setProtocolVersion(con.getVersion());
      InetSocketAddress host = con.getVirtualHost();
      if (host != null) {
        ServerInfo forcedHost = AbstractReconnectHandler.getForcedHost(con);
        request.setTarget(host, forcedHost != null ? forcedHost.getName() : null);
      }

      final ServerPing ping = event.getResponse();
      final ServerPing.Players players = ping.getPlayers();
      final ServerPing.Protocol version = ping.getVersion();

      StatusResponse response =
          request.createResponse(
              core.getStatus(),
              // Return unknown player counts if it has been hidden
              new ResponseFetcher() {
                @Override
                public Integer getOnlinePlayers() {
                  return players != null ? players.getOnline() : null;
                }

                @Override
                public Integer getMaxPlayers() {
                  return players != null ? players.getMax() : null;
                }

                @Override
                public int getProtocolVersion() {
                  return version != null ? version.getProtocol() : 0;
                }
              });

      // Description
      String message = response.getDescription();
      if (message != null) ping.setDescription(message);

      if (version != null) {
        // Version name
        message = response.getVersion();
        if (message != null) version.setName(message);
        // Protocol version
        Integer protocol = response.getProtocolVersion();
        if (protocol != null) version.setProtocol(protocol);
      }

      // Favicon
      FaviconSource favicon = response.getFavicon();
      if (favicon != null) {
        Optional<Favicon> icon = faviconCache.getUnchecked(favicon);
        if (icon.isPresent()) ping.setFavicon(icon.get());
      }

      if (players != null) {
        if (response.hidePlayers()) {
          ping.setPlayers(null);
        } else {
          // Online players
          Integer count = response.getOnlinePlayers();
          if (count != null) players.setOnline(count);
          // Max players
          count = response.getMaxPlayers();
          if (count != null) players.setMax(count);

          // Player hover
          message = response.getPlayerHover();
          if (message != null) {
            if (response.useMultipleSamples()) {
              count = response.getDynamicSamples();
              List<String> lines =
                  count != null
                      ? Helper.splitLinesCached(message, count)
                      : Helper.splitLinesCached(message);

              ServerPing.PlayerInfo[] sample = new ServerPing.PlayerInfo[lines.size()];
              for (int i = 0; i < sample.length; i++)
                sample[i] = new ServerPing.PlayerInfo(lines.get(i), StatusManager.EMPTY_UUID);

              players.setSample(sample);
            } else
              players.setSample(
                  new ServerPing.PlayerInfo[] {
                    new ServerPing.PlayerInfo(message, StatusManager.EMPTY_UUID)
                  });
          }
        }
      }
    }