Solved IllegalArgumentException

Discussion in 'Plugin Development' started by Smeary_Subset, Mar 30, 2022.

  1. Offline

    Smeary_Subset

    I am getting a peculiar error when attempting to read an integer from a YML file I created in the code below:

    Code:
        private int numberOfSpawnpointInArena() {
            String arena = args[0];
            File arenaSpawnpointFile = new File(Main.GUNGAME_WORLDS_STORAGE_PATH + arena + "\\spawnpoints.yml");
            FileConfiguration spawnpointConfig = null;
            try {
                spawnpointConfig = YamlConfiguration.loadConfiguration(arenaSpawnpointFile);
            } catch (IllegalArgumentException e) {
                /*throws error when world hasn't been loaded yet, but makes no difference to functionality*/
            }
            return (int) spawnpointConfig.get("NumberOfSpawnpoints");
        }
    The YML file, which contains serialized locations representing spawnpoints and a NumberOfSpawnpoints entry that has an integer value representing how many spawnpoints are in the file.

    Spawnpoint:
    '0':
    ==: org.bukkit.Location
    world: mineshaft
    x: -27.0
    y: 63.0
    z: 511.0
    pitch: 0.0
    yaw: 0.0
    '1':
    ==: org.bukkit.Location
    world: mineshaft
    x: -26.0
    y: 62.0
    z: 511.0
    pitch: 0.0
    yaw: 0.0
    NumberOfSpawnpoints: 2

    I get the following error even though I have tried avoiding the issue with a try/catch statement.

    Code:
    [15:45:12 ERROR]: [org.bukkit.configuration.serialization.ConfigurationSerialization] 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:1139) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at jdk.internal.reflect.GeneratedMethodAccessor124.invoke(Unknown Source) ~[?:?]
            at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
            at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeViaMethod(ConfigurationSerialization.java:85) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserialize(ConfigurationSerialization.java:127) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.serialization.ConfigurationSerialization.deserializeObject(ConfigurationSerialization.java:207) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConstructor$ConstructCustomObject.construct(YamlConstructor.java:48) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:230) ~[snakeyaml-1.30.jar:?]
            at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:220) ~[snakeyaml-1.30.jar:?]
            at org.bukkit.configuration.file.YamlConstructor.construct(YamlConstructor.java:27) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.fromNodeTree(YamlConfiguration.java:158) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.fromNodeTree(YamlConfiguration.java:156) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:115) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:160) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:128) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:304) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at me.smearysubset.gungame.commandline.CommandChecker.numberOfSpawnpointInArena(CommandChecker.java:75) ~[GunGame.jar:?]
            at me.smearysubset.gungame.commandline.CommandChecker.arenaAllowsEnoughPlayers(CommandChecker.java:68) ~[GunGame.jar:?]
            at me.smearysubset.gungame.commandline.CommandChecker.arenaIsValid(CommandChecker.java:57) ~[GunGame.jar:?]
            at me.smearysubset.gungame.commandline.CommandChecker.argsAreValid(CommandChecker.java:38) ~[GunGame.jar:?]
            at me.smearysubset.gungame.commandline.CommandChecker.commandIsValid(CommandChecker.java:22) ~[GunGame.jar:?]
            at me.smearysubset.gungame.commandline.CLI.onCommand(CLI.java:28) ~[GunGame.jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:159) ~[paper-api-1.18.2-R0.1-SNAPSHOT.jar:?]
            at org.bukkit.craftbukkit.v1_18_R2.CraftServer.dispatchCommand(CraftServer.java:905) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.handleCommand(ServerGamePacketListenerImpl.java:2306) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2117) ~[?:?]
            at net.minecraft.server.network.ServerGamePacketListenerImpl.handleChat(ServerGamePacketListenerImpl.java:2098) ~[?:?]
            at net.minecraft.network.protocol.game.ServerboundChatPacket.handle(ServerboundChatPacket.java:46) ~[?:?]
            at net.minecraft.network.protocol.game.ServerboundChatPacket.a(ServerboundChatPacket.java:6) ~[?:?]
            at net.minecraft.network.protocol.PacketUtils.lambda$ensureRunningOnSameThread$1(PacketUtils.java:51) ~[?:?]
            at net.minecraft.server.TickTask.run(TickTask.java:18) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:153) ~[?:?]
            at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:23) ~[?:?]
            at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1399) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:188) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:126) ~[?:?]
            at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1376) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1369) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:136) ~[?:?]
            at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1347) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1229) ~[paper-1.18.2.jar:git-Paper-267]
            at net.minecraft.server.MinecraftServer.lambda$spin
    To clarify, this error does not impact the functionality of my code and it does return the value I am expecting, however it's annoying that it keeps throwing an error even when put in a try catch. Also, I don't know why but every time I run my command the error is thrown twice, not once.

    Here is something to note: It only throws the error when the world "mineshaft", as seen in the config file, has NOT been generated. But I do not see why that matters given I am extracting the integer from NumberOfSpawnpoints, not a location.
     
  2. Online

    timtower Administrator Administrator Moderator

    Because it can't make a reference to that loaded world as it does not exist.
     
  3. Offline

    Smeary_Subset

    I understand, but I don't see why it is even trying to make a reference. I am getting the path "NumberOfSpawnpoints", (thus returning an int), not the path "0", which would return the location.

    Again, more of a curiosity question.
     
  4. Online

    timtower Administrator Administrator Moderator

    It is probably loading the locations in the background already.
     
  5. Offline

    Smeary_Subset


    Interesting. Thank you.

    Solved.
     

Share This Page