Class Server

java.lang.Object
java.lang.Thread
dev.forbit.server.abstracts.Server
All Implemented Interfaces:
ServerInterface, Runnable
Direct Known Subclasses:
GSONServer, RawServer

public abstract class Server extends Thread implements ServerInterface
Base Server class that defines common methods and functionality for all server types. For implementation see RawServer or GSONServer
  • Constructor Details

    • Server

      public Server()
  • Method Details

    • init

      public void init()
      Description copied from interface: ServerInterface
      Method called when booting up the server.

      Use this to start the thread if your server is extending Thread

      Specified by:
      init in interface ServerInterface
    • shutdown

      public void shutdown()
      Description copied from interface: ServerInterface
      Shutdown all the servers.
      Specified by:
      shutdown in interface ServerInterface
    • updateClients

      public void updateClients()
      Description copied from interface: ServerInterface
      Update the client set, removing inactive clients if required.
      Specified by:
      updateClients in interface ServerInterface
    • getClient

      public Optional<Client> getClient(UUID id)
      Description copied from interface: ServerInterface
      Get client from a given UUID
      Specified by:
      getClient in interface ServerInterface
      Parameters:
      id - the id of the client
      Returns:
      optional containing the client, or empty if it cannot be found
    • getClient

      public Optional<Client> getClient(SocketChannel channel)
      Description copied from interface: ServerInterface
      Get the client from a given SocketChannel.
      Specified by:
      getClient in interface ServerInterface
      Parameters:
      channel - the channel of the client
      Returns:
      optional containing the client, or empty if it cannot be found
    • getClient

      public Optional<Client> getClient(SocketAddress address)
      Description copied from interface: ServerInterface
      Get the client from a given SocketAddress.
      Specified by:
      getClient in interface ServerInterface
      Parameters:
      address - the adress of the client.
      Returns:
      optional containing the client, or empty if it cannot be found.
    • removeClient

      public boolean removeClient(Client client)
      Description copied from interface: ServerInterface
      Remove the client from the Server's list.
      Specified by:
      removeClient in interface ServerInterface
      Parameters:
      client - the client to remove
      Returns:
      whether or not the client was actually in the list.
    • addClient

      public void addClient(Client client)
      Description copied from interface: ServerInterface
      Adds a client to this list.
      Specified by:
      addClient in interface ServerInterface
      Parameters:
      client - the client to add
    • sendPacketTCP

      public void sendPacketTCP(Client client, Packet packet)
      Description copied from interface: ServerInterface
      Send a packet to the client.

      Defaults to TCP.

      Specified by:
      sendPacketTCP in interface ServerInterface
      Parameters:
      client - client
      packet - packet.
    • sendPacketUDP

      public void sendPacketUDP(Client client, Packet packet)
      Specified by:
      sendPacketUDP in interface ServerInterface
    • getScheduler

      public Optional<Scheduler> getScheduler()
      Description copied from interface: ServerInterface
      Returns the scheduler object, or optional.null if not created yet
      Specified by:
      getScheduler in interface ServerInterface
      Returns:
      scheduler
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • forceDisconnect

      public void forceDisconnect(Client client)
      Override this for custom force disconnect behaviour