MI player data now uncached on logout

This commit is contained in:
Indyuce 2022-09-20 18:06:25 +02:00
parent ad5d16b0b0
commit 16a0a1ae14
3 changed files with 17 additions and 11 deletions

View File

@ -303,7 +303,7 @@ public class MMOItems extends JavaPlugin {
return;
// Save player data
PlayerData.getLoaded().forEach(PlayerData::save);
PlayerData.getLoaded().forEach(data -> data.save(false));
// Drop abandonned soulbound items
SoulboundInfo.getAbandonnedInfo().forEach(SoulboundInfo::dropItems);

View File

@ -82,10 +82,17 @@ public class PlayerData {
}
}
public void save() {
public void save(boolean clearForMap) {
// Empty map if required
if (clearForMap)
data.remove(getUniqueId());
// Cancel runnables
cancelRunnables();
ConfigFile config = new ConfigFile("/userdata", getUniqueId().toString());
// Save data in config
final ConfigFile config = new ConfigFile("/userdata", getUniqueId().toString());
config.getConfig().createSection("crafting-queue");
config.getConfig().set("permissions-from-items", new ArrayList<>(permissions));
craftingStatus.save(config.getConfig().getConfigurationSection("crafting-queue"));

View File

@ -26,22 +26,21 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.*;
public class PlayerListener implements Listener {
private final Map<Player, ArrayList<ItemStack>> deathItems = new HashMap<>();
private final Map<Player, List<ItemStack>> deathItems = new HashMap<>();
@EventHandler(priority = EventPriority.NORMAL)
public void loadPlayerData(PlayerJoinEvent event) {
MMOItems.plugin.getRecipes().refreshRecipeBook(event.getPlayer());
PlayerData.load(event.getPlayer()); }
PlayerData.load(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGH)
public void savePlayerData(PlayerQuitEvent event) { PlayerData.get(event.getPlayer()).save(); }
public void savePlayerData(PlayerQuitEvent event) {
PlayerData.get(event.getPlayer()).save(true);
}
/**
* If the player dies, its time to roll the death-downgrade stat!