SetItem works just once

Discussion in 'Plugin Development' started by Eacrow, May 15, 2020.

  1. Offline

    Eacrow

    I'm trying to make a plugin that teleport players and separates inventories between worlds. Everything works fine, but the inventory lines works just once.

    I'm using this for saving the inventory in a yml file.
    Code:
    FileConfiguration config = plugin.getConfig();
    config.set("Config.Jugadores."+Jugador.getUniqueId()+".CordsOW.Inventario", Jugador.getInventory().getContents());
    plugin.saveConfig();
    And this for set the inventory.
    Code:
    List<ItemStack> items = (List<ItemStack>) config.getList("Config.Jugadores."+Jugador.getUniqueId()+".CordsOW.Inventario");
    for (int i=0;i<Jugador.getInventory().getSize();i++) {
        Jugador.getInventory().setItem(i,items.get(i)); //Console says the error is in this line
    }
    What am I doing wrong? I'm new to both java and bukkit.
     
  2. Offline

    Tango_

    Can you paste the error here
     
  3. Offline

    Eacrow

    Yeah, sorry I didn't do it before.

    Code:
    [12:53:11] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'mundo' in plugin uwu v1.0.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:723) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1658) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1498) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:918) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:911) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:895) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:828) [spigot.jar:git-Spigot-2f5d615-d07a78b]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]
    Caused by: java.lang.NullPointerException
        at eacrow.Comandos.mundo.onCommand(mundo.java:93) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot.jar:git-Spigot-2f5d615-d07a78b]
        ... 17 more
     

Share This Page