org.bukkit.event.server.ServerListPingEvent Java Examples

The following examples show how to use org.bukkit.event.server.ServerListPingEvent. 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: MOTD.java    From CardinalPGM with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onServerListPing(ServerListPingEvent event) {
    String name = match.getLoadedMap().getName();
    ChatColor color = ChatColor.GRAY;
    switch (match.getState()) {
        case ENDED:
            color = ChatColor.AQUA;
            break;
        case PLAYING:
            color = ChatColor.GOLD;
            break;
        case STARTING:
            color = ChatColor.GREEN;
            break;
    }
    event.setMotd(color + "\u00BB " + ChatColor.AQUA + name + color + " \u00AB" +
            (!Config.motdMessage.equals("") ? "\n" + ChatColor.translateAlternateColorCodes('`', Config.motdMessage) : ""));

}
 
Example #2
Source File: PingListener.java    From SkyWarsReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onPing(final ServerListPingEvent serverListPingEvent) {
    if (SkyWarsReloaded.get().serverLoaded()) {
        if (GameMap.getMaps().size() > 0) {
            GameMap game = GameMap.getMaps().get(0);
            serverListPingEvent.setMotd(new Messaging.MessageFormatter().setVariable("matchstate", game.getMatchState().toString())
                    .setVariable("playercount","" + game.getPlayerCount()).setVariable("maxplayers", "" + game.getMaxPlayers())
                    .setVariable("displayname", game.getDisplayName()).format("bungee.motd"));
        } else {
            serverListPingEvent.setMotd(new Messaging.MessageFormatter().setVariable("matchstate", MatchState.ENDING.toString() )
                    .setVariable("playercount","0").setVariable("maxplayers", "0")
                    .setVariable("displayname", "null").format("bungee.motd"));
        }
    } else {
        serverListPingEvent.setMotd(new Messaging.MessageFormatter().setVariable("matchstate", MatchState.ENDING.toString() )
                .setVariable("playercount","0").setVariable("maxplayers", "0")
                .setVariable("displayname", "null").format("bungee.motd"));
    }
}
 
Example #3
Source File: ExprMaxPlayers.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
	ServerListPingEvent event = (ServerListPingEvent) e;
	switch (mode) {
		case SET:
			event.setMaxPlayers(((Number) delta[0]).intValue());
			break;
		case ADD:
			event.setMaxPlayers(event.getMaxPlayers() + ((Number) delta[0]).intValue());
			break;
		case REMOVE:
			event.setMaxPlayers(event.getMaxPlayers() - ((Number) delta[0]).intValue());
			break;
		case DELETE:
		case RESET:
			event.setMaxPlayers(Bukkit.getMaxPlayers());
	}
}
 
Example #4
Source File: MotdListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerListPing(ServerListPingEvent event) {
  final String format = PGM.get().getConfiguration().getMotd();
  if (format == null || format.isEmpty()) return;

  event.setMotd(MessageFormat.format(format, event.getMotd(), mapName, phaseColor.toString()));
}
 
Example #5
Source File: PaperEventHandler.java    From ServerListPlus with GNU General Public License v3.0 5 votes vote down vote up
@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 #6
Source File: GameListeners.java    From AnnihilationPro with MIT License 5 votes vote down vote up
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void pingServer(ServerListPingEvent event)
{
	if(GameVars.useMOTD())
	{
		if(Game.getGameMap() == null || Game.getGameMap().getCurrentPhase() < 1)
			event.setMotd("In Lobby");
		else event.setMotd("Phase "+Game.getGameMap().getCurrentPhase());
	}
}
 
Example #7
Source File: EffHidePlayerFromServerList.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #8
Source File: ExprMaxPlayers.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
@Nullable
public Number[] get(Event e) {
	if (isReal)
		return CollectionUtils.array(Bukkit.getMaxPlayers());
	else
		return CollectionUtils.array(((ServerListPingEvent) e).getMaxPlayers());
}
 
Example #9
Source File: ExprMaxPlayers.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #10
Source File: ExprOnlinePlayersCount.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #11
Source File: ExprVersionString.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #12
Source File: ExprMOTD.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
public void change(Event e, @Nullable Object[] delta, ChangeMode mode) {
	ServerListPingEvent event = (ServerListPingEvent) e;
	switch (mode) {
		case SET:
			event.setMotd((String) delta[0]);
			break;
		case DELETE:
			event.setMotd("");
			break;
		case RESET:
			event.setMotd(Bukkit.getMotd());
	}
}
 
Example #13
Source File: GeyserBukkitPingPassthrough.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public GeyserPingInfo getPingInformation() {
    try {
        ServerListPingEvent event = new GeyserPingEvent(InetAddress.getLocalHost(), Bukkit.getMotd(), Bukkit.getOnlinePlayers().size(), Bukkit.getMaxPlayers());
        Bukkit.getPluginManager().callEvent(event);
        GeyserPingInfo geyserPingInfo = new GeyserPingInfo(event.getMotd(), event.getNumPlayers(), event.getMaxPlayers());
        Bukkit.getOnlinePlayers().forEach(player -> {
            geyserPingInfo.addPlayer(player.getName());
        });
        return geyserPingInfo;
    } catch (Exception e) {
        logger.debug("Error while getting Bukkit ping passthrough: " + e.toString());
        return new GeyserPingInfo(null, 0, 0);
    }
}
 
Example #14
Source File: ServerPingDataListener.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onServerListPing(ServerListPingEvent event) {
  if (!ready.get() || legacySportPaper.get()) return;

  // Remove vanished players from player sample/ping count
  Iterator<Player> playerSample = event.iterator();
  while (playerSample.hasNext()) {
    Player player = playerSample.next();
    if (vanishManager.isVanished(player.getUniqueId())) {
      playerSample.remove();
    }
  }

  try {
    JsonObject root = event.getOrCreateExtra(PGM.get());
    this.matchManager
        .getMatches()
        .forEachRemaining(
            match -> {
              String matchId = match.getId();
              try {
                root.add(matchId, this.matchCache.get(match));
              } catch (ExecutionException e) {
                this.logger.log(
                    Level.SEVERE, "Could not load server ping data for match: " + matchId, e);
              }
            });
  } catch (NoSuchMethodError ex) {
    legacySportPaper.compareAndSet(false, true);
  }
}
 
Example #15
Source File: PingListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPing(ServerListPingEvent event){
	GameManager gm = GameManager.getGameManager();

	if (gm == null){
		return; // Still loading
	}

	if (gm.getConfiguration().getDisableMotd()){
		return; // No motd support
	}

	// Display motd
	switch(gm.getGameState()){
		case ENDED:
			event.setMotd(Lang.DISPLAY_MOTD_ENDED);
			break;
		case LOADING:
			event.setMotd(Lang.DISPLAY_MOTD_LOADING);
			break;
		case DEATHMATCH:
		case PLAYING:
			event.setMotd(Lang.DISPLAY_MOTD_PLAYING);
			break;
		case STARTING:
			event.setMotd(Lang.DISPLAY_MOTD_STARTING);
			break;
		case WAITING:
			event.setMotd(Lang.DISPLAY_MOTD_WAITING);
			break;
		default:
			event.setMotd(Lang.DISPLAY_MESSAGE_PREFIX);
			break;
	}
}
 
Example #16
Source File: ExprIP.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 vote down vote up
@Override
@Nullable
public String[] get(Event e) {
	if (isDefault)
		return CollectionUtils.array(Bukkit.getMotd());
	else
		return CollectionUtils.array(((ServerListPingEvent) e).getMotd());
}
 
Example #18
Source File: ExprMOTD.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@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 #19
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #20
Source File: BukkitEventHandler.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onServerListPing(final ServerListPingEvent event) {
    if (bukkit.getCore() == null) return; // Too early, we haven't finished initializing yet
    StatusResponse response = bukkit.getCore().createRequest(event.getAddress()).createResponse(
            bukkit.getCore().getStatus(), new ResponseFetcher() {
                @Override
                public Integer getOnlinePlayers() {
                    return event.getNumPlayers();
                }

                @Override
                public Integer getMaxPlayers() {
                    return event.getMaxPlayers();
                }

                @Override
                public int getProtocolVersion() {
                    return -1;
                }
            });

    // Description
    String message = response.getDescription();
    if (message != null)
        event.setMotd(message);

    // Max players
    Integer max = response.getMaxPlayers();
    if (max != null)
        event.setMaxPlayers(max);

    // 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: BungeemodeListener.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onServerListPing(ServerListPingEvent event) {
    BungeemodeConfig config = addon.getConfig();

    if (!config.isEnabled() || !config.isUseMotd()) {
        return;
    }

    if (!addon.getHeavySpleef().isGamesLoaded()) {
        event.setMotd(addon.getI18n().getString(BungeemodeMessages.MOTD_SERVER_STARTING));
        return;
    }

    String gameName = config.getGame();
    GameManager manager = addon.getHeavySpleef().getGameManager();

    if (!manager.hasGame(gameName)) {
        addon.getLogger().log(Level.WARNING, "Cannot handle server list ping: Game " + gameName + " does not exist!");
        return;
    }

    Game game = manager.getGame(gameName);
    String motdKey;

    switch (game.getGameState()) {
        case DISABLED:
            motdKey = BungeemodeMessages.MOTD_DISABLED;
            break;
        case WAITING:
            motdKey = BungeemodeMessages.MOTD_WAITING;
            break;
        case LOBBY:
            motdKey = BungeemodeMessages.MOTD_LOBBY;
            break;
        case STARTING:
        case WARMUP:
            motdKey = BungeemodeMessages.MOTD_COUNTDOWN;
            break;
        case INGAME:
            motdKey = BungeemodeMessages.MOTD_INGAME;
            break;
        default:
            motdKey = BungeemodeMessages.MOTD_UNKNOWN;
            break;
    }

    String motd = addon.getI18n().getString(motdKey);
    event.setMotd(motd);
}
 
Example #22
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Server methods
 */
public static ServerListPingEvent callServerListPingEvent(Server craftServer, InetAddress address, String motd, int numPlayers, int maxPlayers) {
    ServerListPingEvent event = new ServerListPingEvent(address, motd, numPlayers, maxPlayers);
    craftServer.getPluginManager().callEvent(event);
    return event;
}
 
Example #23
Source File: ServerListener.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler
public void onServerListPing(ServerListPingEvent slpe) {
  // Only enabled on bungeecord
  if (!BedwarsRel.getInstance().isBungee()) {
    return;
  }
  if (BedwarsRel.getInstance().getGameManager() == null
      || BedwarsRel.getInstance().getGameManager().getGames() == null
      || BedwarsRel.getInstance().getGameManager().getGames().size() == 0) {
    return;
  }

  Game game = BedwarsRel.getInstance().getGameManager().getGames().get(0);

  if (game == null) {
    return;
  }

  switch (game.getState()) {
    case STOPPED:
      slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
          BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.stopped"))));
      break;
    case WAITING:
      if (game.isFull()) {
        slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
            BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.full"))));
      } else {
        slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
            BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.lobby"))));
      }

      break;
    case RUNNING:
      slpe.setMotd(replacePlaceholder(game, ChatColor.translateAlternateColorCodes('&',
          BedwarsRel.getInstance().getConfig().getString("bungeecord.motds.running"))));
      break;
    default:
      slpe.setMotd(ChatColor.RED + "INVALID GAME STATE!");
      break;
  }
}
 
Example #24
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #25
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #26
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #27
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #28
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #29
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}
 
Example #30
Source File: PingInjector.java    From PingAPI with MIT License 4 votes vote down vote up
/**
 * Injects a DuplexHandler into each NetworkManager's pipeline when the server receives a ping packet
 * @param event The event
 */
@EventHandler
public void serverListPing(ServerListPingEvent event) {
	this.injectOpenConnections();
}