Enforce userdata save on player dispose.

This commit is contained in:
KHobbits 2014-05-27 04:50:12 +01:00
parent 2ac1ce4f56
commit 4590e7ea26
3 changed files with 22 additions and 1 deletions

View File

@ -320,6 +320,10 @@ public class EssentialsConf extends YamlConfiguration
{ {
try try
{ {
if (pendingDiskWrites.get() > 0)
{
pendingDiskWrites.set(0);
}
Future<?> future = delayedSave(configFile); Future<?> future = delayedSave(configFile);
if (future != null) if (future != null)
{ {
@ -336,6 +340,14 @@ public class EssentialsConf extends YamlConfiguration
} }
} }
public synchronized void cleanup()
{
if (pendingDiskWrites.get() > 0)
{
forceSave();
}
}
private Future<?> delayedSave(final File file) private Future<?> delayedSave(final File file)
{ {
if (file == null) if (file == null)
@ -350,7 +362,10 @@ public class EssentialsConf extends YamlConfiguration
return null; return null;
} }
pendingDiskWrites.incrementAndGet(); if (pendingDiskWrites.incrementAndGet() < 0)
{
pendingDiskWrites.set(1);
}
Future<?> future = EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites)); Future<?> future = EXECUTOR_SERVICE.submit(new WriteRunner(configFile, data, pendingDiskWrites));

View File

@ -242,6 +242,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
{ {
this.base = new OfflinePlayer(base.getUniqueId(), ess.getServer()); this.base = new OfflinePlayer(base.getUniqueId(), ess.getServer());
} }
cleanup();
} }
@Override @Override

View File

@ -53,6 +53,11 @@ public abstract class UserData extends PlayerExtension implements IConf
ess.getUserMap().removeUser(this.getBase().getName()); ess.getUserMap().removeUser(this.getBase().getName());
} }
public final void cleanup()
{
config.cleanup();
}
@Override @Override
public final void reloadConfig() public final void reloadConfig()
{ {