com.destroystokyo.paper.event.server.PaperServerListPingEvent Java Examples
The following examples show how to use
com.destroystokyo.paper.event.server.PaperServerListPingEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExprOnlinePlayersCount.java From Skript with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { PaperServerListPingEvent event = (PaperServerListPingEvent) e; switch (mode) { case SET: event.setNumPlayers(((Number) delta[0]).intValue()); break; case ADD: event.setNumPlayers(event.getNumPlayers() + ((Number) delta[0]).intValue()); break; case REMOVE: event.setNumPlayers(event.getNumPlayers() - ((Number) delta[0]).intValue()); break; case DELETE: case RESET: event.setNumPlayers(PlayerUtils.getOnlinePlayers().size()); } }
Example #2
Source File: ExprServerIcon.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { PaperServerListPingEvent event = (PaperServerListPingEvent) e; switch (mode) { case SET: event.setServerIcon((CachedServerIcon) delta[0]); break; case RESET: event.setServerIcon(Bukkit.getServerIcon()); } }
Example #3
Source File: EffHidePlayerFromServerList.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) || (PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)); if (!isServerPingEvent) { Skript.error("The hide player from server list effect can't be used outside of a server list ping event"); return false; } else if (isDelayed == Kleenean.TRUE) { Skript.error("Can't hide players from the server list anymore after the server list ping event has already passed"); return false; } players = (Expression<Player>) exprs[0]; return true; }
Example #4
Source File: EffPlayerInfoVisibility.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The player info visibility effect requires Paper 1.12.2 or newer"); return false; } else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) { Skript.error("The player info visibility effect can't be used outside of a server list ping event"); return false; } else if (isDelayed == Kleenean.TRUE) { Skript.error("Can't change the player info visibility anymore after the server list ping event has already passed"); return false; } shouldHide = matchedPattern == 0; return true; }
Example #5
Source File: ExprProtocolVersion.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The protocol version expression requires Paper 1.12.2 or newer"); return false; } else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) { Skript.error("The protocol version expression can't be used outside of a server list ping event"); return false; } return true; }
Example #6
Source File: ExprMaxPlayers.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, SkriptParser.ParseResult parseResult) { boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) || (PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)); if (parseResult.mark == 2 && !isServerPingEvent) { Skript.error("The 'shown' max players count expression can't be used outside of a server list ping event"); return false; } isReal = (parseResult.mark == 0 && !isServerPingEvent) || parseResult.mark == 1; return true; }
Example #7
Source File: ExprOnlinePlayersCount.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Number[] get(Event e) { if (isReal) return CollectionUtils.array(PlayerUtils.getOnlinePlayers().size()); else return CollectionUtils.array(((PaperServerListPingEvent) e).getNumPlayers()); }
Example #8
Source File: ExprOnlinePlayersCount.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { boolean isPaperEvent = PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class); if (parseResult.mark == 2) { if (ScriptLoader.isCurrentEvent(ServerListPingEvent.class)) { Skript.error("The 'fake' online players count expression requires Paper 1.12.2 or newer"); return false; } else if (!isPaperEvent) { Skript.error("The 'fake' online players count expression can't be used outside of a server list ping event"); return false; } } isReal = (parseResult.mark == 0 && !isPaperEvent) || parseResult.mark == 1; return true; }
Example #9
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { List<PlayerProfile> values = new ArrayList<>(); if (mode != ChangeMode.DELETE && mode != ChangeMode.RESET) { for (Object o : delta) { if (o instanceof Player) { Player player = ((Player) o); values.add(Bukkit.createProfile(player.getUniqueId(), player.getName())); } else { values.add(Bukkit.createProfile(UUID.randomUUID(), (String) o)); } } } List<PlayerProfile> sample = ((PaperServerListPingEvent) e).getPlayerSample(); switch (mode){ case SET: sample.clear(); sample.addAll(values); break; case ADD: sample.addAll(values); break; case REMOVE: sample.removeAll(values); break; case DELETE: case RESET: sample.clear(); } }
Example #10
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public String[] get(Event e) { return ((PaperServerListPingEvent) e).getPlayerSample().stream() .map(PlayerProfile::getName) .toArray(String[]::new); }
Example #11
Source File: ExprHoverList.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The hover list expression requires Paper 1.12.2 or newer"); return false; } else if (!ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)) { Skript.error("The hover list expression can't be used outside of a server list ping event"); return false; } return true; }
Example #12
Source File: ExprServerIcon.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public CachedServerIcon[] get(Event e) { CachedServerIcon icon = null; if ((isServerPingEvent && !isDefault) && PAPER_EVENT_EXISTS) icon = ((PaperServerListPingEvent) e).getServerIcon(); else icon = Bukkit.getServerIcon(); if (icon == null || icon.getData() == null) return null; return CollectionUtils.array(icon); }
Example #13
Source File: ExprServerIcon.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (!PAPER_EVENT_EXISTS) { Skript.error("The server icon expression requires Paper 1.12.2 or newer"); return false; } isServerPingEvent = ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class); isDefault = (parseResult.mark == 0 && !isServerPingEvent) || parseResult.mark == 1; if (!isServerPingEvent && !isDefault) { Skript.error("The 'shown' server icon expression can't be used outside of a server list ping event"); return false; } return true; }
Example #14
Source File: PaperPingResponseHandler.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override public ServerPingResponseEvent createResponse(Connection connection) { PaperServerListPingEvent bevent = new PaperServerListPingEvent( new StatusClientImpl(connection), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers(), createServerVersionString(), connection.getVersion().getId(), Bukkit.getServerIcon() ); List<PlayerProfile> playerSample = bevent.getPlayerSample(); Bukkit.getOnlinePlayers().stream() .limit(SpigotConfig.playerSample) .map(player -> new NameUUIDPlayerProfile(player.getUniqueId(), player.getName())) .forEach(playerSample::add); Bukkit.getPluginManager().callEvent(bevent); ServerPingResponseEvent revent = new ServerPingResponseEvent( connection, new ProtocolInfo(bevent.getProtocolVersion(), bevent.getVersion()), bevent.getServerIcon() != null ? ServerPlatform.get().getMiscUtils().convertBukkitIconToBase64(bevent.getServerIcon()) : null, bevent.getMotd(), bevent.getNumPlayers(), bevent.getMaxPlayers(), bevent.getPlayerSample().stream().map(PlayerProfile::getName).collect(Collectors.toList()) ); Bukkit.getPluginManager().callEvent(revent); return revent; }
Example #15
Source File: ExprVersionString.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { if (ScriptLoader.isCurrentEvent(ServerListPingEvent.class)) { Skript.error("The version string expression requires Paper 1.12.2 or newer"); return false; } else if (!(PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class))) { Skript.error("The version string expression can't be used outside of a server list ping event"); return false; } return true; }
Example #16
Source File: ExprIP.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"null", "unchecked"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { isProperty = matchedPattern < 2; isConnectEvent = ScriptLoader.isCurrentEvent(PlayerLoginEvent.class); boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) || (PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)); if (isProperty) { players = (Expression<Player>) exprs[0]; } else if (!isConnectEvent && !isServerPingEvent) { Skript.error("You must specify players whose IP addresses to get outside of server list ping and connect events."); return false; } return true; }
Example #17
Source File: ExprMOTD.java From Skript with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings({"unchecked", "null"}) @Override public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { boolean isServerPingEvent = ScriptLoader.isCurrentEvent(ServerListPingEvent.class) || (PAPER_EVENT_EXISTS && ScriptLoader.isCurrentEvent(PaperServerListPingEvent.class)); if (parseResult.mark == 2 && !isServerPingEvent) { Skript.error("The 'shown' MOTD expression can't be used outside of a server list ping event"); return false; } isDefault = (parseResult.mark == 0 && !isServerPingEvent) || parseResult.mark == 1; return true; }
Example #18
Source File: PaperEventHandler.java From ServerListPlus with GNU General Public License v3.0 | 5 votes |
@Override @EventHandler public void onServerListPing(ServerListPingEvent event) { if (event instanceof PaperServerListPingEvent) { handlePaperServerListPing((PaperServerListPingEvent) event); } else { // Still handle events that don't implement PaperServerListPingEvent super.onServerListPing(event); } }
Example #19
Source File: PaperLegacyStatusClient.java From Kettle with GNU General Public License v3.0 | 5 votes |
public static PaperServerListPingEvent processRequest(MinecraftServer server, InetSocketAddress address, int protocolVersion, @Nullable InetSocketAddress virtualHost) { PaperServerListPingEvent event = new PaperServerListPingEventImpl(server, new PaperLegacyStatusClient(address, protocolVersion, virtualHost), Byte.MAX_VALUE, null); server.server.getPluginManager().callEvent(event); if (event.isCancelled()) { return null; } return event; }
Example #20
Source File: PaperEventHandler.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
private void handlePaperServerListPing(final PaperServerListPingEvent event) { if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet StatusRequest request = bukkit.getCore().createRequest(event.getAddress()); request.setProtocolVersion(event.getClient().getProtocolVersion()); InetSocketAddress host = event.getClient().getVirtualHost(); if (host != null) { request.setTarget(host); } StatusResponse response = request.createResponse(bukkit.getCore().getStatus(), // Return unknown player counts if it has been hidden new ResponseFetcher() { @Override public Integer getOnlinePlayers() { return event.shouldHidePlayers() ? null : event.getNumPlayers(); } @Override public Integer getMaxPlayers() { return event.shouldHidePlayers() ? null : event.getMaxPlayers(); } @Override public int getProtocolVersion() { return event.getProtocolVersion(); } } ); // Description String message = response.getDescription(); if (message != null) event.setMotd(message); // Version name message = response.getVersion(); if (message != null) event.setVersion(message); // Protocol version Integer protocol = response.getProtocolVersion(); if (protocol != null) event.setProtocolVersion(protocol); if (response.hidePlayers()) { event.setHidePlayers(true); } else { // Online players Integer count = response.getOnlinePlayers(); if (count != null) event.setNumPlayers(count); // Max players count = response.getMaxPlayers(); if (count != null) event.setMaxPlayers(count); // Player hover message = response.getPlayerHover(); if (message != null) { List<PlayerProfile> profiles = event.getPlayerSample(); profiles.clear(); if (!message.isEmpty()) { if (response.useMultipleSamples()) { count = response.getDynamicSamples(); List<String> lines = count != null ? Helper.splitLinesCached(message, count) : Helper.splitLinesCached(message); for (String line : lines) { profiles.add(bukkit.getServer().createProfile(line)); } } else { profiles.add(bukkit.getServer().createProfile(message)); } } } } // Favicon FaviconSource favicon = response.getFavicon(); if (favicon != null) { CachedServerIcon icon = bukkit.getFavicon(favicon); if (icon != null) try { event.setServerIcon(icon); } catch (UnsupportedOperationException ignored) {} } }
Example #21
Source File: EffPlayerInfoVisibility.java From Skript with GNU General Public License v3.0 | 4 votes |
@Override protected void execute(Event e) { ((PaperServerListPingEvent) e).setHidePlayers(shouldHide); }
Example #22
Source File: ExprProtocolVersion.java From Skript with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { ((PaperServerListPingEvent) e).setProtocolVersion(((Number) delta[0]).intValue()); }
Example #23
Source File: ExprProtocolVersion.java From Skript with GNU General Public License v3.0 | 4 votes |
@Override @Nullable public Number[] get(Event e) { return CollectionUtils.array(((PaperServerListPingEvent) e).getProtocolVersion()); }
Example #24
Source File: ExprVersionString.java From Skript with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("null") @Override public void change(Event e, @Nullable Object[] delta, ChangeMode mode) { ((PaperServerListPingEvent) e).setVersion(((String) delta[0])); }
Example #25
Source File: ExprVersionString.java From Skript with GNU General Public License v3.0 | 4 votes |
@Override @Nullable public String[] get(Event e) { return CollectionUtils.array(((PaperServerListPingEvent) e).getVersion()); }
Example #26
Source File: PaperLegacyStatusClient.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static String getUnformattedMotd(PaperServerListPingEvent event) { // Strip color codes and all other occurrences of the color char (because it's used as delimiter) return getFirstLine(StringUtils.remove(ChatColor.stripColor(event.getMotd()), ChatColor.COLOR_CHAR)); }
Example #27
Source File: PaperLegacyStatusClient.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static String getMotd(PaperServerListPingEvent event) { return getFirstLine(event.getMotd()); }