Add ForceSaveOnUnload config option

This commit is contained in:
GeorgH93 2023-06-02 21:17:11 +02:00
parent 239b8d0ec4
commit 6d6482374c
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
4 changed files with 20 additions and 4 deletions

View File

@ -76,6 +76,9 @@ Database:
# Options: auto, online, offline | auto will decide based on the server online mode option.
# If you are using BungeeCord, set it to whatever you use on your BungeeCord server!!!
UUID_Type: auto
# If enabled the backpack will be saved regardless of if there have been changes to it or not. This will slightly negatively impact performance.
# This will help with changes made to items inside the backpack by other plugins. For example plugins that allow you to interact with items, when you allow your players to store these items inside the backpack.
ForceSaveOnUnload: false
# Settings only for MySQL
SQL:
Host: "localhost:3306"

View File

@ -146,6 +146,11 @@ public class Config extends Configuration implements DatabaseConnectionConfigura
return getConfigE().getBoolean("Database.UseUUIDSeparators", false);
}
public boolean isForceSaveOnUnloadEnabled()
{
return getConfigE().getBoolean("Database.ForceSaveOnUnload", false);
}
public String getUnCacheStrategie()
{
return getConfigE().getString("Database.Cache.UnCache.Strategie", "interval").toLowerCase(Locale.ENGLISH);

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 GeorgH93
* Copyright (C) 2023 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -50,7 +50,7 @@ public abstract class Database implements Listener
protected final Minepacks plugin;
protected final InventorySerializer itsSerializer;
protected final boolean onlineUUIDs, bungeeCordMode;
protected final boolean onlineUUIDs, bungeeCordMode, forceSaveOnUnload;
protected boolean useUUIDSeparators, asyncSave = true;
protected long maxAge;
private final Map<OfflinePlayer, Backpack> backpacks = new ConcurrentHashMap<>();
@ -64,6 +64,7 @@ public abstract class Database implements Listener
useUUIDSeparators = plugin.getConfiguration().getUseUUIDSeparators();
onlineUUIDs = plugin.getConfiguration().useOnlineUUIDs();
bungeeCordMode = plugin.getConfiguration().isBungeeCordModeEnabled();
forceSaveOnUnload = plugin.getConfiguration().isForceSaveOnUnloadEnabled();
maxAge = plugin.getConfiguration().getAutoCleanupMaxInactiveDays();
unCacheStrategie = bungeeCordMode ? new OnDisconnect(this) : UnCacheStrategie.getUnCacheStrategie(this);
backupFolder = new File(this.plugin.getDataFolder(), "backups");
@ -240,7 +241,14 @@ public abstract class Database implements Listener
public void unloadBackpack(Backpack backpack)
{
backpack.save();
if (forceSaveOnUnload)
{
backpack.forceSave();
}
else
{
backpack.save();
}
backpacks.remove(backpack.getOwner());
}

View File

@ -11,7 +11,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<configFileVersion>33</configFileVersion>
<configFileVersion>34</configFileVersion>
<languageFileVersion>20</languageFileVersion>
<pcgfPluginLibVersion>1.0.39-SNAPSHOT</pcgfPluginLibVersion>