martinambrus/BukkitOpFix

server.properties not recognizing and error thrown

Closed this issue · 4 comments

when launching spigot with -c custom_name.properties when server.properties file does not exists, the plugin will crash with the following error.

[18:34:04 ERROR]: Error occurred while enabling BukkitOpFix v1.6 (Is it up to date?)
java.lang.NumberFormatException: For input string: ""
        at java.lang.NumberFormatException.forInputString(Unknown Source) ~[?:1.8.0_241]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_241]
        at java.lang.Integer.parseInt(Unknown Source) ~[?:1.8.0_241]
        at com.martinambrus.bukkitopfix.BukkitOpFix.onEnable(BukkitOpFix.java:66) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:265) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:347) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:410) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugin(CraftServer.java:436) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at org.bukkit.craftbukkit.v1_13_R2.CraftServer.enablePlugins(CraftServer.java:350) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at net.minecraft.server.v1_13_R2.MinecraftServer.l(MinecraftServer.java:580) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:542) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:420) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at net.minecraft.server.v1_13_R2.DedicatedServer.init(DedicatedServer.java:294) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:698) [spigot-1.13.2.jar:git-Spigot-1a3504a-e7700ab]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]

The error does not exist when the file server.properties is there but I doubt the correct server.properties being used.

Pull request welcome.

There is no easy way to actually access minecraft's command line arguments other than creating a version-specific class that will get the args[] array from the Main class.

Using a different server.properties file is quite an edge case, as it's the first time I see anyone actually using this and reporting this bug, therefore I will gladly accept any pull requests fixing this issue but won't be fixing this myself.

Unfortunately, I don't know much about Java and have never written a bukkit plugin before. I wouldn't be able to make this works anyways😞
However, I search on the Internet and find the following code.

Object port = ((DedicatedServer) MinecraftServer.getServer()).propertyManager.properties.get("server-port");

Is it somehow related? If it's related then this would be great then because it doesn't hardcode the "server.properties" file and it should work? Sorry if I was being dumb because I really don't know Java.

Thank you for the provided code. Yes, that would be the correct code to use. However, the MinecraftServer class is located in different places for each of the Minecraft version, which is what I meant by this:

There is no easy way to actually access minecraft's command line arguments other than creating a version-specific class that will get the args[] array from the Main class.

And it would need to be updated to work with every minor and major version from 1.7 upwards, including for all future releases. That's why I'm not too keen on fixing this, as the work involved does not balance out the use of this plugin by the majority of server owners who do not need to change the properties file name at all.