From 301d02c9c575766d5effcfbb1f2a7f68a43d2e2f Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Thu, 5 May 2016 17:38:57 -0700 Subject: [PATCH] Warn when not using Java 8 or greater. Note: this warning is not in the shared WorldEdit class because it doesn't get loaded as early as the individual plugin/mod implementations for some reason. --- .../worldedit/bukkit/WorldEditPlugin.java | 5 ++ .../sk89q/worldedit/util/Java8Detector.java | 46 +++++++++++++++++++ .../sk89q/worldedit/forge/ForgeWorldEdit.java | 7 ++- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/Java8Detector.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java index be6378380..4ffde3d85 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/WorldEditPlugin.java @@ -48,6 +48,8 @@ import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Polygonal2DRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; +import com.sk89q.worldedit.util.Java8Detector; + import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -117,6 +119,9 @@ public class WorldEditPlugin extends JavaPlugin implements TabCompleter { WorldEdit.getInstance().getEventBus().post(new PlatformReadyEvent()); loadAdapter(); // Need an adapter to work with special blocks with NBT data + + // Check Java version + Java8Detector.notifyIfNot8(); } private void loadConfig() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java8Detector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java8Detector.java new file mode 100644 index 000000000..74510840e --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Java8Detector.java @@ -0,0 +1,46 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ +package com.sk89q.worldedit.util; + +import com.google.common.base.Joiner; +import com.sk89q.worldedit.WorldEdit; + +public final class Java8Detector { + + public static void notifyIfNot8() { + String[] ver = System.getProperty("java.version").split("\\."); + int major = Integer.parseInt(ver[1]); + if (major <= 7) { + // Implicitly java 7 because we compile against 7, so this won't + // even launch on 6. + WorldEdit.logger + .warning("WorldEdit has detected you are using Java 7" + + " (based on detected version " + + Joiner.on('.').join(ver) + ")."); + WorldEdit.logger.warning( + "WorldEdit will stop supporting Java less than version 8 in the future," + + " due to Java 7 being EOL since April 2015." + + " Please update your server to Java 8."); + } + } + + private Java8Detector() { + } + +} diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java index 009e1cf13..8f459b2e2 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorldEdit.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.forge; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.common.FMLCommonHandler; import org.apache.logging.log4j.Logger; import com.google.common.base.Joiner; @@ -31,6 +29,7 @@ import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.internal.LocalWorldAdapter; +import com.sk89q.worldedit.util.Java8Detector; import java.io.File; import java.util.Map; @@ -62,6 +61,10 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @Mod(modid = ForgeWorldEdit.MOD_ID, name = "WorldEdit", version = "%VERSION%", acceptableRemoteVersions = "*") public class ForgeWorldEdit { + + static { + Java8Detector.notifyIfNot8(); + } public static Logger logger; public static final String MOD_ID = "worldedit";