1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Encourage Java 16 on older versions

This commit is contained in:
TheBusyBiscuit 2021-06-17 10:53:38 +02:00
parent 80608b1e08
commit 7fcb605d4d
5 changed files with 67 additions and 28 deletions

View File

@ -14,6 +14,7 @@ import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.papermc.lib.PaperLib;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
@ -103,18 +104,7 @@ class VersionsCommand extends SubCommand {
}
private void addJavaVersion(@Nonnull ComponentBuilder builder) {
String javaVer = System.getProperty("java.version");
if (javaVer.startsWith("1.")) {
javaVer = javaVer.substring(2);
}
// If it's like 11.0.1.3 or 8.0_275
if (javaVer.indexOf('.') != -1) {
javaVer = javaVer.substring(0, javaVer.indexOf('.'));
}
int version = Integer.parseInt(javaVer);
int version = NumberUtils.getJavaVersion();
if (version < RECOMMENDED_JAVA_VERSION) {
// @formatter:off

View File

@ -118,6 +118,7 @@ import io.github.thebusybiscuit.slimefun4.integrations.IntegrationsManager;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
import io.github.thebusybiscuit.slimefun4.utils.tags.SlimefunTag;
import io.papermc.lib.PaperLib;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.MenuListener;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
@ -247,31 +248,37 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
*/
private void onPluginStart() {
long timestamp = System.nanoTime();
Logger logger = getLogger();
// Check if Paper (<3) is installed
if (PaperLib.isPaper()) {
getLogger().log(Level.INFO, "Paper was detected! Performance optimizations have been applied.");
logger.log(Level.INFO, "Paper was detected! Performance optimizations have been applied.");
} else {
PaperLib.suggestPaper(this);
}
// Check if CS-CoreLib is installed (it is no longer needed)
if (getServer().getPluginManager().getPlugin("CS-CoreLib") != null) {
StartupWarnings.discourageCSCoreLib(getLogger());
StartupWarnings.discourageCSCoreLib(logger);
}
// Encourage Java 16
if (NumberUtils.getJavaVersion() < 16) {
StartupWarnings.oldJavaVersion(logger);
}
// If the server has no "data-storage" folder, it's _probably_ a new install. So mark it for metrics.
isNewlyInstalled = !new File("data-storage/Slimefun").exists();
// Creating all necessary Folders
getLogger().log(Level.INFO, "Creating directories...");
logger.log(Level.INFO, "Creating directories...");
createDirectories();
// Load various config settings into our cache
registry.load(this, config);
// Set up localization
getLogger().log(Level.INFO, "Loading language files...");
logger.log(Level.INFO, "Loading language files...");
String chatPrefix = config.getString("options.chat-prefix");
String serverDefaultLanguage = config.getString("options.language");
local = new LocalizationService(this, chatPrefix, serverDefaultLanguage);
@ -280,7 +287,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// Make sure that the network size is a valid input
if (networkSize < 1) {
getLogger().log(Level.WARNING, "Your 'networks.max-size' setting is misconfigured! It must be at least 1, it was set to: {0}", networkSize);
logger.log(Level.WARNING, "Your 'networks.max-size' setting is misconfigured! It must be at least 1, it was set to: {0}", networkSize);
networkSize = 1;
}
@ -291,29 +298,29 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// Starting the Auto-Updater
if (config.getBoolean("options.auto-update")) {
getLogger().log(Level.INFO, "Starting Auto-Updater...");
logger.log(Level.INFO, "Starting Auto-Updater...");
updaterService.start();
} else {
updaterService.disable();
}
// Registering all GEO Resources
getLogger().log(Level.INFO, "Loading GEO-Resources...");
logger.log(Level.INFO, "Loading GEO-Resources...");
GEOResourcesSetup.setup();
getLogger().log(Level.INFO, "Loading Tags...");
logger.log(Level.INFO, "Loading Tags...");
loadTags();
getLogger().log(Level.INFO, "Loading items...");
logger.log(Level.INFO, "Loading items...");
loadItems();
getLogger().log(Level.INFO, "Loading researches...");
logger.log(Level.INFO, "Loading researches...");
loadResearches();
registry.setResearchingEnabled(getResearchCfg().getBoolean("enable-researching"));
PostSetup.setupWiki();
getLogger().log(Level.INFO, "Registering listeners...");
logger.log(Level.INFO, "Registering listeners...");
registerListeners();
// Initiating various Stuff and all items with a slight delay (0ms after the Server finished loading)
@ -325,7 +332,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
try {
recipeService.refresh();
} catch (Exception | LinkageError x) {
getLogger().log(Level.SEVERE, x, () -> "An Exception occurred while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")");
logger.log(Level.SEVERE, x, () -> "An Exception occurred while iterating through the Recipe list on Minecraft Version " + minecraftVersion.getName() + " (Slimefun v" + getVersion() + ")");
}
}), 0);
@ -334,7 +341,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
try {
command.register();
} catch (Exception | LinkageError x) {
getLogger().log(Level.SEVERE, "An Exception occurred while registering the /slimefun command", x);
logger.log(Level.SEVERE, "An Exception occurred while registering the /slimefun command", x);
}
// Armor Update Task
@ -349,12 +356,12 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
ticker.start(this);
// Loading integrations
getLogger().log(Level.INFO, "Loading Third-Party plugin integrations...");
logger.log(Level.INFO, "Loading Third-Party plugin integrations...");
integrations.start();
gitHubService.start(this);
// Hooray!
getLogger().log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
logger.log(Level.INFO, "Slimefun has finished loading in {0}", getStartupTime(timestamp));
}
@Override

View File

@ -5,6 +5,8 @@ import java.util.logging.Logger;
import javax.annotation.ParametersAreNonnullByDefault;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
/**
* This class stores some startup warnings we occasionally need to print.
* If you setup your server the recommended way, you are never going to see
@ -56,4 +58,20 @@ final class StartupWarnings {
logger.log(Level.SEVERE, BORDER);
}
@ParametersAreNonnullByDefault
static void oldJavaVersion(Logger logger) {
int javaVersion = NumberUtils.getJavaVersion();
logger.log(Level.SEVERE, BORDER);
logger.log(Level.SEVERE, PREFIX + "Your Java version (Java {0}) is out of date.", javaVersion);
logger.log(Level.SEVERE, PREFIX);
logger.log(Level.SEVERE, PREFIX + "We recommend you to update to Java 16.");
logger.log(Level.SEVERE, PREFIX + "Java 16 is required as of Minecraft 1.17 and");
logger.log(Level.SEVERE, PREFIX + "we would like to utilise all the new features");
logger.log(Level.SEVERE, PREFIX + "that come with it as soon as possible.");
logger.log(Level.SEVERE, PREFIX + "Slimefun will also require Java 16 in");
logger.log(Level.SEVERE, PREFIX + "the foreseeable future, so please update!");
logger.log(Level.SEVERE, BORDER);
}
}

View File

@ -7,6 +7,7 @@ import java.util.Set;
import java.util.function.Predicate;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
@ -129,7 +130,7 @@ public class ProduceCollector extends AContainer implements RecipeDisplayItem {
}
@Override
protected @Nonnull MachineRecipe findNextRecipe(@Nonnull BlockMenu inv) {
protected @Nullable MachineRecipe findNextRecipe(@Nonnull BlockMenu inv) {
for (int slot : getInputSlots()) {
for (AnimalProduce produce : animalProduces) {
ItemStack item = inv.getItemInSlot(slot);

View File

@ -6,6 +6,7 @@ import java.text.NumberFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Locale;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -13,6 +14,8 @@ import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
/**
* This class contains various utilities related to numbers and number formatting.
*
@ -257,4 +260,24 @@ public final class NumberUtils {
return value;
}
}
public static int getJavaVersion() {
String javaVer = System.getProperty("java.version");
if (javaVer.startsWith("1.")) {
javaVer = javaVer.substring(2);
}
// If it's like 11.0.1.3 or 8.0_275
if (javaVer.indexOf('.') != -1) {
javaVer = javaVer.substring(0, javaVer.indexOf('.'));
}
if (PatternUtils.NUMERIC.matcher(javaVer).matches()) {
return Integer.parseInt(javaVer);
} else {
SlimefunPlugin.logger().log(Level.SEVERE, "Error: Cannot identify Java version - {0}", javaVer);
return 0;
}
}
}