Knowing when a player joins, if he has joined a forced-host or not.

Discussion in 'BungeeCord Plugin Development' started by Jerod5, Jul 5, 2013.

  1. I am creating a mini games network and I am redirecting players into games but would also like to put a build/factions server under the same BungeeCord server. How would I know if the player joined a forced-host compared to just joining the the regular host?
     
  2. I would try to compare the server name, to that the player joined, is equal to your lobby server name....
    Code (Text):
    @EventHandler
    public void onPlayerJoin(PostLoginEvent event){
      if (event.getPlayer().getServer().getInfo().getName().equals("lobby")){
            //Not forced host/default server
      }else{
           //Maybe forced host
      }
    }    
    €: You should use force_default_server: true
     
    #2 MisterErwin, Jul 5, 2013
    Last edited: Jul 5, 2013
  3. Isn't the login prior to the player being put into a game?
     
  4. Into a game => switching server?

    No - There's a ServerSwitchEvent.

    And at the end are you checking i the player is connecting to the lobby server=> no forced-host / lobby.domain.tld or if he joins a server directly without the lobby server.
     
  5. Ok ill try it a see where I can get. Thanks for your help so far!
     
  6. I tried what you said, to get the server the player is connecting to from the PostLoginEvent.

    Code (Text):
    @EventHandler
    public void onPlayerLogin(PostLoginEvent event){
        this.getProxy().getLogger().log(Level.INFO, event.getPlayer().getServer().getInfo().getName());
    }
    And got a NPE from getting the server from the ProxiedPlayer.

    Could I find the ip the player connected to from the pending connection of the player?
     

  7. Dammit - The server isn't actually on a server - try to use the ServerConnectedEvent AND the event.getServer() - This 'll return the server the player is going to connect.
    Code (Text):
    @EventHandler
    public void onPlayerJoin(ServerConnectedEvent event){
        if (event.getServer().getInfo().getName().equals("lobby")){
          event.getPlayer().sendMessage("Lobby!");
      }else{
        event.getPlayer().sendMessage("Forced host: " + event.getPlayer().getServer().getInfo().getName());
     
      }
    }  
     
  8. I figured it out,
    -To find the Ip the ProxiedPlayer connected through is:
    Code (Text):
    event.getPlayer().getPendingConnection().getVirtualHost().getHostString()
    -To find what the ForcedHosts are on the server is a little more tricky, you have to first find the ListenerInfo of the server and then get the ForcedHost of them... It is a lot easier to explain in code.
    Code (Text):
    package com.Test;
     
    import java.util.HashMap;
    import java.util.Map.Entry;
    import net.md_5.bungee.api.config.ListenerInfo;
    import net.md_5.bungee.api.event.PostLoginEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.api.plugin.Plugin;
    import net.md_5.bungee.event.EventHandler;
     
    public class BungeeCordForcedHostTest extends Plugin implements Listener{
        /*
        * KEY: ForcedHost
        * VALUE: Server the ForceHost points to
        */
        public static HashMap<String, String> forcedhosts = new HashMap<String, String>();
     
        public void onEnable(){
            this.getProxy().getPluginManager().registerListener(this, this);
       
            //Loop through the ListenerInfos of the Server
            for(ListenerInfo li : this.getProxy().getConfigurationAdapter().getListeners()){
                //Loop through the ForcedHosts of Each ListenerInfo
                for(Entry<String, String> host : li.getForcedHosts().entrySet()){
                    //Store the ForcedHosts and what server they point to
                    forcedhosts.put(host.getKey().toLowerCase(), host.getValue().toLowerCase());
                }
            }
        }
     
        @EventHandler
        public void onPlayerLogin(PostLoginEvent event){
            if(forcedhosts.containsKey(event.getPlayer().getPendingConnection()
                    .getVirtualHost().getHostString().toLowerCase())){
                //Connected through a forced host
            }else{
                //Connected another way
            }
        }
     
    }
     
    Thanks again for your help MisterErwin.
     
    #8 Jerod5, Jul 5, 2013
    Last edited: Jul 5, 2013
    • Like Like x 1
    • Informative Informative x 1
    • Useful Useful x 1
  9. Jerod5: ok.... I think that's the more flexibel way;)

    And your welcome