Package dev.forbit.server.abstracts
Class Server
java.lang.Object
java.lang.Thread
dev.forbit.server.abstracts.Server
- All Implemented Interfaces:
ServerInterface,Runnable
- Direct Known Subclasses:
GSONServer,RawServer
Base Server class that defines common methods and functionality for all server types.
For implementation see
RawServer or GSONServer-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a client to this list.voidforceDisconnect(Client client)Override this for custom force disconnect behaviourgetClient(SocketAddress address)Get the client from a given SocketAddress.getClient(SocketChannel channel)Get the client from a given SocketChannel.Get client from a given UUIDReturns the scheduler object, or optional.null if not created yetvoidinit()Method called when booting up the server.booleanremoveClient(Client client)Remove the client from the Server's list.voidrun()voidsendPacketTCP(Client client, Packet packet)Send a packet to the client.voidsendPacketUDP(Client client, Packet packet)voidshutdown()Shutdown all the servers.voidUpdate the client set, removing inactive clients if required.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.forbit.server.interfaces.ServerInterface
getServerProperties, getTCPServer, getTimeout, getUDPServer, onConnect, onDisconnect, setServerProperties, setTCPServer, setUDPServer
-
Constructor Details
-
Server
public Server()
-
-
Method Details
-
init
public void init()Description copied from interface:ServerInterfaceMethod called when booting up the server.Use this to start the thread if your server is extending Thread
- Specified by:
initin interfaceServerInterface
-
shutdown
public void shutdown()Description copied from interface:ServerInterfaceShutdown all the servers.- Specified by:
shutdownin interfaceServerInterface
-
updateClients
public void updateClients()Description copied from interface:ServerInterfaceUpdate the client set, removing inactive clients if required.- Specified by:
updateClientsin interfaceServerInterface
-
getClient
Description copied from interface:ServerInterfaceGet client from a given UUID- Specified by:
getClientin interfaceServerInterface- Parameters:
id- the id of the client- Returns:
- optional containing the client, or empty if it cannot be found
-
getClient
Description copied from interface:ServerInterfaceGet the client from a given SocketChannel.- Specified by:
getClientin interfaceServerInterface- Parameters:
channel- the channel of the client- Returns:
- optional containing the client, or empty if it cannot be found
-
getClient
Description copied from interface:ServerInterfaceGet the client from a given SocketAddress.- Specified by:
getClientin interfaceServerInterface- Parameters:
address- the adress of the client.- Returns:
- optional containing the client, or empty if it cannot be found.
-
removeClient
Description copied from interface:ServerInterfaceRemove the client from the Server's list.- Specified by:
removeClientin interfaceServerInterface- Parameters:
client- the client to remove- Returns:
- whether or not the client was actually in the list.
-
addClient
Description copied from interface:ServerInterfaceAdds a client to this list.- Specified by:
addClientin interfaceServerInterface- Parameters:
client- the client to add
-
sendPacketTCP
Description copied from interface:ServerInterfaceSend a packet to the client.Defaults to TCP.
- Specified by:
sendPacketTCPin interfaceServerInterface- Parameters:
client- clientpacket- packet.
-
sendPacketUDP
- Specified by:
sendPacketUDPin interfaceServerInterface
-
getScheduler
Description copied from interface:ServerInterfaceReturns the scheduler object, or optional.null if not created yet- Specified by:
getSchedulerin interfaceServerInterface- Returns:
- scheduler
-
run
public void run() -
forceDisconnect
Override this for custom force disconnect behaviour
-