#Wait Elgar
1 messages · Page 1 of 1 (latest)
?
public class TestConfig {
private static File file;
private static FileConfiguration fileConfig;
public static void setup() {
file = new File(Main.main().getDataFolder(), "locations.yml");
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
fileConfig = new YamlConfiguration();
}
public static void save() {
try {
fileConfig.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public static FileConfiguration get() {
return fileConfig;
}
public static void load() {
try {
fileConfig.load(file);
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
}
}
}
This is the all config and file methods
public class Main extends JavaPlugin {
private static Main plugin;
private static HashSet<String> players = new HashSet<>();
@Override
public void onEnable() {
plugin = this;
saveDefaultConfig();
TestConfig.setup();
TestConfig.load();
getServer().getPluginManager().registerEvents(new onDie(), this);
getServer().getPluginManager().registerEvents(new onJoin(), this);
getCommand("takestats").setExecutor(new TakeStats());
TestConfig.save();
}
@Override
public void onDisable() {
}
public static HashSet<String> getPlayers() {
return players;
}
}``` This is the main
@EventHandler
public void onJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
TestConfig.load();
Main.getPlayers().add(p.getUniqueId().toString());
TestConfig.get().set("players", Main.getPlayers());
TestConfig.save();
TestConfig.get().set(p.getName() + ".deaths", 0);
TestConfig.get().set(p.getName() + ".kills", 0);
TestConfig.save();
}``` And this is the event
The players on Main is over and over wiping on config
@plain chasm
bruh
fileConfig = YamlConfiguration.loadConfiguration(file);
never do new YamlConfiguration
It is the same way