mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2025-07-05 03:26:42 +00:00
Beta 20220422-SNAPSHOT
Changelog: - Added a configuration with editable rarity values and rarity types for the different events that can occur, to give the end user more control over how often players receive the effects. - Modified listeners to use the respective Configuration values. - Added the ability to reload a specific player configuration with /luck reload -p <player_name> - Added the ability to reload the main configuration using /luck reload -m - Added an integrity checker to validate the main configuration on boot.
This commit is contained in:
@ -2,6 +2,8 @@ package io.github.simplex.luck.player;
|
||||
|
||||
import io.github.simplex.luck.FeelingLucky;
|
||||
import io.github.simplex.luck.util.SneakyWorker;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,16 +13,18 @@ import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerConfig {
|
||||
private final File configFile;
|
||||
private final FeelingLucky plugin;
|
||||
private final OfflinePlayer player;
|
||||
private volatile YamlConfiguration config;
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public PlayerConfig(FeelingLucky plugin, Player player) {
|
||||
this.plugin = plugin;
|
||||
File dataFolder = plugin.getDataFolder();
|
||||
this.player = player;
|
||||
if (!plugin.getDataFolder().exists()) plugin.getDataFolder().mkdirs();
|
||||
File dataFolder = new File(plugin.getDataFolder(), "players");
|
||||
if (!dataFolder.exists()) dataFolder.mkdirs();
|
||||
File file = new File(dataFolder, player.getUniqueId() + ".yml");
|
||||
if (!file.exists()) {
|
||||
@ -54,8 +58,8 @@ public class PlayerConfig {
|
||||
}
|
||||
|
||||
protected PlayerConfig(FeelingLucky plugin, File file) {
|
||||
this.plugin = plugin;
|
||||
this.configFile = file;
|
||||
this.player = Bukkit.getOfflinePlayer(UUID.fromString(file.getName().split("\\.")[0]));
|
||||
config = YamlConfiguration.loadConfiguration(configFile);
|
||||
}
|
||||
|
||||
@ -77,6 +81,10 @@ public class PlayerConfig {
|
||||
load();
|
||||
}
|
||||
|
||||
public OfflinePlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setUsername(String name) {
|
||||
config.set("username", name);
|
||||
save();
|
||||
|
Reference in New Issue
Block a user