Solved Location error when loading my plugin [1.12]

Discussion in 'Spigot Plugin Development' started by Stephanech, Jul 6, 2017.

  1. NOTE: My main language is not english, so, i'm not the best in it D:

    Well, I'm currently developing a plugin called "DropShop", the name says everything: Creating an item shop, but not with signs, with items dropped

    So, everything was fine in 1.11.2, but, when I updated my local server and the plugin to 1.12, a really weird error appeared:

    Code (Text):

    [20:06:39] [Server thread/ERROR]: Could not call method 'public static org.bukkit.Location org.bukkit.Location.deserialize(java.util.Map)' of class org.bukkit.Location for deserialization
    java.lang.IllegalArgumentException: unknown world
       at org.bukkit.Location.deserialize(Location.java:612) ~[spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
       at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:77) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:117) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:195) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:35) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:143) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:129) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:505) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.Yaml.load(Yaml.java:424) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:162) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:130) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:179) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:160) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:135) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at com.wonderland.stephanech.Main.<init>(Main.java:317) [DropShop.jar:?]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_131]
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_131]
       at java.lang.reflect.Constructor.newInstance(Unknown Source) [?:1.8.0_131]
       at java.lang.Class.newInstance(Unknown Source) [?:1.8.0_131]
       at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:326) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:302) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    [20:06:39] [Server thread/ERROR]: Could not call method 'public static org.bukkit.Location org.bukkit.Location.deserialize(java.util.Map)' of class org.bukkit.Location for deserialization
    java.lang.IllegalArgumentException: unknown world
       at org.bukkit.Location.deserialize(Location.java:612) ~[spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
       at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
       at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:77) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:117) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:195) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:35) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping2ndStep(BaseConstructor.java:376) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:185) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:357) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:532) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:26) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:184) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:143) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:129) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:505) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.yaml.snakeyaml.Yaml.load(Yaml.java:424) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:54) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:162) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:130) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:179) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:160) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:135) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at com.wonderland.stephanech.Main.<init>(Main.java:317) [DropShop.jar:?]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_131]
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_131]
       at java.lang.reflect.Constructor.newInstance(Unknown Source) [?:1.8.0_131]
       at java.lang.Class.newInstance(Unknown Source) [?:1.8.0_131]
       at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:326) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:248) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at org.bukkit.craftbukkit.v1_12_R1.CraftServer.loadPlugins(CraftServer.java:302) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:205) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot-1.12.jar:git-Spigot-7228328-11323bf]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    [20:06:39] [Server thread/INFO]: [DropsShop] Loading DropsShop v1.0

     
    Continuing, the plugin stores everything in a config.yml: When an item is placed, the plugin saves the UUID of it, with the ItemStack and Location (The plugin also automatically checks if the dropped item's UUID match with the config item's UUID, so, there is no problem when the UUID changes)

    Code (YAML):

    item-uuid-list
    :
    - 0d785fa1-00c3-4a3d-8956-9d4aee419a1d

    drops
    :
      0d785fa1-00c3-4a3d-8956-9d4aee419a1d
    : // A diamond sword enchanted with Sharpness 4
        location
    :
          ==
    : org.bukkit.Location
          world
    : world
          x
    : 780.5
          y
    : 82.0
          z
    : 280.5
          pitch
    : 22.03522
          yaw
    : 272.62552
        item
    :
          ==
    : org.bukkit.inventory.ItemStack
          type
    : DIAMOND_SWORD
          damage
    : 1
          meta
    :
            ==
    : ItemMeta
            meta-type
    : UNSPECIFIC
            enchants
    :
              DAMAGE_ALL
    : 4
            repair-cost
    : 1
     
    So, I was doing some tweaks in the plugin, I save it, stop and start the server, and then, boom, the location of every item stored was magically disappeared!

    Code (YAML):

    item-uuid-list
    :
    - 0d785fa1-00c3-4a3d-8956-9d4aee419a1d

    drops
    :
      0d785fa1-00c3-4a3d-8956-9d4aee419a1d
    :
        item
    :
          ==
    : org.bukkit.inventory.ItemStack
          type
    : DIAMOND_SWORD
          damage
    : 1
          meta
    :
            ==
    : ItemMeta
            meta-type
    : UNSPECIFIC
            enchants
    :
              DAMAGE_ALL
    : 4
            repair-cost
    : 1
     
    (Of course the plugin went crazy because it couldn't find the location of the items)

    The error code really tells me nothing I can understand, but, it mentions something about the line 317 with my Main plugin class, which it is:

    Code (Java):
     List<String> itemuuidlist = (List<String>) this.getConfig().getStringList("item-uuid-list");
    Just a statement of a list, I use it for getting the items

    Any idea what I could do? thanks for the help <3

    Some things that may be important:

    - I'm coding it all in the Main class
    - The Main class is: com.wonderland.stephanech.Main (WonderLand = The server for which I am doing the plugin)
    - i ran out of things
     
  2. Error indicates the world of the location object is invalid
     
    • Like Like x 1
  3. Unusual...

    I tried by deleting that world and creating a new one... Nothing changed

    BUT!, The error doesn't appear if I only reload the server, it works perfectly. The story change when I restart it
     
  4. What's the name of that world and the code for this location method, because I can't tell what's wrong without the actual code :p
     
  5. The name is "world" (the very first world of all time)

    I exactly don't know, I just saved it like a object directly in the config (the same with the ItemStack), maybe it's written in the Spigot code (if that is what you are reffering to)

    Code (Java):

    ItemStack iteminhand = player.getInventory().getItemInMainHand();
                             
                         
    Entity item = player.getWorld().dropItemNaturally(player.getLocation(), iteminhand);
    Location loc = player.getLocation();
    double X = loc.getBlockX() + 0.500;
    double Z = loc.getBlockZ() + 0.500;
                                 
    loc.setX(X);
    loc.setY(loc.getBlockY());
    loc.setZ(Z);
                           
    item.setVelocity(item.getVelocity().multiply(0));
    item.teleport(loc);


    itemuuidlist.add(item.getUniqueId().toString());
    getConfig().set("item-uuid-list", itemuuidlist);

      getConfig().set("drops." + item.getUniqueId().toString() + ".location", loc); // Here
      getConfig().set("drops." + item.getUniqueId().toString() + ".item", iteminhand);
        saveConfig();        
     
     
  6. How do you load the location?
    Also as a sidenote, i don't recommend storing classes as an object as they can be changed in versions at any time so that they maybe aren't deserializeable anymore.
     
  7. Code (Java):
    Location loc = (Location) getConfig().get("drops." + uuid + ".location");
    Also, thanks for the note :)
     
  8. You're retrieve an object from this path but there is no object, you''ll have to create a new location and retrieve your path + "." x,y,z,pitch,yaw and world and then it will work
     
  9. Save the location as a weakblock or weaklocation, you shouldn't load raw Location objects on startup
     
  10. Thanks to all!, I solved it by simply serializing the Location in a String and moving the 317 line to another spot. Pretty odd