Skip to content

Commit

Permalink
This should fix some of the server.properties issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dries007 committed Sep 24, 2014
1 parent 28620e1 commit bde8600
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/net/doubledoordev/backend/server/Server.java
Expand Up @@ -93,7 +93,7 @@ public class Server
private Logger logger;
private File folder;
private File propertiesFile;
private boolean propertiesLoaded = false;
private long propertiesFileLastModified = 0L;
private Properties properties = new Properties();

/**
Expand Down Expand Up @@ -201,8 +201,7 @@ public MCQuery getQuery()
*/
public Properties getProperties()
{
propertiesLoaded = true;
if (propertiesFile.exists())
if (propertiesFile.exists() && propertiesFile.lastModified() > propertiesFileLastModified)
{
try
{
Expand All @@ -216,6 +215,7 @@ public Properties getProperties()
e.printStackTrace();
}
}
normalizeProperties();
return properties;
}

Expand All @@ -224,10 +224,7 @@ public Properties getProperties()
*/
public void saveProperties()
{
if (!propertiesLoaded) getProperties();

normalizeProperties();

getProperties();
try
{
if (!propertiesFile.exists()) //noinspection ResultOfMethodCallIgnored
Expand All @@ -236,6 +233,7 @@ public void saveProperties()
logger.debug("Saving properties with encoding: " + fileWriter.getEncoding());
properties.store(fileWriter, "Minecraft server properties\nModified by D3Backend");
fileWriter.close();
propertiesFileLastModified = propertiesFile.lastModified();
}
catch (IOException e)
{
Expand Down Expand Up @@ -578,6 +576,7 @@ public List<String> getAdmins()
@SuppressWarnings("UnusedDeclaration")
public String getPropertiesAsText()
{
getProperties();
StringWriter stringWriter = new StringWriter();
try
{
Expand Down Expand Up @@ -690,6 +689,7 @@ public void run()
try
{
last25LogLines.clear();
last25LogLines.add("----=====##### STARTING SERVER #####=====-----");
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null)
Expand Down Expand Up @@ -737,13 +737,15 @@ public boolean stopServer() throws ServerOnlineException
try
{
getRCon().stop();
last25LogLines.add("----=====##### STOPPING SERVER WITH RCON #####=====-----");
return true;
}
catch (Exception e)
{
PrintWriter printWriter = new PrintWriter(process.getOutputStream());
printWriter.println("stop");
printWriter.flush();
last25LogLines.add("----=====##### STOPPING SERVER VIA STREAM #####=====-----");
return false;
}
}
Expand All @@ -753,6 +755,7 @@ public boolean forceStopServer() throws Exception
{
if (!getOnline()) throw new ServerOfflineException();
logger.warn("Killing server process!");
last25LogLines.add("----=====##### KILLING SERVER #####=====-----");
process.destroy();
try
{
Expand All @@ -769,8 +772,6 @@ public boolean forceStopServer() throws Exception
process.getInputStream().close();
}
catch (IOException ignored) {}
process.destroy();
process.exitValue();
return true;
}

Expand Down

0 comments on commit bde8600

Please sign in to comment.