PlayerServers API Usage and Info »

API JavaDocs


Getting Started »

  1. Install PlayerServers in your local maven repo.
  2. Add it to your pom.xml:

      

        <dependency>
            <groupId>net.cakemine</groupId>
            <artifactId>PlayerServers</artifactId>
            <version>2.0</version>
        </dependency>

      

  3. Get an instance of the API:

     

    PlayerServersApi psApi = PlayerServers.getApi();
    

     


Example API method »

Get an integer for the current server port of a ProxiedPlayer's server:


   

int getPlayerServerPort(ProxiedPlayer player) {
	StoredPlayer stored = PlayerServers.getApi().loadPlayer(player);  // load the player from disk.
        if (stored != null && stored.hasServer()) {  			// check they have been loaded and that they have a server.
            return stored.getServer().getAddress().getPort()		//return their current port number.
        }
        return -1; //return -1 to indicate the port can't be found, since integers can't be null.
}

   

OR (if you've gotten the instance already and set it to a variable like the example above):


    

int getPlayerServerPort(ProxiedPlayer player) {
	StoredPlayer stored = psApi.loadPlayer(player);  	// load the player from disk.
        if (stored != null && stored.hasServer()) {  		// check they have been loaded and that they have a server.
            return stored.getServer().getAddress().getPort()	//return their current port number.
        }
        return -1; //return -1 to indicate the port can't be found, since integers can't be null.
}

    


Example Event »


  

import net.cakemine.playerservers.bungee.events.ServerStartEvent;

public class Listeners implements Listener {

        @EventHandler
        public void onServerStart(ServerStartEvent event) {
                if (true) { //always true, do your own thing here.
                        event.setCancelled(true);  //cancels the server starting event.
                }
        }
}