|
41 | 41 | import net.md_5.bungee.api.config.ServerInfo; |
42 | 42 | import net.md_5.bungee.api.connection.PendingConnection; |
43 | 43 | import net.md_5.bungee.api.connection.ProxiedPlayer; |
| 44 | +import net.md_5.bungee.api.event.AsyncEvent; |
44 | 45 | import net.md_5.bungee.api.event.LoginEvent; |
45 | 46 | import net.md_5.bungee.api.event.PlayerDisconnectEvent; |
46 | 47 | import net.md_5.bungee.api.event.ProxyPingEvent; |
@@ -211,13 +212,6 @@ public int getProtocolVersion() { |
211 | 212 | if (protocol != null) version.setProtocol(protocol); |
212 | 213 | } |
213 | 214 |
|
214 | | - // Favicon |
215 | | - FaviconSource favicon = response.getFavicon(); |
216 | | - if (favicon != null) { |
217 | | - Optional<Favicon> icon = faviconCache.getUnchecked(favicon); |
218 | | - if (icon.isPresent()) ping.setFavicon(icon.get()); |
219 | | - } |
220 | | - |
221 | 215 | if (players != null) { |
222 | 216 | if (response.hidePlayers()) { |
223 | 217 | ping.setPlayers(null); |
@@ -248,7 +242,49 @@ public int getProtocolVersion() { |
248 | 242 | } |
249 | 243 | } |
250 | 244 | } |
| 245 | + |
| 246 | + // Favicon |
| 247 | + FaviconSource favicon = response.getFavicon(); |
| 248 | + if (favicon != null) { |
| 249 | + Optional<Favicon> icon; |
| 250 | + // Check if instanceof AsyncEvent for compatibility with 1.7.10 |
| 251 | + if (event instanceof AsyncEvent) { |
| 252 | + icon = faviconCache.getIfPresent(favicon); |
| 253 | + } else { |
| 254 | + icon = faviconCache.getUnchecked(favicon); |
| 255 | + } |
| 256 | + |
| 257 | + if (icon == null) { |
| 258 | + // Load favicon asynchronously |
| 259 | + event.registerIntent(BungeePlugin.this); |
| 260 | + getProxy().getScheduler().runAsync(BungeePlugin.this, new AsyncFaviconLoader(event, favicon)); |
| 261 | + } else if (icon.isPresent()) { |
| 262 | + ping.setFavicon(icon.get()); |
| 263 | + } |
| 264 | + } |
| 265 | + } |
| 266 | + } |
| 267 | + |
| 268 | + private final class AsyncFaviconLoader implements Runnable { |
| 269 | + |
| 270 | + private final ProxyPingEvent event; |
| 271 | + private final FaviconSource source; |
| 272 | + |
| 273 | + private AsyncFaviconLoader(ProxyPingEvent event, FaviconSource source) { |
| 274 | + this.event = event; |
| 275 | + this.source = source; |
251 | 276 | } |
| 277 | + |
| 278 | + @Override |
| 279 | + public void run() { |
| 280 | + Optional<Favicon> favicon = faviconCache.getUnchecked(this.source); |
| 281 | + if (favicon.isPresent()) { |
| 282 | + event.getResponse().setFavicon(favicon.get()); |
| 283 | + } |
| 284 | + |
| 285 | + event.completeIntent(BungeePlugin.this); |
| 286 | + } |
| 287 | + |
252 | 288 | } |
253 | 289 |
|
254 | 290 | @Override |
|
0 commit comments