Solved Can't cast short from config after restart

Discussion in 'Plugin Development' started by TGamingStudio, Aug 20, 2019.

Thread Status:
Not open for further replies.
  1. Hello, I've created command that saves material and data to config,
    Second command loads that material.
    When i save the material and load it it works fine.
    But when i save the material, restart server and load it, it returns error:
    Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Short
    Saving:
    Code:
    config.set("warp." + args[0] + ".material", ((Player) sender).getItemInHand().getType().toString());
    config.set("warp." + args[0] + ".data", ((Player) sender).getItemInHand().getDurability());
    saveConfig();

    Loading:
    Code:
    mat = Material.getMaterial(config.getString("warp." + warp + ".material"));
    data = (short) config.get("warp." + warp + ".data");
    How can i fix this?
     
  2. Online

    timtower Administrator Administrator Moderator

  3. @timtower Don't want to save amount and metadata
     
  4. Online

    timtower Administrator Administrator Moderator

  5. @timtower Please can you explain why its happening only after restart?
     
  6. Online

    timtower Administrator Administrator Moderator

    @TGamingStudio Are you calling the same line somewhere in between restarts? Or only when the plugin is starting?
     
  7. @timtower No, I was calling it like:
    Save
    Load: working
    Restart
    Load: error
    Save
    Load: working
    Same load code
     
  8. Online

    timtower Administrator Administrator Moderator

    @TGamingStudio Might be saved in memory as a short, then saved to file, then it becomes an int when the file gets loaded again.
     
    TGamingStudio likes this.
Thread Status:
Not open for further replies.

Share This Page