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. Offline

    TGamingStudio

    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. Offline

    timtower Moderator Moderator

  3. Offline

    TGamingStudio

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

    timtower Moderator Moderator

  5. Offline

    TGamingStudio

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

    timtower Moderator Moderator

    @TGamingStudio Are you calling the same line somewhere in between restarts? Or only when the plugin is starting?
     
  7. Offline

    TGamingStudio

    @timtower No, I was calling it like:
    Save
    Load: working
    Restart
    Load: error
    Save
    Load: working
    Same load code
     
  8. Offline

    timtower Moderator 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.
  9. Offline

    TGamingStudio

Thread Status:
Not open for further replies.

Share This Page