This commit is contained in:
parent
47a9d6454f
commit
94e674658f
@ -1,5 +1,8 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.0.5**
|
||||||
|
* Allow Forcing Preview Features With ``freshcoffee:preview_features_required``
|
||||||
|
|
||||||
**1.0.4**
|
**1.0.4**
|
||||||
* Replace Reflection With New Fabric Loader API
|
* Replace Reflection With New Fabric Loader API
|
||||||
* Enable Java Preview Features
|
* Enable Java Preview Features
|
||||||
|
@ -36,3 +36,12 @@ You can set a maximum version of Java by adding this to ``fabric.mod.json``:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can also force Java preview features:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"custom": {
|
||||||
|
"freshcoffee:preview_features_required": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_loader_version = 0.10.3+build.211
|
fabric_loader_version = 0.10.3+build.211
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.0.4
|
mod_version = 1.0.5
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -4,6 +4,7 @@ import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
|||||||
import com.thebrokenrail.freshcoffee.dialog.Dialog;
|
import com.thebrokenrail.freshcoffee.dialog.Dialog;
|
||||||
import com.thebrokenrail.freshcoffee.download.AdoptOpenJDK;
|
import com.thebrokenrail.freshcoffee.download.AdoptOpenJDK;
|
||||||
import com.thebrokenrail.freshcoffee.util.PlatformUtil;
|
import com.thebrokenrail.freshcoffee.util.PlatformUtil;
|
||||||
|
import com.thebrokenrail.freshcoffee.util.PreviewUtil;
|
||||||
import com.thebrokenrail.freshcoffee.util.ReLaunchUtil;
|
import com.thebrokenrail.freshcoffee.util.ReLaunchUtil;
|
||||||
import com.thebrokenrail.freshcoffee.util.Util;
|
import com.thebrokenrail.freshcoffee.util.Util;
|
||||||
import com.thebrokenrail.freshcoffee.util.ExtractUtil;
|
import com.thebrokenrail.freshcoffee.util.ExtractUtil;
|
||||||
@ -17,7 +18,7 @@ import java.net.URL;
|
|||||||
public class FreshCoffee implements PreLaunchEntrypoint {
|
public class FreshCoffee implements PreLaunchEntrypoint {
|
||||||
@Override
|
@Override
|
||||||
public void onPreLaunch() {
|
public void onPreLaunch() {
|
||||||
if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue()) {
|
if (Util.JAVA_VERSION < LimitUtil.getMinimumJavaVersion().getValue() || Util.JAVA_VERSION > LimitUtil.getMaximumJavaVersion().getValue() || (PreviewUtil.arePreviewFeaturesRequired() && !PreviewUtil.arePreviewFeaturesEnabled())) {
|
||||||
if (LimitUtil.getMinimumJavaVersion().getValue() > LimitUtil.getMaximumJavaVersion().getValue()) {
|
if (LimitUtil.getMinimumJavaVersion().getValue() > LimitUtil.getMaximumJavaVersion().getValue()) {
|
||||||
Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.MINIMUM_HIGHER_THAN_MAXIMUM_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), LimitUtil.getMaximumJavaVersion().toString()));
|
Dialog.getInstance().showErrorDialog(String.format(HardcodedConfig.MINIMUM_HIGHER_THAN_MAXIMUM_MESSAGE, LimitUtil.getMinimumJavaVersion().toString(), LimitUtil.getMaximumJavaVersion().toString()));
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -5,6 +5,7 @@ import java.io.File;
|
|||||||
public final class HardcodedConfig {
|
public final class HardcodedConfig {
|
||||||
public static final String MINIMUM_JSON_KEY = "freshcoffee:minimum_java_version";
|
public static final String MINIMUM_JSON_KEY = "freshcoffee:minimum_java_version";
|
||||||
public static final String MAXIMUM_JSON_KEY = "freshcoffee:maximum_java_version";
|
public static final String MAXIMUM_JSON_KEY = "freshcoffee:maximum_java_version";
|
||||||
|
public static final String PREVIEW_JSON_KEY = "freshcoffee:preview_features_required";
|
||||||
|
|
||||||
public static final String TITLE = "FreshCoffee";
|
public static final String TITLE = "FreshCoffee";
|
||||||
|
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.thebrokenrail.freshcoffee.util;
|
||||||
|
|
||||||
|
import com.thebrokenrail.freshcoffee.config.HardcodedConfig;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||||
|
|
||||||
|
import java.lang.management.ManagementFactory;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class PreviewUtil {
|
||||||
|
public static boolean arePreviewFeaturesRequired() {
|
||||||
|
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
||||||
|
ModMetadata metadata = mod.getMetadata();
|
||||||
|
if (metadata.containsCustomValue(HardcodedConfig.PREVIEW_JSON_KEY)) {
|
||||||
|
try {
|
||||||
|
boolean newValue = metadata.getCustomValue(HardcodedConfig.PREVIEW_JSON_KEY).getAsBoolean();
|
||||||
|
if (newValue) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
Util.getLogger().error("Invalid Value For Preview Features: " + metadata.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean arePreviewFeaturesEnabled() {
|
||||||
|
List<String> vmArgs = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
||||||
|
return vmArgs.contains("--enable-preview");
|
||||||
|
}
|
||||||
|
}
|
@ -58,8 +58,12 @@ public final class ReLaunchUtil {
|
|||||||
// Remove Debugger
|
// Remove Debugger
|
||||||
vmArgs.removeIf(arg -> arg.startsWith("-agentlib") || arg.startsWith("-javaagent"));
|
vmArgs.removeIf(arg -> arg.startsWith("-agentlib") || arg.startsWith("-javaagent"));
|
||||||
// Enable Java Preview Features
|
// Enable Java Preview Features
|
||||||
if (!vmArgs.contains("--enable-preview")) {
|
if (PreviewUtil.arePreviewFeaturesRequired()) {
|
||||||
vmArgs.add("--enable-preview");
|
if (!vmArgs.contains("--enable-preview")) {
|
||||||
|
vmArgs.add("--enable-preview");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vmArgs.remove("--enable-preview");
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> mainArgs = getMainArgs();
|
List<String> mainArgs = getMainArgs();
|
||||||
|
Reference in New Issue
Block a user