Fix async backpack save on unload (Fixes #43)

This commit is contained in:
GeorgH93 2019-07-13 01:08:41 +02:00
parent b5cedf3033
commit f521f56195
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 6 additions and 4 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>at.pcgamingfreaks</groupId>
<artifactId>Minepacks</artifactId>
<version>2.0.8-RC2</version>
<version>2.0.8-RC3</version>
<scm>
<connection>scm:git:git@github.com:GeorgH93/Minepacks.git</connection>

View File

@ -50,7 +50,7 @@ public abstract class Database implements Listener
protected final Minepacks plugin;
protected final InventorySerializer itsSerializer;
protected final boolean useUUIDs, bungeeCordMode;
protected boolean useUUIDSeparators;
protected boolean useUUIDSeparators, asyncSave = true;
protected long maxAge;
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
private final UnCacheStrategie unCacheStrategie;
@ -77,6 +77,7 @@ public void init()
public void close()
{
HandlerList.unregisterAll(this);
asyncSave = false;
backpacks.forEach((key, value) -> value.closeAll());
backpacks.clear();
unCacheStrategie.close();

View File

@ -300,7 +300,7 @@ public void saveBackpack(final Backpack backpack)
final int id = backpack.getOwnerID(), usedSerializer = itsSerializer.getUsedSerializer();
final String nameOrUUID = getPlayerNameOrUUID(backpack.getOwner()), name = backpack.getOwner().getName();
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Runnable runnable = () -> {
try(Connection connection = getConnection())
{
if(id <= 0)
@ -335,7 +335,8 @@ public void saveBackpack(final Backpack backpack)
e.printStackTrace();
writeBackup(name, nameOrUUID, usedSerializer, data);
}
});
};
if(asyncSave) Bukkit.getScheduler().runTaskAsynchronously(plugin, runnable); else runnable.run();
}
@Override