saving playerdata

Discussion in 'Plugin Help/Development/Requests' started by DaanSander, Mar 27, 2015.

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

    DaanSander

    Hello i am trying to save a inventory for a player the save works but when i try to load the inventory it wont work

    stack trace:
    Code:
    [12:08:03 INFO]: DaanSander issued server command: /loadinv
    [12:08:03 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'load
    inv' in plugin Em v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:645) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_31]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
            at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    83) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    23) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :526) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.IllegalArgumentException: Item cannot be null
            at org.apache.commons.lang.Validate.noNullElements(Validate.java:364) ~[
    spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory.addItem(Craft
    Inventory.java:267) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            at me.daansander.em.Em.onCommand(Em.java:77) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
            ... 14 more
    >
    code:
    Code:
    package me.daansander.em;
    
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.PlayerInventory;
    
    /**
    * Created by Daan on 27-3-2015.
    */
    public class PlayerInv {
    
        private String name;
        private PlayerInventory inv;
    
        public PlayerInv(String name, PlayerInventory inv) {
            this.name = name;
            this.inv = inv;
        }
    
        public String getPlayer() {
            return name;
        }
        public PlayerInventory getInv() {
            return inv;
        }
    }
    
    command:
    Code:
    if(cmd.getName().equalsIgnoreCase("saveinv")) {
                player.add(new PlayerInv(p.getName(), p.getInventory()));
                p.sendMessage("saved inv");
                return true;
            } if(cmd.getName().equalsIgnoreCase("loadinv")) {
                PlayerInv inv = getData(p);
                p.getInventory().addItem(inv.getInv().getContents());
                p.getInventory().setArmorContents(inv.getInv().getArmorContents());
                p.sendMessage("loaded inv");
                return true;
            }
            return true;
    }
       private PlayerInv getData(Player p) {
       for(PlayerInv pd : player) {
       if(pd.getPlayer().equalsIgnoreCase(p.getName())) return pd;}
       return null;
           }
       }
    
    sorry for bad english
     
  2. Offline

    DaanSander

    @FisheyLP thats the second time someone sends me that but it still do not get what the problem is
     
  3. Read it and you know how to solve the problem (or at least send use the line of code where the error appears).
    tipps (open)

    [12:08:03 INFO]: DaanSander issued server command: /loadinv
    [12:08:03 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'load
    inv' in plugin Em v1.0
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServe
    r.java:645) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:1115) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java
    :950) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :26) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :53) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_31]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_31]
    at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:6
    83) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:3
    16) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:6
    23) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java
    :526) [spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Caused by: java.lang.IllegalArgumentException: Item cannot be null
    at org.apache.commons.lang.Validate.noNullElements(Validate.java:364) ~[
    spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at org.bukkit.craftbukkit.v1_8_R1.inventory.CraftInventory.addItem(Craft
    Inventory.java:267) ~[spigot-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    at me.daansander.em.Em.onCommand(Em.java:77) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got-1.8-R0.1-SNAPSHOT.jar:git-Spigot-13716d9-0899683]
    ... 14 more
     
  4. Offline

    DaanSander

    alright is see that tje item is null but i still do not get why its giving the error
     
  5. Maybe because the ite is null and you can't handle with items that are null??
    It would be helpful if you show the error..
     
  6. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
Thread Status:
Not open for further replies.

Share This Page