mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-25 17:17:49 +01:00
Fix async backpack save on unload (Fixes #43)
This commit is contained in:
parent
b5cedf3033
commit
f521f56195
2
pom.xml
2
pom.xml
@ -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>
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user