2014-08-01 23:56:29 +02:00
|
|
|
package mineplex.serverdata;
|
|
|
|
|
|
|
|
public class MinecraftServer
|
|
|
|
{
|
|
|
|
// The name of this server.
|
|
|
|
private String _name;
|
|
|
|
public String getName() { return _name; }
|
|
|
|
|
|
|
|
// The ServerGroup that this MinecraftServer belongs to.
|
|
|
|
private String _group;
|
|
|
|
public String getGroup() { return _group; }
|
|
|
|
|
|
|
|
// The current message of the day (MOTD) of the server.
|
|
|
|
private String _motd;
|
|
|
|
public String getMotd() { return _motd; }
|
|
|
|
|
|
|
|
// The number of players currently online.
|
|
|
|
private int _playerCount;
|
|
|
|
public int getPlayerCount() { return _playerCount; }
|
|
|
|
public void incrementPlayerCount(int amount) { this._playerCount += amount; }
|
|
|
|
|
|
|
|
// The maximum number of players allowed on the server.
|
|
|
|
private int _maxPlayerCount;
|
|
|
|
public int getMaxPlayerCount() { return _maxPlayerCount; }
|
2014-09-15 19:22:11 +02:00
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
// The ticks per second (TPS) of the server.
|
|
|
|
private int _tps;
|
|
|
|
public int getTps() { return _tps; }
|
|
|
|
|
|
|
|
// The current amount of RAM allocated to the server.
|
|
|
|
private int _ram;
|
|
|
|
public int getRam() { return _ram; }
|
|
|
|
|
|
|
|
// The maximum amount of available RAM that can be allocated to the server.
|
|
|
|
private int _maxRam;
|
|
|
|
public int getMaxRam() { return _maxRam; }
|
|
|
|
|
|
|
|
// The public I.P address used by players to connect to the server.
|
|
|
|
private String _publicAddress;
|
|
|
|
public String getPublicAddress() { return _publicAddress; }
|
|
|
|
|
|
|
|
// The port the server is currently running/listening on.
|
|
|
|
private int _port;
|
|
|
|
public int getPort() { return _port; }
|
|
|
|
|
2014-09-15 19:22:11 +02:00
|
|
|
private long _startUpDate;
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
/**
|
|
|
|
* Class constructor
|
|
|
|
* @param name
|
|
|
|
* @param group
|
|
|
|
* @param motd
|
|
|
|
* @param publicAddress
|
|
|
|
* @param port
|
|
|
|
* @param playerCount
|
|
|
|
* @param maxPlayerCount
|
|
|
|
* @param tps
|
|
|
|
* @param ram
|
|
|
|
* @param maxRam
|
|
|
|
*/
|
|
|
|
public MinecraftServer(String name, String group, String motd, String publicAddress, int port,
|
2014-09-15 19:22:11 +02:00
|
|
|
int playerCount, int maxPlayerCount, int tps, int ram, int maxRam, long startUpDate)
|
2014-08-01 23:56:29 +02:00
|
|
|
{
|
|
|
|
this._name = name;
|
|
|
|
this._group = group;
|
|
|
|
this._motd = motd;
|
|
|
|
this._playerCount = playerCount;
|
|
|
|
this._maxPlayerCount = maxPlayerCount;
|
|
|
|
this._tps = tps;
|
|
|
|
this._ram = ram;
|
|
|
|
this._maxRam = maxRam;
|
|
|
|
this._publicAddress = publicAddress;
|
|
|
|
this._port = port;
|
2014-09-15 19:22:11 +02:00
|
|
|
this._startUpDate = startUpDate;
|
2014-08-01 23:56:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true, if {@value _playerCount} equals 0, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isEmpty()
|
|
|
|
{
|
|
|
|
return _playerCount == 0;
|
|
|
|
}
|
|
|
|
|
2014-09-15 19:22:11 +02:00
|
|
|
/**
|
|
|
|
* @return the amount of time (in seconds) that this {@link MinecraftServer} has been online for.
|
|
|
|
*/
|
|
|
|
public double getUptime()
|
|
|
|
{
|
|
|
|
return (System.currentTimeMillis() - _startUpDate) / 1000d;
|
|
|
|
}
|
|
|
|
|
2014-08-01 23:56:29 +02:00
|
|
|
/**
|
|
|
|
* @return true, if this server is currently joinable by players, false otherwise.
|
|
|
|
*/
|
|
|
|
public boolean isJoinable()
|
|
|
|
{
|
|
|
|
if (_motd != null && (_motd.contains("Starting") || _motd.contains("Recruiting")
|
2014-10-11 13:40:53 +02:00
|
|
|
|| _motd.contains("Waiting") || _motd.contains("Open in") || _motd.isEmpty()))
|
2014-08-01 23:56:29 +02:00
|
|
|
{
|
|
|
|
if (_playerCount < _maxPlayerCount)
|
|
|
|
{
|
|
|
|
int availableSlots = _maxPlayerCount - _playerCount;
|
|
|
|
return _motd.isEmpty() ? (availableSlots > 20) : true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|