Closed lucyydotp closed 3 years ago
Would System.getProperty("java.version").startsWith("11")
work?
Edit:
Full code:
@Override public void onEnable(){ if(!System.getProperty("java.version").startsWith("11")) this.getServer().getPluginManager().disablePlugin(this); }
Well, let's consider other scenarios. If we are running on Java 15 or something above Java 11, should WaterCore also run? Because if that is the case System.getProperty("java.version").startsWith("11")
will not work.
Well, in that case, it would be better to do:
@Override public void onEnable(){ try{ int ver = Integer.parseInt(System.getProperty("java.version").substring(0, 2)); if(!(ver >= 11)) this.getServer().getPluginManager().disablePlugin(this); } catch(NumberFormatException e) { this.getServer().getPluginManager().disablePlugin(this); } }
Maybe use this instead to avoid the try/catch statement.
@Override
public void onEnable() {
if (getVersion() < 11) {
getServer().getPluginManager().disablePlugin(this);
}
}
private static int getVersion() {
final String ver = System.getProperty("java.version");
if (ver.startsWith("1.")) {
ver = ver.substring(2, 3);
} else {
int dot = ver.indexOf(".");
if (dot != -1) {
ver = ver.substring(0, dot);
}
}
return Integer.parseInt(version);
}
"Throwing/Handling should normally be used for exceptional events, not normal flow control"
That works too.
anyone up for PRing this in?
Krypton depends on java 11 anyway, we don't need to check it there
Maybe use this instead to avoid the try/catch statement.
@Override public void onEnable() { if (getVersion() < 11) { getServer().getPluginManager().disablePlugin(this); } } private static int getVersion() { final String ver = System.getProperty("java.version"); if (ver.startsWith("1.")) { ver = ver.substring(2, 3); } else { int dot = ver.indexOf("."); if (dot != -1) { ver = ver.substring(0, dot); } } return Integer.parseInt(version); }
"Throwing/Handling should normally be used for exceptional events, not normal flow control"
Could you not just read up to the first dot? Seeing as we're only checking for 11+, if it starts with 1 it doesn't matter as it's too old.
final String ver = System.getProperty("java.version");
final int dotIdx = ver.indexOf('.');
return Integer.parseInt(dotIdx == -1 ? ver : ver.substring(0, dotIdx));
We can't directly use that plugin manager disable system, since we need to have it work multiplatform, so maybe this could call the plugin abstraction player's disable and that's how it disables itself?
Krypton depends on java 11 anyway, we don't need to check it there
can you read
Other platforms too. What about BungeeCord for example?
This issue is labeled "platform: bukkit", other platforms are currently not a concern.
ooooooooof. And also yeah that works too. I just used that way cause I usually log java versions lmao.
I can pr this later. Ill just add it to the main class.
WaterCore depends on Java 11, it should gracefully disable itself if it's not running on it.