Skip to content

Commit 2580437

Browse files
committed
Added a version check,
which prints a message and disables the plugin, if no suitable server version is found. Took 9 minutes
1 parent be83c79 commit 2580437

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

custom-ore-generator/src/main/java/de/derfrzocker/custom/ore/generator/CustomOreGenerator.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
import java.util.function.BiFunction;
8888
import java.util.function.Function;
8989
import java.util.function.Supplier;
90+
import java.util.logging.Level;
9091

9192
public class CustomOreGenerator extends JavaPlugin {
9293

@@ -103,11 +104,27 @@ public class CustomOreGenerator extends JavaPlugin {
103104

104105
@Override
105106
public void onLoad() {
107+
version = Version.getServerVersion(getServer());
108+
109+
// if no suitable version was found, log and return
110+
if (version == Version.UNKNOWN) {
111+
getLogger().warning("The Server version which you are running is unsupported, you are running version '" + version + "'");
112+
getLogger().warning("The plugin supports following versions " + combineVersions(Version.v1_8_R1, Version.v1_8_R2, Version.v1_8_R3,
113+
Version.v1_9_R1, Version.v1_9_R2, Version.v1_10_R1, Version.v1_11_R1, Version.v1_12_R1, Version.v1_13_R1, Version.v1_13_R2,
114+
Version.v1_14_R1, Version.v1_15_R1, Version.v1_16_R1, Version.v1_16_R2, Version.v1_16_R3));
115+
getLogger().warning("(Spigot / Paper version 1.8 - 1.16.4), if you are running such a Minecraft version, than your bukkit implementation is unsupported, in this case please contact the developer, so he can resolve this Issue");
116+
117+
if (version == Version.UNKNOWN) {
118+
getLogger().warning("The Version '" + version + "' can indicate, that you are using a newer Minecraft version than currently supported.");
119+
getLogger().warning("In this case please update to the newest version of this plugin. If this is the newest Version, than please be patient. It can take some weeks until the plugin is updated");
120+
}
121+
122+
return;
123+
}
124+
106125
messages = new CustomOreGeneratorMessages(this);
107126
permissions = new Permissions(this);
108127

109-
version = Version.getServerVersion(getServer());
110-
111128
final WorldConfigYamlDao worldConfigYamlDao = new WorldConfigYamlDao(new File(getDataFolder(), "data/world-config"));
112129
final OreConfigYamlDao oreConfigYamlDao = new OreConfigYamlDao(new File(getDataFolder(), "data/ore-config"));
113130
final CustomOreGeneratorService service = new CustomOreGeneratorServiceImpl(worldConfigYamlDao, oreConfigYamlDao, getLogger());
@@ -122,6 +139,13 @@ public void onLoad() {
122139

123140
@Override
124141
public void onEnable() {
142+
if (version == Version.UNKNOWN) {
143+
// print a stack Trace, so that the server owner can easily spot, that the plugin is not working
144+
getLogger().log(Level.WARNING, "No compatible Server version found!", new IllegalStateException("No compatible Server version found!"));
145+
getServer().getPluginManager().disablePlugin(this);
146+
return;
147+
}
148+
125149
getCommand("oregen").setExecutor(new OreGenCommand(CustomOreGeneratorServiceSupplier.INSTANCE, this, messages, permissions));
126150

127151
if (version.isNewerOrSameThan(Version.v1_14_R1)) {
@@ -319,4 +343,24 @@ public CustomOreGeneratorService get() {
319343

320344
}
321345

346+
private String combineVersions(Version... versions) {
347+
StringBuilder stringBuilder = new StringBuilder();
348+
349+
boolean first = true;
350+
351+
for (Version version : versions) {
352+
if (first) {
353+
first = false;
354+
} else {
355+
stringBuilder.append(" ");
356+
}
357+
358+
stringBuilder.append("'");
359+
stringBuilder.append(version);
360+
stringBuilder.append("'");
361+
}
362+
363+
return stringBuilder.toString();
364+
}
365+
322366
}

0 commit comments

Comments
 (0)