Getting Armor Back from File

Discussion in 'Plugin Development' started by RUDD33, Nov 6, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    RUDD33

    I'm using (@KingFaris11)'s method of saving and getting inventories with files. Here is a link to the page:

    https://forums.bukkit.org/threads/util-saving-getting-inventories-from-a-file.164145/

    I was able to figure out how to save a player's armor to the data file, but I am unable to figure out how to get it back from the file. Here is the code that I am currently using:
    Code:
                if (alias.equalsIgnoreCase("iload")) {
                    Inventory playerInventory = (Test.getInventoryFromFile(new File(this.getDataFolder(), "inv.invsave")));
                    ItemStack[] contents = playerInventory.getContents();
                    ItemStack[] armcontents = ((PlayerInventory) playerInventory).getArmorContents();
                    if (armcontents != null) player.getInventory().setArmorContents(armcontents);
                    if (contents != null) player.getInventory().setContents(contents);
                        player.sendMessage("Inventory loaded!");
                }

    This, however, creates an error in the console and does not load the armor. Also, in the line
    Code:
    ItemStack[] armcontents = ((PlayerInventory) playerInventory).getArmorContents();

    I have to add the cast "(PlayerInventory)" which I believe is causing the error. Here is the error that is sent to console:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'iloa
    d' in plugin Test v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServe
    r.java:740) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:956) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java
    :817) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:2
    60) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
    Caused by: java.lang.NullPointerException
            at me.RUDD33.com.Test.onCommand(Test.java:172) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            ... 13 more
    What I am trying to figure out, is how to get the armor back from the file and give it directly to the player in the armor slots. Any help would be appreciated. :)
     
    ProMCKingz likes this.
  2. Offline

    RUDD33

    Bump.
     
  3. Offline

    yewtree8

    Show us the other classes used, you used the class "Test" I may be able to help if you show us it?
     
  4. Offline

    mine-care

    In line 172 there is a null variable causing null pointer exception. We might find it and help you solve it if you do what yewtree8 told you :)
     
Thread Status:
Not open for further replies.

Share This Page