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 TypeMethodDescriptionvoid
Adds a client to this list.void
forceDisconnect(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 yetvoid
init()
Method called when booting up the server.boolean
removeClient(Client client)
Remove the client from the Server's list.void
run()
void
sendPacketTCP(Client client, Packet packet)
Send a packet to the client.void
sendPacketUDP(Client client, Packet packet)
void
shutdown()
Shutdown all the servers.void
Update 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, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:ServerInterface
Method called when booting up the server.Use this to start the thread if your server is extending Thread
- Specified by:
init
in interfaceServerInterface
-
shutdown
public void shutdown()Description copied from interface:ServerInterface
Shutdown all the servers.- Specified by:
shutdown
in interfaceServerInterface
-
updateClients
public void updateClients()Description copied from interface:ServerInterface
Update the client set, removing inactive clients if required.- Specified by:
updateClients
in interfaceServerInterface
-
getClient
Description copied from interface:ServerInterface
Get client from a given UUID- Specified by:
getClient
in 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:ServerInterface
Get the client from a given SocketChannel.- Specified by:
getClient
in 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:ServerInterface
Get the client from a given SocketAddress.- Specified by:
getClient
in 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:ServerInterface
Remove the client from the Server's list.- Specified by:
removeClient
in interfaceServerInterface
- Parameters:
client
- the client to remove- Returns:
- whether or not the client was actually in the list.
-
addClient
Description copied from interface:ServerInterface
Adds a client to this list.- Specified by:
addClient
in interfaceServerInterface
- Parameters:
client
- the client to add
-
sendPacketTCP
Description copied from interface:ServerInterface
Send a packet to the client.Defaults to TCP.
- Specified by:
sendPacketTCP
in interfaceServerInterface
- Parameters:
client
- clientpacket
- packet.
-
sendPacketUDP
- Specified by:
sendPacketUDP
in interfaceServerInterface
-
getScheduler
Description copied from interface:ServerInterface
Returns the scheduler object, or optional.null if not created yet- Specified by:
getScheduler
in interfaceServerInterface
- Returns:
- scheduler
-
run
public void run() -
forceDisconnect
Override this for custom force disconnect behaviour
-