Solved Spigot config returns null until server restart.

Discussion in 'Spigot Plugin Development' started by Ch1ckenman, Mar 8, 2020.

Thread Status:
Not open for further replies.
  1. I am currently making a plugin, obviously, where when you place a specific block that block's location is put into a config file so that you can play around with the block.
    I currently have it so that the block when placed successfully adds that information to a config file, you can view it in the config file the tick the block is placed if, but when trying to access the location of the block it returns null unless I restart the server and I have no idea why.
    The data is stored in a custom yml if that helps.
    some code if this helps
    Code (Text):
                if (player.getInventory().getItemInMainHand().getItemMeta().getLore().equals(lifeTableLore)) {
                    String path = block.getWorld().getName() + "_" + block.getX() + "_" + block.getY() + "_" + block.getZ();
                    config.getDataFile().set(path + ".world", block.getWorld().getName());
                    config.getDataFile().set(path + ".x", block.getX());
                    config.getDataFile().set(path + ".y", block.getY());
                    config.getDataFile().set(path + ".z", block.getZ());
                    if (plugin.getConfig().getBoolean("items.lifeTable.hologram")) {
                        plugin.spawnHologram(event.getPlayer(), block.getWorld().getName(), block.getX(), block.getY(), block.getZ());
                        config.getDataFile().set(path + ".hologram", plugin.publicStand.getUniqueId().toString());
    Code (Text):
            System.out.println(config.getDataFile().get(block.getWorld().getName() + "_" + block.getX() + "_" + block.getY() + "_" + block.getZ() + ".x"));
            if (config.getDataFile().get(block.getWorld().getName() + "_" + block.getX() + "_" + block.getY() + "_" + block.getZ()) != null && event.getAction() == Action.LEFT_CLICK_BLOCK) {
                plugin.location = block.getWorld().getName() + "_" + block.getX() + "_" + block.getY() + "_" + block.getZ();
    with this being the config entry
    Code (Text):
      world: world
      x: -259
      y: 75
      z: 124
      hologram: 0f2e2767-9e41-4ec3-9c29-7e8194f991f3

    EDIT: Had to just use normal config because the custom YAML file wouldn't save correctly. Code I was using is here
    Code (Text):
    public void saveFile(FileConfiguration ymlConfig, File ymlFile) {
            try {
            } catch (IOException e) {
    anyone have an idea why that wouldn't save the custom file like the built in saveConfig feature does?
    #1 Ch1ckenman, Mar 8, 2020
    Last edited: Mar 8, 2020
  2. event.getAction().toString() == "LEFT_CLICK_BLOCK"
    this will very rarely return true. why are you comparing a string? just do event.getAction() == Action.LEFT_CLICK_BLOCK
    strings are compared with #equals

    need more info. how do you know something is null? what is null?
    • Informative Informative x 1
  3. Sorry, new to coding java.
  4. Whilst what you are doing may well seem fine, you have missed something about how the system works.

    You are saving your data onto the disk storage, however, the active data is held in a memory location, and 'this' is what you have to update as well.

    You have to reload the altered configuration into the memory, for the new data to be affective.
  5. nope..
    this would be true with multiple instances of the same file, but as far as i can tell hes only using one instance. you have to write to the memory of the data to save it to a file.. its already in the memory.
Thread Status:
Not open for further replies.