Rename Player if already online

Discussion in 'Spigot Plugin Help' started by xprtnwork, Mar 29, 2020.

  1. Hello Spigot Community,

    (I think i joined the wrong forum, am making a craftbukkit plugin, couldnt fint the right topic)

    What i want to achieve is so that one account can connect multiple times, to achieve playing with a friend on the same account on one server by renaming the second Player.
    (Already set online-mode to false)

    Code (Java):

    public void onPlayerLogin(PlayerLoginEvent event)
        Player login_player = event.getPlayer();
        boolean is_already_online = false;
        String original_name = login_player.getName();

        getLogger().info("Player " + original_name + " joined the server!");

        for(Player connected_player : Bukkit.getOnlinePlayers()){
                is_already_online = true;
                getLogger().info(original_name + " is already online!");

        if (is_already_online) { // Rename Player
            getLogger().info("[MultiACC] Renaming Player: " + original_name + "[MULTI]");
            login_player.setDisplayName(original_name + "[MULTI]");
            login_player.setCustomName(original_name + "[MULTI]");
            login_player.setPlayerListName(original_name + "[MULTI]");
        } else { // Restore Original Name, to be sure there is no [MULTI] on the first one
    But as you maybe already know, it doesnt work the way i thought.
    Before the Client gets renamed, the first client gets kicked.

    Any suggestions and tips on how i could achieve that are welcome.
    (Or if it even is possible)

    Greets, xprtnwork
    #1 xprtnwork, Mar 29, 2020
    Last edited: Mar 29, 2020