mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-21 17:35:01 +00:00
Alpha 1.0 RC02 PATCH 01
Fixed an issue where initializing a new PlayerConfig would attempt to read a non existent value from the Luck Container list.
This commit is contained in:
parent
93ee1e2c43
commit
0383bfeaf3
@ -201,7 +201,7 @@ public record PlayerListener(FeelingLucky plugin) implements Listener {
|
||||
if (cause.equals(DamageCause.MAGIC) || cause.equals(DamageCause.POISON)) {
|
||||
if (luck.quickRNG(33.0)) {
|
||||
luck.takeFrom(5.0);
|
||||
plugin.handler.updatePlayer(player, luck);
|
||||
PlayerHandler.updatePlayer(player, luck);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package io.github.simplex.luck.player;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.SneakyWorker;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@ -22,7 +23,7 @@ public class PlayerConfig {
|
||||
File file = new File(dataFolder, player.getUniqueId() + ".yml");
|
||||
if (!file.exists()) {
|
||||
String name = "username: " + player.getName();
|
||||
String luck = "luck: " + PlayerHandler.getLuckContainer(player).defaultValue();
|
||||
String luck = "luck: " + player.getAttribute(Attribute.GENERIC_LUCK).getDefaultValue();
|
||||
String multiplier = "multiplier: " + 1.0;
|
||||
|
||||
SneakyWorker.sneakyTry(() -> {
|
||||
|
@ -31,24 +31,28 @@ public record PlayerHandler(FeelingLucky plugin) implements Listener {
|
||||
return markedPlayers.contains(player);
|
||||
}
|
||||
|
||||
public static void updatePlayer(Player player, Luck luck) {
|
||||
playerLuckMap.replace(player, luck);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void initializePlayer(PlayerLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
PlayerConfig config = FeelingLucky.getConfigMap().get(player.getUniqueId());
|
||||
PlayerConfig playerConfig = FeelingLucky.getConfigMap().get(player.getUniqueId());
|
||||
|
||||
if (config == null) {
|
||||
config = new PlayerConfig(plugin, player);
|
||||
FeelingLucky.getConfigMap().put(player.getUniqueId(), config);
|
||||
if (playerConfig == null) {
|
||||
playerConfig = new PlayerConfig(plugin, player);
|
||||
FeelingLucky.getConfigMap().put(player.getUniqueId(), playerConfig);
|
||||
}
|
||||
|
||||
String username = config.getString("username");
|
||||
double luck = config.getDouble("luck");
|
||||
double multiplier = config.getDouble("multiplier");
|
||||
String username = playerConfig.getConfig().getString("username");
|
||||
double luck = playerConfig.getConfig().getDouble("luck");
|
||||
double multiplier = playerConfig.getConfig().getDouble("multiplier");
|
||||
|
||||
if (!player.getName().equalsIgnoreCase(username)) {
|
||||
config.set("username", player.getName());
|
||||
config.save();
|
||||
config.load();
|
||||
playerConfig.getConfig().set("username", player.getName());
|
||||
playerConfig.save();
|
||||
playerConfig.load();
|
||||
}
|
||||
|
||||
Luck container = new Luck(player, multiplier);
|
||||
@ -56,8 +60,4 @@ public record PlayerHandler(FeelingLucky plugin) implements Listener {
|
||||
|
||||
playerLuckMap.put(player, container);
|
||||
}
|
||||
|
||||
public static void updatePlayer(Player player, Luck luck) {
|
||||
playerLuckMap.replace(player, luck);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user