#Wait Elgar

1 messages · Page 1 of 1 (latest)

finite rapids
#

Wait

analog violet
#

?

finite rapids
#
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

plain chasm
#

bruh

#

fileConfig = YamlConfiguration.loadConfiguration(file);

#

never do new YamlConfiguration

finite rapids
plain chasm
#

and don't call load() in your event

#

it's not needed

finite rapids
#

well

#

why the "players" section is wiping after reloading

plain chasm
#

Main.getPlayers().add(p.getUniqueId().toString());

#

what does it return

#

Is that a list of player id's?

#

and how do you initialize it

#

as far as i can see it should wipe

#

like it's the only way how plugin would work

finite rapids
#

Its an arraylist